📄 keyview.c
字号:
}
if( err == kPGPError_EndOfIteration )
err = 0;
if(showFingerprints)
pgpShowKeyFingerprint( filebPtr, key );
return err;
}
static void pgpGetSigStatusChar( PGPSigRef sig, char *prop )
{
PGPError err;
PGPBoolean boo;
/**prop = ' ';*/
/* return based on some state ??*/
err = PGPGetSigBoolean( sig, kPGPSigPropIsTried, &boo );
pgpAssertNoErr(err);
if(boo) {
err = PGPGetSigBoolean( sig, kPGPSigPropIsVerified, &boo );
pgpAssertNoErr(err);
if(boo)
*prop = '!';
else
*prop = '*';
err = PGPGetSigBoolean( sig, kPGPSigPropIsNotCorrupt, &boo );
pgpAssertNoErr(err);
if(!boo)
*prop = '%';
} else
*prop = '?';
}
PGPError pgpShowKeySig( struct pgpfileBones *filebPtr, PGPKeySetRef
keyringset, PGPSigRef sig, PGPFlags showFlags )
{
struct pgpenvBones *envbPtr = filebPtr->envbPtr;
PGPError err;
PGPKeyRef skey;
PGPKeyID kid;
char kstr[kPGPMaxKeyIDStringSize];
PGPUserIDRef userid;
char useridstr[ kPGPMaxUserIDSize ];
char prop = ' ';
PGPSize actual;
PGPBoolean compatible = envbPtr->compatible;
/* print the certifier...*/
err = PGPGetSigCertifierKey( sig, keyringset, &skey );
if( IsntPGPError(err) ) {
err = PGPGetKeyIDFromKey( skey, &kid );
pgpAssertNoErr(err);
err = PGPGetPrimaryUserID( skey, &userid);
pgpAssertNoErr(err);
err = PGPGetUserIDStringBuffer( userid, kPGPUserIDPropName,
256, useridstr, &actual );
pgpAssertNoErr(err);
} else {
err = PGPGetKeyIDOfCertifier( sig, &kid );
pgpAssertNoErr(err);
strcpy(useridstr, LANG("(Unknown signator, can't be checked)"));
}
err = pgpGetKeyIDStringCompat( &kid, TRUE, compatible, kstr );
pgpAssertNoErr(err);
if( showFlags & kShow_Checks )
pgpGetSigStatusChar( sig, &prop );
if( !compatible )
fprintf( filebPtr->pgpout, "%s%c %s %s\n",
"sig", prop, kstr, useridstr );
else
fprintf( filebPtr->pgpout, "%s%c %s %s\n",
"sig", prop, kstr, useridstr );
return err;
}
PGPError pgpShowKeyFingerprint( struct pgpfileBones *filebPtr,
PGPKeyRef key )
{
PGPError err;
PGPSize actual;
char h1[30], h2[30], h3[15];
unsigned char fp[20];
err = PGPGetKeyPropertyBuffer ( key, kPGPKeyPropFingerprint, 20,
&fp, &actual);
pgpAssertNoErr(err);
sprintf( h1, " %02x %02x %02x %02x %02x %02x %02x %02x",
fp[0],fp[1],fp[2],fp[3],fp[4],fp[5],fp[6],fp[7] );
strupr( h1 );
sprintf( h2, " %02x %02x %02x %02x %02x %02x %02x %02x",
fp[8],fp[9],fp[10],fp[11],fp[12],fp[13],fp[14],fp[15]);
strupr( h2 );
if(actual > 16) {
sprintf( h3, " %02x %02x %02x %02x",fp[16],fp[17],fp[18],fp[19] );
strupr( h3 );
} else
h3[0] = '\0';
fprintf( filebPtr->pgpout,
LANG(" Key fingerprint =%s%s%s\n"), h1, h2, h3 );
return err;
}
/* show the key properties, but not the userid's yet. */
PGPError pgpShowKeyPropertiesListFormat( struct pgpfileBones *filebPtr,
PGPKeyRef key, PGPKeyIterRef iterContext, char *kstr, char schar,
PGPFlags showFlags )
{
struct pgpenvBones *envbPtr = filebPtr->envbPtr;
PGPBoolean compatible = envbPtr->compatible;
PGPTime creation;
PGPUInt32 numbits,subbits,algorithm;
PGPError err;
PGPUInt16 yyyy, mm, dd;
PGPBoolean isSecret,isRevoked;
PGPSize keyIDLength,bitsLength;
PGPBoolean tab=FALSE;
keyIDLength = (compatible ? 8 : 10);
bitsLength = (compatible ? 4 : 9);
err = PGPGetKeyNumber(key, kPGPKeyPropAlgID, &algorithm);
pgpAssertNoErr(err);
err = PGPGetKeyBoolean( key, kPGPKeyPropIsSecret, &isSecret);
pgpAssertNoErr(err);
/* what number of bits?*/
err = PGPGetKeyNumber( key, kPGPKeyPropBits, &numbits );
pgpAssertNoErr(err);
/* when was it created?*/
err = PGPGetKeyTime ( key, kPGPKeyPropCreation, &creation );
pgpAssertNoErr(err);
PGPGetYMDFromPGPTime( creation, &yyyy, &mm, &dd);
/* now what about the subkey(s)?*/
subbits=0;
if( (showFlags & kShow_Subkeys) && !compatible) {
char bitsstr[20];
char *algstr;
PGPBoolean isexp;
/* Enumerate all subkeys. NOTE, do not expose the subkey ID
because the rules for selecting what subkey to use are complex
and governed by the user's cipher preferences, expiration,
validity, etc. so that if the user tries to specify what
subkey to use, she may not get what she's asking for. */
algstr = (char *)pgpPKAlgIDString( algorithm );
sprintf( bitsstr, "%4d",numbits);
fprintf( filebPtr->pgpout, "%3s%c %-9s %10s %4d/%02d/%02d ",
algstr, schar, bitsstr, kstr, yyyy, mm, dd );
/* what is the status? */
err = PGPGetKeyBoolean( key, kPGPKeyPropIsRevoked, &isRevoked );
pgpAssertNoErr(err);
if( isRevoked ) {
fprintf( filebPtr->pgpout, LANG("*** KEY REVOKED ***"));
/*"\n %-*s %-*s "),bitsLength,"",keyIDLength,"" );*/
tab=TRUE;
}
PGPGetKeyBoolean( key, kPGPKeyPropIsExpired, &isexp );
if(isexp) {
fprintf( filebPtr->pgpout, LANG("*** KEY EXPIRED ***"));
/*"\n %-*s %-*s "),bitsLength,"",keyIDLength,"" );*/
tab=TRUE;
} else {
PGPTime expyTime;
err = PGPGetKeyTime( key, kPGPKeyPropExpiration, &expyTime);
pgpAssertNoErr(err);
if(expyTime != kPGPExpirationTime_Never) {
PGPGetYMDFromPGPTime( expyTime, &yyyy, &mm, &dd);
fprintf( filebPtr->pgpout, LANG("expires %4d/%02d/%02d"),
yyyy, mm, dd);
tab=TRUE;
}
}
/* what number of bits for the subkey(s)?...*/
/*if( algorithm == kPGPPublicKeyAlgorithm_DSA )*/
{
PGPSubKeyRef subKey;
PGPKeyIterSeek(iterContext, key);
err = PGPKeyIterNextSubKey(iterContext, &subKey);
while( IsntPGPError( err ) )
{
err = PGPGetSubKeyNumber(subKey, kPGPKeyPropBits, &subbits);
pgpAssertNoErr(err);
sprintf( bitsstr, "%4d",subbits);
err = PGPGetSubKeyNumber(subKey, kPGPKeyPropAlgID,
&algorithm);
pgpAssertNoErr(err);
algstr = (char *)pgpPKAlgIDString( algorithm );
/* when was it created?*/
err = PGPGetSubKeyTime ( subKey, kPGPKeyPropCreation,
&creation );
pgpAssertNoErr(err);
PGPGetYMDFromPGPTime( creation, &yyyy, &mm, &dd);
tab=FALSE;
fprintf( filebPtr->pgpout, "\n%3s %-*s %-*s %4d/%02d/%02d ",
algstr, bitsLength, bitsstr, keyIDLength, kstr,
yyyy, mm, dd );
/* what is the status? */
err = PGPGetSubKeyBoolean( subKey, kPGPKeyPropIsRevoked,
&isRevoked );
pgpAssertNoErr(err);
if( isRevoked ) {
fprintf( filebPtr->pgpout, LANG("*** KEY REVOKED ***"));
tab=TRUE;
}
PGPGetSubKeyBoolean( subKey, kPGPKeyPropIsExpired, &isexp );
if(isexp) {
fprintf( filebPtr->pgpout, LANG("*** KEY EXPIRED ***"));
tab=TRUE;
} else {
PGPTime expyTime;
err = PGPGetSubKeyTime( subKey, kPGPKeyPropExpiration,
&expyTime);
pgpAssertNoErr(err);
if(expyTime != kPGPExpirationTime_Never) {
PGPGetYMDFromPGPTime( expyTime, &yyyy, &mm, &dd);
fprintf( filebPtr->pgpout,
LANG("expires %4d/%02d/%02d"), yyyy, mm, dd);
tab=TRUE;
}
}
err = PGPKeyIterNextSubKey(iterContext, &subKey);
}
}
} else {
/* what number of bits for the subkey(s)?... show the first one
only.*/
/*if( algorithm == kPGPPublicKeyAlgorithm_DSA ) not just DSA, uknow*/
{
PGPSubKeyRef subKey;
PGPKeyIterSeek(iterContext, key);
err = PGPKeyIterNextSubKey(iterContext, &subKey);
if( IsntPGPError( err ) )
{
err = PGPGetSubKeyNumber(subKey, kPGPKeyPropBits, &subbits);
pgpAssertNoErr(err);
}
}
if(!compatible) {
char bitsstr[20];
const char *algstr = pgpPKAlgIDString( algorithm );
if( subbits > 0 )
sprintf( bitsstr, "%4d/%d",subbits,numbits);
else
sprintf( bitsstr, "%4d",numbits);
fprintf( filebPtr->pgpout, "%3s%c %-9s %10s %4d/%02d/%02d ",
algstr, schar, bitsstr, kstr, yyyy, mm, dd );
} else
fprintf( filebPtr->pgpout, "%3s%c %4d/%8s %4d/%02d/%02d ",
isSecret ? "sec" : "pub", schar, numbits, kstr,
yyyy, mm, dd );
/* what is the status? */
err = PGPGetKeyBoolean( key, kPGPKeyPropIsRevoked, &isRevoked );
pgpAssertNoErr(err);
if( isRevoked ) {
fprintf( filebPtr->pgpout, LANG("*** KEY REVOKED ***"
" %-*s %-*s "),
bitsLength,"",keyIDLength,"" );
tab=TRUE;
}
if(!compatible)
{
PGPTime expyTime;
PGPBoolean isexp;
PGPGetKeyBoolean( key, kPGPKeyPropIsExpired, &isexp );
if(isexp) {
fprintf( filebPtr->pgpout, LANG("*** KEY EXPIRED ***"
" %-*s %-*s "),
bitsLength,"",keyIDLength,"" );
tab=TRUE;
} else {
err = PGPGetKeyTime( key, kPGPKeyPropExpiration, &expyTime);
pgpAssertNoErr(err);
if(expyTime != kPGPExpirationTime_Never) {
PGPGetYMDFromPGPTime( expyTime, &yyyy, &mm, &dd);
fprintf( filebPtr->pgpout, LANG("expires %4d/%02d/%02d"
" %-*s %-*s "), yyyy, mm, dd,
bitsLength,"",keyIDLength,"" );
tab=TRUE;
}
}
}
}
if(tab)
fprintf( filebPtr->pgpout, "\n %-*s %-*s ",
bitsLength,"",keyIDLength,"" );
if(err == kPGPError_EndOfIteration)
err = kPGPError_NoErr;
return err;
}
PGPError pgpShowKeyListFormat( struct pgpfileBones *filebPtr, PGPKeySetRef
keyringset, PGPKeyIterRef iterContext, PGPKeyRef key, PGPFlags
showFlags )
{
struct pgpenvBones *envbPtr = filebPtr->envbPtr;
PGPBoolean isSecret;
char kstr[kPGPMaxKeyIDStringSize];
PGPUserIDRef userid;
char useridstr[ kPGPMaxUserIDSize ];
PGPSize actual;
PGPError err;
PGPBoolean compatible = envbPtr->compatible;
char schar;
PGPSize keyIDLength,bitsLength;
/* used to display default signing key */
static PGPKeyRef defaultKey = kPGPInvalidRef;
static PGPBoolean bNoDefaultKey = FALSE;
keyIDLength = (compatible ? 8 : 10);
bitsLength = (compatible ? 4 : 9);
/* get the key properties*/
/* is this a public or secret key?*/
err = PGPGetKeyBoolean( key, kPGPKeyPropIsSecret, &isSecret);
pgpAssertNoErr(err);
err = pgpGetKeyIDStringCompatFromKey( key, TRUE, compatible, kstr );
pgpAssertNoErr(err);
schar = ' ';
{ /* print if key format is corrupted*/
PGPBoolean isok;
PGPGetKeyBoolean( key, kPGPKeyPropIsNotCorrupt, &isok );
if( !isok )
schar='?';
}
{ /* print if it is disabled*/
PGPBoolean isdis;
PGPGetKeyBoolean( key, kPGPKeyPropIsDisabled, &isdis );
if( isdis )
schar='@';
}
err = pgpShowKeyPropertiesListFormat( filebPtr, key, iterContext,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -