From: Jakub Jelen Date: Fri, 28 Feb 2020 17:50:53 +0000 (+0100) Subject: tests: Verify writing and reading of ECDSA public keys from PKCS#11 X-Git-Tag: 3.6.13~14^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d684748cf79d4a99dcddadeeb95f24da73e9668;p=thirdparty%2Fgnutls.git tests: Verify writing and reading of ECDSA public keys from PKCS#11 Signed-off-by: Jakub Jelen --- diff --git a/tests/pkcs11/pkcs11-ec-privkey-test.c b/tests/pkcs11/pkcs11-ec-privkey-test.c index c256e6b0d9..1b24c8150f 100644 --- a/tests/pkcs11/pkcs11-ec-privkey-test.c +++ b/tests/pkcs11/pkcs11-ec-privkey-test.c @@ -79,6 +79,8 @@ void doit(void) gnutls_privkey_t pkey; gnutls_pubkey_t pubkey; gnutls_pubkey_t pubkey2; + gnutls_pubkey_t pubkey3; + gnutls_pubkey_t pubkey4; unsigned i; bin = softhsm_bin(); @@ -180,8 +182,21 @@ void doit(void) exit(1); } + /* Write pubkey to the card too */ + assert(gnutls_pubkey_init(&pubkey) == 0); + assert(gnutls_pubkey_import_x509(pubkey, crt, 0) == 0); + + ret = gnutls_pkcs11_copy_pubkey(SOFTHSM_URL, pubkey, "cert", NULL, + GNUTLS_KEY_DIGITAL_SIGNATURE | + GNUTLS_KEY_KEY_ENCIPHERMENT, 0); + if (ret < 0) { + fail("gnutls_pkcs11_copy_pubkey: %s\n", + gnutls_strerror(ret)); + } + gnutls_x509_crt_deinit(crt); gnutls_x509_privkey_deinit(key); + gnutls_pubkey_deinit(pubkey); gnutls_pkcs11_set_pin_function(NULL, NULL); assert(gnutls_privkey_init(&pkey) == 0); @@ -192,6 +207,31 @@ void doit(void) exit(1); } + /* Try to read the public key with public key URI */ + assert(gnutls_pubkey_init(&pubkey3) == 0); + + + ret = + gnutls_pubkey_import_pkcs11_url(pubkey3, + SOFTHSM_URL + ";object=cert;object-type=public;pin-value=" + PIN, 0); + if (ret < 0) { + fail("error in gnutls_pubkey_import_pkcs11_url: %s\n", gnutls_strerror(ret)); + } + + /* Try to read the public key with certificate URI */ + assert(gnutls_pubkey_init(&pubkey4) == 0); + + ret = + gnutls_pubkey_import_pkcs11_url(pubkey4, + SOFTHSM_URL + ";object=cert;object-type=cert;pin-value=" + PIN, 0); + if (ret < 0) { + fail("error in gnutls_pubkey_import_pkcs11_url: %s\n", gnutls_strerror(ret)); + } + assert(gnutls_pubkey_init(&pubkey) == 0); assert(gnutls_pubkey_import_privkey(pubkey, pkey, 0, 0) == 0); @@ -228,6 +268,8 @@ void doit(void) gnutls_free(s.data); } + gnutls_pubkey_deinit(pubkey4); + gnutls_pubkey_deinit(pubkey3); gnutls_pubkey_deinit(pubkey2); gnutls_pubkey_deinit(pubkey); gnutls_privkey_deinit(pkey);