Skip to content

Commit 6eda342

Browse files
committed
In wolfSSL_CTX_set_cert_store, send certificates into the CertMgr
1 parent 5e8d018 commit 6eda342

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

src/ssl.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12904,6 +12904,7 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1290412904

1290512905
void wolfSSL_CTX_set_cert_store(WOLFSSL_CTX* ctx, WOLFSSL_X509_STORE* str)
1290612906
{
12907+
WOLFSSL_X509 *x = NULL;
1290712908
WOLFSSL_ENTER("wolfSSL_CTX_set_cert_store");
1290812909
if (ctx == NULL || str == NULL || ctx->cm == str->cm) {
1290912910
return;
@@ -12920,6 +12921,20 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1292012921
ctx->cm = str->cm;
1292112922
ctx->x509_store.cm = str->cm;
1292212923

12924+
/* wolfSSL_CTX_set_cert_store() (this function) associates str with the
12925+
* wolfSSL_CTX. It is clear that this is a TLS use case which means we
12926+
* should move all the certs, if any, into the CertMgr and set
12927+
* str->certs to NULL as that will allow the certs to be properly
12928+
* processed. */
12929+
if (str->certs != NULL) {
12930+
while (wolfSSL_sk_X509_num(str->certs) > 0) {
12931+
x = wolfSSL_sk_X509_pop(str->certs);
12932+
X509StoreAddCa(str, x, WOLFSSL_USER_CA);
12933+
}
12934+
wolfSSL_sk_X509_pop_free(str->certs, NULL);
12935+
str->certs = NULL;
12936+
}
12937+
1292312938
/* free existing store if it exists */
1292412939
wolfSSL_X509_STORE_free(ctx->x509_store_pt);
1292512940
ctx->x509_store.cache = str->cache;

src/x509_str.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
#ifdef OPENSSL_EXTRA
3535
static int X509StoreGetIssuerEx(WOLFSSL_X509 **issuer,
3636
WOLFSSL_STACK *certs, WOLFSSL_X509 *x);
37-
static int X509StoreAddCa(WOLFSSL_X509_STORE* store,
38-
WOLFSSL_X509* x509, int type);
3937
#endif
4038

4139
/* Based on OpenSSL default max depth */
@@ -1361,8 +1359,7 @@ WOLFSSL_X509_LOOKUP* wolfSSL_X509_STORE_add_lookup(WOLFSSL_X509_STORE* store,
13611359
return &store->lookup;
13621360
}
13631361

1364-
static int X509StoreAddCa(WOLFSSL_X509_STORE* store,
1365-
WOLFSSL_X509* x509, int type)
1362+
int X509StoreAddCa(WOLFSSL_X509_STORE* store, WOLFSSL_X509* x509, int type)
13661363
{
13671364
int result = WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR);
13681365
DerBuffer* derCert = NULL;

wolfssl/internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,6 +2780,11 @@ WOLFSSL_LOCAL int X509StoreLoadCertBuffer(WOLFSSL_X509_STORE *str,
27802780
byte *buf, word32 bufLen, int type);
27812781
#endif /* !defined NO_CERTS */
27822782

2783+
#ifdef OPENSSL_EXTRA
2784+
WOLFSSL_LOCAL int X509StoreAddCa(WOLFSSL_X509_STORE* store,
2785+
WOLFSSL_X509* x509, int type);
2786+
#endif
2787+
27832788
/* wolfSSL Sock Addr */
27842789
struct WOLFSSL_SOCKADDR {
27852790
unsigned int sz; /* sockaddr size */

0 commit comments

Comments
 (0)