Skip to content

Commit f1351e0

Browse files
committed
setopt: add TLS 1.3 ciphersuites
Adds CURLOPT_TLS13_CIPHERS and CURLOPT_PROXY_TLS13_CIPHERS. curl: added --tls13-ciphers and --proxy-tls13-ciphers Fixes #2435 Reported-by: zzq1015 on github
1 parent 954284f commit f1351e0

19 files changed

+260
-11
lines changed

docs/CIPHERS.md

+10
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ libcurl was built to use. This is an attempt to list known cipher names.
142142
`ECDHE-RSA-CAMELLIA128-SHA256`
143143
`ECDHE-RSA-CAMELLIA256-SHA384`
144144

145+
### TLS 1.3 cipher suites
146+
147+
(Note: the TLS 1.3 cipher suites are set with a separate option.)
148+
149+
`TLS13-AES-256-GCM-SHA384`
150+
`TLS13-CHACHA20-POLY1305-SHA256`
151+
`TLS13-AES-128-GCM-SHA256`
152+
`TLS13-AES-128-CCM-8-SHA256`
153+
`TLS13-AES-128-CCM-SHA256`
154+
145155
## NSS
146156

147157
### Totally insecure

docs/cmdline-opts/Makefile.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ DPAGES = abstract-unix-socket.d anyauth.d append.d basic.d cacert.d capath.d cer
4747
tlsv1.3.d tlsv1.d trace-ascii.d trace.d trace-time.d tr-encoding.d \
4848
unix-socket.d upload-file.d url.d use-ascii.d user-agent.d user.d \
4949
verbose.d version.d write-out.d xattr.d request-target.d \
50-
styled-output.d
50+
styled-output.d tls13-ciphers.d proxy-tls13-ciphers.d
5151

5252
OTHERPAGES = page-footer page-header
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Long: proxy-tls13-ciphers
2+
Arg: <ciphersuite list>
3+
help: TLS 1.3 proxy cipher suites
4+
Protocols: TLS
5+
---
6+
Specifies which cipher suites to use in the connection to your HTTPS proxy
7+
when it negotiates TLS 1.3. The list of ciphers suites must specify valid
8+
ciphers. Read up on TLS 1.3 cipher suite details on this URL:
9+
10+
https://curl.haxx.se/docs/ssl-ciphers.html
11+
12+
If this option is used several times, the last one will be used.

docs/cmdline-opts/tls13-ciphers.d

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Long: tls13-ciphers
2+
Arg: <list of TLS 1.3 ciphersuites>
3+
help: TLS 1.3 cipher suites to use
4+
Protocols: TLS
5+
---
6+
Specifies which cipher suites to use in the connection if it negotiates TLS
7+
1.3. The list of ciphers suites must specify valid ciphers. Read up on TLS 1.3
8+
cipher suite details on this URL:
9+
10+
https://curl.haxx.se/docs/ssl-ciphers.html
11+
12+
If this option is used several times, the last one will be used.

docs/libcurl/curl_easy_setopt.3

