| 1 | Make libcurl respect the SSL_CERT_{DIR,FILE} variables by default. The variables
|
| 2 | are fetched during initialization to preserve thread-safety (curl_global_init(3)
|
| 3 | must be called when no other threads exist).
|
| 4 |
|
| 5 | This fixes network functionality in rust:cargo, and probably removes the need
|
| 6 | for other future workarounds.
|
| 7 | diff --git a/lib/easy.c b/lib/easy.c
|
| 8 | index d60bdae..d25d670 100644
|
| 9 | |
| 10 | |
| 11 | @@ -117,6 +117,9 @@ curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
|
| 12 | static char *leakpointer;
|
| 13 | #endif
|
| 14 |
|
| 15 | +char * Curl_ssl_cert_dir = NULL;
|
| 16 | +char * Curl_ssl_cert_file = NULL;
|
| 17 | +
|
| 18 | /**
|
| 19 | * curl_global_init() globally initializes curl given a bitwise set of the
|
| 20 | * different features of what to initialize.
|
| 21 | @@ -140,6 +143,9 @@ static CURLcode global_init(long flags, bool memoryfuncs)
|
| 22 | goto fail;
|
| 23 | }
|
| 24 |
|
| 25 | + Curl_ssl_cert_dir = curl_getenv("SSL_CERT_DIR");
|
| 26 | + Curl_ssl_cert_file = curl_getenv("SSL_CERT_FILE");
|
| 27 | +
|
| 28 | if(!Curl_ssl_init()) {
|
| 29 | DEBUGF(curl_mfprintf(stderr, "Error: Curl_ssl_init failed\n"));
|
| 30 | goto fail;
|
| 31 | @@ -269,6 +275,9 @@ void curl_global_cleanup(void)
|
| 32 | Curl_ssl_cleanup();
|
| 33 | Curl_async_global_cleanup();
|
| 34 |
|
| 35 | + free(Curl_ssl_cert_dir);
|
| 36 | + free(Curl_ssl_cert_file);
|
| 37 | +
|
| 38 | #ifdef _WIN32
|
| 39 | Curl_win32_cleanup(easy_init_flags);
|
| 40 | #endif
|
| 41 | diff --git a/lib/vtls/vtls_config.c b/lib/vtls/vtls_config.c
|
| 42 | index 4a9b696..3e780f3 100644
|
| 43 | |
| 44 | |
| 45 | @@ -257,10 +257,8 @@ CURLcode Curl_ssl_easy_config_complete(struct Curl_easy *data,
|
| 46 | struct Curl_peer *origin)
|
| 47 | {
|
| 48 | struct ssl_config_data *sslc = &data->set.ssl;
|
| 49 | -#if defined(CURL_CA_PATH) || defined(CURL_CA_BUNDLE)
|
| 50 | struct UserDefined *set = &data->set;
|
| 51 | CURLcode result;
|
| 52 | -#endif
|
| 53 |
|
| 54 | ssl_easy_config_compl_options(origin, data->state.initial_origin, sslc);
|
| 55 |
|
| 56 | @@ -283,6 +281,21 @@ CURLcode Curl_ssl_easy_config_complete(struct Curl_easy *data,
|
| 57 | return result;
|
| 58 | }
|
| 59 | #endif
|
| 60 | + extern char * Curl_ssl_cert_dir;
|
| 61 | + extern char * Curl_ssl_cert_file;
|
| 62 | + if(Curl_ssl_cert_dir) {
|
| 63 | + if(result = Curl_setstropt(&set->str[STRING_SSL_CAPATH], Curl_ssl_cert_dir))
|
| 64 | + return result;
|
| 65 | + if(result = Curl_setstropt(&set->str[STRING_SSL_CAPATH_PROXY], Curl_ssl_cert_dir))
|
| 66 | + return result;
|
| 67 | + }
|
| 68 | +
|
| 69 | + if(Curl_ssl_cert_file) {
|
| 70 | + if(result = Curl_setstropt(&set->str[STRING_SSL_CAFILE], Curl_ssl_cert_file))
|
| 71 | + return result;
|
| 72 | + if(result = Curl_setstropt(&set->str[STRING_SSL_CAFILE_PROXY], Curl_ssl_cert_file))
|
| 73 | + return result;
|
| 74 | + }
|
| 75 | }
|
| 76 | sslc->primary.CAfile = data->set.str[STRING_SSL_CAFILE];
|
| 77 | sslc->primary.CRLfile = data->set.str[STRING_SSL_CRLFILE];
|