Blame SOURCES/0007-EP11-Supply-CKA_PUBLIC_KEY_INFO-with-CKM_IBM_BTC_DER.patch

1f6f0c
From 63a42a9398f5ec7b2b139810ee7b5beb7ad1abc3 Mon Sep 17 00:00:00 2001
1f6f0c
From: Ingo Franzki <ifranzki@linux.ibm.com>
1f6f0c
Date: Fri, 4 Nov 2022 09:31:29 +0100
1f6f0c
Subject: [PATCH 07/34] EP11: Supply CKA_PUBLIC_KEY_INFO with
1f6f0c
 CKM_IBM_BTC_DERIVE of public key
1f6f0c
1f6f0c
When deriving a public EC key with the CKM_IBM_BTC_DERIVE mechanism,
1f6f0c
also supply the SPKI in the CKA_PUBLIC_KEY_INFO attribute.
1f6f0c
1f6f0c
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
1f6f0c
---
1f6f0c
 usr/lib/ep11_stdll/ep11_specific.c | 28 ++++++++++++++++++++++++++++
1f6f0c
 1 file changed, 28 insertions(+)
1f6f0c
1f6f0c
diff --git a/usr/lib/ep11_stdll/ep11_specific.c b/usr/lib/ep11_stdll/ep11_specific.c
1f6f0c
index a56b5b82..886692c4 100644
1f6f0c
--- a/usr/lib/ep11_stdll/ep11_specific.c
1f6f0c
+++ b/usr/lib/ep11_stdll/ep11_specific.c
1f6f0c
@@ -4989,6 +4989,9 @@ CK_RV ep11tok_derive_key(STDLL_TokData_t * tokdata, SESSION * session,
1f6f0c
     CK_MECHANISM_PTR mech_orig = mech;
1f6f0c
     CK_ATTRIBUTE *ec_params;
1f6f0c
     CK_IBM_BTC_DERIVE_PARAMS *btc_params = NULL;
1f6f0c
+    CK_BYTE *spki = NULL;
1f6f0c
+    CK_ULONG spki_length = 0;
1f6f0c
+    CK_ATTRIBUTE *spki_attr = NULL;
1f6f0c
 
1f6f0c
     memset(newblob, 0, sizeof(newblob));
1f6f0c
 
1f6f0c
@@ -5329,6 +5332,29 @@ CK_RV ep11tok_derive_key(STDLL_TokData_t * tokdata, SESSION * session,
1f6f0c
                         __func__, rc);
1f6f0c
             goto error;
1f6f0c
         }
1f6f0c
+
1f6f0c
+        /* Extract the SPKI and add CKA_PUBLIC_KEY_INFO to key */
1f6f0c
+        rc = publ_key_get_spki(key_obj->template, ktype, FALSE,
1f6f0c
+                               &spki, &spki_length);
1f6f0c
+        if (rc != CKR_OK) {
1f6f0c
+            TRACE_DEVEL("publ_key_get_spki failed\n");
1f6f0c
+            goto error;
1f6f0c
+        }
1f6f0c
+
1f6f0c
+        rc = build_attribute(CKA_PUBLIC_KEY_INFO, spki, spki_length, &spki_attr);
1f6f0c
+        if (rc != CKR_OK) {
1f6f0c
+            TRACE_ERROR("%s build_attribute failed with rc=0x%lx\n",
1f6f0c
+                        __func__, rc);
1f6f0c
+            goto error;
1f6f0c
+        }
1f6f0c
+
1f6f0c
+        rc = template_update_attribute(key_obj->template, spki_attr);
1f6f0c
+        if (rc != CKR_OK) {
1f6f0c
+            TRACE_ERROR("%s template_update_attribute failed with "
1f6f0c
+                        "rc=0x%lx\n", __func__, rc);
1f6f0c
+            goto error;
1f6f0c
+        }
1f6f0c
+        spki_attr = NULL;
1f6f0c
     }
1f6f0c
 
1f6f0c
     if (class == CKO_SECRET_KEY || class == CKO_PRIVATE_KEY) {
1f6f0c
@@ -5381,6 +5407,8 @@ error:
1f6f0c
         free(opaque_attr);
1f6f0c
     if (chk_attr != NULL)
1f6f0c
         free(chk_attr);
1f6f0c
+    if (spki_attr != NULL)
1f6f0c
+        free(spki_attr);
1f6f0c
     if (new_attrs)
1f6f0c
         free_attribute_array(new_attrs, new_attrs_len);
1f6f0c
     if (new_attrs1)
1f6f0c
-- 
1f6f0c
2.16.2.windows.1
1f6f0c