Blame SOURCES/opencryptoki-3.16.0-4e3b43c3d8844402c04a66b55c6c940f965109f0.patch

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