From b65275d6f8275abd86f1b0c0976b1cfd324fc16c Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Wed, 22 May 2019 15:46:41 +0200 Subject: [PATCH] p11test: Improve error reporting on unknown EC groups --- src/tests/p11test/p11test_case_common.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/tests/p11test/p11test_case_common.c b/src/tests/p11test/p11test_case_common.c index 58a0d0ec..bd63458a 100644 --- a/src/tests/p11test/p11test_case_common.c +++ b/src/tests/p11test/p11test_case_common.c @@ -321,9 +321,24 @@ int callback_public_keys(test_certs_t *objects, /* Parse the nid out of the EC_PARAMS */ p = template[6].pValue; oid = d2i_ASN1_OBJECT(NULL, &p, template[6].ulValueLen); + if (oid == NULL) { + debug_print(" [WARN %s ] Failed to convert EC_PARAMS" + " to OpenSSL format", o->id_str); + return -1; + } nid = OBJ_obj2nid(oid); ASN1_OBJECT_free(oid); + if (nid == NID_undef) { + debug_print(" [WARN %s ] Failed to convert EC_PARAMS" + " to NID", o->id_str); + return -1; + } ecgroup = EC_GROUP_new_by_curve_name(nid); + if (ecgroup == NULL) { + debug_print(" [WARN %s ] Failed to create new EC_GROUP" + " from NID", o->id_str); + return -1; + } EC_GROUP_set_asn1_flag(ecgroup, OPENSSL_EC_NAMED_CURVE); p = template[7].pValue; @@ -334,7 +349,7 @@ int callback_public_keys(test_certs_t *objects, ASN1_STRING_free(s); if (bn == NULL) { debug_print(" [WARN %s ] Can not convert EC_POINT from" - "PKCS#11 to BIGNUM", o->id_str); + " PKCS#11 to BIGNUM", o->id_str); EC_GROUP_free(ecgroup); return -1; } @@ -343,7 +358,7 @@ int callback_public_keys(test_certs_t *objects, BN_free(bn); if (ecpoint == NULL) { debug_print(" [WARN %s ] Can not convert EC_POINT from" - "BIGNUM to OpenSSL format", o->id_str); + " BIGNUM to OpenSSL format", o->id_str); EC_GROUP_free(ecgroup); return -1; }