gnutls_pubkey_import_ecc_raw: set the public key bits
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Thu, 20 Dec 2018 16:49:21 +0000 (17:49 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Fri, 21 Dec 2018 18:49:08 +0000 (19:49 +0100)
This sets the number of key bits once an ECC key is imported.

Resolves #640

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
NEWS
lib/pubkey.c
tests/pubkey-import-export.c

diff --git a/NEWS b/NEWS
index ea0752831cc3ac8c82d9caf60a0f43116ad4aa7c..739ab21651680101ed05c2e7b1b16a2baad79d53 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,9 @@ See the end for copying conditions.
 
 * Version 3.6.6 (unreleased)
 
+** libgnutls: gnutls_pubkey_import_ecc_raw() was fixed to set the number bits
+   on the public key (#640).
+
 ** libgnutls: Added support for raw public-key authentication as defined in RFC7250.
    Raw public-keys can be negotiated by enabling the corresponding certificate
    types via the priority strings. The raw public-key mechanism must be explicitly
index aad40beacc930c3b717d3e02d4c8833cd680d28a..5c8bb9837b723beedd4c9deae32156c161e7c0c7 100644 (file)
@@ -1431,6 +1431,7 @@ gnutls_pubkey_import_ecc_raw(gnutls_pubkey_t key,
 
                key->params.algo = GNUTLS_PK_EDDSA_ED25519;
                key->params.curve = curve;
+               key->bits = pubkey_to_bits(&key->params);
 
                return 0;
        }
@@ -1454,6 +1455,7 @@ gnutls_pubkey_import_ecc_raw(gnutls_pubkey_t key,
        }
        key->params.params_nr++;
        key->params.algo = GNUTLS_PK_ECDSA;
+       key->bits = pubkey_to_bits(&key->params);
 
        return 0;
 
index 46bfb729d99eeeb8ce81d43b115bcdf02b4563dd..b11ce560d65f89f1761f5f83be61611abc683b1c 100644 (file)
@@ -168,6 +168,7 @@ int check_pubkey_import_export(void)
        gnutls_datum_t p, q, g, y, x;
        gnutls_datum_t m, e;
        gnutls_ecc_curve_t curve;
+       unsigned bits;
        int ret;
 
        global_init();
@@ -180,6 +181,11 @@ int check_pubkey_import_export(void)
        if (ret < 0)
                fail("error\n");
 
+       bits = 0;
+       ret = gnutls_pubkey_get_pk_algorithm(key, &bits);
+       if (ret <= 0 || bits == 0)
+               fail("error: %s [%u]\n", gnutls_strerror(ret), bits);
+
        ret = gnutls_pubkey_export_dsa_raw2(key, &p, &q, &g, &y, 0);
        if (ret < 0)
                fail("error: %s\n", gnutls_strerror(ret));
@@ -216,6 +222,11 @@ int check_pubkey_import_export(void)
        if (ret < 0)
                fail("error\n");
 
+       bits = 0;
+       ret = gnutls_pubkey_get_pk_algorithm(key, &bits);
+       if (ret <= 0 || bits == 0)
+               fail("error: %s [%u]\n", gnutls_strerror(ret), bits);
+
        ret = gnutls_pubkey_export_rsa_raw2(key, &m, &e, 0);
        if (ret < 0)
                fail("error\n");
@@ -244,6 +255,11 @@ int check_pubkey_import_export(void)
        if (ret < 0)
                fail("error\n");
 
+       bits = 0;
+       ret = gnutls_pubkey_get_pk_algorithm(key, &bits);
+       if (ret <= 0 || bits == 0)
+               fail("error: %s [%u]\n", gnutls_strerror(ret), bits);
+
        ret = gnutls_pubkey_export_ecc_raw2(key, &curve, &x, &y, 0);
        if (ret < 0)
                fail("error\n");
@@ -285,6 +301,11 @@ int check_pubkey_import_export(void)
        if (ret < 0)
                fail("error\n");
 
+       bits = 0;
+       ret = gnutls_pubkey_get_pk_algorithm(key, &bits);
+       if (ret <= 0 || bits == 0)
+               fail("error: %s [%u]\n", gnutls_strerror(ret), bits);
+
        ret = gnutls_pubkey_verify_params(key);
        if (ret != 0)
                fail("error: %s\n", gnutls_strerror(ret));