From 6ab12af386dbce8fdb4265edf630b80fc5ed978f Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos Date: Thu, 31 Dec 2015 17:33:55 +0200 Subject: pkcs11: fixes to store the imported URL This ammends 603d0db776537c19bdfd907e0fc77c7321874bf0 with changes for the 3.3.x branch. --- lib/pkcs11_privkey.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/pkcs11_privkey.c b/lib/pkcs11_privkey.c index 1934cea8ac..772f6f9af4 100644 --- a/lib/pkcs11_privkey.c +++ b/lib/pkcs11_privkey.c @@ -64,6 +64,7 @@ struct gnutls_pkcs11_privkey_st { gnutls_pk_algorithm_t pk_algorithm; unsigned int flags; struct p11_kit_uri *uinfo; + char *url; struct pkcs11_session_info sinfo; ck_object_handle_t ref; /* the key in the session */ @@ -110,6 +111,7 @@ int gnutls_pkcs11_privkey_init(gnutls_pkcs11_privkey_t * key) void gnutls_pkcs11_privkey_deinit(gnutls_pkcs11_privkey_t key) { p11_kit_uri_free(key->uinfo); + gnutls_free(key->url); if (key->sinfo.init != 0) pkcs11_close_session(&key->sinfo); gnutls_free(key); @@ -380,6 +382,15 @@ gnutls_pkcs11_privkey_import_url(gnutls_pkcs11_privkey_t pkey, memset(&pkey->sinfo, 0, sizeof(pkey->sinfo)); + if (pkey->url) { + gnutls_free(pkey->url); + pkey->url = NULL; + } + + pkey->url = gnutls_strdup(url); + if (pkey->url == NULL) + return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR); + ret = pkcs11_url_to_info(url, &pkey->uinfo, flags|GNUTLS_PKCS11_OBJ_FLAG_EXPECT_PRIVKEY); if (ret < 0) { gnutls_assert(); @@ -900,7 +911,7 @@ static int load_pubkey_obj(gnutls_pkcs11_privkey_t pkey, gnutls_pubkey_t pub) gnutls_x509_crt_set_pin_function(crt, pkey->pin.cb, pkey->pin.data); - ret = gnutls_x509_crt_import_url(crt, pkey->url, pkey->flags); + ret = gnutls_x509_crt_import_pkcs11_url(crt, pkey->url, pkey->flags); if (ret < 0) { ret = iret; goto cleanup; -- cgit v1.2.1