+4
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@ Identify EGD socket for entropy. See \fICURLOPT_EGDSOCKET(3)\fP
548548
Ciphers to use. See \fICURLOPT_SSL_CIPHER_LIST(3)\fP
549549
.IP CURLOPT_PROXY_SSL_CIPHER_LIST
550550
Proxy ciphers to use. See \fICURLOPT_PROXY_SSL_CIPHER_LIST(3)\fP
551+
.IP CURLOPT_TLS13_CIPHERS
552+
TLS 1.3 cipher suites to use. See \fICURLOPT_TLS13_CIPHERS(3)\fP
553+
.IP CURLOPT_PROXY_TLS13_CIPHERS
554+
Proxy TLS 1.3 cipher suites to use. See \fICURLOPT_PROXY_TLS13_CIPHERS(3)\fP
551555
.IP CURLOPT_SSL_SESSIONID_CACHE
552556
Disable SSL session-id cache. See \fICURLOPT_SSL_SESSIONID_CACHE(3)\fP
553557
.IP CURLOPT_SSL_OPTIONS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.\" **************************************************************************
2+
.\" * _ _ ____ _
3+
.\" * Project ___| | | | _ \| |
4+
.\" * / __| | | | |_) | |
5+
.\" * | (__| |_| | _ <| |___
6+
.\" * \___|\___/|_| \_\_____|
7+
.\" *
8+
.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <[email protected]>, et al.
9+
.\" *
10+
.\" * This software is licensed as described in the file COPYING, which
11+
.\" * you should have received as part of this distribution. The terms
12+
.\" * are also available at https://curl.haxx.se/docs/copyright.html.
13+
.\" *
14+
.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15+
.\" * copies of the Software, and permit persons to whom the Software is
16+
.\" * furnished to do so, under the terms of the COPYING file.
17+
.\" *
18+
.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19+
.\" * KIND, either express or implied.
20+
.\" *
21+
.\" **************************************************************************
22+
.\"
23+
.TH CURLOPT_PROXY_TLS13_CIPHERS 3 "25 May 2018" "libcurl 7.61.0" "curl_easy_setopt options"
24+
.SH NAME
25+
CURLOPT_PROXY_TLS13_CIPHERS \- ciphers suites for proxy TLS 1.3
26+
.SH SYNOPSIS
27+
#include <curl/curl.h>
28+
29+
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_PROXY_TLS13_CIPHERS, char *list);
30+
.SH DESCRIPTION
31+
Pass a char *, pointing to a zero terminated string holding the list of cipher
32+
suites to use for the TLS 1.3 connection to a proxy. The list must be
33+
syntactically correct, it consists of one or more cipher suite strings
34+
separated by colons.
35+
36+
You'll find more details about cipher lists on this URL:
37+
38+
https://curl.haxx.se/docs/ssl-ciphers.html
39+
40+
The application does not have to keep the string around after setting this
41+
option.
42+
.SH DEFAULT
43+
NULL, use internal default
44+
.SH PROTOCOLS
45+
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
46+
.SH EXAMPLE
47+
.nf
48+
CURL *curl = curl_easy_init();
49+
if(curl) {
50+
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
51+
curl_easy_setopt(curl, CURLOPT_PROXY_TLS13_CIPHERS,
52+
"TLS13-CHACHA20-POLY1305-SHA256");
53+
ret = curl_easy_perform(curl);
54+
curl_easy_cleanup(curl);
55+
}
56+
.fi
57+
.SH AVAILABILITY
58+
Added in 7.61.0.
59+
Available when built with OpenSSL >= 1.1.1.
60+
.SH RETURN VALUE
61+
Returns CURLE_OK if supported, CURLE_NOT_BUILT_IN otherwise.
62+
.SH "SEE ALSO"
63+
.BR CURLOPT_SSLVERSION "(3), " CURLOPT_TLS13_CIPHERS "(3), "
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
.\" **************************************************************************
2+
.\" * _ _ ____ _
3+
.\" * Project ___| | | | _ \| |
4+
.\" * / __| | | | |_) | |
5+
.\" * | (__| |_| | _ <| |___
6+
.\" * \___|\___/|_| \_\_____|
7+
.\" *
8+
.\" * Copyright (C) 1998 - 2018, Daniel Stenberg, <[email protected]>, et al.
9+
.\" *
10+
.\" * This software is licensed as described in the file COPYING, which
11+
.\" * you should have received as part of this distribution. The terms
12+
.\" * are also available at https://curl.haxx.se/docs/copyright.html.
13+
.\" *
14+
.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15+
.\" * copies of the Software, and permit persons to whom the Software is
16+
.\" * furnished to do so, under the terms of the COPYING file.
17+
.\" *
18+
.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19+
.\" * KIND, either express or implied.
20+
.\" *
21+
.\" **************************************************************************
22+
.\"
23+
.TH CURLOPT_TLS13_CIPHERS 3 "25 May 2018" "libcurl 7.61.0" "curl_easy_setopt options"
24+
.SH NAME
25+
CURLOPT_TLS13_CIPHERS \- specify ciphers suites to use for TLS 1.3
26+
.SH SYNOPSIS
27+
#include <curl/curl.h>
28+
29+
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_TLS13_CIPHERS, char *list);
30+
.SH DESCRIPTION
31+
Pass a char *, pointing to a zero terminated string holding the list of cipher
32+
suites to use for the TLS 1.3 connection. The list must be syntactically
33+
correct, it consists of one or more cipher suite strings separated by colons.
34+
35+
You'll find more details about cipher lists on this URL:
36+
37+
https://curl.haxx.se/docs/ssl-ciphers.html
38+
39+
The application does not have to keep the string around after setting this
40+
option.
41+
.SH DEFAULT
42+
NULL, use internal default
43+
.SH PROTOCOLS
44+
All TLS based protocols: HTTPS, FTPS, IMAPS, POP3S, SMTPS etc.
45+
.SH EXAMPLE
46+
.nf
47+
CURL *curl = curl_easy_init();
48+
if(curl) {
49+
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
50+
curl_easy_setopt(curl, CURLOPT_TLS13_CIPHERS,
51+
"TLS13-CHACHA20-POLY1305-SHA256");
52+
ret = curl_easy_perform(curl);
53+
curl_easy_cleanup(curl);
54+
}
55+
.fi
56+
.SH AVAILABILITY
57+
Added in 7.61.0.
58+
Available when built with OpenSSL >= 1.1.1.
59+
.SH RETURN VALUE
60+
Returns CURLE_OK if supported, CURLE_NOT_BUILT_IN otherwise.
61+
.SH "SEE ALSO"
62+
.BR CURLOPT_SSLVERSION "(3), " CURLOPT_PROXY_TLS13_CIPHERS "(3), "

