⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgpkui.c

📁 著名的加密软件的应用于电子邮件中
💻 C
📖 第 1 页 / 共 3 页
字号:
		SpecifiedOutputString(TRUE, OutputType, 0, "sec");
    else
		SpecifiedOutputString(TRUE, OutputType, 0, "pub");

    pgpGetKeyBoolean (key, kPGPKeyPropIsAxiomatic, &axiomatic);
    pgpGetKeyBoolean (key, kPGPKeyPropIsDisabled, &disabled);
	if (axiomatic)
		SpecifiedOutputString(FALSE, OutputType, 0, "+ ");
    else if (disabled)
		SpecifiedOutputString(FALSE, OutputType, 0, "@ ");
    else
		SpecifiedOutputString(FALSE, OutputType, 0, "  ");

    pgpGetKeyNumber (key, kPGPKeyPropBits, &keybits);

	SpecifiedOutputString(FALSE, OutputType, 0, "%4u ", (unsigned) keybits);
	keyidlen = 8;
	pgpGetKeyString (key, kPGPKeyPropKeyId, keyid, &keyidlen);
    kdbTtyPutKeyID(FALSE, OutputType, keyid);
	SpecifiedOutputString(FALSE, OutputType, 0, " ");
    pgpGetKeyTime (key, kPGPKeyPropCreation, &creation);
    if (creation > 0) {
        pgpDateString ((word32) creation, datestring);
		SpecifiedOutputString(FALSE, OutputType, 0, "%s ", datestring);
    }
    else
		SpecifiedOutputString(FALSE, OutputType, 0, "---------- ");

    pgpGetKeyBoolean (key, kPGPKeyPropIsRevoked, &revoked);
    if (revoked)
		SpecifiedOutputString(FALSE, OutputType, 0,"*REVOKED*  ");
    else {
        pgpGetKeyTime (key, kPGPKeyPropExpiration, &expiration);
	if (expiration > 0) {
	    pgpDateString ((word32) expiration, datestring);
		SpecifiedOutputString(FALSE, OutputType, 0, "%s ", datestring);
	}
	else
		SpecifiedOutputString(FALSE, OutputType, 0, "---------- ");
    }

	SpecifiedOutputString(FALSE,
						  OutputType,
						  0,
						  "%-14s  %-15s\n",
						  getKeyAlg (key),
						  getKeyUse (key));

    if (mode == 2) {
        char fingerprint[20];
		size_t	flen = sizeof (fingerprint);
		pgpGetKeyString (key, kPGPKeyPropFingerprint, fingerprint, &flen);
		if (flen == 20) {
			SpecifiedOutputString(TRUE,
								  OutputType,
								  0,
								  "f20    Fingerprint20 = ");
			kdbTtyPutFingerprint20(FALSE, OutputType, fingerprint, 50);
		}
		else {
			SpecifiedOutputString(TRUE,
								  OutputType,
								  0,
								  "f16    Fingerprint16 = ");
			kdbTtyPutFingerprint16(FALSE, OutputType, fingerprint, 48);
		}
		SpecifiedOutputString(FALSE, OutputType, 0, "\n");
    }

	while ((subkey = pgpKeyIterNextSubKey (iter)) != NULL) {
		/* Print out its status */
		SpecifiedOutputString(TRUE, OutputType, 0, "sub  ");
		pgpGetSubKeyNumber (subkey, kPGPKeyPropBits, &keybits);
		SpecifiedOutputString(TRUE,
							  OutputType,
							  0,
							  "%4u ",
							  (unsigned) keybits);
		keyidlen = 8;
		pgpGetSubKeyString (subkey, kPGPKeyPropKeyId, keyid, &keyidlen);
		kdbTtyPutKeyID(FALSE, OutputType, keyid);
		SpecifiedOutputString(FALSE, OutputType, 0, " ");
		pgpGetSubKeyTime (subkey, kPGPKeyPropCreation, &creation);
		if (creation > 0) {
			pgpDateString (creation, datestring);
			SpecifiedOutputString(FALSE, OutputType, 0, "%s ", datestring);
		}
		else
			SpecifiedOutputString(FALSE, OutputType, 0, "---------- ");

		/* If superkey revoked, don't print expiration */
		if (revoked)
			SpecifiedOutputString(FALSE, OutputType, 0, "           ");
		else {
			pgpGetSubKeyTime (subkey, kPGPKeyPropExpiration, &expiration);
			if (expiration > 0) {
				pgpDateString (expiration, datestring);
				SpecifiedOutputString(FALSE,
									  OutputType,
									  0,
									  "%s ",
									  datestring);
			}
			else
				SpecifiedOutputString(FALSE, OutputType, 0, "---------- ");
		}
		SpecifiedOutputString(FALSE,
							  OutputType,
							  0,
							  "%-8s  %-15s\n",
							  getSubKeyAlg (subkey),
							  getSubKeyUse (subkey));
		if (mode == 2) {
			char fingerprint[20];
			size_t flen = sizeof (fingerprint);
			pgpGetSubKeyString (subkey, kPGPKeyPropFingerprint, fingerprint,
								&flen);
			SpecifiedOutputString(TRUE,
								  OutputType,
								  0,
								  "f20    Fingerprint20 = ");
			kdbTtyPutFingerprint20(FALSE, OutputType, fingerprint, 50);
			SpecifiedOutputString(FALSE, OutputType, 0, "\n");
		}
	}

	SpecifiedOutputString(TRUE, OutputType, 0, "uid  ");

    name = pgpKeyIterNextUserID (iter);
    if (!name)
		SpecifiedOutputString(FALSE,
							  OutputType,
							  0,
							  "*** This key is unnamed ***\n");

    while (name != NULL) {
        len = sizeof (namestring);
		pgpGetUserIDString (name, kPGPUserIDPropName, namestring, &len);
		kdbTtyPutString (namestring,
						 len,
						 (unsigned) len,
						 FALSE,
						 OutputType,
						 0,
						 0);
		SpecifiedOutputString(FALSE, OutputType, 0, "\n");
		
		if (mode > 0)
		    kdbTtyShowSigs(OutputType, iter, allkeys, mode);
		
		name = pgpKeyIterNextUserID (iter);
		if (name)
			SpecifiedOutputString(TRUE, OutputType, 0, "uid  ");
    } /* end while */
    return 0;
}


