Skip to content

Commit ebd83bf

Browse files
darktohkabagder
authored andcommitted
wolfssl: support setting CA certificates as blob
Closes curl#11445
1 parent eccf896 commit ebd83bf

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docs/libcurl/opts/CURLOPT_CAINFO_BLOB.3

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ if(curl) {
6464
Added in 7.77.0.
6565

6666
This option is supported by the BearSSL (since 7.79.0), mbedTLS (since 7.81.0),
67-
rustls (since 7.82.0), OpenSSL, Secure Transport and Schannel backends.
67+
rustls (since 7.82.0), wolfSSL (since 8.2.0), OpenSSL, Secure Transport and Schannel backends.
6868
.SH RETURN VALUE
6969
Returns CURLE_OK if the option is supported, CURLE_UNKNOWN_OPTION if not, or
7070
CURLE_OUT_OF_MEMORY if there was insufficient heap space.

lib/vtls/wolfssl.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ wolfssl_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data)
359359
struct wolfssl_ssl_backend_data *backend =
360360
(struct wolfssl_ssl_backend_data *)connssl->backend;
361361
struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
362+
const struct curl_blob *ca_info_blob = conn_config->ca_info_blob;
362363
const struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);
363364
SSL_METHOD* req_method = NULL;
364365
#ifdef HAVE_LIBOQS
@@ -371,6 +372,7 @@ wolfssl_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data)
371372
#else
372373
#define use_sni(x) Curl_nop_stmt
373374
#endif
375+
bool imported_ca_info_blob = false;
374376

375377
DEBUGASSERT(backend);
376378

@@ -504,13 +506,28 @@ wolfssl_connect_step1(struct Curl_cfilter *cf, struct Curl_easy *data)
504506
}
505507
}
506508
}
509+
510+
if(ca_info_blob) {
511+
if(wolfSSL_CTX_load_verify_buffer(
512+
backend->ctx, ca_info_blob->data, ca_info_blob->len,
513+
SSL_FILETYPE_PEM
514+
) != SSL_SUCCESS) {
515+
failf(data, "error importing CA certificate blob");
516+
return CURLE_SSL_CACERT_BADFILE;
517+
}
518+
else {
519+
imported_ca_info_blob = true;
520+
infof(data, "successfully imported CA certificate blob");
521+
}
522+
}
523+
507524
#ifndef NO_FILESYSTEM
508525
/* load trusted cacert */
509526
if(conn_config->CAfile) {
510527
if(1 != SSL_CTX_load_verify_locations(backend->ctx,
511528
conn_config->CAfile,
512529
conn_config->CApath)) {
513-
if(conn_config->verifypeer) {
530+
if(conn_config->verifypeer && !imported_ca_info_blob) {
514531
/* Fail if we insist on successfully verifying the server. */
515532
failf(data, "error setting certificate verify locations:"
516533
" CAfile: %s CApath: %s",
@@ -1341,6 +1358,7 @@ const struct Curl_ssl Curl_ssl_wolfssl = {
13411358
#ifdef USE_BIO_CHAIN
13421359
SSLSUPP_HTTPS_PROXY |
13431360
#endif
1361+
SSLSUPP_CAINFO_BLOB |
13441362
SSLSUPP_SSL_CTX,
13451363

13461364
sizeof(struct wolfssl_ssl_backend_data),

0 commit comments

Comments
 (0)