curl: make --libcurl output better CURLOPT_*SSLVERSION

The option is really two enums ORed together, so it needs special
attention to make the code output nice.

Added test 1481 to verify. Both the server and the proxy versions.

Reported-by: Boris Verkhovskiy
Fixes #13127
Closes #13129
This commit is contained in:
Daniel Stenberg 2024-03-14 13:58:45 +01:00
parent 09f367977a
commit 40948189ff
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 187 additions and 5 deletions

View file

@ -1763,11 +1763,11 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if(config->falsestart)
my_setopt(curl, CURLOPT_SSL_FALSESTART, 1L);
my_setopt_enum(curl, CURLOPT_SSLVERSION,
config->ssl_version | config->ssl_version_max);
my_setopt_SSLVERSION(curl, CURLOPT_SSLVERSION,
config->ssl_version | config->ssl_version_max);
if(config->proxy)
my_setopt_enum(curl, CURLOPT_PROXY_SSLVERSION,
config->proxy_ssl_version);
my_setopt_SSLVERSION(curl, CURLOPT_PROXY_SSLVERSION,
config->proxy_ssl_version);
{
long mask =

View file

@ -107,6 +107,16 @@ const struct NameValue setopt_nv_CURL_SSLVERSION[] = {
NVEND,
};
const struct NameValue setopt_nv_CURL_SSLVERSION_MAX[] = {
NV(CURL_SSLVERSION_MAX_NONE),
NV(CURL_SSLVERSION_MAX_DEFAULT),
NV(CURL_SSLVERSION_MAX_TLSv1_0),
NV(CURL_SSLVERSION_MAX_TLSv1_1),
NV(CURL_SSLVERSION_MAX_TLSv1_2),
NV(CURL_SSLVERSION_MAX_TLSv1_3),
NVEND,
};
const struct NameValue setopt_nv_CURL_TIMECOND[] = {
NV(CURL_TIMECOND_IFMODSINCE),
NV(CURL_TIMECOND_IFUNMODSINCE),
@ -296,6 +306,50 @@ nomem:
return ret;
}
/* setopt wrapper for CURLOPT_SSLVERSION */
CURLcode tool_setopt_SSLVERSION(CURL *curl, struct GlobalConfig *config,
const char *name, CURLoption tag,
long lval)
{
CURLcode ret = CURLE_OK;
bool skip = FALSE;
ret = curl_easy_setopt(curl, tag, lval);
if(!lval)
skip = TRUE;
if(config->libcurl && !skip && !ret) {
/* we only use this for real if --libcurl was used */
const struct NameValue *nv = NULL;
const struct NameValue *nv2 = NULL;
for(nv = setopt_nv_CURL_SSLVERSION; nv->name; nv++) {
if(nv->value == (lval & 0xffff))
break; /* found it */
}
for(nv2 = setopt_nv_CURL_SSLVERSION_MAX; nv2->name; nv2++) {
if(nv2->value == (lval & ~0xffff))
break; /* found it */
}
if(!nv->name) {
/* If no definition was found, output an explicit value.
* This could happen if new values are defined and used
* but the NameValue list is not updated. */
CODE2("curl_easy_setopt(hnd, %s, %ldL);", name, lval);
}
else {
CODE3("curl_easy_setopt(hnd, %s, (long)(%s | %s));",
name, nv->name, nv2->name);
}
}
#ifdef DEBUGBUILD
if(ret)
warnf(config, "option %s returned error (%d)", name, (int)ret);
#endif
nomem:
return ret;
}
/* setopt wrapper for bitmasks */
CURLcode tool_setopt_bitmask(CURL *curl, struct GlobalConfig *config,
const char *name, CURLoption tag,

View file

@ -52,6 +52,7 @@ extern const struct NameValue setopt_nv_CURLPROXY[];
extern const struct NameValue setopt_nv_CURL_SOCKS_PROXY[];
extern const struct NameValue setopt_nv_CURL_HTTP_VERSION[];
extern const struct NameValue setopt_nv_CURL_SSLVERSION[];
extern const struct NameValue setopt_nv_CURL_SSLVERSION_MAX[];
extern const struct NameValue setopt_nv_CURL_TIMECOND[];
extern const struct NameValue setopt_nv_CURLFTPSSL_CCC[];
extern const struct NameValue setopt_nv_CURLUSESSL[];
@ -81,6 +82,9 @@ extern const struct NameValueUnsigned setopt_nv_CURLHSTS[];
CURLcode tool_setopt_enum(CURL *curl, struct GlobalConfig *config,
const char *name, CURLoption tag,
const struct NameValue *nv, long lval);
CURLcode tool_setopt_SSLVERSION(CURL *curl, struct GlobalConfig *config,
const char *name, CURLoption tag,
long lval);
CURLcode tool_setopt_flags(CURL *curl, struct GlobalConfig *config,
const char *name, CURLoption tag,
const struct NameValue *nv, long lval);
@ -106,6 +110,9 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
#define my_setopt_enum(x,y,z) \
SETOPT_CHECK(tool_setopt_enum(x, global, #y, y, setopt_nv_ ## y, z), y)
#define my_setopt_SSLVERSION(x,y,z) \
SETOPT_CHECK(tool_setopt_SSLVERSION(x, global, #y, y, z), y)
#define my_setopt_bitmask(x,y,z) \
SETOPT_CHECK(tool_setopt_bitmask(x, global, #y, y, setopt_nv_ ## y, z), y)
@ -132,6 +139,9 @@ CURLcode tool_setopt(CURL *curl, bool str, struct GlobalConfig *global,
#define my_setopt_enum(x,y,z) \
SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
#define my_setopt_SSLVERSION(x,y,z) \
SETOPT_CHECK(curl_easy_setopt(x, y, z), y)
#define my_setopt_bitmask(x,y,z) \
SETOPT_CHECK(curl_easy_setopt(x, y, z), y)