]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
gnutls_pkcs11_privkey_generate2: set a CKA_ID on key generation
authorNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 27 Mar 2015 09:27:10 +0000 (10:27 +0100)
committerNikos Mavrogiannopoulos <nmav@redhat.com>
Fri, 27 Mar 2015 09:27:10 +0000 (10:27 +0100)
lib/pkcs11_privkey.c

index 3b5a991ccff90e589f8d4b8b1f4de0472d485ea9..694b36690b58f6e173bf5d351f77ba581f6d221c 100644 (file)
@@ -668,6 +668,7 @@ gnutls_pkcs11_privkey_generate2(const char *url, gnutls_pk_algorithm_t pk,
        gnutls_datum_t der = {NULL, 0};
        ck_key_type_t key_type;
        char pubEx[3] = { 1,0,1 }; // 65537 = 0x10001
+       uint8_t id[20];
 
        PKCS11_CHECK_INIT;
 
@@ -697,6 +698,17 @@ gnutls_pkcs11_privkey_generate2(const char *url, gnutls_pk_algorithm_t pk,
        mech.parameter_len = 0;
        mech.mechanism = pk_to_genmech(pk, &key_type);
 
+       gnutls_rnd(GNUTLS_RND_NONCE, id, sizeof(id));
+       a[a_val].type = CKA_ID;
+       a[a_val].value = (void *) id;
+       a[a_val].value_len = sizeof(id);
+       a_val++;
+
+       p[p_val].type = CKA_ID;
+       p[p_val].value = (void *) id;
+       p[p_val].value_len = sizeof(id);
+       p_val++;
+
        switch (pk) {
        case GNUTLS_PK_RSA:
                p[p_val].type = CKA_DECRYPT;
@@ -868,6 +880,7 @@ gnutls_pkcs11_privkey_generate2(const char *url, gnutls_pk_algorithm_t pk,
 
        /* extract the public key */
        if (pubkey) {
+
                ret = gnutls_pubkey_init(&pkey);
                if (ret < 0) {
                        gnutls_assert();
@@ -903,7 +916,6 @@ gnutls_pkcs11_privkey_generate2(const char *url, gnutls_pk_algorithm_t pk,
                }
        }
 
-
       cleanup:
        if (obj != NULL)
                gnutls_pkcs11_obj_deinit(obj);