Skip to content

Commit f91d66f

Browse files
committed
wolfssl, x509 store share fix
When sharing the x509 store in wolfSSL, always use an explicitly constructed one, as the SSLCTX might have "only" an internal one which is not obeying reference count lifetimes. - refs curl#14278
1 parent 11e248b commit f91d66f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/vtls/wolfssl.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -585,14 +585,26 @@ CURLcode Curl_wssl_setup_x509_store(struct Curl_cfilter *cf,
585585
&& wolfSSL_X509_STORE_up_ref(cached_store)) {
586586
wolfSSL_CTX_set_cert_store(wssl->ctx, cached_store);
587587
}
588-
else {
589-
X509_STORE *store = wolfSSL_CTX_get_cert_store(wssl->ctx);
588+
else if(cache_criteria_met) {
589+
/* wolfSSL's initial store in CTX is not shareable by default.
590+
* Make a new one, suitable for adding to the cache. See #14278 */
591+
X509_STORE *store = wolfSSL_X509_STORE_new();
592+
if(!store) {
593+
failf(data, "SSL: could not create a X509 store");
594+
return CURLE_OUT_OF_MEMORY;
595+
}
596+
wolfSSL_CTX_set_cert_store(wssl->ctx, store);
590597

591598
result = populate_x509_store(cf, data, store, wssl);
592-
if(result == CURLE_OK && cache_criteria_met) {
599+
if(!result) {
593600
set_cached_x509_store(cf, data, store);
594601
}
595602
}
603+
else {
604+
/* We'll never share the CTX's store, use it. */
605+
X509_STORE *store = wolfSSL_CTX_get_cert_store(wssl->ctx);
606+
result = populate_x509_store(cf, data, store, wssl);
607+
}
596608

597609
return result;
598610
}

0 commit comments

Comments
 (0)