You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

473 lines
23 KiB

  1. commit 4be76416751aa22992a44f2f5cfdba506809fd89
  2. Author: Dirkjan Bussink <d.bussink@gmail.com>
  3. Date: Fri Sep 14 11:14:21 2018 +0200
  4. MEDIUM: ssl: add support for ciphersuites option for TLSv1.3
  5. OpenSSL released support for TLSv1.3. It also added a separate function
  6. SSL_CTX_set_ciphersuites that is used to set the ciphers used in the
  7. TLS 1.3 handshake. This change adds support for that new configuration
  8. option by adding a ciphersuites configuration variable that works
  9. essentially the same as the existing ciphers setting.
  10. Note that it should likely be backported to 1.8 in order to ease usage
  11. of the now released openssl-1.1.1.
  12. (cherry picked from commit 415150f7640b06740fa832363d186c5c6565338e)
  13. Signed-off-by: Willy Tarreau <w@1wt.eu>
  14. diff --git a/doc/configuration.txt b/doc/configuration.txt
  15. index 580194ec..7a268386 100644
  16. --- a/doc/configuration.txt
  17. +++ b/doc/configuration.txt
  18. @@ -580,8 +580,10 @@ The following keywords are supported in the "global" section :
  19. - setenv
  20. - stats
  21. - ssl-default-bind-ciphers
  22. + - ssl-default-bind-ciphersuites
  23. - ssl-default-bind-options
  24. - ssl-default-server-ciphers
  25. + - ssl-default-server-ciphersuites
  26. - ssl-default-server-options
  27. - ssl-dh-param-file
  28. - ssl-server-verify
  29. @@ -984,11 +986,25 @@ setenv <name> <value>
  30. ssl-default-bind-ciphers <ciphers>
  31. This setting is only available when support for OpenSSL was built in. It sets
  32. the default string describing the list of cipher algorithms ("cipher suite")
  33. - that are negotiated during the SSL/TLS handshake for all "bind" lines which
  34. - do not explicitly define theirs. The format of the string is defined in
  35. - "man 1 ciphers" from OpenSSL man pages, and can be for instance a string such
  36. - as "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" (without quotes). Please check the
  37. - "bind" keyword for more information.
  38. + that are negotiated during the SSL/TLS handshake except for TLSv1.3 for all
  39. + "bind" lines which do not explicitly define theirs. The format of the string
  40. + is defined in "man 1 ciphers" from OpenSSL man pages, and can be for instance
  41. + a string such as "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" (without quotes). For
  42. + TLSv1.3 cipher configuration, please check the "ssl-default-bind-ciphersuites"
  43. + keyword. Please check the "bind" keyword for more information.
  44. +
  45. +ssl-default-bind-ciphersuites <ciphersuites>
  46. + This setting is only available when support for OpenSSL was built in and
  47. + OpenSSL 1.1.1 or later was used to build HAProxy. It sets the default string
  48. + describing the list of cipher algorithms ("cipher suite") that are negotiated
  49. + during the TLSv1.3 handshake for all "bind" lines which do not explicitly define
  50. + theirs. The format of the string is defined in
  51. + "man 1 ciphers" from OpenSSL man pages under the section "ciphersuites", and can
  52. + be for instance a string such as
  53. + "TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256"
  54. + (without quotes). For cipher configuration for TLSv1.2 and earlier, please check
  55. + the "ssl-default-bind-ciphers" keyword. Please check the "bind" keyword for more
  56. + information.
  57. ssl-default-bind-options [<option>]...
  58. This setting is only available when support for OpenSSL was built in. It sets
  59. @@ -1002,10 +1018,21 @@ ssl-default-bind-options [<option>]...
  60. ssl-default-server-ciphers <ciphers>
  61. This setting is only available when support for OpenSSL was built in. It
  62. sets the default string describing the list of cipher algorithms that are
  63. - negotiated during the SSL/TLS handshake with the server, for all "server"
  64. - lines which do not explicitly define theirs. The format of the string is
  65. - defined in "man 1 ciphers". Please check the "server" keyword for more
  66. - information.
  67. + negotiated during the SSL/TLS handshake except for TLSv1.3 with the server,
  68. + for all "server" lines which do not explicitly define theirs. The format of
  69. + the string is defined in "man 1 ciphers". For TLSv1.3 cipher configuration,
  70. + please check the "ssl-default-server-ciphersuites" keyword. Please check the
  71. + "server" keyword for more information.
  72. +
  73. +ssl-default-server-ciphersuites <ciphersuites>
  74. + This setting is only available when support for OpenSSL was built in and
  75. + OpenSSL 1.1.1 or later was used to build HAProxy. It sets the default
  76. + string describing the list of cipher algorithms that are negotiated during
  77. + the TLSv1.3 handshake with the server, for all "server" lines which do not
  78. + explicitly define theirs. The format of the string is defined in
  79. + "man 1 ciphers" under the "ciphersuites" section. For cipher configuration for
  80. + TLSv1.2 and earlier, please check the "ssl-default-server-ciphers" keyword.
  81. + Please check the "server" keyword for more information.
  82. ssl-default-server-options [<option>]...
  83. This setting is only available when support for OpenSSL was built in. It sets
  84. @@ -10510,13 +10537,26 @@ ca-sign-pass <passphrase>
  85. ciphers <ciphers>
  86. This setting is only available when support for OpenSSL was built in. It sets
  87. the string describing the list of cipher algorithms ("cipher suite") that are
  88. - negotiated during the SSL/TLS handshake. The format of the string is defined
  89. - in "man 1 ciphers" from OpenSSL man pages, and can be for instance a string
  90. - such as "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" (without quotes).
  91. - Depending on the compatibility and security requirements, the list of suitable
  92. - ciphers depends on a variety of variables. For background information and
  93. - recommendations see e. g. (https://wiki.mozilla.org/Security/Server_Side_TLS)
  94. - and (https://mozilla.github.io/server-side-tls/ssl-config-generator/).
  95. + negotiated during the SSL/TLS handshake except for TLSv1.3. The format of the
  96. + string is defined in "man 1 ciphers" from OpenSSL man pages, and can be for
  97. + instance a string such as "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH" (without
  98. + quotes). Depending on the compatibility and security requirements, the list
  99. + of suitable ciphers depends on a variety of variables. For background
  100. + information and recommendations see e.g.
  101. + (https://wiki.mozilla.org/Security/Server_Side_TLS) and
  102. + (https://mozilla.github.io/server-side-tls/ssl-config-generator/). For TLSv1.3
  103. + cipher configuration, please check the "ciphersuites" keyword.
  104. +
  105. +ciphersuites <ciphersuites>
  106. + This setting is only available when support for OpenSSL was built in and
  107. + OpenSSL 1.1.1 or later was used to build HAProxy. It sets the string describing
  108. + the list of cipher algorithms ("cipher suite") that are negotiated during the
  109. + TLSv1.3 handshake. The format of the string is defined in "man 1 ciphers" from
  110. + OpenSSL man pages under the "ciphersuites" section, and can be for instance a
  111. + string such as
  112. + "TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256"
  113. + (without quotes). For cipher configuration for TLSv1.2 and earlier, please check
  114. + the "ciphers" keyword.
  115. crl-file <crlfile>
  116. This setting is only available when support for OpenSSL was built in. It
  117. @@ -11226,8 +11266,9 @@ check-ssl
  118. this option.
  119. ciphers <ciphers>
  120. - This option sets the string describing the list of cipher algorithms that is
  121. - is negotiated during the SSL/TLS handshake with the server. The format of the
  122. + This setting is only available when support for OpenSSL was built in. This
  123. + option sets the string describing the list of cipher algorithms that is
  124. + negotiated during the SSL/TLS handshake with the server. The format of the
  125. string is defined in "man 1 ciphers". When SSL is used to communicate with
  126. servers on the local network, it is common to see a weaker set of algorithms
  127. than what is used over the internet. Doing so reduces CPU usage on both the
  128. @@ -11235,6 +11276,13 @@ ciphers <ciphers>
  129. Some algorithms such as RC4-SHA1 are reasonably cheap. If no security at all
  130. is needed and just connectivity, using DES can be appropriate.
  131. +ciphersuites <ciphersuites>
  132. + This setting is only available when support for OpenSSL was built in and
  133. + OpenSSL 1.1.1 or later was used to build HAProxy. This option sets the string
  134. + describing the list of cipher algorithms that is negotiated during the TLS
  135. + 1.3 handshake with the server. The format of the string is defined in
  136. + "man 1 ciphers" under the "ciphersuites" section.
  137. +
  138. cookie <value>
  139. The "cookie" parameter sets the cookie value assigned to the server to
  140. <value>. This value will be checked in incoming requests, and the first
  141. diff --git a/include/common/defaults.h b/include/common/defaults.h
  142. index f53c611e..a45ab0da 100644
  143. --- a/include/common/defaults.h
  144. +++ b/include/common/defaults.h
  145. @@ -234,11 +234,21 @@
  146. #define CONNECT_DEFAULT_CIPHERS NULL
  147. #endif
  148. +/* ciphers used as defaults on TLS 1.3 connect */
  149. +#ifndef CONNECT_DEFAULT_CIPHERSUITES
  150. +#define CONNECT_DEFAULT_CIPHERSUITES NULL
  151. +#endif
  152. +
  153. /* ciphers used as defaults on listeners */
  154. #ifndef LISTEN_DEFAULT_CIPHERS
  155. #define LISTEN_DEFAULT_CIPHERS NULL
  156. #endif
  157. +/* cipher suites used as defaults on TLS 1.3 listeners */
  158. +#ifndef LISTEN_DEFAULT_CIPHERSUITES
  159. +#define LISTEN_DEFAULT_CIPHERSUITES NULL
  160. +#endif
  161. +
  162. /* named curve used as defaults for ECDHE ciphers */
  163. #ifndef ECDHE_DEFAULT_CURVE
  164. #define ECDHE_DEFAULT_CURVE "prime256v1"
  165. diff --git a/include/types/listener.h b/include/types/listener.h
  166. index c55569cd..ea2eadb5 100644
  167. --- a/include/types/listener.h
  168. +++ b/include/types/listener.h
  169. @@ -128,6 +128,9 @@ struct ssl_bind_conf {
  170. char *ca_file; /* CAfile to use on verify */
  171. char *crl_file; /* CRLfile to use on verify */
  172. char *ciphers; /* cipher suite to use if non-null */
  173. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  174. + char *ciphersuites; /* TLS 1.3 cipher suite to use if non-null */
  175. +#endif
  176. char *curves; /* curves suite to use for ECDHE */
  177. char *ecdhe; /* named curve to use for ECDHE */
  178. struct tls_version_filter ssl_methods; /* ssl methods */
  179. diff --git a/include/types/server.h b/include/types/server.h
  180. index fd3c8bad..79ae7b72 100644
  181. --- a/include/types/server.h
  182. +++ b/include/types/server.h
  183. @@ -281,6 +281,9 @@ struct server {
  184. int allocated_size;
  185. } * reused_sess;
  186. char *ciphers; /* cipher suite to use if non-null */
  187. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  188. + char *ciphersuites; /* TLS 1.3 cipher suite to use if non-null */
  189. +#endif
  190. int options; /* ssl options */
  191. int verify; /* verify method (set of SSL_VERIFY_* flags) */
  192. struct tls_version_filter methods; /* ssl methods */
  193. diff --git a/src/server.c b/src/server.c
  194. index 842e4149..4941bd03 100644
  195. --- a/src/server.c
  196. +++ b/src/server.c
  197. @@ -1380,6 +1380,10 @@ static void srv_ssl_settings_cpy(struct server *srv, struct server *src)
  198. srv->ssl_ctx.verify_host = strdup(src->ssl_ctx.verify_host);
  199. if (src->ssl_ctx.ciphers != NULL)
  200. srv->ssl_ctx.ciphers = strdup(src->ssl_ctx.ciphers);
  201. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  202. + if (src->ssl_ctx.ciphersuites != NULL)
  203. + srv->ssl_ctx.ciphersuites = strdup(src->ssl_ctx.ciphersuites);
  204. +#endif
  205. if (src->sni_expr != NULL)
  206. srv->sni_expr = strdup(src->sni_expr);
  207. }
  208. diff --git a/src/ssl_sock.c b/src/ssl_sock.c
  209. index 08fdffab..2da0df68 100644
  210. --- a/src/ssl_sock.c
  211. +++ b/src/ssl_sock.c
  212. @@ -169,6 +169,10 @@ static struct {
  213. char *listen_default_ciphers;
  214. char *connect_default_ciphers;
  215. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  216. + char *listen_default_ciphersuites;
  217. + char *connect_default_ciphersuites;
  218. +#endif
  219. int listen_default_ssloptions;
  220. int connect_default_ssloptions;
  221. struct tls_version_filter listen_default_sslmethods;
  222. @@ -186,6 +190,14 @@ static struct {
  223. #endif
  224. #ifdef CONNECT_DEFAULT_CIPHERS
  225. .connect_default_ciphers = CONNECT_DEFAULT_CIPHERS,
  226. +#endif
  227. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  228. +#ifdef LISTEN_DEFAULT_CIPHERSUITES
  229. + .listen_default_ciphersuites = LISTEN_DEFAULT_CIPHERSUITES,
  230. +#endif
  231. +#ifdef CONNECT_DEFAULT_CIPHERSUITES
  232. + .connect_default_ciphersuites = CONNECT_DEFAULT_CIPHERSUITES,
  233. +#endif
  234. #endif
  235. .listen_default_ssloptions = BC_SSL_O_NONE,
  236. .connect_default_ssloptions = SRV_SSL_O_NONE,
  237. @@ -3528,6 +3540,10 @@ void ssl_sock_free_ssl_conf(struct ssl_bind_conf *conf)
  238. conf->crl_file = NULL;
  239. free(conf->ciphers);
  240. conf->ciphers = NULL;
  241. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  242. + free(conf->ciphersuites);
  243. + conf->ciphersuites = NULL;
  244. +#endif
  245. free(conf->curves);
  246. conf->curves = NULL;
  247. free(conf->ecdhe);
  248. @@ -4061,6 +4077,9 @@ int ssl_sock_prepare_ctx(struct bind_conf *bind_conf, struct ssl_bind_conf *ssl_
  249. int verify = SSL_VERIFY_NONE;
  250. struct ssl_bind_conf __maybe_unused *ssl_conf_cur;
  251. const char *conf_ciphers;
  252. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  253. + const char *conf_ciphersuites;
  254. +#endif
  255. const char *conf_curves = NULL;
  256. if (ssl_conf) {
  257. @@ -4160,6 +4179,16 @@ int ssl_sock_prepare_ctx(struct bind_conf *bind_conf, struct ssl_bind_conf *ssl_
  258. cfgerr++;
  259. }
  260. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  261. + conf_ciphersuites = (ssl_conf && ssl_conf->ciphersuites) ? ssl_conf->ciphersuites : bind_conf->ssl_conf.ciphersuites;
  262. + if (conf_ciphersuites &&
  263. + !SSL_CTX_set_ciphersuites(ctx, conf_ciphersuites)) {
  264. + ha_alert("Proxy '%s': unable to set TLS 1.3 cipher suites to '%s' for bind '%s' at [%s:%d].\n",
  265. + curproxy->id, conf_ciphersuites, bind_conf->arg, bind_conf->file, bind_conf->line);
  266. + cfgerr++;
  267. + }
  268. +#endif
  269. +
  270. #ifndef OPENSSL_NO_DH
  271. /* If tune.ssl.default-dh-param has not been set,
  272. neither has ssl-default-dh-file and no static DH
  273. @@ -4642,6 +4671,16 @@ int ssl_sock_prepare_srv_ctx(struct server *srv)
  274. cfgerr++;
  275. }
  276. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  277. + if (srv->ssl_ctx.ciphersuites &&
  278. + !SSL_CTX_set_cipher_list(srv->ssl_ctx.ctx, srv->ssl_ctx.ciphersuites)) {
  279. + ha_alert("Proxy '%s', server '%s' [%s:%d] : unable to set TLS 1.3 cipher suites to '%s'.\n",
  280. + curproxy->id, srv->id,
  281. + srv->conf.file, srv->conf.line, srv->ssl_ctx.ciphersuites);
  282. + cfgerr++;
  283. + }
  284. +#endif
  285. +
  286. return cfgerr;
  287. }
  288. @@ -7101,6 +7140,26 @@ static int bind_parse_ciphers(char **args, int cur_arg, struct proxy *px, struct
  289. {
  290. return ssl_bind_parse_ciphers(args, cur_arg, px, &conf->ssl_conf, err);
  291. }
  292. +
  293. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  294. +/* parse the "ciphersuites" bind keyword */
  295. +static int ssl_bind_parse_ciphersuites(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
  296. +{
  297. + if (!*args[cur_arg + 1]) {
  298. + memprintf(err, "'%s' : missing cipher suite", args[cur_arg]);
  299. + return ERR_ALERT | ERR_FATAL;
  300. + }
  301. +
  302. + free(conf->ciphersuites);
  303. + conf->ciphersuites = strdup(args[cur_arg + 1]);
  304. + return 0;
  305. +}
  306. +static int bind_parse_ciphersuites(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
  307. +{
  308. + return ssl_bind_parse_ciphersuites(args, cur_arg, px, &conf->ssl_conf, err);
  309. +}
  310. +#endif
  311. +
  312. /* parse the "crt" bind keyword */
  313. static int bind_parse_crt(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
  314. {
  315. @@ -7492,6 +7551,10 @@ static int bind_parse_ssl(char **args, int cur_arg, struct proxy *px, struct bin
  316. if (global_ssl.listen_default_ciphers && !conf->ssl_conf.ciphers)
  317. conf->ssl_conf.ciphers = strdup(global_ssl.listen_default_ciphers);
  318. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  319. + if (global_ssl.listen_default_ciphersuites && !conf->ssl_conf.ciphersuites)
  320. + conf->ssl_conf.ciphersuites = strdup(global_ssl.listen_default_ciphersuites);
  321. +#endif
  322. conf->ssl_options |= global_ssl.listen_default_ssloptions;
  323. conf->ssl_conf.ssl_methods.flags |= global_ssl.listen_default_sslmethods.flags;
  324. if (!conf->ssl_conf.ssl_methods.min)
  325. @@ -7689,6 +7752,10 @@ static int srv_parse_check_ssl(char **args, int *cur_arg, struct proxy *px, stru
  326. newsrv->check.use_ssl = 1;
  327. if (global_ssl.connect_default_ciphers && !newsrv->ssl_ctx.ciphers)
  328. newsrv->ssl_ctx.ciphers = strdup(global_ssl.connect_default_ciphers);
  329. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  330. + if (global_ssl.connect_default_ciphersuites && !newsrv->ssl_ctx.ciphersuites)
  331. + newsrv->ssl_ctx.ciphersuites = strdup(global_ssl.connect_default_ciphersuites);
  332. +#endif
  333. newsrv->ssl_ctx.options |= global_ssl.connect_default_ssloptions;
  334. newsrv->ssl_ctx.methods.flags |= global_ssl.connect_default_sslmethods.flags;
  335. if (!newsrv->ssl_ctx.methods.min)
  336. @@ -7712,6 +7779,21 @@ static int srv_parse_ciphers(char **args, int *cur_arg, struct proxy *px, struct
  337. return 0;
  338. }
  339. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  340. +/* parse the "ciphersuites" server keyword */
  341. +static int srv_parse_ciphersuites(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
  342. +{
  343. + if (!*args[*cur_arg + 1]) {
  344. + memprintf(err, "'%s' : missing cipher suite", args[*cur_arg]);
  345. + return ERR_ALERT | ERR_FATAL;
  346. + }
  347. +
  348. + free(newsrv->ssl_ctx.ciphersuites);
  349. + newsrv->ssl_ctx.ciphersuites = strdup(args[*cur_arg + 1]);
  350. + return 0;
  351. +}
  352. +#endif
  353. +
  354. /* parse the "crl-file" server keyword */
  355. static int srv_parse_crl_file(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
  356. {
  357. @@ -7853,6 +7935,10 @@ static int srv_parse_ssl(char **args, int *cur_arg, struct proxy *px, struct ser
  358. newsrv->use_ssl = 1;
  359. if (global_ssl.connect_default_ciphers && !newsrv->ssl_ctx.ciphers)
  360. newsrv->ssl_ctx.ciphers = strdup(global_ssl.connect_default_ciphers);
  361. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  362. + if (global_ssl.connect_default_ciphersuites && !newsrv->ssl_ctx.ciphersuites)
  363. + newsrv->ssl_ctx.ciphersuites = strdup(global_ssl.connect_default_ciphersuites);
  364. +#endif
  365. return 0;
  366. }
  367. @@ -8092,6 +8178,32 @@ static int ssl_parse_global_ciphers(char **args, int section_type, struct proxy
  368. return 0;
  369. }
  370. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  371. +/* parse the "ssl-default-bind-ciphersuites" / "ssl-default-server-ciphersuites" keywords
  372. + * in global section. Returns <0 on alert, >0 on warning, 0 on success.
  373. + */
  374. +static int ssl_parse_global_ciphersuites(char **args, int section_type, struct proxy *curpx,
  375. + struct proxy *defpx, const char *file, int line,
  376. + char **err)
  377. +{
  378. + char **target;
  379. +
  380. + target = (args[0][12] == 'b') ? &global_ssl.listen_default_ciphersuites : &global_ssl.connect_default_ciphersuites;
  381. +
  382. + if (too_many_args(1, args, err, NULL))
  383. + return -1;
  384. +
  385. + if (*(args[1]) == 0) {
  386. + memprintf(err, "global statement '%s' expects a cipher suite as an argument.", args[0]);
  387. + return -1;
  388. + }
  389. +
  390. + free(*target);
  391. + *target = strdup(args[1]);
  392. + return 0;
  393. +}
  394. +#endif
  395. +
  396. /* parse various global tune.ssl settings consisting in positive integers.
  397. * Returns <0 on alert, >0 on warning, 0 on success.
  398. */
  399. @@ -8599,6 +8711,9 @@ static struct ssl_bind_kw ssl_bind_kws[] = {
  400. { "alpn", ssl_bind_parse_alpn, 1 }, /* set ALPN supported protocols */
  401. { "ca-file", ssl_bind_parse_ca_file, 1 }, /* set CAfile to process verify on client cert */
  402. { "ciphers", ssl_bind_parse_ciphers, 1 }, /* set SSL cipher suite */
  403. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  404. + { "ciphersuites", ssl_bind_parse_ciphersuites, 1 }, /* set TLS 1.3 cipher suite */
  405. +#endif
  406. { "crl-file", ssl_bind_parse_crl_file, 1 }, /* set certificat revocation list file use on client cert verify */
  407. { "curves", ssl_bind_parse_curves, 1 }, /* set SSL curve suite */
  408. { "ecdhe", ssl_bind_parse_ecdhe, 1 }, /* defines named curve for elliptic curve Diffie-Hellman */
  409. @@ -8618,6 +8733,9 @@ static struct bind_kw_list bind_kws = { "SSL", { }, {
  410. { "ca-sign-file", bind_parse_ca_sign_file, 1 }, /* set CAFile used to generate and sign server certs */
  411. { "ca-sign-pass", bind_parse_ca_sign_pass, 1 }, /* set CAKey passphrase */
  412. { "ciphers", bind_parse_ciphers, 1 }, /* set SSL cipher suite */
  413. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  414. + { "ciphersuites", bind_parse_ciphersuites, 1 }, /* set TLS 1.3 cipher suite */
  415. +#endif
  416. { "crl-file", bind_parse_crl_file, 1 }, /* set certificat revocation list file use on client cert verify */
  417. { "crt", bind_parse_crt, 1 }, /* load SSL certificates from this location */
  418. { "crt-ignore-err", bind_parse_ignore_err, 1 }, /* set error IDs to ingore on verify depth == 0 */
  419. @@ -8661,6 +8779,9 @@ static struct srv_kw_list srv_kws = { "SSL", { }, {
  420. { "check-sni", srv_parse_check_sni, 1, 1 }, /* set SNI */
  421. { "check-ssl", srv_parse_check_ssl, 0, 1 }, /* enable SSL for health checks */
  422. { "ciphers", srv_parse_ciphers, 1, 1 }, /* select the cipher suite */
  423. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  424. + { "ciphersuites", srv_parse_ciphersuites, 1, 1 }, /* select the cipher suite */
  425. +#endif
  426. { "crl-file", srv_parse_crl_file, 1, 1 }, /* set certificate revocation list file use on server cert verify */
  427. { "crt", srv_parse_crt, 1, 1 }, /* set client certificate */
  428. { "force-sslv3", srv_parse_tls_method_options, 0, 1 }, /* force SSLv3 */
  429. @@ -8716,6 +8837,10 @@ static struct cfg_kw_list cfg_kws = {ILH, {
  430. { CFG_GLOBAL, "tune.ssl.capture-cipherlist-size", ssl_parse_global_capture_cipherlist },
  431. { CFG_GLOBAL, "ssl-default-bind-ciphers", ssl_parse_global_ciphers },
  432. { CFG_GLOBAL, "ssl-default-server-ciphers", ssl_parse_global_ciphers },
  433. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  434. + { CFG_GLOBAL, "ssl-default-bind-ciphersuites", ssl_parse_global_ciphersuites },
  435. + { CFG_GLOBAL, "ssl-default-server-ciphersuites", ssl_parse_global_ciphersuites },
  436. +#endif
  437. { 0, NULL, NULL },
  438. }};
  439. @@ -8793,6 +8918,12 @@ static void __ssl_sock_init(void)
  440. global_ssl.listen_default_ciphers = strdup(global_ssl.listen_default_ciphers);
  441. if (global_ssl.connect_default_ciphers)
  442. global_ssl.connect_default_ciphers = strdup(global_ssl.connect_default_ciphers);
  443. +#if (OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
  444. + if (global_ssl.listen_default_ciphersuites)
  445. + global_ssl.listen_default_ciphersuites = strdup(global_ssl.listen_default_ciphersuites);
  446. + if (global_ssl.connect_default_ciphersuites)
  447. + global_ssl.connect_default_ciphersuites = strdup(global_ssl.connect_default_ciphersuites);
  448. +#endif
  449. xprt_register(XPRT_SSL, &ssl_sock);
  450. SSL_library_init();