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

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