Skip to content

Commit 17c9e92

Browse files
ColtonWilleydouzzer
authored andcommitted
Initial rewrite of X509 STORE to replicate openssl behavior
1 parent 8227309 commit 17c9e92

6 files changed

Lines changed: 818 additions & 97 deletions

File tree

src/ssl_certman.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,12 @@ int wolfSSL_CertManagerUnloadCAs(WOLFSSL_CERT_MANAGER* cm)
455455
return ret;
456456
}
457457

458-
int wolfSSL_CertManagerUnloadIntermediateCerts(WOLFSSL_CERT_MANAGER* cm)
458+
static int wolfSSL_CertManagerUnloadIntermediateCertsEx(WOLFSSL_CERT_MANAGER* cm,
459+
int type)
459460
{
460461
int ret = WOLFSSL_SUCCESS;
461462

462-
WOLFSSL_ENTER("wolfSSL_CertManagerUnloadIntermediateCerts");
463+
WOLFSSL_ENTER("wolfSSL_CertManagerUnloadIntermediateCertsEx");
463464

464465
/* Validate parameter. */
465466
if (cm == NULL) {
@@ -471,7 +472,7 @@ int wolfSSL_CertManagerUnloadIntermediateCerts(WOLFSSL_CERT_MANAGER* cm)
471472
}
472473
if (ret == WOLFSSL_SUCCESS) {
473474
/* Dispose of CA table. */
474-
FreeSignerTableType(cm->caTable, CA_TABLE_SIZE, WOLFSSL_CHAIN_CA,
475+
FreeSignerTableType(cm->caTable, CA_TABLE_SIZE, type,
475476
cm->heap);
476477

477478
/* Unlock CA table. */
@@ -481,6 +482,20 @@ int wolfSSL_CertManagerUnloadIntermediateCerts(WOLFSSL_CERT_MANAGER* cm)
481482
return ret;
482483
}
483484

485+
#if defined(OPENSSL_EXTRA)
486+
static int wolfSSL_CertManagerUnloadTempIntermediateCerts(WOLFSSL_CERT_MANAGER* cm)
487+
{
488+
WOLFSSL_ENTER("wolfSSL_CertManagerUnloadTempIntermediateCerts");
489+
return wolfSSL_CertManagerUnloadIntermediateCertsEx(cm, WOLFSSL_INTER_CA);
490+
}
491+
#endif
492+
493+
int wolfSSL_CertManagerUnloadIntermediateCerts(WOLFSSL_CERT_MANAGER* cm)
494+
{
495+
WOLFSSL_ENTER("wolfSSL_CertManagerUnloadIntermediateCerts");
496+
return wolfSSL_CertManagerUnloadIntermediateCertsEx(cm, WOLFSSL_CHAIN_CA);
497+
}
498+
484499
#ifdef WOLFSSL_TRUST_PEER_CERT
485500
/* Unload the trusted peers table.
486501
*

src/x509.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5559,7 +5559,7 @@ WOLFSSL_EVP_PKEY* wolfSSL_X509_get_pubkey(WOLFSSL_X509* x509)
55595559
* size of this subset and its memory usage */
55605560
#endif /* OPENSSL_EXTRA_X509_SMALL || KEEP_PEER_CERT || SESSION_CERTS */
55615561

5562-
#if defined(OPENSSL_ALL)
5562+
#if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA)
55635563
/*
55645564
* Converts a and b to DER and then does an XMEMCMP to check if they match.
55655565
* Returns 0 when certificates match and WOLFSSL_FATAL_ERROR when they don't.
@@ -7536,7 +7536,6 @@ int wolfSSL_X509_LOOKUP_load_file(WOLFSSL_X509_LOOKUP* lookup,
75367536
byte* pem = NULL;
75377537
byte* curr = NULL;
75387538
byte* prev = NULL;
7539-
WOLFSSL_X509* x509;
75407539
const char* header = NULL;
75417540
const char* footer = NULL;
75427541

@@ -7597,12 +7596,8 @@ int wolfSSL_X509_LOOKUP_load_file(WOLFSSL_X509_LOOKUP* lookup,
75977596
}
75987597
else if (wc_PemGetHeaderFooter(CERT_TYPE, &header, &footer) == 0 &&
75997598
XSTRNSTR((char*)curr, header, (unsigned int)sz) != NULL) {
7600-
x509 = wolfSSL_X509_load_certificate_buffer(curr, (int)sz,
7601-
WOLFSSL_FILETYPE_PEM);
7602-
if (x509 == NULL)
7603-
goto end;
7604-
ret = wolfSSL_X509_STORE_add_cert(lookup->store, x509);
7605-
wolfSSL_X509_free(x509);
7599+
ret = wolfSSL_X509_STORE_load_cert_buffer(lookup->store, curr, sz,
7600+
WOLFSSL_FILETYPE_PEM);
76067601
if (ret != WOLFSSL_SUCCESS)
76077602
goto end;
76087603
curr = (byte*)XSTRNSTR((char*)curr, footer, (unsigned int)sz);

0 commit comments

Comments
 (0)