Skip to content

Commit 805cc3a

Browse files
committed
curl: Add an option to select the SSL/TLS backend (if available)
If libcurl is built with MultiSSL support (not the case for e.g. Debian/Ubuntu, which ship separate, conflicting libraries), this allows selecting the SSL/TLS backend libcurl uses.
1 parent d11868f commit 805cc3a

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

conf/plugins/curl.opt

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
charon.plugins.curl.redir = -1
22
Maximum number of redirects followed by the plugin, set to 0 to disable
33
following redirects, set to -1 for no limit.
4+
5+
charon.plugins.curl.tls_backend =
6+
The SSL/TLS backend to configure in curl if multiple are available.
7+
8+
The SSL/TLS backend to configure in curl if multiple are available (requires
9+
libcurl 7.56 or newer). A list of available options is logged on level 2 if
10+
nothing is configured. Similar but on level 1 if the selected backend isn't
11+
available.

src/libstrongswan/plugins/curl/curl_plugin.c

+59
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (C) 2023 Tobias Brunner
23
* Copyright (C) 2008 Martin Willi
34
*
45
* Copyright (C) secunet Security Networks AG
@@ -152,6 +153,60 @@ METHOD(plugin_t, destroy, void,
152153
free(this);
153154
}
154155

156+
#if LIBCURL_VERSION_NUM >= 0x073800
157+
/**
158+
* Configure a specific SSL backend if multiple are available
159+
*/
160+
static void set_ssl_backend()
161+
{
162+
const curl_ssl_backend **avail;
163+
char *backend, buf[BUF_LEN] = "";
164+
int i, len = 0, added;
165+
166+
backend = lib->settings->get_str(lib->settings, "%s.plugins.curl.tls_backend",
167+
NULL, lib->ns);
168+
switch (curl_global_sslset(-1, backend, &avail))
169+
{
170+
case CURLSSLSET_UNKNOWN_BACKEND:
171+
for (i = 0; avail[i]; i++)
172+
{
173+
added = snprintf(buf + len, sizeof(buf) - len, " %s",
174+
avail[i]->name);
175+
if (added < sizeof(buf) - len)
176+
{
177+
len += added;
178+
}
179+
}
180+
if (backend)
181+
{
182+
DBG1(DBG_LIB, "unsupported TLS backend '%s' in libcurl, "
183+
"available:%s", backend, buf);
184+
}
185+
else
186+
{
187+
DBG2(DBG_LIB, "available TLS backends in libcurl:%s", buf);
188+
}
189+
break;
190+
case CURLSSLSET_NO_BACKENDS:
191+
if (backend)
192+
{
193+
DBG1(DBG_LIB, "unable to set TLS backend '%s', libcurl was "
194+
"built without TLS support", backend);
195+
}
196+
break;
197+
case CURLSSLSET_TOO_LATE:
198+
if (backend)
199+
{
200+
DBG1(DBG_LIB, "unable to set TLS backend '%s' in libcurl, "
201+
"already set", backend);
202+
}
203+
break;
204+
case CURLSSLSET_OK:
205+
break;
206+
}
207+
}
208+
#endif
209+
155210
/*
156211
* see header file
157212
*/
@@ -170,6 +225,10 @@ plugin_t *curl_plugin_create()
170225
},
171226
);
172227

228+
#if LIBCURL_VERSION_NUM >= 0x073800
229+
set_ssl_backend();
230+
#endif
231+
173232
res = curl_global_init(CURL_GLOBAL_SSL);
174233
if (res != CURLE_OK)
175234
{

0 commit comments

Comments
 (0)