int
kdbTtyCheckKey (PgpOutputType OutputType,
				PGPKeyIter *iter,
				PGPKeySet *allkeys, int mode)
{
    PGPKey				  *key = NULL;
    PGPUserID             *name = NULL;
    char                   namestring[256];
    size_t				   namelen;
    long				   confidence;
    long				   validity;
    int                    name_leader = 0;
    long				   trust;
    PgpTrustModel          pgptrustmodel;
    Boolean				   revoked, axiomatic;
	char                   keyid[8];
	size_t                   keyidlen = sizeof(keyid);

    pgpAssert (iter != NULL);
    pgpAssert (mode == 4 || mode == 5);
    pgpAssert (pgpKeyIterKey (iter));

    pgptrustmodel = PGPTRUST0;
    key = pgpKeyIterKey (iter);

    pgpGetKeyBoolean (key, kPGPKeyPropIsRevoked, &revoked);
    if (revoked)
		SpecifiedOutputString(TRUE, OutputType, 0, "# ");
    else {
        pgpGetKeyBoolean (key, kPGPKeyPropIsAxiomatic, &axiomatic);
	if (axiomatic)
		SpecifiedOutputString(TRUE, OutputType, 0, "* ");
	else
		SpecifiedOutputString(TRUE, OutputType, 0, "  ");
    }

	keyidlen = 8;
	pgpGetKeyString (key, kPGPKeyPropKeyId, keyid, &keyidlen);
    kdbTtyPutKeyID (FALSE, OutputType, keyid);

    if (pgptrustmodel == PGPTRUST0) {
        pgpGetKeyNumber (key, kPGPKeyPropTrust, &trust);
		SpecifiedOutputString(FALSE,
							  OutputType,
							  0,
							  " %-10s",
							  keyTrustTable[trust]);
    }

    name = pgpKeyIterNextUserID (iter);
    if (!name)
		SpecifiedOutputString(FALSE,
							  OutputType,
							  0,
							  "\
                     *** This key is unnamed ***\n");

    while (name != NULL) {
        if (pgptrustmodel==PGPTRUST0) {
			if (name_leader)
				SpecifiedOutputString(FALSE,
									  OutputType,
									  0,
									  "%*s",
									  name_indent - 9,
									  "");
			name_leader = 1;
			pgpGetUserIDNumber (name, kPGPUserIDPropValidity, &trust);
			SpecifiedOutputString(FALSE,
								  OutputType,
								  0,
								  "%-10s",
								  uidValidityTable[trust]);
		}
		else {
			if (name_leader)
				SpecifiedOutputString(FALSE,
									  OutputType,
									  0,
									  "%*s",
									  name_indent - 20,
									  "");
			name_leader = 1;
			pgpGetUserIDNumber (name, kPGPUserIDPropConfidence, &confidence);
			pgpGetUserIDNumber (name, kPGPUserIDPropValidity, &validity);
			SpecifiedOutputString(FALSE,
								  OutputType,
								  0,
								  " %10s",
								  getTrustStatement ((word16) confidence));
			SpecifiedOutputString(FALSE,
								  OutputType,
								  0,
								  "%10s",
								  getTrustStatement ((word16) validity));
		}
		
		namelen = sizeof (namestring);
		pgpGetUserIDString (name, kPGPUserIDPropName, namestring, &namelen);
		kdbTtyPutString (namestring,
						 namelen,
						 (unsigned) namelen,
						 FALSE,
						 OutputType,
						 0,
						 0);
		
		kdbTtyCheckSigs(OutputType, iter, allkeys, mode);
	
		name = pgpKeyIterNextUserID (iter);
    }
    return 0;
}


