Blame SOURCES/opencryptoki-3.16.0-4e3b43c3d8844402c04a66b55c6c940f965109f0.patch

bf3226
commit 4e3b43c3d8844402c04a66b55c6c940f965109f0
bf3226
Author: Ingo Franzki <ifranzki@linux.ibm.com>
bf3226
Date:   Mon May 3 10:05:07 2021 +0200
bf3226
bf3226
    SOFT: Check the EC Key on C_CreateObject and C_DeriveKey
bf3226
    
bf3226
    When constructing an OpenSSL EC public or private key from PKCS#11
bf3226
    attributes or ECDH public data, check that the key is valid, i.e. that
bf3226
    the point is on the curve.
bf3226
    
bf3226
    This prevents one from creating an EC key object via C_CreateObject with
bf3226
    invalid key data. It also prevents C_DeriveKey to derive a secret using
bf3226
    ECDH with an EC public key (public data) that uses a different curve
bf3226
    or is invalid by other means.
bf3226
    
bf3226
    Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
bf3226
bf3226
diff --git a/usr/lib/soft_stdll/soft_specific.c b/usr/lib/soft_stdll/soft_specific.c
bf3226
index c30be1da..aeff39a9 100644
bf3226
--- a/usr/lib/soft_stdll/soft_specific.c
bf3226
+++ b/usr/lib/soft_stdll/soft_specific.c
bf3226
@@ -4365,6 +4365,12 @@ static CK_RV fill_ec_key_from_pubkey(EC_KEY *ec_key, const CK_BYTE *data,
bf3226
         goto out;
bf3226
     }
bf3226
 
bf3226
+    if (!EC_KEY_check_key(ec_key)) {
bf3226
+        TRACE_ERROR("EC_KEY_check_key failed\n");
bf3226
+        rc = CKR_PUBLIC_KEY_INVALID;
bf3226
+        goto out;
bf3226
+    }
bf3226
+
bf3226
 out:
bf3226
     if (allocated && ecpoint != NULL)
bf3226
         free(ecpoint);
bf3226
@@ -4404,6 +4410,12 @@ static CK_RV fill_ec_key_from_privkey(EC_KEY *ec_key, const CK_BYTE *data,
bf3226
         goto out;
bf3226
     }
bf3226
 
bf3226
+    if (!EC_KEY_check_key(ec_key)) {
bf3226
+        TRACE_ERROR("EC_KEY_check_key failed\n");
bf3226
+        rc = CKR_FUNCTION_FAILED;
bf3226
+        goto out;
bf3226
+    }
bf3226
+
bf3226
 out:
bf3226
     if (point != NULL)
bf3226
         EC_POINT_free(point);