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
31 changes: 31 additions & 0 deletions src/crl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,37 @@ static CRL_Entry* DupCRL_Entry(const CRL_Entry* ent, void* heap)
CRL_Entry_free(dupl, heap);
return NULL;
}
#elif defined(OPENSSL_EXTRA)
{
int i;

/* certs is an in-struct array living after verifyMutex, so the bulk
* copy above aliased every extensions pointer with the original's.
* Cleaning the whole array first. */
for (i = 0; i < CRL_MAX_REVOKED_CERTS; i++) {
dupl->certs[i].extensions = NULL;
dupl->certs[i].extensionsSz = 0;
}

/* Deep copy the entry extensions, as DupRevokedCertList() does for the
* linked-list build. */
for (i = 0; i < ent->totalCerts; i++) {
if (ent->certs[i].extensions == NULL ||
ent->certs[i].extensionsSz == 0) {
continue;
}
dupl->certs[i].extensions = (byte*)XMALLOC(
ent->certs[i].extensionsSz, heap, DYNAMIC_TYPE_REVOKED);
if (dupl->certs[i].extensions == NULL) {
WOLFSSL_MSG("Failed to allocate revoked cert extensions");
CRL_Entry_free(dupl, heap);
return NULL;
}
XMEMCPY(dupl->certs[i].extensions, ent->certs[i].extensions,
ent->certs[i].extensionsSz);
dupl->certs[i].extensionsSz = ent->certs[i].extensionsSz;
}
}
#endif
#ifdef OPENSSL_EXTRA
dupl->issuer = wolfSSL_X509_NAME_dup(ent->issuer);
Expand Down
49 changes: 49 additions & 0 deletions tests/api/test_certman.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#endif

#include <wolfssl/ssl.h>
#include <wolfssl/internal.h>
#include <wolfssl/ocsp.h>
#include <tests/api/api.h>
#include <tests/api/test_certman.h>
Expand Down Expand Up @@ -2602,6 +2603,54 @@ int test_wolfSSL_CRL_static_revoked_list(void)
return EXPECT_RESULT();
}

int test_wolfSSL_CRL_static_revoked_list_dup(void)
{
EXPECT_DECLS;
#if defined(CRL_STATIC_REVOKED_LIST) && defined(HAVE_CRL) && \
defined(OPENSSL_EXTRA) && !defined(NO_RSA) && !defined(NO_CERTS) && \
defined(WOLFSSL_PEM_TO_DER) && !defined(NO_FILESYSTEM) && \
!defined(NO_STDIO_FILESYSTEM)
/* certs/crl/crl_reason.pem revokes serial 01 and carries a
* crlEntryExtensions (CRL Reason Code) for that entry.
* Under OPENSSL_EXTRA GetRevoked() heap-allocates
* RevokedCert.extensions to hold the raw DER of those extensions. */
const char* crlReasonFile = "./certs/crl/crl_reason.pem";
XFILE fp = XBADFILE;
WOLFSSL_X509_CRL* crl = NULL;
WOLFSSL_X509_CRL* dupl = NULL;

ExpectTrue((fp = XFOPEN(crlReasonFile, "rb")) != XBADFILE);
ExpectNotNull(crl = wolfSSL_PEM_read_X509_CRL(fp, NULL, NULL, NULL));
if (fp != XBADFILE)
XFCLOSE(fp);

ExpectNotNull(crl != NULL ? crl->crlList : NULL);
ExpectIntGT((crl != NULL && crl->crlList != NULL) ?
crl->crlList->totalCerts : 0, 0);
ExpectNotNull((crl != NULL && crl->crlList != NULL) ?
crl->crlList->certs[0].extensions : NULL);

ExpectNotNull(dupl = wolfSSL_X509_CRL_dup(crl));

/* Every duplicated revoked cert must own its own extensions buffer. This
* fails when the bulk copy aliased them. */
if (crl != NULL && dupl != NULL && crl->crlList != NULL &&
dupl->crlList != NULL) {
int i;
for (i = 0; i < crl->crlList->totalCerts; i++) {
if (crl->crlList->certs[i].extensions != NULL) {
ExpectPtrNE(dupl->crlList->certs[i].extensions,
crl->crlList->certs[i].extensions);
}
}
}

wolfSSL_X509_CRL_free(dupl);
wolfSSL_X509_CRL_free(crl);
#endif
return EXPECT_RESULT();
}

int test_wolfSSL_CRL_duplicate_extensions(void)
{
EXPECT_DECLS;
Expand Down
2 changes: 2 additions & 0 deletions tests/api/test_certman.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ int test_wolfSSL_X509_check_host_URI_SAN_not_DNS_match(void);
int test_wolfSSL_CertManagerCRL(void);
int test_wolfSSL_CRL_reason_extensions_cleanup(void);
int test_wolfSSL_CRL_static_revoked_list(void);
int test_wolfSSL_CRL_static_revoked_list_dup(void);
int test_wolfSSL_CRL_duplicate_extensions(void);
int test_wolfSSL_CRL_critical_idp(void);
int test_wolfSSL_CRL_unknown_critical_ext(void);
Expand Down Expand Up @@ -82,6 +83,7 @@ int test_wolfSSL_CertManagerNameConstraint_skid_disambiguates(void);
TEST_DECL_GROUP("certman", test_wolfSSL_CertManagerCRL), \
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_reason_extensions_cleanup), \
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_static_revoked_list), \
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_static_revoked_list_dup), \
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_duplicate_extensions), \
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_critical_idp), \
TEST_DECL_GROUP("certman", test_wolfSSL_CRL_unknown_critical_ext), \
Expand Down
Loading