1*6236dae4SAndroid Build Coastguard Worker<!-- 2*6236dae4SAndroid Build Coastguard WorkerCopyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard Worker 4*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 5*6236dae4SAndroid Build Coastguard Worker--> 6*6236dae4SAndroid Build Coastguard Worker 7*6236dae4SAndroid Build Coastguard Worker## curl cipher options 8*6236dae4SAndroid Build Coastguard Worker 9*6236dae4SAndroid Build Coastguard WorkerWith curl's option 10*6236dae4SAndroid Build Coastguard Worker[`--tls13-ciphers`](https://curl.se/docs/manpage.html#--tls13-ciphers) 11*6236dae4SAndroid Build Coastguard Workeror 12*6236dae4SAndroid Build Coastguard Worker[`CURLOPT_TLS13_CIPHERS`](https://curl.se/libcurl/c/CURLOPT_TLS13_CIPHERS.html) 13*6236dae4SAndroid Build Coastguard Workerusers can control which cipher suites to consider when negotiating TLS 1.3 14*6236dae4SAndroid Build Coastguard Workerconnections. With option 15*6236dae4SAndroid Build Coastguard Worker[`--ciphers`](https://curl.se/docs/manpage.html#--ciphers) 16*6236dae4SAndroid Build Coastguard Workeror 17*6236dae4SAndroid Build Coastguard Worker[`CURLOPT_SSL_CIPHER_LIST`](https://curl.se/libcurl/c/CURLOPT_SSL_CIPHER_LIST.html) 18*6236dae4SAndroid Build Coastguard Workerusers can control which cipher suites to consider when negotiating 19*6236dae4SAndroid Build Coastguard WorkerTLS 1.2 (1.1, 1.0) connections. 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard WorkerBy default, curl may negotiate TLS 1.3 and TLS 1.2 connections, so the cipher 22*6236dae4SAndroid Build Coastguard Workersuites considered when negotiating a TLS connection are a union of the TLS 1.3 23*6236dae4SAndroid Build Coastguard Workerand TLS 1.2 cipher suites. If you want curl to consider only TLS 1.3 cipher 24*6236dae4SAndroid Build Coastguard Workersuites for the connection, you have to set the minimum TLS version to 1.3 by 25*6236dae4SAndroid Build Coastguard Workerusing [`--tlsv1.3`](https://curl.se/docs/manpage.html#--tlsv13) 26*6236dae4SAndroid Build Coastguard Workeror [`CURLOPT_SSLVERSION`](https://curl.se/libcurl/c/CURLOPT_SSLVERSION.html) 27*6236dae4SAndroid Build Coastguard Workerwith `CURL_SSLVERSION_TLSv1_3`. 28*6236dae4SAndroid Build Coastguard Worker 29*6236dae4SAndroid Build Coastguard WorkerBoth the TLS 1.3 and TLS 1.2 cipher options expect a list of cipher suites 30*6236dae4SAndroid Build Coastguard Workerseparated by colons (`:`). This list is parsed opportunistically, cipher suites 31*6236dae4SAndroid Build Coastguard Workerthat are not recognized or implemented are ignored. As long as there is at 32*6236dae4SAndroid Build Coastguard Workerleast one recognized cipher suite in the list, the list is considered valid. 33*6236dae4SAndroid Build Coastguard Worker 34*6236dae4SAndroid Build Coastguard WorkerFor both the TLS 1.3 and TLS 1.2 cipher options, the order in which the 35*6236dae4SAndroid Build Coastguard Workercipher suites are specified determine the preference of them. When negotiating 36*6236dae4SAndroid Build Coastguard Workera TLS connection the server picks a cipher suite from the intersection of the 37*6236dae4SAndroid Build Coastguard Workercipher suites supported by the server and the cipher suites sent by curl. If 38*6236dae4SAndroid Build Coastguard Workerthe server is configured to honor the client's cipher preference, the first 39*6236dae4SAndroid Build Coastguard Workercommon cipher suite in the list sent by curl is chosen. 40*6236dae4SAndroid Build Coastguard Worker 41*6236dae4SAndroid Build Coastguard Worker## TLS 1.3 cipher suites 42*6236dae4SAndroid Build Coastguard Worker 43*6236dae4SAndroid Build Coastguard WorkerSetting TLS 1.3 cipher suites is supported by curl with 44*6236dae4SAndroid Build Coastguard WorkerOpenSSL (1.1.1+, curl 7.61.0+), LibreSSL (3.4.1+, curl 8.3.0+), 45*6236dae4SAndroid Build Coastguard WorkerwolfSSL (curl 8.10.0+), mbedTLS (3.6.0+, curl 8.10.0+) and 46*6236dae4SAndroid Build Coastguard WorkerSchannel (curl 7.85.0+). 47*6236dae4SAndroid Build Coastguard Worker 48*6236dae4SAndroid Build Coastguard WorkerThe list of cipher suites that can be used for the `--tls13-ciphers` option: 49*6236dae4SAndroid Build Coastguard Worker``` 50*6236dae4SAndroid Build Coastguard WorkerTLS_AES_128_GCM_SHA256 51*6236dae4SAndroid Build Coastguard WorkerTLS_AES_256_GCM_SHA384 52*6236dae4SAndroid Build Coastguard WorkerTLS_CHACHA20_POLY1305_SHA256 53*6236dae4SAndroid Build Coastguard WorkerTLS_AES_128_CCM_SHA256 54*6236dae4SAndroid Build Coastguard WorkerTLS_AES_128_CCM_8_SHA256 55*6236dae4SAndroid Build Coastguard Worker``` 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard Worker### wolfSSL notes 58*6236dae4SAndroid Build Coastguard Worker 59*6236dae4SAndroid Build Coastguard WorkerIn addition to above list the following cipher suites can be used: 60*6236dae4SAndroid Build Coastguard Worker`TLS_SM4_GCM_SM3` `TLS_SM4_CCM_SM3` `TLS_SHA256_SHA256` `TLS_SHA384_SHA384`. 61*6236dae4SAndroid Build Coastguard WorkerUsage of these cipher suites is not recommended. (The last two cipher suites 62*6236dae4SAndroid Build Coastguard Workerare NULL ciphers, offering no encryption whatsoever.) 63*6236dae4SAndroid Build Coastguard Worker 64*6236dae4SAndroid Build Coastguard Worker### Schannel notes 65*6236dae4SAndroid Build Coastguard Worker 66*6236dae4SAndroid Build Coastguard WorkerSchannel does not support setting individual TLS 1.3 cipher suites directly. 67*6236dae4SAndroid Build Coastguard WorkerTo support `--tls13-ciphers` curl emulates it by adding or restricting 68*6236dae4SAndroid Build Coastguard Workeralgorithms to use. Due to this the specified order of preference of the 69*6236dae4SAndroid Build Coastguard Workercipher suites is not taken into account. 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker## TLS 1.2 (1.1, 1.0) cipher suites 72*6236dae4SAndroid Build Coastguard Worker 73*6236dae4SAndroid Build Coastguard WorkerSetting TLS 1.2 cipher suites is supported by curl with OpenSSL, LibreSSL, 74*6236dae4SAndroid Build Coastguard WorkerBoringSSL, mbedTLS (curl 8.8.0+), wolfSSL (curl 7.53.0+), 75*6236dae4SAndroid Build Coastguard WorkerSecure Transport (curl 7.77.0+) and BearSSL (curl 7.83.0+). Schannel does not 76*6236dae4SAndroid Build Coastguard Workersupport setting cipher suites directly, but does support setting algorithms 77*6236dae4SAndroid Build Coastguard Worker(curl 7.61.0+), see Schannel notes below. 78*6236dae4SAndroid Build Coastguard Worker 79*6236dae4SAndroid Build Coastguard WorkerFor TLS 1.2 cipher suites there are multiple naming schemes, the two most used 80*6236dae4SAndroid Build Coastguard Workerare with OpenSSL names (e.g. `ECDHE-RSA-AES128-GCM-SHA256`) and IANA names 81*6236dae4SAndroid Build Coastguard Worker(e.g. `TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256`). IANA names of TLS 1.2 cipher 82*6236dae4SAndroid Build Coastguard Workersuites look similar to TLS 1.3 cipher suite names, to distinguish them note 83*6236dae4SAndroid Build Coastguard Workerthat TLS 1.2 names contain `_WITH_`, while TLS 1.3 names do not. When setting 84*6236dae4SAndroid Build Coastguard WorkerTLS 1.2 cipher suites with curl it is recommended that you use OpenSSL names 85*6236dae4SAndroid Build Coastguard Workeras these are most widely recognized by the supported SSL backends. 86*6236dae4SAndroid Build Coastguard Worker 87*6236dae4SAndroid Build Coastguard WorkerThe complete list of cipher suites that may be considered for the `--ciphers` 88*6236dae4SAndroid Build Coastguard Workeroption is extensive, it consists of more than 300 ciphers suites. However, 89*6236dae4SAndroid Build Coastguard Workernowadays for most of them their usage is discouraged, and support for a lot of 90*6236dae4SAndroid Build Coastguard Workerthem have been removed from the various SSL backends, if ever implemented at 91*6236dae4SAndroid Build Coastguard Workerall. 92*6236dae4SAndroid Build Coastguard Worker 93*6236dae4SAndroid Build Coastguard WorkerA shortened list (based on [recommendations by 94*6236dae4SAndroid Build Coastguard WorkerMozilla](https://wiki.mozilla.org/Security/Server_Side_TLS)) of cipher suites, 95*6236dae4SAndroid Build Coastguard Workerwhich are (mostly) supported by all SSL backends, that can be used for the 96*6236dae4SAndroid Build Coastguard Worker`--ciphers` option: 97*6236dae4SAndroid Build Coastguard Worker``` 98*6236dae4SAndroid Build Coastguard WorkerECDHE-ECDSA-AES128-GCM-SHA256 99*6236dae4SAndroid Build Coastguard WorkerECDHE-RSA-AES128-GCM-SHA256 100*6236dae4SAndroid Build Coastguard WorkerECDHE-ECDSA-AES256-GCM-SHA384 101*6236dae4SAndroid Build Coastguard WorkerECDHE-RSA-AES256-GCM-SHA384 102*6236dae4SAndroid Build Coastguard WorkerECDHE-ECDSA-CHACHA20-POLY1305 103*6236dae4SAndroid Build Coastguard WorkerECDHE-RSA-CHACHA20-POLY1305 104*6236dae4SAndroid Build Coastguard WorkerDHE-RSA-AES128-GCM-SHA256 105*6236dae4SAndroid Build Coastguard WorkerDHE-RSA-AES256-GCM-SHA384 106*6236dae4SAndroid Build Coastguard WorkerDHE-RSA-CHACHA20-POLY1305 107*6236dae4SAndroid Build Coastguard WorkerECDHE-ECDSA-AES128-SHA256 108*6236dae4SAndroid Build Coastguard WorkerECDHE-RSA-AES128-SHA256 109*6236dae4SAndroid Build Coastguard WorkerECDHE-ECDSA-AES128-SHA 110*6236dae4SAndroid Build Coastguard WorkerECDHE-RSA-AES128-SHA 111*6236dae4SAndroid Build Coastguard WorkerECDHE-ECDSA-AES256-SHA384 112*6236dae4SAndroid Build Coastguard WorkerECDHE-RSA-AES256-SHA384 113*6236dae4SAndroid Build Coastguard WorkerECDHE-ECDSA-AES256-SHA 114*6236dae4SAndroid Build Coastguard WorkerECDHE-RSA-AES256-SHA 115*6236dae4SAndroid Build Coastguard WorkerDHE-RSA-AES128-SHA256 116*6236dae4SAndroid Build Coastguard WorkerDHE-RSA-AES256-SHA256 117*6236dae4SAndroid Build Coastguard WorkerAES128-GCM-SHA256 118*6236dae4SAndroid Build Coastguard WorkerAES256-GCM-SHA384 119*6236dae4SAndroid Build Coastguard WorkerAES128-SHA256 120*6236dae4SAndroid Build Coastguard WorkerAES256-SHA256 121*6236dae4SAndroid Build Coastguard WorkerAES128-SHA 122*6236dae4SAndroid Build Coastguard WorkerAES256-SHA 123*6236dae4SAndroid Build Coastguard WorkerDES-CBC3-SHA 124*6236dae4SAndroid Build Coastguard Worker``` 125*6236dae4SAndroid Build Coastguard Worker 126*6236dae4SAndroid Build Coastguard WorkerSee this [list](https://github.com/curl/curl/blob/master/docs/CIPHERS-TLS12.md) 127*6236dae4SAndroid Build Coastguard Workerfor a complete list of TLS 1.2 cipher suites. 128*6236dae4SAndroid Build Coastguard Worker 129*6236dae4SAndroid Build Coastguard Worker### OpenSSL notes 130*6236dae4SAndroid Build Coastguard Worker 131*6236dae4SAndroid Build Coastguard WorkerIn addition to specifying a list of cipher suites, OpenSSL also accepts a 132*6236dae4SAndroid Build Coastguard Workerformat with specific cipher strings (like `TLSv1.2`, `AESGCM`, `CHACHA20`) and 133*6236dae4SAndroid Build Coastguard Worker`!`, `-` and `+` operators. Refer to the 134*6236dae4SAndroid Build Coastguard Worker[OpenSSL cipher documentation](https://docs.openssl.org/master/man1/openssl-ciphers/#cipher-list-format) 135*6236dae4SAndroid Build Coastguard Workerfor further information on that format. 136*6236dae4SAndroid Build Coastguard Worker 137*6236dae4SAndroid Build Coastguard Worker### Schannel notes 138*6236dae4SAndroid Build Coastguard Worker 139*6236dae4SAndroid Build Coastguard WorkerSchannel does not support setting individual TLS 1.2 cipher suites directly. 140*6236dae4SAndroid Build Coastguard WorkerIt only allows the enabling and disabling of encryption algorithms. These are 141*6236dae4SAndroid Build Coastguard Workerin the form of `CALG_xxx`, see the [Schannel `ALG_ID` 142*6236dae4SAndroid Build Coastguard Workerdocumentation](https://docs.microsoft.com/windows/desktop/SecCrypto/alg-id) 143*6236dae4SAndroid Build Coastguard Workerfor a list of these algorithms. Also, (since curl 7.77.0) 144*6236dae4SAndroid Build Coastguard Worker`SCH_USE_STRONG_CRYPTO` can be given to pass that flag to Schannel, lookup the 145*6236dae4SAndroid Build Coastguard Worker[documentation for the Windows version in 146*6236dae4SAndroid Build Coastguard Workeruse](https://learn.microsoft.com/en-us/windows/win32/secauthn/cipher-suites-in-schannel) 147*6236dae4SAndroid Build Coastguard Workerto see how that affects the cipher suite selection. When not specifying the 148*6236dae4SAndroid Build Coastguard Worker`--chiphers` and `--tl13-ciphers` options curl passes this flag by default. 149*6236dae4SAndroid Build Coastguard Worker 150*6236dae4SAndroid Build Coastguard Worker## Examples 151*6236dae4SAndroid Build Coastguard Worker 152*6236dae4SAndroid Build Coastguard Worker```sh 153*6236dae4SAndroid Build Coastguard Workercurl \ 154*6236dae4SAndroid Build Coastguard Worker --tls13-ciphers TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256 \ 155*6236dae4SAndroid Build Coastguard Worker --ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:\ 156*6236dae4SAndroid Build Coastguard WorkerECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305 \ 157*6236dae4SAndroid Build Coastguard Worker https://example.com/ 158*6236dae4SAndroid Build Coastguard Worker``` 159*6236dae4SAndroid Build Coastguard WorkerRestrict ciphers to `aes128-gcm` and `chacha20`. Works with OpenSSL, LibreSSL, 160*6236dae4SAndroid Build Coastguard WorkermbedTLS and wolfSSL. 161*6236dae4SAndroid Build Coastguard Worker 162*6236dae4SAndroid Build Coastguard Worker```sh 163*6236dae4SAndroid Build Coastguard Workercurl \ 164*6236dae4SAndroid Build Coastguard Worker --tlsv1.3 \ 165*6236dae4SAndroid Build Coastguard Worker --tls13-ciphers TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256 \ 166*6236dae4SAndroid Build Coastguard Worker https://example.com/ 167*6236dae4SAndroid Build Coastguard Worker``` 168*6236dae4SAndroid Build Coastguard WorkerRestrict to only TLS 1.3 with `aes128-gcm` and `chacha20` ciphers. Works with 169*6236dae4SAndroid Build Coastguard WorkerOpenSSL, LibreSSL, mbedTLS, wolfSSL and Schannel. 170*6236dae4SAndroid Build Coastguard Worker 171*6236dae4SAndroid Build Coastguard Worker```sh 172*6236dae4SAndroid Build Coastguard Workercurl \ 173*6236dae4SAndroid Build Coastguard Worker --ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:\ 174*6236dae4SAndroid Build Coastguard WorkerECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305 \ 175*6236dae4SAndroid Build Coastguard Worker https://example.com/ 176*6236dae4SAndroid Build Coastguard Worker``` 177*6236dae4SAndroid Build Coastguard WorkerRestrict TLS 1.2 ciphers to `aes128-gcm` and `chacha20`, use default TLS 1.3 178*6236dae4SAndroid Build Coastguard Workerciphers (if TLS 1.3 is available). Works with OpenSSL, LibreSSL, BoringSSL, 179*6236dae4SAndroid Build Coastguard WorkermbedTLS, wolfSSL, Secure Transport and BearSSL. 180*6236dae4SAndroid Build Coastguard Worker 181*6236dae4SAndroid Build Coastguard Worker## Further reading 182*6236dae4SAndroid Build Coastguard Worker- [OpenSSL cipher suite names documentation](https://docs.openssl.org/master/man1/openssl-ciphers/#cipher-suite-names) 183*6236dae4SAndroid Build Coastguard Worker- [wolfSSL cipher support documentation](https://www.wolfssl.com/documentation/manuals/wolfssl/chapter04.html#cipher-support) 184*6236dae4SAndroid Build Coastguard Worker- [mbedTLS cipher suites reference](https://mbed-tls.readthedocs.io/projects/api/en/development/api/file/ssl__ciphersuites_8h/) 185*6236dae4SAndroid Build Coastguard Worker- [Schannel cipher suites documentation](https://learn.microsoft.com/en-us/windows/win32/secauthn/cipher-suites-in-schannel) 186*6236dae4SAndroid Build Coastguard Worker- [BearSSL supported crypto](https://www.bearssl.org/support.html) 187*6236dae4SAndroid Build Coastguard Worker- [Secure Transport cipher suite values](https://developer.apple.com/documentation/security/1550981-ssl_cipher_suite_values) 188*6236dae4SAndroid Build Coastguard Worker- [IANA cipher suites list](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-4) 189*6236dae4SAndroid Build Coastguard Worker- [Wikipedia cipher suite article](https://en.wikipedia.org/wiki/Cipher_suite) 190