Example #1
0
static void print_cert(gnutls_buffer_st * str, gnutls_openpgp_crt_t cert)
{
	int i, subkeys;
	int err;

	print_key_revoked(str, cert, -1);

	/* Version. */
	{
		int version = gnutls_openpgp_crt_get_version(cert);
		if (version < 0)
			addf(str, "error: get_version: %s\n",
			     gnutls_strerror(version));
		else
			addf(str, _("\tVersion: %d\n"), version);
	}

	/* ID. */
	print_key_id(str, cert, -1);

	print_key_fingerprint(str, cert);

	/* Names. */
	i = 0;
	do {
		char *dn;
		size_t dn_size = 0;

		err = gnutls_openpgp_crt_get_name(cert, i, NULL, &dn_size);
		if (err != GNUTLS_E_SHORT_MEMORY_BUFFER
		    && err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
		    && err != GNUTLS_E_OPENPGP_UID_REVOKED)
			addf(str, "error: get_name: %s\n",
			     gnutls_strerror(err));
		else {
			dn = gnutls_malloc(dn_size);
			if (!dn)
				addf(str, "error: malloc (%d): %s\n",
				     (int) dn_size,
				     gnutls_strerror
				     (GNUTLS_E_MEMORY_ERROR));
			else {
				err =
				    gnutls_openpgp_crt_get_name(cert, i,
								dn,
								&dn_size);
				if (err < 0
				    && err !=
				    GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE
				    && err != GNUTLS_E_OPENPGP_UID_REVOKED)
					addf(str, "error: get_name: %s\n",
					     gnutls_strerror(err));
				else if (err >= 0)
					addf(str, _("\tName[%d]: %s\n"), i,
					     dn);
				else if (err ==
					 GNUTLS_E_OPENPGP_UID_REVOKED)
					addf(str,
					     _("\tRevoked Name[%d]: %s\n"),
					     i, dn);

				gnutls_free(dn);
			}
		}

		i++;
	}
	while (err >= 0);

	print_key_times(str, cert, -1);

	print_key_info(str, cert, -1);
	print_key_usage(str, cert, -1);

	subkeys = gnutls_openpgp_crt_get_subkey_count(cert);
	if (subkeys < 0)
		return;

	for (i = 0; i < subkeys; i++) {
		addf(str, _("\n\tSubkey[%d]:\n"), i);

		print_key_revoked(str, cert, i);
		print_key_id(str, cert, i);
		print_key_times(str, cert, i);
		print_key_info(str, cert, i);
		print_key_usage(str, cert, i);
	}

}
Example #2
0
/*ARGSUSED*/
int
cmd_keyinfo(TSS_HCONTEXT hContext, TSS_HTPM hTPM, int argc, char *argv[])
{
	TSS_RESULT ret;
	UINT32 i, num_keys;
	TSS_KM_KEYINFO2 *keys;
	hash_node_t *parent, *child, *srk = NULL;
	TSS_HKEY hKey;
	union {
		uuid_t arr_uuid;
		TSS_UUID tss_uuid;
	} uuid;

	switch (argc) {
	case 1:
		/* Print key hierarchy */
		ret = Tspi_Context_GetRegisteredKeysByUUID2(hContext,
		    TSS_PS_TYPE_USER, NULL, &num_keys, &keys);
		if (ret) {
			print_error(ret, gettext("Get key hierarchy"));
			return (ERR_FAIL);
		}

		for (i = 0; i < num_keys; i++) {
			parent = hash_insert(keys[i].parentKeyUUID, NULL);
			child = hash_insert(keys[i].keyUUID, &keys[i]);
			add_child(parent, child);
			if (memcmp(&(keys[i].keyUUID), &srk_uuid,
			    sizeof (TSS_UUID)) == 0)
				srk = child;
		}

		if (srk != NULL)
			print_all(srk, 0);
		ret = Tspi_Context_FreeMemory(hContext, (BYTE *) keys);
		if (ret) {
			print_error(ret, gettext("Free key list"));
			return (ERR_FAIL);
		}
		return (0);

	case 2:
		/* Print detailed info about a single key */
		if (uuid_parse(argv[1], uuid.arr_uuid))
			return (ERR_FAIL);
		ret = Tspi_Context_GetKeyByUUID(hContext, TSS_PS_TYPE_USER,
		    uuid.tss_uuid, &hKey);
		if (ret == TSP_ERROR(TSS_E_PS_KEY_NOTFOUND)) {
			ret = Tspi_Context_GetKeyByUUID(hContext,
			    TSS_PS_TYPE_SYSTEM, uuid.tss_uuid, &hKey);
		}
		if (ret) {
			print_error(ret, gettext("Get key by UUID"));
			return (ERR_FAIL);
		}
		print_key_info(hContext, hKey);
		return (0);

	default:
		(void) fprintf(stderr, gettext("Usage:\n"));
		(void) fprintf(stderr, "\tkeyinfo [uuid]\n");
		return (ERR_USAGE);
	}
}
Example #3
0
File: main.c Project: CDragu/pspsdk
/* Print out a directory key */
void print_key(const char *dir)
{
	struct RegParam reg;
	REGHANDLE h;

	if(strcmp(dir, ROOT_DIR) == 0)
	{
		print_key_root();
		return;
	}

	dir = strchr(&dir[1], '/');
	if(dir == NULL)
	{
		return;
	}

	memset(&reg, 0, sizeof(reg));
	reg.regtype = 1;
	reg.namelen = strlen("/system");
	reg.unk2 = 1;
	reg.unk3 = 1;
	strcpy(reg.name, "/system");
	if(sceRegOpenRegistry(&reg, 2, &h) == 0)
	{
		REGHANDLE hd;
		if(!sceRegOpenCategory(h, dir, 2, &hd))
		{
			int num;

			if(!sceRegGetKeysNum(hd, &num))
			{
				char *data;
				printf("Key Entries: %d\n", num);
				data = malloc(num*27);
				if(data)
				{
					if(!sceRegGetKeys(hd, data, num))
					{
						int i;
						for(i = 0; i < num; i++)
						{
							print_key_info(hd, &data[i*27]);
						}
						free(data);
					}
					else
					{
						printf("Could not get key values\n");
					}
				}
				else
				{
					printf("Could not allocate key data\n");
				}
			}
			else
			{
				printf("Could not get number of keys\n");
			}
			sceRegCloseCategory(hd);
		}
		else
		{
			printf("Could not open directory\n");
		}

		sceRegCloseRegistry(h);
	}
	else
	{
		printf("Could not open registry\n");
	}
}