Skip to content

Commit e732603

Browse files
authored
[FIPS 4.0 CHERRY-PICK #3181 and #3194] Map rsaesOaep SPKI to RSA in parse_key_type (#3246)
### Issues: n/a ### Description of changes: Cherry-pick #3181 and #3194 ### Testing: * CI By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent 0a96b98 commit e732603

2 files changed

Lines changed: 46 additions & 5 deletions

File tree

crypto/evp_extra/evp_asn1.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
// specific key type implementations like PQDSA.
7979
// The OID is then searched against ASN.1 methods for a method with that OID.
8080
// As the |OID| is read from |cbs| the buffer is advanced.
81-
// For the case of |NID_rsa| the method |rsa_asn1_meth| is returned.
81+
// For the case of |NID_rsa| or |NID_rsaesOaep| the method |rsa_asn1_meth| is returned.
8282
// For the case of |EVP_PKEY_PQDSA| the method |pqdsa_asn1.meth| is returned.
8383
// For the case of |EVP_PKEY_KEM| the method |kem_asn1.meth| is returned.
8484
static const EVP_PKEY_ASN1_METHOD *parse_key_type(CBS *cbs, CBS *out_oid) {
@@ -99,20 +99,25 @@ static const EVP_PKEY_ASN1_METHOD *parse_key_type(CBS *cbs, CBS *out_oid) {
9999
}
100100
}
101101

102-
// Special logic to handle the rarer |NID_rsa|.
102+
// Special logic to handle the rarer |NID_rsa| and |NID_rsaesOaep|.
103+
// NID_rsa:
103104
// https://www.itu.int/ITU-T/formal-language/itu-t/x/x509/2008/AlgorithmObjectIdentifiers.html
104-
if (OBJ_cbs2nid(&oid) == NID_rsa) {
105+
// NID_rsaesOaep: underlying key is the same as |NID_rsa|. Used by
106+
// TPM 1.2 Endorsement Key certificates per TCG Credential Profiles
107+
// V1.2, section 3.2.7.
108+
int nid = OBJ_cbs2nid(&oid);
109+
if (nid == NID_rsa || nid == NID_rsaesOaep) {
105110
return &rsa_asn1_meth;
106111
}
107112

108113
// The pkey_id for the pqdsa_asn1_meth is EVP_PKEY_PQDSA, as this holds all
109114
// asn1 functions for pqdsa types. However, the incoming CBS has the OID for
110115
// the specific algorithm. So we must search explicitly for the algorithm.
111-
const EVP_PKEY_ASN1_METHOD *pqdsa_method = PQDSA_find_asn1_by_nid(OBJ_cbs2nid(&oid));
116+
const EVP_PKEY_ASN1_METHOD *pqdsa_method = PQDSA_find_asn1_by_nid(nid);
112117
if (pqdsa_method != NULL) {
113118
return pqdsa_method;
114119
}
115-
return KEM_find_asn1_by_nid(OBJ_cbs2nid(&oid));
120+
return KEM_find_asn1_by_nid(nid);
116121
}
117122

118123
EVP_PKEY *EVP_parse_public_key(CBS *cbs) {

crypto/x509/x509_test.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6284,6 +6284,42 @@ TEST(X509Test, ITUT_X509_nid_rsa) {
62846284
EXPECT_TRUE(rsa);
62856285
}
62866286

6287+
// kRsaesOaepCertPEM is a TPM 1.2 EK certificate with |NID_rsaesOaep| SPKI.
6288+
static const char kRsaesOaepCertPEM[] = R"(
6289+
-----BEGIN CERTIFICATE-----
6290+
MIIDhDCCAmygAwIBAgIUBchBXcXPAWxNMJEsLXEXHv/eVZswDQYJKoZIhvcNAQEL
6291+
BQAwVTELMAkGA1UEBhMCQ0gxHjAcBgNVBAoTFVNUTWljcm9lbGVjdHJvbmljcyBO
6292+
VjEmMCQGA1UEAxMdU1RNIFRQTSBFSyBJbnRlcm1lZGlhdGUgQ0EgMDIwHhcNMjEw
6293+
OTA0MDAwMDAwWhcNMzEwOTA0MDAwMDAwWjAAMIIBNzAiBgkqhkiG9w0BAQcwFaIT
6294+
MBEGCSqGSIb3DQEBCQQEVENQQQOCAQ8AMIIBCgKCAQEAxpd3DnecpD87acEsYp4J
6295+
stM2q5Ss3CkjAP2Ei8yGjbO6DG/6WBIZjTdI5RfIcInoqN4QMso94vm8VqijdRI+
6296+
Zo5hLTCPLKXYwa6UG5yIPZ3ENQdhgZWeEPWe+pp9VUwz8wi78Ifk+CCV6Xp/5kQi
6297+
DCsR+RYbOVb9QgR6kjq+cx1z8YFp5u+k3Pl9tMq9xgIp5E6hT2MaS12KnoN8+hYI
6298+
mfCYVnpzBeQaHDp1KUoyDK6xGt86VxB0QyRbniHI38qgQL6qhO7z96aQ0pNGoQde
6299+
QUxFf/sETurQ5zSf+3btnS8afjxdVBKzj3isv5BaQrt0mdB7+3XWD+ASda33SY12
6300+
6wIDAQABo4GLMIGIMB8GA1UdIwQYMBaAFFcfgGtHzOeb+jWUfO2IuNEAWuCeMEIG
6301+
A1UdIAQ7MDkwNwYEVR0gADAvMC0GCCsGAQUFBwIBFiFodHRwOi8vd3d3LnN0LmNv
6302+
bS9UUE0vcmVwb3NpdG9yeS8wDAYDVR0TAQH/BAIwADATBgNVHSUBAf8ECTAHBgVn
6303+
gQUIATANBgkqhkiG9w0BAQsFAAOCAQEAMOhFPNcebyCRFOBztlWhmDb2DHTCD0nC
6304+
DVobH4WZJXGf4bkYNO3mOLyWtHEVzb36kiq7enh3f/eGhDPwKB8axlozpR5KAvER
6305+
szKNO8iLGOjuYzI2A4DazkttczFfzSB9QDgJrwTNEfIJtwRm2HQSiL0zzuEQOnaS
6306+
UWyt/iKn4/34BjEeaw4/Ld7+f06LXqSr18SUr0LTB2kk+Zzf0Och1C+G1CNLgJMM
6307+
MNQikAv0xdaOMX3HzA+phFlLbw/x8sboMlzmrbr92a/4Fp5WvmOSHH3ciwTtbAQn
6308+
A2TfExNOaKD2BG5FnB7c66puw2/yVxhveocQYgmT9XtMrNX00vEZJQ==
6309+
-----END CERTIFICATE-----
6310+
)";
6311+
6312+
TEST(X509Test, RsaesOaepSPKI) {
6313+
bssl::UniquePtr<X509> cert(CertFromPEM(kRsaesOaepCertPEM));
6314+
ASSERT_TRUE(cert);
6315+
6316+
bssl::UniquePtr<EVP_PKEY> evp_pkey(X509_get_pubkey(cert.get()));
6317+
EXPECT_TRUE(evp_pkey);
6318+
6319+
bssl::UniquePtr<RSA> rsa(EVP_PKEY_get1_RSA(evp_pkey.get()));
6320+
EXPECT_TRUE(rsa);
6321+
}
6322+
62876323
// kLargeSerialPEM is a certificate with a large serial number.
62886324
static const char kLargeSerialPEM[] = R"(
62896325
-----BEGIN CERTIFICATE-----

0 commit comments

Comments
 (0)