summaryrefslogtreecommitdiff
path: root/gnu/packages/patches/curl-use-ssl-cert-env.patch
blob: 445e52c430f6900ea49a2a3d718f89f6da8694dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
Make libcurl respect the SSL_CERT_{DIR,FILE} variables by default. The variables
are fetched during initialization to preserve thread-safety (curl_global_init(3)
must be called when no other threads exist).

This fixes network functionality in rust:cargo, and probably removes the need
for other future workarounds.
===================================================================
Index: curl-8.19.0/lib/easy.c
===================================================================
--- curl-8.19.0.orig/lib/easy.c
+++ curl-8.19.0/lib/easy.c
@@ -117,6 +117,9 @@ curl_calloc_callback Curl_ccalloc = (cur
 static char *leakpointer;
 #endif
 
+char * Curl_ssl_cert_dir = NULL;
+char * Curl_ssl_cert_file = NULL;
+
 /**
  * curl_global_init() globally initializes curl given a bitwise set of the
  * different features of what to initialize.
@@ -140,6 +143,9 @@ static CURLcode global_init(long flags,
     goto fail;
   }
 
+  Curl_ssl_cert_dir = curl_getenv("SSL_CERT_DIR");
+  Curl_ssl_cert_file = curl_getenv("SSL_CERT_FILE");
+
   if(!Curl_ssl_init()) {
     DEBUGF(curl_mfprintf(stderr, "Error: Curl_ssl_init failed\n"));
     goto fail;
@@ -269,6 +275,9 @@ void curl_global_cleanup(void)
   Curl_ssl_cleanup();
   Curl_async_global_cleanup();
 
+  free(Curl_ssl_cert_dir);
+  free(Curl_ssl_cert_file);
+
 #ifdef _WIN32
   Curl_win32_cleanup(easy_init_flags);
 #endif
Index: curl-8.19.0/lib/vtls/vtls.c
===================================================================
--- curl-8.19.0.orig/lib/vtls/vtls.c
+++ curl-8.19.0/lib/vtls/vtls.c
@@ -294,10 +294,8 @@ static void free_primary_ssl_config(stru
 CURLcode Curl_ssl_easy_config_complete(struct Curl_easy *data)
 {
   struct ssl_config_data *sslc = &data->set.ssl;
-#if defined(CURL_CA_PATH) || defined(CURL_CA_BUNDLE)
   struct UserDefined *set = &data->set;
   CURLcode result;
-#endif
 
   if(Curl_ssl_backend() != CURLSSLBACKEND_SCHANNEL) {
 #if defined(USE_APPLE_SECTRUST) || defined(CURL_CA_NATIVE)
@@ -318,6 +316,21 @@ CURLcode Curl_ssl_easy_config_complete(s
         return result;
     }
 #endif
+    extern char * Curl_ssl_cert_dir;
+    extern char * Curl_ssl_cert_file;
+    if(Curl_ssl_cert_dir) {
+      if(result = Curl_setstropt(&set->str[STRING_SSL_CAPATH], Curl_ssl_cert_dir))
+        return result;
+      if(result = Curl_setstropt(&set->str[STRING_SSL_CAPATH_PROXY], Curl_ssl_cert_dir))
+        return result;
+    }
+
+    if(Curl_ssl_cert_file) {
+      if(result = Curl_setstropt(&set->str[STRING_SSL_CAFILE], Curl_ssl_cert_file))
+        return result;
+      if(result = Curl_setstropt(&set->str[STRING_SSL_CAFILE_PROXY], Curl_ssl_cert_file))
+        return result;
+    }
   }
   sslc->primary.CAfile = data->set.str[STRING_SSL_CAFILE];
   sslc->primary.CRLfile = data->set.str[STRING_SSL_CRLFILE];