Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
590 changes: 389 additions & 201 deletions src/crl.c

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -18613,15 +18613,29 @@ static int ProcessPeerCertsChainOCSPStatusCheck(WOLFSSL* ssl)
static int ProcessPeerCertsChainCRLCheck(WOLFSSL* ssl, ProcPeerCertArgs* args)
{
Signer* prev = NULL;
Signer* prevPrev = NULL;
int ret = 0;
WOLFSSL_CERT_MANAGER* cm = SSL_CM(ssl);
Signer* ca = args->dCert->ca;
/* End loop if no more issuers found or if we have
* found a self signed cert (ca == prev) */
for (; ret == 0 && ca != NULL && ca != prev;
prev = ca, ca = GetCAByName(cm, ca->issuerNameHash)) {
word32 depth = 0;
/* Walk up the chain checking each CA against its issuer's CRL. */
for (; ret == 0 && ca != NULL && ca != prev && ca != prevPrev;
prevPrev = prev, prev = ca,
ca = FindSignerByAkidOrName(cm, NULL, ca)) {
/* ca's AKID identifies the key that signed ca, which picks out that
* key's CRL when the issuer has several keys under one name. */
byte* caAkid = NULL;

if (++depth > WOLFSSL_MAX_CHAIN_DEPTH) {
ret = ASN_PATHLEN_SIZE_E;
break;
}
#ifndef NO_SKID
if (ca->authKeyIdSet)
caAkid = ca->authKeyIdHash;
#endif
ret = CheckCertCRL_ex(cm->crl, ca->issuerNameHash, NULL, 0,
ca->serialHash, NULL, 0, NULL);
ca->serialHash, NULL, 0, NULL, caAkid);
#ifdef WOLFSSL_NONBLOCK_OCSP
if (ret == WC_NO_ERR_TRACE(OCSP_WANT_READ))
break;
Expand Down
3 changes: 2 additions & 1 deletion src/wolfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,8 @@ int wolfIO_HttpProcessResponseCrl(WOLFSSL_CRL* crl, int sfd, byte* httpBuf,
ret = wolfIO_HttpProcessResponse(sfd, appStrList,
&respBuf, httpBuf, httpBufSz, DYNAMIC_TYPE_CRL, crl->heap);
if (ret >= 0) {
ret = BufferLoadCRL(crl, respBuf, ret, WOLFSSL_FILETYPE_ASN1, 0);
ret = BufferLoadCRL(crl, respBuf, ret, WOLFSSL_FILETYPE_ASN1,
VERIFY_SKIP_DATE);
Comment thread
aidankeefe2022 marked this conversation as resolved.
Resolved
}
XFREE(respBuf, crl->heap, DYNAMIC_TYPE_CRL);

Expand Down
343 changes: 340 additions & 3 deletions tests/api/test_certman.c

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/api/test_certman.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ int test_wolfSSL_CRL_unknown_ext_cb_positive_return_fails_load(void);
int test_wolfSSL_CRL_unknown_ext_cb_noctx(void);
int test_wolfSSL_CRL_cross_ca_akid(void);
int test_wolfSSL_CRL_unverified_no_evict(void);
int test_wolfSSL_CRL_same_name_key_rollover(void);
int test_wolfSSL_cert_critical_policy_constraints(void);
int test_wolfSSL_CRL_unknown_ext_cb_32_preferred(void);
int test_wolfSSL_CertManagerCheckOCSPResponse(void);
Expand Down Expand Up @@ -108,6 +109,7 @@ int test_wolfSSL_trust_peer_cert_dates(void);
test_wolfSSL_CRL_unknown_ext_cb_noctx), \
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_cross_ca_akid), \
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_unverified_no_evict), \
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_same_name_key_rollover), \
TEST_DECL_GROUP("certman", test_wolfSSL_cert_critical_policy_constraints), \
TEST_DECL_GROUP("certman", \
test_wolfSSL_CRL_unknown_ext_cb_32_preferred), \
Expand Down
18 changes: 9 additions & 9 deletions tests/unit-mcdc/test_crl_whitebox.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ static void wb_check_cert_crl_ex(WOLFSSL_CERT_MANAGER* cm)
XMEMSET(issuerHash, 0x22, sizeof(issuerHash));

WB_NOTE(CheckCertCRLCm(cm->crl, issuerHash, NULL, (int)sizeof(serial),
hash, NULL, 0, NULL, cm, 1));
hash, NULL, 0, NULL, cm, 1, NULL));
WB_NOTE(CheckCertCRLCm(cm->crl, issuerHash, NULL, (int)sizeof(serial),
NULL, NULL, 0, NULL, cm, 1));
NULL, NULL, 0, NULL, cm, 1, NULL));
WB_NOTE(CheckCertCRLCm(cm->crl, issuerHash, serial, 0,
NULL, NULL, 0, NULL, cm, 1));
NULL, NULL, 0, NULL, cm, 1, NULL));
WB_NOTE(CheckCertCRLCm(cm->crl, issuerHash, serial, (int)sizeof(serial),
NULL, NULL, 0, NULL, cm, 1));
NULL, NULL, 0, NULL, cm, 1, NULL));
}


