Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
332 changes: 223 additions & 109 deletions src/crl.c

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -18477,18 +18477,36 @@ static int ProcessPeerCertsChainOCSPStatusCheck(WOLFSSL* ssl)
#endif

#ifdef HAVE_CRL

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 walkIterationCnt = 0;
/* Walk up the chain checking each CA against its issuer's CRL. Stop when:
* - the issuer isn't loaded (ca == NULL),
* - we reach a self-signed root (GetCAIssuer returns ca, so ca == prev),
* - two cross-certified CAs point back at each other (ca == prevPrev).
* Longer loops are stopped by the WOLFSSL_MAX_CHAIN_DEPTH limit. */
for (; ret == 0 && ca != NULL && ca != prev && ca != prevPrev;
prevPrev = prev, prev = ca, ca = GetCAIssuer(cm, 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. */
const byte* caAkid = NULL;

if (++walkIterationCnt > 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
60 changes: 60 additions & 0 deletions src/ssl_certman.c
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,66 @@ Signer* GetCAByName(WOLFSSL_CERT_MANAGER* cm, byte* hash)
}
#endif

#ifdef HAVE_CRL
/* Find the loaded CA that issued ca.
* Returns ca itself if ca is self-signed (a root), or NULL if the issuer is
* not loaded in cm. */
Signer* GetCAIssuer(WOLFSSL_CERT_MANAGER* cm, Signer* ca)
{
Signer* candidateIssuer = NULL;

if (ca->selfSigned)
return ca;

#ifndef NO_SKID
if (ca->authKeyIdSet) {
/* Look the issuer up by key (ca's AKID) */
candidateIssuer = GetCA(cm, ca->authKeyIdHash);
if (candidateIssuer != NULL &&
XMEMCMP(candidateIssuer->subjectNameHash, ca->issuerNameHash,
SIGNER_DIGEST_SIZE) != 0) {
candidateIssuer = NULL;
}
return candidateIssuer;
}
/* No AKID: the issuer name is all there is to go on. */
return GetCAByName(cm, ca->issuerNameHash);
#else
/* No AKID: the issuer name is all there is to go on.
* GetCA uses issuer when NO_SKID is set */
(void)candidateIssuer;
return GetCA(cm, ca->issuerNameHash);
#endif
}

/* Find the trust anchor that ca chains up to in cm.
* Walks issuers with GetCAIssuer() and returns the top of the chain: the first
* CA that is self-signed or whose issuer isn't loaded.
* Returns NULL if ca is NULL, or if no single anchor exists because the chain
* loops or is longer than WOLFSSL_MAX_CHAIN_DEPTH. */
Signer* GetCATrustAnchor(WOLFSSL_CERT_MANAGER* cm, Signer* ca)
{
Signer* prev = NULL;
Signer* issuer;
word32 depth = 0;

while (ca != NULL) {
if (++depth > WOLFSSL_MAX_CHAIN_DEPTH)
return NULL;
issuer = GetCAIssuer(cm, ca);
if (issuer == NULL || issuer == ca)
return ca;
/* Two CAs that issued each other (cross-certified): no anchor.
* Longer loops are caught by the depth limit. */
if (issuer == prev)
return NULL;
prev = ca;
ca = issuer;
}
return NULL;
}
#endif /* HAVE_CRL */

#ifdef WOLFSSL_TRUST_PEER_CERT
/* add a trusted peer cert to linked list */
int AddTrustedPeer(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int verify)
Expand Down
34 changes: 30 additions & 4 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -32037,35 +32037,61 @@ static int test_sk_X509_CRL_encode(void)
defined(HAVE_CRL) && !defined(NO_FILESYSTEM) && \
!defined(NO_STDIO_FILESYSTEM) && defined(WOLFSSL_CERT_GEN) && \
!defined(NO_ASN_TIME)
/* The generated CRLs really revoke server-cert.pem and server-ecc.pem, so
* write them to a private directory, not certs/crl/ where the example
* client loads every CRL and would then reject the test servers. */
char tmpDir[16] = {0};
#ifndef NO_RSA
static const char* crlRsaPemFile = "./certs/crl/crlRsaOut.pem";
static const char* crlRsaDerFile = "./certs/crl/crlRsaOut.der";
char crlRsaPemFile[64] = {0};
char crlRsaDerFile[64] = {0};
static const char* testRsaKeyFile = "./certs/ca-key.pem";
/* Use ca-cert.pem to match ca-key.pem for proper CRL verification */
static const char* testRsaCertFile = "./certs/ca-cert.pem";
static const char* revokeRsaCertFile = "./certs/server-cert.pem";
#endif
#ifdef HAVE_ECC
static const char* crlEccPemFile = "./certs/crl/crlEccOut.pem";
static const char* crlEccDerFile = "./certs/crl/crlEccOut.der";
char crlEccPemFile[64] = {0};
char crlEccDerFile[64] = {0};
static const char* testEccKeyFile = "./certs/ca-ecc-key.pem";
/* Use ca-ecc-cert.pem to match ca-ecc-key.pem for proper CRL
* verification */
static const char* testEccCertFile = "./certs/ca-ecc-cert.pem";
static const char* revokeEccCertFile = "./certs/server-ecc.pem";
#endif

XMEMSET(tmpDir, 0, sizeof(tmpDir));
ExpectNotNull(create_tmp_dir(tmpDir, (int)sizeof(tmpDir) - 1));

#ifndef NO_RSA
ExpectIntGT(XSNPRINTF(crlRsaPemFile, sizeof(crlRsaPemFile),
"%s/crlRsaOut.pem", tmpDir), 0);
ExpectIntGT(XSNPRINTF(crlRsaDerFile, sizeof(crlRsaDerFile),
"%s/crlRsaOut.der", tmpDir), 0);
/* Generate RSA-signed CRL (PEM and DER) */
ExpectIntEQ(generate_crl_test(testRsaKeyFile, testRsaCertFile,
crlRsaDerFile, crlRsaPemFile, revokeRsaCertFile), TEST_SUCCESS);
if (crlRsaPemFile[0] != '\0')
(void)rem_file(crlRsaPemFile);
if (crlRsaDerFile[0] != '\0')
(void)rem_file(crlRsaDerFile);
#endif

#ifdef HAVE_ECC
ExpectIntGT(XSNPRINTF(crlEccPemFile, sizeof(crlEccPemFile),
"%s/crlEccOut.pem", tmpDir), 0);
ExpectIntGT(XSNPRINTF(crlEccDerFile, sizeof(crlEccDerFile),
"%s/crlEccOut.der", tmpDir), 0);
/* Generate ECC-signed CRL (PEM and DER) */
ExpectIntEQ(generate_crl_test(testEccKeyFile, testEccCertFile,
crlEccDerFile, crlEccPemFile, revokeEccCertFile), TEST_SUCCESS);
if (crlEccPemFile[0] != '\0')
(void)rem_file(crlEccPemFile);
if (crlEccDerFile[0] != '\0')
(void)rem_file(crlEccDerFile);
#endif

if (tmpDir[0] != '\0')
(void)rem_dir(tmpDir);
#endif
return EXPECT_RESULT();
}
Expand Down
1 change: 1 addition & 0 deletions tests/api/include.am
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ EXTRA_DIST += tests/api/test_evp_digest.h
EXTRA_DIST += tests/api/test_evp_cipher.h
EXTRA_DIST += tests/api/test_evp_pkey.h
EXTRA_DIST += tests/api/test_certman.h
EXTRA_DIST += tests/api/test_certman_crl_fixtures.h
EXTRA_DIST += tests/api/test_tls13.h
EXTRA_DIST += tests/api/test_tls13_bounds.h
EXTRA_DIST += tests/api/test_tls13_features.h
Expand Down
Loading
Loading