Exemplo n.º 1
0
/**
 * gnutls_random_art:
 * @type: The type of the random art (for now only %GNUTLS_RANDOM_ART_OPENSSH is supported)
 * @key_type: The type of the key (RSA, DSA etc.)
 * @key_size: The size of the key in bits
 * @fpr: The fingerprint of the key
 * @fpr_size: The size of the fingerprint
 * @art: The returned random art
 *
 * This function will convert a given fingerprint to an "artistic"
 * image. The returned image is allocated using gnutls_malloc().
 *
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
 *   an error code is returned.
 *
 **/
int gnutls_random_art(gnutls_random_art_t type,
		      const char *key_type, unsigned int key_size,
		      void *fpr, size_t fpr_size, gnutls_datum_t * art)
{
	if (type != GNUTLS_RANDOM_ART_OPENSSH)
		return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);

	art->data =
	    (void *) _gnutls_key_fingerprint_randomart(fpr, fpr_size,
						       key_type, key_size,
						       NULL);
	if (art->data == NULL)
		return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);

	art->size = strlen((char *) art->data);

	return 0;
}
Exemplo n.º 2
0
/* idx == -1 indicates main key
 * otherwise the subkey.
 */
static void
print_key_fingerprint(gnutls_buffer_st * str, gnutls_openpgp_crt_t cert)
{
	uint8_t fpr[128];
	size_t fpr_size = sizeof(fpr);
	int err;
	const char *name;
	char *p;
	unsigned int bits;

	err = gnutls_openpgp_crt_get_fingerprint(cert, fpr, &fpr_size);
	if (err < 0)
		addf(str, "error: get_fingerprint: %s\n",
		     gnutls_strerror(err));
	else {
		adds(str, _("\tFingerprint (hex): "));
		_gnutls_buffer_hexprint(str, fpr, fpr_size);
		addf(str, "\n");
	}

	err = gnutls_openpgp_crt_get_pk_algorithm(cert, &bits);
	if (err < 0)
		return;

	name = gnutls_pk_get_name(err);
	if (name == NULL)
		return;

	p = _gnutls_key_fingerprint_randomart(fpr, fpr_size, name, bits,
					      "\t\t");
	if (p == NULL)
		return;

	adds(str, _("\tFingerprint's random art:\n"));
	adds(str, p);
	adds(str, "\n");

	gnutls_free(p);
}