Skip to content

Commit 1cb2231

Browse files
committed
Added build option to allow certificate CA matching using AKID with signers SKID ( WOLFSSL_ALLOW_AKID_SKID_MATCH). Fixed issue with cert->extAuthKeyIdSz not being set with ASN template code.
1 parent d26c11c commit 1cb2231

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ WOLFSSL_AESNI_BY6
653653
WOLFSSL_AES_CTR_EXAMPLE
654654
WOLFSSL_AFTER_DATE_CLOCK_SKEW
655655
WOLFSSL_ALGO_HW_MUTEX
656+
WOLFSSL_ALLOW_AKID_SKID_MATCH
656657
WOLFSSL_ALLOW_BAD_TLS_LEGACY_VERSION
657658
WOLFSSL_ALLOW_CRIT_AIA
658659
WOLFSSL_ALLOW_CRIT_AKID

wolfcrypt/src/asn.c

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

wolfssl/wolfcrypt/asn.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,24 +1952,24 @@ struct Signer {
19521952
int nameLen;
19531953
char* name; /* common name */
19541954
#ifndef IGNORE_NAME_CONSTRAINTS
1955-
Base_entry* permittedNames;
1956-
Base_entry* excludedNames;
1957-
#endif /* !IGNORE_NAME_CONSTRAINTS */
1955+
Base_entry* permittedNames;
1956+
Base_entry* excludedNames;
1957+
#endif
19581958
byte subjectNameHash[SIGNER_DIGEST_SIZE];
19591959
/* sha hash of names in certificate */
1960-
#if defined(HAVE_OCSP) || defined(HAVE_CRL) || defined(WOLFSSL_AKID_NAME)
1961-
byte issuerNameHash[SIGNER_DIGEST_SIZE];
1962-
/* sha hash of issuer names in certificate.
1963-
* Used in OCSP to check for authorized
1964-
* responders. */
1965-
#endif
1966-
#ifndef NO_SKID
1967-
byte subjectKeyIdHash[SIGNER_DIGEST_SIZE];
1968-
/* sha hash of key in certificate */
1969-
#endif
1970-
#ifdef HAVE_OCSP
1971-
byte subjectKeyHash[KEYID_SIZE];
1972-
#endif
1960+
#if defined(HAVE_OCSP) || defined(HAVE_CRL) || defined(WOLFSSL_AKID_NAME)
1961+
byte issuerNameHash[SIGNER_DIGEST_SIZE];
1962+
/* sha hash of issuer names in certificate.
1963+
* Used in OCSP to check for authorized
1964+
* responders. */
1965+
#endif
1966+
#ifndef NO_SKID
1967+
byte subjectKeyIdHash[SIGNER_DIGEST_SIZE];
1968+
/* sha hash of key in certificate */
1969+
#endif
1970+
#ifdef HAVE_OCSP
1971+
byte subjectKeyHash[KEYID_SIZE];
1972+
#endif
19731973
#if defined(WOLFSSL_AKID_NAME) || defined(HAVE_CRL)
19741974
byte serialHash[SIGNER_DIGEST_SIZE]; /* serial number hash */
19751975
#endif

0 commit comments

Comments
 (0)