/* Note:  No mode 5 for the moment */

int
kdbTtyKeyCheck (PgpOutputType OutputType,
				PGPKeyList *viewkeys,
				PGPKeySet *allkeys, int mode)
{

    PGPKeyIter          *iter = NULL;
    char header0[] = "\n\n  KeyID    Trust     Validity  User ID\n";
    char header1[] = "\n\n  KeyID   Confidence  Validity User ID\n";
    PgpTrustModel       pgptrustmodel;
    int			        list_create = 0;;

    pgpAssert (allkeys != NULL);
    pgptrustmodel = pgpGetTrustModel ();

    if (viewkeys == NULL) {
        viewkeys = pgpOrderKeySet (allkeys, kPGPAnyOrdering);
		list_create = 1;
    }

    if (pgptrustmodel == PGPTRUST0) {
		SpecifiedOutputString(TRUE, OutputType, 0, header0);
    } else {
		SpecifiedOutputString(TRUE, OutputType, 0, header1);
    }
    iter = pgpNewKeyIter (viewkeys);
    while (pgpKeyIterNext (iter) != NULL)
        kdbTtyCheckKey (OutputType, iter, allkeys, mode);

    pgpFreeKeyIter (iter);
    if (list_create)
        pgpFreeKeyList (viewkeys);
    return 0;
}


/* Modes:

   0         list keys, but no fingerprints or signatures (-kv)
   1         list keys with signatures, but no fingerprints (-kvv)
   2         list keys with fingerprints and signatures (-kvc)
   3         list keys with signature status info (-ka)
   4         list keys with signature status info, plus trust info (-kc)
   5         same as 4, but do not output numeric trust info
   (not implemented yet)
   */



int
kdbTtyKeyView (PGPKeyList *viewkeys, PGPKeySet *allkeys,
				char const *keyring, int mode)
{
    PGPKeyIter       *iter;
    char			 header[] =
		"Type Bits KeyID    Created    Expires    Algorithm       Use\n";
    int				  count = 0;
    int              list_create = 0;

    pgpAssert (mode <= 5);
    pgpAssert (allkeys != NULL);

    if (viewkeys == NULL) {
        viewkeys = pgpOrderKeySet (allkeys, kPGPAnyOrdering);
		list_create = 1;
    }

    if (keyring)
		PrimaryOutputString("Key ring: \'%s\'\n", keyring);

    PrimaryOutputString(header);

    iter = pgpNewKeyIter (viewkeys);
    while (pgpKeyIterNext (iter) != NULL) {
        count++;
		kdbTtyShowKey (OUTPUT_PRIMARY, iter, allkeys, mode);
#if 0
		/* Temporary test of message recovery keys */
		{
			PGPKey *curkey = pgpKeyIterKey (iter);
			PGPKey *mrkey;
			byte kclass = 0;
			int nkey = 0;
			PGPError mrerr;
			for ( ; ; ) {
				mrerr = pgpGetMessageRecoveryKey (curkey, allkeys, nkey++,
					&mrkey, &kclass, NULL);
				if (mrkey) {
					fprintf (fp, " message recovery key, class 0x%02x:\n  ",
							 kclass);
					pgpKeyIterSet (iter, mrkey);
					kdbTtyShowKey (TRUE, OUTPUT_PRIMARY, iter, allkeys, mode);
					pgpKeyIterSet (iter, curkey);
				} else if (mrerr) {
					fprintf (fp,
					" *** missing message recovery key, class 0x%02x ***\n",
							 kclass);
				} else {
					break;
				}
			}
		}
#endif
		PrimaryOutputString("\n");
    }
    pgpFreeKeyIter (iter);

    if (mode < 4) {
        if (count == 1)
			PrimaryOutputString("1 matching key found\n");
		else
			PrimaryOutputString("%d matching keys found\n", count);
    }
    else
        kdbTtyKeyCheck (OUTPUT_PRIMARY, viewkeys, allkeys, mode);

    if (list_create)
        pgpFreeKeyList (viewkeys);
    return 0;
}

/*
 * Local Variables:
 * tab-width: 4
 * End:
 * vi: ts=4 sw=4
 * vim: si
 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -