@@ -104,6 +104,9 @@ ASN Options:
104104 * DO NOT enable this unless required for interoperability.
105105 * WOLFSSL_ASN_EXTRA: Make more ASN.1 APIs available regardless of internal
106106 * usage.
107+ * WOLFSSL_ALLOW_AKID_SKID_MATCH: By default cert issuer is found using hash
108+ * of cert subject hash with signers subject hash. This option allows fallback
109+ * to using AKID and SKID matching.
107110*/
108111
109112#ifndef NO_RSA
@@ -21339,42 +21342,25 @@ static int DecodeAuthKeyIdInternal(const byte* input, word32 sz,
2133921342 ret = DecodeAuthKeyId(input, sz, &extAuthKeyId, &extAuthKeyIdSz,
2134021343 &extAuthKeyIdIssuer, &extAuthKeyIdIssuerSz, &extAuthKeyIdIssuerSN,
2134121344 &extAuthKeyIdIssuerSNSz);
21342-
21343- if (ret != 0)
21344- return ret;
21345-
21346- #ifndef WOLFSSL_ASN_TEMPLATE
21347-
21348- if (extAuthKeyIdSz == 0)
21349- {
21345+ if (ret != 0) {
2135021346 cert->extAuthKeyIdSet = 0;
21351- return 0 ;
21347+ return ret ;
2135221348 }
2135321349
21354- cert->extAuthKeyIdSz = extAuthKeyIdSz;
21350+ /* Each field is optional */
21351+ if (extAuthKeyIdSz > 0) {
21352+ cert->extAuthKeyIdSet = 1;
21353+ cert->extAuthKeyIdSz = extAuthKeyIdSz;
2135521354
2135621355#if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)
21357- #ifdef WOLFSSL_AKID_NAME
21358- cert->extRawAuthKeyIdSrc = input;
21359- cert->extRawAuthKeyIdSz = sz;
21356+ cert->extAuthKeyIdSrc = extAuthKeyId;
2136021357#endif
21361- cert->extAuthKeyIdSrc = extAuthKeyId;
21362- #endif /* OPENSSL_EXTRA */
21363-
21364- return GetHashId(extAuthKeyId, extAuthKeyIdSz, cert->extAuthKeyId,
21365- HashIdAlg(cert->signatureOID));
21366- #else
2136721358
21368- /* Each field is optional */
21369- if (extAuthKeyIdSz > 0) {
21370- #ifdef OPENSSL_EXTRA
21371- cert->extAuthKeyIdSrc = extAuthKeyId;
21372- cert->extAuthKeyIdSz = extAuthKeyIdSz;
21373- #endif /* OPENSSL_EXTRA */
2137421359 /* Get the hash or hash of the hash if wrong size. */
2137521360 ret = GetHashId(extAuthKeyId, (int)extAuthKeyIdSz, cert->extAuthKeyId,
2137621361 HashIdAlg(cert->signatureOID));
2137721362 }
21363+
2137821364#ifdef WOLFSSL_AKID_NAME
2137921365 if (ret == 0 && extAuthKeyIdIssuerSz > 0) {
2138021366 cert->extAuthKeyIdIssuer = extAuthKeyIdIssuer;
@@ -21386,15 +21372,15 @@ static int DecodeAuthKeyIdInternal(const byte* input, word32 sz,
2138621372 }
2138721373#endif /* WOLFSSL_AKID_NAME */
2138821374 if (ret == 0) {
21389- #if defined(OPENSSL_EXTRA) && defined(WOLFSSL_AKID_NAME)
21375+ #if (defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL)) && \
21376+ defined(WOLFSSL_AKID_NAME)
2139021377 /* Store the raw authority key id. */
2139121378 cert->extRawAuthKeyIdSrc = input;
2139221379 cert->extRawAuthKeyIdSz = sz;
21393- #endif /* OPENSSL_EXTRA */
21380+ #endif
2139421381 }
2139521382
2139621383 return ret;
21397- #endif /* WOLFSSL_ASN_TEMPLATE */
2139821384}
2139921385
2140021386/* Decode subject key id extension.
@@ -25723,7 +25709,22 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
2572325709 }
2572425710 if (cert->ca != NULL && XMEMCMP(cert->issuerHash,
2572525711 cert->ca->subjectNameHash, KEYID_SIZE) != 0) {
25726- cert->ca = NULL;
25712+ #ifdef WOLFSSL_ALLOW_AKID_SKID_MATCH
25713+ /* if hash of cert subject does not match hash of issuer
25714+ * then try with AKID/SKID if available */
25715+ if (cert->extAuthKeyIdSet && cert->extAuthKeyIdSz > 0 &&
25716+ cert->extAuthKeyIdSz ==
25717+ (word32)sizeof(cert->ca->subjectKeyIdHash) &&
25718+ XMEMCMP(cert->extAuthKeyId, cert->ca->subjectKeyIdHash,
25719+ cert->extAuthKeyIdSz) == 0) {
25720+ WOLFSSL_MSG("Cert AKID matches CA SKID");
25721+ }
25722+ else
25723+ #endif
25724+ {
25725+ WOLFSSL_MSG("Cert subject hash does not match issuer hash");
25726+ cert->ca = NULL;
25727+ }
2572725728 }
2572825729 if (cert->ca == NULL) {
2572925730 cert->ca = GetCAByName(cm, cert->issuerHash);
0 commit comments