docs/libcurl/opts/Makefile.inc

+2
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ man_MANS = \
237237
CURLOPT_PROXY_SSL_OPTIONS.3 \
238238
CURLOPT_PROXY_SSL_VERIFYHOST.3 \
239239
CURLOPT_PROXY_SSL_VERIFYPEER.3 \
240+
CURLOPT_PROXY_TLS13_CIPHERS.3 \
240241
CURLOPT_PROXY_TLSAUTH_PASSWORD.3 \
241242
CURLOPT_PROXY_TLSAUTH_TYPE.3 \
242243
CURLOPT_PROXY_TLSAUTH_USERNAME.3 \
@@ -315,6 +316,7 @@ man_MANS = \
315316
CURLOPT_TIMEOUT_MS.3 \
316317
CURLOPT_TIMEVALUE.3 \
317318
CURLOPT_TIMEVALUE_LARGE.3 \
319+
CURLOPT_TLS13_CIPHERS.3 \
318320
CURLOPT_TLSAUTH_PASSWORD.3 \
319321
CURLOPT_TLSAUTH_TYPE.3 \
320322
CURLOPT_TLSAUTH_USERNAME.3 \

docs/libcurl/symbols-in-versions

+5-3
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ CURLE_PEER_FAILED_VERIFICATION 7.17.1
101101
CURLE_QUOTE_ERROR 7.17.0
102102
CURLE_RANGE_ERROR 7.17.0
103103
CURLE_READ_ERROR 7.1
104-
CURLE_RECV_ERROR 7.10
105104
CURLE_RECURSIVE_API_CALL 7.59.0
105+
CURLE_RECV_ERROR 7.10
106106
CURLE_REMOTE_ACCESS_DENIED 7.17.0
107107
CURLE_REMOTE_DISK_FULL 7.17.0
108108
CURLE_REMOTE_FILE_EXISTS 7.17.0
@@ -514,6 +514,7 @@ CURLOPT_PROXY_SSL_CIPHER_LIST 7.52.0
514514
CURLOPT_PROXY_SSL_OPTIONS 7.52.0
515515
CURLOPT_PROXY_SSL_VERIFYHOST 7.52.0
516516
CURLOPT_PROXY_SSL_VERIFYPEER 7.52.0
517+
CURLOPT_PROXY_TLS13_CIPHERS 7.61.0
517518
CURLOPT_PROXY_TLSAUTH_PASSWORD 7.52.0
518519
CURLOPT_PROXY_TLSAUTH_TYPE 7.52.0
519520
CURLOPT_PROXY_TLSAUTH_USERNAME 7.52.0
@@ -528,6 +529,8 @@ CURLOPT_REDIR_PROTOCOLS 7.19.4
528529
CURLOPT_REFERER 7.1
529530
CURLOPT_REQUEST_TARGET 7.55.0
530531
CURLOPT_RESOLVE 7.21.3
532+
CURLOPT_RESOLVER_START_DATA 7.59.0
533+
CURLOPT_RESOLVER_START_FUNCTION 7.59.0
531534
CURLOPT_RESUME_FROM 7.1
532535
CURLOPT_RESUME_FROM_LARGE 7.11.0
533536
CURLOPT_RTSPHEADER 7.20.0
@@ -602,13 +605,12 @@ CURLOPT_TIMEOUT 7.1
602605
CURLOPT_TIMEOUT_MS 7.16.2
603606
CURLOPT_TIMEVALUE 7.1
604607
CURLOPT_TIMEVALUE_LARGE 7.59.0
608+
CURLOPT_TLS13_CIPHERS 7.61.0
605609
CURLOPT_TLSAUTH_PASSWORD 7.21.4
606610
CURLOPT_TLSAUTH_TYPE 7.21.4
607611
CURLOPT_TLSAUTH_USERNAME 7.21.4
608612
CURLOPT_TRANSFERTEXT 7.1.1
609613
CURLOPT_TRANSFER_ENCODING 7.21.6
610-
CURLOPT_RESOLVER_START_FUNCTION 7.59.0
611-
CURLOPT_RESOLVER_START_DATA 7.59.0
612614
CURLOPT_UNIX_SOCKET_PATH 7.40.0
613615
CURLOPT_UNRESTRICTED_AUTH 7.10.4
614616
CURLOPT_UPLOAD 7.1