Expand Down Expand Up @@ -154,14 +154,14 @@ static void wb_missing_crl_callbacks(WOLFSSL_CERT_MANAGER* cm)
/* 1. cm NULL: operand 0 false for both decisions. */
WB_NOTE(CheckCertCRLCm(cm->crl, issuerHash, serial, (int)sizeof(serial),
NULL, (const byte*)url, (int)XSTRLEN(url), NULL,
NULL, 1));
NULL, 1, NULL));

/* 2. real cm, no callbacks: operand 0 true, operand 1 false. */
cm->cbMissingCRL = NULL;
cm->crlCb = NULL;
WB_NOTE(CheckCertCRLCm(cm->crl, issuerHash, serial, (int)sizeof(serial),
NULL, (const byte*)url, (int)XSTRLEN(url), NULL,
cm, 1));
cm, 1, NULL));

/* 3. both callbacks installed, error cb returns 0: takes :668 TRUE (the
* partner that gives operands 0 and 1 their pairs) and :686 to its third
Expand All @@ -171,14 +171,14 @@ static void wb_missing_crl_callbacks(WOLFSSL_CERT_MANAGER* cm)
g_crlCbResult = 0;
WB_NOTE(CheckCertCRLCm(cm->crl, issuerHash, serial, (int)sizeof(serial),
NULL, (const byte*)url, (int)XSTRLEN(url), NULL,
cm, 1));
cm, 1, NULL));

/* 4. error cb returns non-zero: :686 operand 2 true, decision TRUE, which
* is the override-the-CRL-error path. */
g_crlCbResult = 1;
WB_NOTE(CheckCertCRLCm(cm->crl, issuerHash, serial, (int)sizeof(serial),
NULL, (const byte*)url, (int)XSTRLEN(url), NULL,
cm, 1));
cm, 1, NULL));

/* 5. a url longer than the 256-byte stack buffer takes the "CRL url too
* long" arm of the copy guard inside the :668 body, which the short url
Expand All @@ -189,7 +189,7 @@ static void wb_missing_crl_callbacks(WOLFSSL_CERT_MANAGER* cm)
longUrl[sizeof(longUrl) - 1] = '\0';
WB_NOTE(CheckCertCRLCm(cm->crl, issuerHash, serial,
(int)sizeof(serial), NULL, (const byte*)longUrl,
(int)sizeof(longUrl) - 1, NULL, cm, 1));
(int)sizeof(longUrl) - 1, NULL, cm, 1, NULL));
}

cm->cbMissingCRL = NULL;
Expand Down
7 changes: 4 additions & 3 deletions tests/unit-mcdc/test_internal_revocation_whitebox.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ static int mcdc_CheckCertCRL(WOLFSSL_CRL* crl, DecodedCert* cert)
* answer. */
static int mcdc_CheckCertCRL_ex(WOLFSSL_CRL* crl, byte* issuerHash,
byte* serial, int serialSz, byte* serialHash, const byte* extCrlInfo,
int extCrlInfoSz, void* issuerName)
int extCrlInfoSz, void* issuerName, byte* akid)
{
(void)crl; (void)issuerHash; (void)serial; (void)serialSz;
(void)serialHash; (void)extCrlInfo; (void)extCrlInfoSz; (void)issuerName;
(void)akid;
g_crlCalls++;
return g_crlRet;
}
Expand All @@ -121,8 +122,8 @@ static int mcdc_CheckCertCRL_ex(WOLFSSL_CRL* crl, byte* issuerHash,
#endif
#ifdef HAVE_CRL
#define CheckCertCRL(a, b) mcdc_CheckCertCRL((a), (b))
#define CheckCertCRL_ex(a, b, c, d, e, f, g, h) \
mcdc_CheckCertCRL_ex((a), (b), (c), (d), (e), (f), (g), (h))
#define CheckCertCRL_ex(a, b, c, d, e, f, g, h, i) \
mcdc_CheckCertCRL_ex((a), (b), (c), (d), (e), (f), (g), (h), (i))
#endif

#include <src/internal.c>
Expand Down
11 changes: 7 additions & 4 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -25876,11 +25876,11 @@ Signer* findSignerByName(Signer *list, byte *hash)
return NULL;
}

