Esempio n. 1
0
static
void check_loaded_key(gnutls_certificate_credentials_t cred)
{
	int err;
	gnutls_openpgp_privkey_t key;
	gnutls_openpgp_crt_t *crts;
	unsigned n_crts;
	gnutls_openpgp_keyid_t keyid;
	unsigned i;

	/* check that the getter functions for openpgp keys of
	 * gnutls_certificate_credentials_t work and deliver the
	 * expected key ID. */

	err = gnutls_certificate_get_openpgp_key(cred, 0, &key);
	if (err != 0)
		fail("get openpgp key %s\n",
		     gnutls_strerror(err));

	gnutls_openpgp_privkey_get_subkey_id(key, 0, keyid);
	if (keyid[0] != 0xf3 || keyid[1] != 0x0f || keyid[2] != 0xd4 || keyid[3] != 0x23 ||
	    keyid[4] != 0xc1 || keyid[5] != 0x43 || keyid[6] != 0xe7 || keyid[7] != 0xba)
		fail("incorrect key id (privkey)\n");

	err = gnutls_certificate_get_openpgp_crt(cred, 0, &crts, &n_crts);
	if (err != 0)
		fail("get openpgp crts %s\n",
		     gnutls_strerror(err));

	if (n_crts != 1)
		fail("openpgp n_crts != 1\n");

	gnutls_openpgp_crt_get_subkey_id(crts[0], 0, keyid);
	if (keyid[0] != 0xf3 || keyid[1] != 0x0f || keyid[2] != 0xd4 || keyid[3] != 0x23 ||
	    keyid[4] != 0xc1 || keyid[5] != 0x43 || keyid[6] != 0xe7 || keyid[7] != 0xba)
		fail("incorrect key id (pubkey)\n");

	for (i = 0; i < n_crts; ++i)
		gnutls_openpgp_crt_deinit(crts[i]);
	gnutls_free(crts);
	gnutls_openpgp_privkey_deinit(key);
}
Esempio n. 2
0
/* idx == -1 indicates main key
 * otherwise the subkey.
 */
static void
print_key_id(gnutls_buffer_st * str, gnutls_openpgp_crt_t cert, int idx)
{
	gnutls_openpgp_keyid_t id;
	int err;

	if (idx < 0)
		err = gnutls_openpgp_crt_get_key_id(cert, id);
	else
		err = gnutls_openpgp_crt_get_subkey_id(cert, idx, id);

	if (err < 0)
		addf(str, "error: get_key_id: %s\n", gnutls_strerror(err));
	else {
		adds(str, _("\tID (hex): "));
		_gnutls_buffer_hexprint(str, id, sizeof(id));
		addf(str, "\n");
	}

}