include/curl/curl.h

+4
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,10 @@ typedef enum {
18491849
/* shuffle addresses before use when DNS returns multiple */
18501850
CINIT(DNS_SHUFFLE_ADDRESSES, LONG, 275),
18511851

1852+
/* Specify which TLS 1.3 ciphers suites to use */
1853+
CINIT(TLS13_CIPHERS, STRINGPOINT, 276),
1854+
CINIT(PROXY_TLS13_CIPHERS, STRINGPOINT, 277),
1855+
18521856
CURLOPT_LASTENTRY /* the last unused */
18531857
} CURLoption;
18541858

lib/setopt.c

+19
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,25 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option,
142142
va_arg(param, char *));
143143
break;
144144

145+
case CURLOPT_TLS13_CIPHERS:
146+
if(Curl_ssl_tls13_ciphersuites()) {
147+
/* set preferred list of TLS 1.3 cipher suites */
148+
result = Curl_setstropt(&data->set.str[STRING_SSL_CIPHER13_LIST_ORIG],
149+
va_arg(param, char *));
150+
}
151+
else
152+
return CURLE_NOT_BUILT_IN;
153+
break;
154+
case CURLOPT_PROXY_TLS13_CIPHERS:
155+
if(Curl_ssl_tls13_ciphersuites()) {
156+
/* set preferred list of TLS 1.3 cipher suites for proxy */
157+
result = Curl_setstropt(&data->set.str[STRING_SSL_CIPHER13_LIST_PROXY],
158+
va_arg(param, char *));
159+
}
160+
else
161+
return CURLE_NOT_BUILT_IN;
162+
break;
163+
145164
case CURLOPT_RANDOM_FILE:
146165
/*
147166
* This is the path name to a file that contains random data to seed

lib/urldata.h

+3
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ struct ssl_primary_config {
227227
char *random_file; /* path to file containing "random" data */
228228
char *egdsocket; /* path to file containing the EGD daemon socket */
229229
char *cipher_list; /* list of ciphers to use */
230+
char *cipher_list13; /* list of TLS 1.3 cipher suites to use */
230231
};
231232

232233
struct ssl_config_data {
@@ -1401,6 +1402,8 @@ enum dupstring {
14011402
STRING_SSL_PINNEDPUBLICKEY_PROXY, /* public key file to verify proxy */
14021403
STRING_SSL_CIPHER_LIST_ORIG, /* list of ciphers to use */
14031404
STRING_SSL_CIPHER_LIST_PROXY, /* list of ciphers to use */
1405+
STRING_SSL_CIPHER13_LIST_ORIG, /* list of TLS 1.3 ciphers to use */
1406+
STRING_SSL_CIPHER13_LIST_PROXY, /* list of TLS 1.3 ciphers to use */
14041407
STRING_SSL_EGDSOCKET, /* path to file containing the EGD daemon socket */
14051408
STRING_SSL_RANDOM_FILE, /* path to file containing "random" data */
14061409
STRING_USERAGENT, /* User-Agent string */

lib/vtls/openssl.c

+24
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ static unsigned long OpenSSL_version_num(void)
166166
#define HAVE_KEYLOG_CALLBACK
167167
#endif
168168

169+
/* Whether SSL_CTX_set_ciphersuites is available.
170+
* OpenSSL: supported since 1.1.1 (commit a53b5be6a05)
171+
* BoringSSL: no
172+
* LibreSSL: no
173+
*/
174+
#if ((OPENSSL_VERSION_NUMBER >= 0x10101000L) && \
175+
!defined(LIBRESSL_VERSION_NUMBER) && \
176+
!defined(OPENSSL_IS_BORINGSSL))
177+
#define HAVE_SSL_CTX_SET_CIPHERSUITES
178+
#endif
179+
169180
#if defined(LIBRESSL_VERSION_NUMBER)
170181
#define OSSL_PACKAGE "LibreSSL"
171182
#elif defined(OPENSSL_IS_BORINGSSL)
@@ -2413,6 +2424,19 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
24132424
infof(data, "Cipher selection: %s\n", ciphers);
24142425
}
24152426

