]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Corrected bug in public key import.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 22 May 2011 14:26:12 +0000 (16:26 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 22 May 2011 14:26:16 +0000 (16:26 +0200)
print information on ECC public keys.

src/certtool-common.c
src/certtool.c

index a4cc71c92ba627323d5f9d026476cb52a942ccfe..91fbbeb3148d8ef5d7d026868ef0805f4ef11144 100644 (file)
@@ -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);
index 83b7f53bec18f7da045abf177635bdd344e9d4ad..17443cfb83c61a759abc33a6d3a3706de893ce55 100644 (file)
@@ -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)