Skip to content

Commit

Permalink
SOFT: Check the EC Key on C_CreateObject and C_DeriveKey
Browse files Browse the repository at this point in the history
When constructing an OpenSSL EC public or private key from PKCS#11
attributes or ECDH public data, check that the key is valid, i.e. that
the point is on the curve.

This prevents one from creating an EC key object via C_CreateObject with
invalid key data. It also prevents C_DeriveKey to derive a secret using
ECDH with an EC public key (public data) that uses a different curve
or is invalid by other means.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
  • Loading branch information
ifranzki authored and p-steuer committed May 11, 2021
1 parent 7b7d83c commit 4e3b43c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions usr/lib/soft_stdll/soft_specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -4365,6 +4365,12 @@ static CK_RV fill_ec_key_from_pubkey(EC_KEY *ec_key, const CK_BYTE *data,
goto out;
}

if (!EC_KEY_check_key(ec_key)) {
TRACE_ERROR("EC_KEY_check_key failed\n");
rc = CKR_PUBLIC_KEY_INVALID;
goto out;
}

out:
if (allocated && ecpoint != NULL)
free(ecpoint);
Expand Down Expand Up @@ -4404,6 +4410,12 @@ static CK_RV fill_ec_key_from_privkey(EC_KEY *ec_key, const CK_BYTE *data,
goto out;
}

if (!EC_KEY_check_key(ec_key)) {
TRACE_ERROR("EC_KEY_check_key failed\n");
rc = CKR_FUNCTION_FAILED;
goto out;
}

out:
if (point != NULL)
EC_POINT_free(point);
Expand Down

0 comments on commit 4e3b43c

Please sign in to comment.