2427+
#ifdef HAVE_SSL_CTX_SET_CIPHERSUITES
2428+
{
2429+
char *ciphers13 = SSL_CONN_CONFIG(cipher_list13);
2430+
if(ciphers13) {
2431+
if(!SSL_CTX_set_ciphersuites(BACKEND->ctx, ciphers13)) {
2432+
failf(data, "failed setting TLS 1.3 cipher suite: %s", ciphers);
2433+
return CURLE_SSL_CIPHER;
2434+
}
2435+
infof(data, "TLS 1.3 cipher selection: %s\n", ciphers13);
2436+
}
2437+
}
2438+
#endif
2439+
24162440
#ifdef USE_TLS_SRP
24172441
if(ssl_authtype == CURL_TLSAUTH_SRP) {
24182442
char * const ssl_username = SSL_SET_OPTION(username);

lib/vtls/vtls.c

+8
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,14 @@ bool Curl_ssl_false_start(void)
979979
return Curl_ssl->false_start();
980980
}
981981

982+
/*
983+
* Check whether the SSL backend supports setting TLS 1.3 cipher suites
984+
*/
985+
bool Curl_ssl_tls13_ciphersuites(void)
986+
{
987+
return Curl_ssl->supports & SSLSUPP_TLS13_CIPHERSUITES;
988+
}
989+
982990
/*
983991
* Default implementations for unsupported functions.
984992
*/

lib/vtls/vtls.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct ssl_connect_data;
3131
#define SSLSUPP_PINNEDPUBKEY (1<<2) /* supports CURLOPT_PINNEDPUBLICKEY */
3232
#define SSLSUPP_SSL_CTX (1<<3) /* supports CURLOPT_SSL_CTX */
3333
#define SSLSUPP_HTTPS_PROXY (1<<4) /* supports access via HTTPS proxies */
34+
#define SSLSUPP_TLS13_CIPHERSUITES (1<<5) /* supports TLS 1.3 ciphersuites */
3435

3536
struct Curl_ssl {
3637
/*
@@ -93,6 +94,7 @@ CURLcode Curl_none_set_engine(struct Curl_easy *data, const char *engine);
9394
CURLcode Curl_none_set_engine_default(struct Curl_easy *data);
9495
struct curl_slist *Curl_none_engines_list(struct Curl_easy *data);
9596
bool Curl_none_false_start(void);
97+
bool Curl_ssl_tls13_ciphersuites(void);
9698
CURLcode Curl_none_md5sum(unsigned char *input, size_t inputlen,
9799
unsigned char *md5sum, size_t md5len);
98100

@@ -246,7 +248,7 @@ bool Curl_ssl_false_start(void);
246248

247249
#define SSL_SHUTDOWN_TIMEOUT 10000 /* ms */
248250

249-
#else
251+
#else /* if not USE_SSL */
250252

251253
/* When SSL support is not present, just define away these function calls */
252254
#define Curl_ssl_init() 1
@@ -270,6 +272,7 @@ bool Curl_ssl_false_start(void);
270272
#define Curl_ssl_random(x,y,z) ((void)x, CURLE_NOT_BUILT_IN)
271273
#define Curl_ssl_cert_status_request() FALSE
272274
#define Curl_ssl_false_start() FALSE
275+
#define Curl_ssl_tls13_ciphersuites() FALSE
273276
#endif
274277

275278
#endif /* HEADER_CURL_VTLS_H */

src/tool_cfgable.h

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ struct OperationConfig {
117117
struct getout *url_ul; /* point to the node to fill in upload */
118118
char *cipher_list;
119119
char *proxy_cipher_list;
120+
char *cipher13_list;
121+
char *proxy_cipher13_list;
120122
char *cert;
121123
char *proxy_cert;
122124
char *cert_type;

0 commit comments

Comments
 (0)