📄 pgpkui.c
字号:
char keyid[8];
size_t keyidlen = sizeof (keyid);
pgpGetKeyNumber (key, kPGPKeyPropBits, &keybits);
SpecifiedOutputString(DisplayHeaders,
OutputType,
0,
"%6u bits, Key ID ",
(unsigned) keybits);
pgpGetKeyString (key, kPGPKeyPropKeyId, keyid, &keyidlen);
kdbTtyPutKeyID(FALSE, OutputType, keyid);
pgpGetKeyTime (key, kPGPKeyPropCreation, &tstamp);
if (tstamp) {
pgpDateString((word32) tstamp, buf);
SpecifiedOutputString(FALSE, OutputType, 0, ", created %s\n", buf);
}
else
SpecifiedOutputString(FALSE, OutputType, 0, "\n");
#if 0
if (trust & PGP_KEYTRUSTF_REVOKED)
fprintf(f, "%sThis key has been revoked by its owner\n",
prefix);
#endif
}
void
kdbKeyPrint(PgpOutputType OutputType, PGPKeyIter *keyiter, int level)
{
char name[256];
PGPKey *key = pgpKeyIterKey (keyiter);
PGPKeyIter *iter = NULL;
PGPUserID *userid = NULL;
size_t len;
kdbTtyPutKeyInfo(TRUE, OutputType, key);
iter = pgpCopyKeyIter (keyiter);
pgpKeyIterSet (iter, key);
while ((userid = pgpKeyIterNextUserID (iter))) {
len = sizeof (name);
pgpGetUserIDString (userid, kPGPUserIDPropName, name, &len);
SpecifiedOutputString(TRUE, OutputType, 0, "%*s", level+2, "");
(void) kdbTtyPutString(name,
len,
-1u,
FALSE,
OutputType,
'"',
'"');
SpecifiedOutputString(FALSE, OutputType, 0, "\n");
/* break; */
}
pgpFreeKeyIter (iter);
}
/* Functions for displaying keys */
static const int name_indent = 30;
static const int sig_indent = 32;
/* List of algorithms indexed by the pkalg byte. Each entry contains
the name of the algorithm and what it can be used for. */
static const char *pkalg_list[] =
{NULL, "RSA", "RSA", "RSA", NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, "Diffie-Hellman", "DSS"};
static const char *
getKeyAlg (PGPKey *key)
{
long pkalg;
pgpGetKeyNumber (key, kPGPKeyPropAlgId, &pkalg);
return pkalg_list[pkalg];
}
static const char *
getSubKeyAlg (PGPSubKey *subkey)
{
(void)subkey;
return pkalg_list[16];
}
static const char *keyuse_list[] =
{"", "Sign only", "Encrypt only", "Sign and Encrypt"};
static const char *
getKeyUse (PGPKey *key)
{
Boolean cansign, canencrypt;
pgpGetKeyBoolean (key, kPGPKeyPropCanSign, &cansign);
pgpGetKeyBoolean (key, kPGPKeyPropCanEncrypt, &canencrypt);
if (cansign && canencrypt)
return keyuse_list[3];
else if (cansign)
return keyuse_list[1];
else if (canencrypt)
return keyuse_list[2];
return keyuse_list[0];
}
static const char *
getSubKeyUse (PGPSubKey *subkey)
{
(void)subkey;
return keyuse_list[0];
}
/* List of algorithms indexed by the pkalg byte. Each entry contains
the name of the algorithm and what it can be used for. */
static char statement[11];
static char *
getTrustStatement (word16 trust)
{
int d = trust - PGP_TRUST_DECADE - PGP_TRUST_OCTAVE;
int i;
unsigned long l;
int wid = 9;
char number[10];
if (trust == PGP_TRUST_INFINITE)
strcpy (statement, " maximum ");
else if (trust == 0)
strcpy (statement, " none ");
else {
/*
* Note: The following was taken from Colin's
* prettyprint routine.
*/
d -= d % PGP_TRUST_DECADE;
i = d / PGP_TRUST_DECADE;
l = ringTrustToInt(trust - d);
if (i)
wid -= sprintf(number, "%lu%0*u ", l, i, 0);
else
wid -= sprintf(number, "%lu ", l);
sprintf (statement, "%*s%s", wid, "", number);
}
return statement;
}
/* This function displays a single signature. */
int
kdbTtyShowSig(PgpOutputType OutputType,
PGPKeyIter *sigiter,
PGPKeySet *allkeys,
int check)
{
PGPKey *sigkey = NULL;
PGPCert *sig = pgpKeyIterCert (sigiter);
PGPTime creation;
char datestring[11];
char namestring[256];
size_t len;
Boolean revoked = FALSE, valid, checked, tried, mycert;
pgpGetCertifier (sig, allkeys, &sigkey);
if(sigkey)
pgpIncKeyRefCount(sigkey);
pgpGetCertBoolean (sig, kPGPCertPropIsRevoked, &revoked);
if (revoked)
SpecifiedOutputString(TRUE, OutputType, 0, "ret");
else {
pgpGetCertBoolean (sig, kPGPCertPropIsMyCert, &mycert);
if (mycert)
SpecifiedOutputString(TRUE, OutputType, 0, "SIG");
else
SpecifiedOutputString(TRUE, OutputType, 0, "sig");
}
pgpGetCertBoolean (sig, kPGPCertPropIsValid, &valid);
if (!valid)
SpecifiedOutputString(FALSE, OutputType, 0, "%");
else if (!sigkey)
SpecifiedOutputString(FALSE, OutputType, 0, "?");
else {
pgpGetCertBoolean (sig, kPGPCertPropIsChecked, &checked);
if (check && checked)
SpecifiedOutputString(FALSE, OutputType, 0, "!");
else {
pgpGetCertBoolean (sig, kPGPCertPropIsTried, &tried);
if (check && tried)
SpecifiedOutputString(FALSE, OutputType, 0, "*");
else
SpecifiedOutputString(FALSE, OutputType, 0, " ");
}
}
SpecifiedOutputString(FALSE, OutputType, 0, " ");
kdbTtyPutSigID (FALSE, OUTPUT_PRIMARY, sig);
SpecifiedOutputString(FALSE, OutputType, 0, " ");
/* Signature date */
pgpGetCertTime (sig, kPGPCertPropCreation, &creation);
if (creation > 0) {
pgpDateString ((word32 )creation, datestring);
SpecifiedOutputString(FALSE, OutputType, 0, datestring);
}
else
SpecifiedOutputString(FALSE, OutputType, 0, "----------");
if (sigkey) {
len = sizeof (namestring);
pgpGetPrimaryUserIDName (sigkey, namestring, &len);
SpecifiedOutputString(FALSE, OutputType, 0, " ");
kdbTtyPutString (namestring,
len,
(unsigned) len,
FALSE,
OutputType,
0,
0);
SpecifiedOutputString(FALSE, OutputType, 0, "\n");
pgpFreeKey (sigkey);
}
else
SpecifiedOutputString(FALSE,
OutputType,
0,
" (Unknown signator, can't be checked)\n");
return 0;
}
/* This function displays a set of signatures attached to a name. */
int
kdbTtyShowSigs (PgpOutputType OutputType,
PGPKeyIter *iter,
PGPKeySet *allkeys,
int mode)
{
PGPCert *sig = NULL;
int check;
pgpAssert (iter != NULL);
pgpAssert (allkeys != NULL);
check = (mode == 3 || mode == 4);
/* Display sigs attached to the Name */
while ((sig = pgpKeyIterNextUIDCert (iter))) {
kdbTtyShowSig(OutputType, iter, allkeys, check);
}
return 0;
}
int
kdbTtyCheckSigs (PgpOutputType OutputType,
PGPKeyIter *iter,
PGPKeySet *allkeys,
int mode)
{
PGPKey *sigkey = NULL;
PGPCert *sig = NULL;
size_t len;
char const *output;
char namestring[256];
long sigtrust, validity;
long confidence;
Boolean revoked;
PgpTrustModel pgptrustmodel;
pgpAssert (iter != NULL);
pgpAssert (mode == 4 || mode == 5);
pgptrustmodel = pgpGetTrustModel ();
/* Display sigs attached to the Name */
while ((sig = pgpKeyIterNextUIDCert (iter))) {
pgpGetCertifier (sig, allkeys, &sigkey);
if (sigkey)
pgpIncKeyRefCount (sigkey);
SpecifiedOutputString(TRUE, OutputType, 0, "%*s", 11, "");
if (pgptrustmodel == PGPTRUST0) {
if (!sigkey || sigkey ==
pgpKeyIterKey (iter))
sigtrust = PGP_SIGTRUST_NOKEY;
else {
pgpGetCertBoolean (sig, kPGPCertPropIsRevoked, &revoked);
if (revoked)
sigtrust = PGP_SIGTRUST_RETIRED;
else {
pgpGetKeyBoolean (sigkey, kPGPKeyPropIsRevoked, &revoked);
if (revoked)
sigtrust = PGP_SIGTRUST_REVOKED;
else {
pgpGetKeyNumber (sigkey, kPGPKeyPropValidity,
&validity);
if (validity != PGP_VALIDITY_COMPLETE)
sigtrust = PGP_KEYTRUST_NEVER;
else
pgpGetKeyNumber (sigkey, kPGPKeyPropTrust,
&sigtrust);
}
}
}
output = keyTrustTable[sigtrust];
SpecifiedOutputString(FALSE,
OutputType,
0,
"%-10s%*s",
output,
12,
"");
}
else { /* new trust model */
if (!sigkey || sigkey ==
pgpKeyIterKey (iter))
output = " ";
else {
pgpGetCertBoolean (sig, kPGPCertPropIsRevoked, &revoked);
if (revoked)
output = "retired ";
else {
pgpGetKeyBoolean (sigkey, kPGPKeyPropIsRevoked, &revoked);
if (revoked)
output = "revoked ";
else {
pgpGetKeyNumber (sigkey, kPGPKeyPropValidity,
&confidence);
output = getTrustStatement ((word16) confidence);
}
}
}
SpecifiedOutputString(FALSE,
OutputType,
0,
"%10s%*s",
output,
12,
"");
}
if (sigkey) {
len = sizeof (namestring);
pgpGetPrimaryUserIDName (sigkey, namestring, &len);
kdbTtyPutString (namestring, len,
(unsigned) len, FALSE, OutputType, 0, 0);
SpecifiedOutputString(FALSE,
0,
OutputType,
"\n");
pgpFreeKey (sigkey);
}
else {
SpecifiedOutputString(FALSE,
0,
OutputType,
" (KeyID:");
kdbTtyPutSigID (FALSE, OutputType, sig);
SpecifiedOutputString(FALSE,
0,
OutputType,
")\n");
}
}
return 0;
}
/* This function displays a key in -kv, -kvv, -kvc, or the first section
of a -kc format. */
int
kdbTtyShowKey (PgpOutputType OutputType,
PGPKeyIter *iter,
PGPKeySet *allkeys,
int mode)
{
PGPKey *key;
PGPSubKey *subkey;
PGPUserID *name;
size_t len;
PGPTime creation, expiration;
char datestring[11];
char namestring[256];
Boolean secret, axiomatic, disabled, revoked;
long keybits;
char keyid[8];
size_t keyidlen;
pgpAssert (iter != NULL);
pgpAssert (mode <= 5);
key = pgpKeyIterKey (iter);
pgpGetKeyBoolean (key, kPGPKeyPropIsSecret, &secret);
if (secret)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -