From 6448f98c1857de521fb2dd3f9d4e5659845b5474 Mon Sep 17 00:00:00 2001 From: Jozef Kralik Date: Tue, 13 Dec 2016 21:10:00 +0100 Subject: vtls: add options to specify range of enabled TLS versions This commit introduces the CURL_SSLVERSION_MAX_* constants as well as the --tls-max option of the curl tool. Closes https://github.com/curl/curl/pull/1166 --- src/tool_paramhlp.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/tool_paramhlp.c') diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 257e5c697..6b534ce5d 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -550,3 +550,36 @@ CURLcode get_args(struct OperationConfig *config, const size_t i) return result; } + +/* + * Parse the string and modify ssl_version in the val argument. Return PARAM_OK + * on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS! + * + * Since this function gets called with the 'nextarg' pointer from within the + * getparameter a lot, we must check it for NULL before accessing the str + * data. + */ + +ParameterError str2tls_max(long *val, const char *str) +{ + static struct s_tls_max { + const char *tls_max_str; + long tls_max; + } const tls_max_array[] = { + { "default", CURL_SSLVERSION_MAX_DEFAULT }, + { "1.0", CURL_SSLVERSION_MAX_TLSv1_0 }, + { "1.1", CURL_SSLVERSION_MAX_TLSv1_1 }, + { "1.2", CURL_SSLVERSION_MAX_TLSv1_2 }, + { "1.3", CURL_SSLVERSION_MAX_TLSv1_3 } + }; + size_t i = 0; + if(!str) + return PARAM_REQUIRES_PARAMETER; + for(i = 0; i < sizeof(tls_max_array)/sizeof(tls_max_array[0]); i++) { + if(!strcmp(str, tls_max_array[i].tls_max_str)) { + *val = tls_max_array[i].tls_max; + return PARAM_OK; + } + } + return PARAM_BAD_USE; +} -- cgit v1.2.3