#ifndef IGNORE_NAME_CONSTRAINTS
#if !defined(IGNORE_NAME_CONSTRAINTS) || defined(HAVE_CRL)
/* Find a signer for cert in cm and extraCAList. Prefers AKID->SKID
* with name-hash validation. Fall back to name-only when AKID is
* absent. */
static Signer* FindSignerByAkidOrName(WOLFSSL_CERT_MANAGER* cm,
Signer* FindSignerByAkidOrName(WOLFSSL_CERT_MANAGER* cm,
Signer* extraCAList, Signer* cert)
{
Signer* signer = NULL;
Expand All @@ -25892,6 +25892,9 @@ static Signer* FindSignerByAkidOrName(WOLFSSL_CERT_MANAGER* cm,
(void)extraCAList;
#endif

if (cert->selfSigned == 1)
return cert;

#ifndef NO_SKID
if (cert->authKeyIdSet) {
signer = GetCA(cm, cert->authKeyIdHash);
Expand Down Expand Up @@ -25939,7 +25942,7 @@ static Signer* FindSignerByAkidOrName(WOLFSSL_CERT_MANAGER* cm,

return signer;
}
#endif /* !IGNORE_NAME_CONSTRAINTS */
#endif /* !IGNORE_NAME_CONSTRAINTS || HAVE_CRL */

#ifdef WOLFSSL_DUAL_ALG_CERTS
/* Build the PreTBS used to verify an alternative signature, allocating the
Expand Down Expand Up @@ -27002,7 +27005,7 @@ int FillSigner(Signer* signer, DecodedCert* cert, int type, DerBuffer *der)
#ifndef NO_SKID
XMEMCPY(signer->subjectKeyIdHash, cert->extSubjKeyId,
SIGNER_DIGEST_SIZE);
#ifndef IGNORE_NAME_CONSTRAINTS
#if !defined(IGNORE_NAME_CONSTRAINTS) || defined(HAVE_CRL)
if (cert->extAuthKeyIdSet) {
XMEMCPY(signer->authKeyIdHash, cert->extAuthKeyId,
SIGNER_DIGEST_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion wolfssl/crl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ WOLFSSL_LOCAL int BufferStoreCRL(WOLFSSL_CRL* crl, byte* buff, long* inOutSz,
WOLFSSL_LOCAL int CheckCertCRL(WOLFSSL_CRL* crl, DecodedCert* cert);
WOLFSSL_LOCAL int CheckCertCRL_ex(WOLFSSL_CRL* crl, byte* issuerHash,
byte* serial, int serialSz, byte* serialHash, const byte* extCrlInfo,
int extCrlInfoSz, void* issuerName);
int extCrlInfoSz, void* issuerName, byte* akid);
WOLFSSL_LOCAL int CheckCertCRLFromCm(WOLFSSL_CERT_MANAGER* cm,
WOLFSSL_CRL* crl, DecodedCert* cert);
#ifdef HAVE_CRL_UPDATE_CB
Expand Down
15 changes: 11 additions & 4 deletions wolfssl/wolfcrypt/asn.h
Original file line number Diff line number Diff line change
Expand Up @@ -2393,10 +2393,11 @@ struct Signer {
*/
WC_BITFIELD extNameConstraintCrit:1;
WC_BITFIELD extNameConstraintHasUnsupported:1;
#ifndef NO_SKID
#endif
#if !defined(NO_SKID) && \
(!defined(IGNORE_NAME_CONSTRAINTS) || defined(HAVE_CRL))
WC_BITFIELD authKeyIdSet:1; /* true when authKeyIdHash holds the
* AKID extension's keyId */
#endif
#endif
const byte* publicKey;
int nameLen;
Expand All @@ -2417,10 +2418,11 @@ struct Signer {
#ifndef NO_SKID
byte subjectKeyIdHash[SIGNER_DIGEST_SIZE];
/* sha hash of key in certificate */
#ifndef IGNORE_NAME_CONSTRAINTS
#if !defined(IGNORE_NAME_CONSTRAINTS) || defined(HAVE_CRL)
byte authKeyIdHash[SIGNER_DIGEST_SIZE];
/* sha hash of AKID; locates signer
* during name-constraint walk */
* during name-constraint and CRL
* issuer walks */
#endif
#endif
#ifdef HAVE_OCSP
Expand Down Expand Up @@ -2683,6 +2685,11 @@ WOLFSSL_LOCAL int wc_GetPubX509(DecodedCert* cert, int verify, int* badDate);
WOLFSSL_LOCAL const byte* OidFromId(word32 id, word32 type, word32* oidSz);
WOLFSSL_LOCAL Signer* findSignerByKeyHash(Signer *list, byte *hash);
WOLFSSL_LOCAL Signer* findSignerByName(Signer *list, byte *hash);
#if !defined(IGNORE_NAME_CONSTRAINTS) || defined(HAVE_CRL)
WOLFSSL_LOCAL Signer* FindSignerByAkidOrName(WOLFSSL_CERT_MANAGER* cm,
Signer* extraCAList,
Signer* cert);
#endif
WOLFSSL_TEST_VIS int FillSigner(Signer* signer, DecodedCert* cert, int type, DerBuffer *der);
WOLFSSL_TEST_VIS Signer* MakeSigner(void* heap);
WOLFSSL_TEST_VIS void FreeSigner(Signer* signer, void* heap);
Expand Down
Loading