From: Nikos Mavrogiannopoulos Date: Sun, 22 May 2011 14:26:12 +0000 (+0200) Subject: Corrected bug in public key import. X-Git-Tag: gnutls_2_99_2~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f91665debbb2b044ef95b0676a41cbf9c8ba2e79;p=thirdparty%2Fgnutls.git Corrected bug in public key import. print information on ECC public keys. --- diff --git a/src/certtool-common.c b/src/certtool-common.c index a4cc71c92b..91fbbeb314 100644 --- a/src/certtool-common.c +++ b/src/certtool-common.c @@ -547,7 +547,7 @@ load_pubkey (int mand, common_info_st * info) if (info->pubkey == NULL) error (EXIT_FAILURE, 0, "missing --load-pubkey"); - if (strncmp(info->privkey, "pkcs11:", 7) == 0) + if (strncmp(info->pubkey, "pkcs11:", 7) == 0) return _load_pkcs11_pubkey(info->pubkey); ret = gnutls_pubkey_init (&key); diff --git a/src/certtool.c b/src/certtool.c index 83b7f53bec..17443cfb83 100644 --- a/src/certtool.c +++ b/src/certtool.c @@ -143,6 +143,21 @@ print_dsa_pkey (gnutls_datum_t * x, gnutls_datum_t * y, gnutls_datum_t * p, print_hex_datum (g); } +static void +print_ecc_pkey (gnutls_ecc_curve_t curve, gnutls_datum_t* k, gnutls_datum_t * x, gnutls_datum_t * y) +{ + if (k) + { + fprintf (outfile, "private key:"); + print_hex_datum (k); + } + fprintf (outfile, "curve:\t%s\n", gnutls_ecc_curve_get_name(curve)); + fprintf (outfile, "x:"); + print_hex_datum (x); + fprintf (outfile, "y:"); + print_hex_datum (y); +} + static void print_rsa_pkey (gnutls_datum_t * m, gnutls_datum_t * e, gnutls_datum_t * d, gnutls_datum_t * p, gnutls_datum_t * q, gnutls_datum_t * u, @@ -2933,6 +2948,22 @@ pubkey_info (gnutls_x509_crt_t crt, common_info_st * cinfo) gnutls_free (g.data); } } + else if (ret == GNUTLS_PK_ECC) + { + gnutls_datum_t x, y; + gnutls_ecc_curve_t curve; + + ret = gnutls_pubkey_get_pk_ecc_raw (pubkey, &curve, &x, &y); + if (ret < 0) + fprintf (stderr, "Error in key ECC data export: %s\n", + gnutls_strerror (ret)); + else + { + print_ecc_pkey (curve, NULL, &y, &x); + gnutls_free (y.data); + gnutls_free (x.data); + } + } ret = gnutls_pubkey_get_key_usage (pubkey, &usage); if (ret < 0)