blob: 374ca920b1e8cca2500922c726173511e1a2cee7 [file] [log] [blame]
William Lallemanddad31052020-05-14 17:47:32 +02001/*
2 *
3 * Copyright (C) 2012 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
4 * Copyright (C) 2020 HAProxy Technologies, William Lallemand <wlallemand@haproxy.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 *
12 * Configuration parsing for SSL.
13 * This file is split in 3 parts:
14 * - global section parsing
15 * - bind keyword parsing
16 * - server keyword parsing
17 *
18 * Please insert the new keywords at the right place
19 */
20
21#define _GNU_SOURCE
22#include <ctype.h>
23#include <dirent.h>
24#include <errno.h>
25#include <fcntl.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <unistd.h>
30
31#include <sys/stat.h>
32#include <sys/types.h>
33
34#include <common/base64.h>
35#include <common/cfgparse.h>
36#include <common/initcall.h>
37#include <common/openssl-compat.h>
38
39#include <types/ssl_sock.h>
40
41#include <proto/listener.h>
42#include <proto/ssl_sock.h>
43
44
45/****************** Global Section Parsing ********************************************/
46
47static int ssl_load_global_issuers_from_path(char **args, int section_type, struct proxy *curpx,
48 struct proxy *defpx, const char *file, int line,
49 char **err)
50{
51 char *path;
52 struct dirent **de_list;
53 int i, n;
54 struct stat buf;
55 char *end;
56 char fp[MAXPATHLEN+1];
57
58 if (too_many_args(1, args, err, NULL))
59 return -1;
60
61 path = args[1];
62 if (*path == 0 || stat(path, &buf)) {
63 memprintf(err, "%sglobal statement '%s' expects a directory path as an argument.\n",
64 err && *err ? *err : "", args[0]);
65 return -1;
66 }
67 if (S_ISDIR(buf.st_mode) == 0) {
68 memprintf(err, "%sglobal statement '%s': %s is not a directory.\n",
69 err && *err ? *err : "", args[0], path);
70 return -1;
71 }
72
73 /* strip trailing slashes, including first one */
74 for (end = path + strlen(path) - 1; end >= path && *end == '/'; end--)
75 *end = 0;
76 /* path already parsed? */
77 if (global_ssl.issuers_chain_path && strcmp(global_ssl.issuers_chain_path, path) == 0)
78 return 0;
79 /* overwrite old issuers_chain_path */
80 free(global_ssl.issuers_chain_path);
81 global_ssl.issuers_chain_path = strdup(path);
82 ssl_free_global_issuers();
83
84 n = scandir(path, &de_list, 0, alphasort);
85 if (n < 0) {
86 memprintf(err, "%sglobal statement '%s': unable to scan directory '%s' : %s.\n",
87 err && *err ? *err : "", args[0], path, strerror(errno));
88 return -1;
89 }
90 for (i = 0; i < n; i++) {
91 struct dirent *de = de_list[i];
92 BIO *in = NULL;
93 char *warn = NULL;
94
95 snprintf(fp, sizeof(fp), "%s/%s", path, de->d_name);
96 free(de);
97 if (stat(fp, &buf) != 0) {
98 ha_warning("unable to stat certificate from file '%s' : %s.\n", fp, strerror(errno));
99 goto next;
100 }
101 if (!S_ISREG(buf.st_mode))
102 goto next;
103
104 in = BIO_new(BIO_s_file());
105 if (in == NULL)
106 goto next;
107 if (BIO_read_filename(in, fp) <= 0)
108 goto next;
109 ssl_load_global_issuer_from_BIO(in, fp, &warn);
110 if (warn) {
111 ha_warning("%s", warn);
112 free(warn);
113 warn = NULL;
114 }
115 next:
116 if (in)
117 BIO_free(in);
118 }
119 free(de_list);
120
121 return 0;
122}
123
William Lallemanddad31052020-05-14 17:47:32 +0200124/* parse the "ssl-mode-async" keyword in global section.
125 * Returns <0 on alert, >0 on warning, 0 on success.
126 */
127static int ssl_parse_global_ssl_async(char **args, int section_type, struct proxy *curpx,
128 struct proxy *defpx, const char *file, int line,
129 char **err)
130{
131#if (HA_OPENSSL_VERSION_NUMBER >= 0x1010000fL) && !defined(OPENSSL_NO_ASYNC)
132 global_ssl.async = 1;
133 global.ssl_used_async_engines = nb_engines;
134 return 0;
135#else
136 memprintf(err, "'%s': openssl library does not support async mode", args[0]);
137 return -1;
138#endif
139}
140
William Lallemand5520d6f2020-05-18 13:42:49 +0200141#ifndef OPENSSL_NO_ENGINE
William Lallemanddad31052020-05-14 17:47:32 +0200142/* parse the "ssl-engine" keyword in global section.
143 * Returns <0 on alert, >0 on warning, 0 on success.
144 */
145static int ssl_parse_global_ssl_engine(char **args, int section_type, struct proxy *curpx,
146 struct proxy *defpx, const char *file, int line,
147 char **err)
148{
149 char *algo;
150 int ret = -1;
151
152 if (*(args[1]) == 0) {
153 memprintf(err, "global statement '%s' expects a valid engine name as an argument.", args[0]);
154 return ret;
155 }
156
157 if (*(args[2]) == 0) {
158 /* if no list of algorithms is given, it defaults to ALL */
159 algo = strdup("ALL");
160 goto add_engine;
161 }
162
163 /* otherwise the expected format is ssl-engine <engine_name> algo <list of algo> */
164 if (strcmp(args[2], "algo") != 0) {
165 memprintf(err, "global statement '%s' expects to have algo keyword.", args[0]);
166 return ret;
167 }
168
169 if (*(args[3]) == 0) {
170 memprintf(err, "global statement '%s' expects algorithm names as an argument.", args[0]);
171 return ret;
172 }
173 algo = strdup(args[3]);
174
175add_engine:
176 if (ssl_init_single_engine(args[1], algo)==0) {
177 openssl_engines_initialized++;
178 ret = 0;
179 }
180 free(algo);
181 return ret;
182}
183#endif
184
185/* parse the "ssl-default-bind-ciphers" / "ssl-default-server-ciphers" keywords
186 * in global section. Returns <0 on alert, >0 on warning, 0 on success.
187 */
188static int ssl_parse_global_ciphers(char **args, int section_type, struct proxy *curpx,
189 struct proxy *defpx, const char *file, int line,
190 char **err)
191{
192 char **target;
193
194 target = (args[0][12] == 'b') ? &global_ssl.listen_default_ciphers : &global_ssl.connect_default_ciphers;
195
196 if (too_many_args(1, args, err, NULL))
197 return -1;
198
199 if (*(args[1]) == 0) {
200 memprintf(err, "global statement '%s' expects a cipher suite as an argument.", args[0]);
201 return -1;
202 }
203
204 free(*target);
205 *target = strdup(args[1]);
206 return 0;
207}
208
209#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
210/* parse the "ssl-default-bind-ciphersuites" / "ssl-default-server-ciphersuites" keywords
211 * in global section. Returns <0 on alert, >0 on warning, 0 on success.
212 */
213static int ssl_parse_global_ciphersuites(char **args, int section_type, struct proxy *curpx,
214 struct proxy *defpx, const char *file, int line,
215 char **err)
216{
217 char **target;
218
219 target = (args[0][12] == 'b') ? &global_ssl.listen_default_ciphersuites : &global_ssl.connect_default_ciphersuites;
220
221 if (too_many_args(1, args, err, NULL))
222 return -1;
223
224 if (*(args[1]) == 0) {
225 memprintf(err, "global statement '%s' expects a cipher suite as an argument.", args[0]);
226 return -1;
227 }
228
229 free(*target);
230 *target = strdup(args[1]);
231 return 0;
232}
233#endif
234
235#if ((HA_OPENSSL_VERSION_NUMBER >= 0x1000200fL) || defined(LIBRESSL_VERSION_NUMBER))
236/*
237 * parse the "ssl-default-bind-curves" keyword in a global section.
238 * Returns <0 on alert, >0 on warning, 0 on success.
239 */
240static int ssl_parse_global_curves(char **args, int section_type, struct proxy *curpx,
241 struct proxy *defpx, const char *file, int line,
242 char **err)
243{
244 char **target;
245 target = &global_ssl.listen_default_curves;
246
247 if (too_many_args(1, args, err, NULL))
248 return -1;
249
250 if (*(args[1]) == 0) {
251 memprintf(err, "global statement '%s' expects a curves suite as an arguments.", args[0]);
252 return -1;
253 }
254
255 free(*target);
256 *target = strdup(args[1]);
257 return 0;
258}
259#endif
260/* parse various global tune.ssl settings consisting in positive integers.
261 * Returns <0 on alert, >0 on warning, 0 on success.
262 */
263static int ssl_parse_global_int(char **args, int section_type, struct proxy *curpx,
264 struct proxy *defpx, const char *file, int line,
265 char **err)
266{
267 int *target;
268
269 if (strcmp(args[0], "tune.ssl.cachesize") == 0)
270 target = &global.tune.sslcachesize;
271 else if (strcmp(args[0], "tune.ssl.maxrecord") == 0)
272 target = (int *)&global_ssl.max_record;
273 else if (strcmp(args[0], "tune.ssl.ssl-ctx-cache-size") == 0)
274 target = &global_ssl.ctx_cache;
275 else if (strcmp(args[0], "maxsslconn") == 0)
276 target = &global.maxsslconn;
277 else if (strcmp(args[0], "tune.ssl.capture-cipherlist-size") == 0)
278 target = &global_ssl.capture_cipherlist;
279 else {
280 memprintf(err, "'%s' keyword not unhandled (please report this bug).", args[0]);
281 return -1;
282 }
283
284 if (too_many_args(1, args, err, NULL))
285 return -1;
286
287 if (*(args[1]) == 0) {
288 memprintf(err, "'%s' expects an integer argument.", args[0]);
289 return -1;
290 }
291
292 *target = atoi(args[1]);
293 if (*target < 0) {
294 memprintf(err, "'%s' expects a positive numeric value.", args[0]);
295 return -1;
296 }
297 return 0;
298}
299
300static int ssl_parse_global_capture_cipherlist(char **args, int section_type, struct proxy *curpx,
301 struct proxy *defpx, const char *file, int line,
302 char **err)
303{
304 int ret;
305
306 ret = ssl_parse_global_int(args, section_type, curpx, defpx, file, line, err);
307 if (ret != 0)
308 return ret;
309
310 if (pool_head_ssl_capture) {
311 memprintf(err, "'%s' is already configured.", args[0]);
312 return -1;
313 }
314
315 pool_head_ssl_capture = create_pool("ssl-capture", sizeof(struct ssl_capture) + global_ssl.capture_cipherlist, MEM_F_SHARED);
316 if (!pool_head_ssl_capture) {
317 memprintf(err, "Out of memory error.");
318 return -1;
319 }
320 return 0;
321}
322
323/* parse "ssl.force-private-cache".
324 * Returns <0 on alert, >0 on warning, 0 on success.
325 */
326static int ssl_parse_global_private_cache(char **args, int section_type, struct proxy *curpx,
327 struct proxy *defpx, const char *file, int line,
328 char **err)
329{
330 if (too_many_args(0, args, err, NULL))
331 return -1;
332
333 global_ssl.private_cache = 1;
334 return 0;
335}
336
337/* parse "ssl.lifetime".
338 * Returns <0 on alert, >0 on warning, 0 on success.
339 */
340static int ssl_parse_global_lifetime(char **args, int section_type, struct proxy *curpx,
341 struct proxy *defpx, const char *file, int line,
342 char **err)
343{
344 const char *res;
345
346 if (too_many_args(1, args, err, NULL))
347 return -1;
348
349 if (*(args[1]) == 0) {
350 memprintf(err, "'%s' expects ssl sessions <lifetime> in seconds as argument.", args[0]);
351 return -1;
352 }
353
354 res = parse_time_err(args[1], &global_ssl.life_time, TIME_UNIT_S);
355 if (res == PARSE_TIME_OVER) {
356 memprintf(err, "timer overflow in argument '%s' to <%s> (maximum value is 2147483647 s or ~68 years).",
357 args[1], args[0]);
358 return -1;
359 }
360 else if (res == PARSE_TIME_UNDER) {
361 memprintf(err, "timer underflow in argument '%s' to <%s> (minimum non-null value is 1 s).",
362 args[1], args[0]);
363 return -1;
364 }
365 else if (res) {
366 memprintf(err, "unexpected character '%c' in argument to <%s>.", *res, args[0]);
367 return -1;
368 }
369 return 0;
370}
371
372#ifndef OPENSSL_NO_DH
373/* parse "ssl-dh-param-file".
374 * Returns <0 on alert, >0 on warning, 0 on success.
375 */
376static int ssl_parse_global_dh_param_file(char **args, int section_type, struct proxy *curpx,
377 struct proxy *defpx, const char *file, int line,
378 char **err)
379{
380 if (too_many_args(1, args, err, NULL))
381 return -1;
382
383 if (*(args[1]) == 0) {
384 memprintf(err, "'%s' expects a file path as an argument.", args[0]);
385 return -1;
386 }
387
388 if (ssl_sock_load_global_dh_param_from_file(args[1])) {
389 memprintf(err, "'%s': unable to load DH parameters from file <%s>.", args[0], args[1]);
390 return -1;
391 }
392 return 0;
393}
394
395/* parse "ssl.default-dh-param".
396 * Returns <0 on alert, >0 on warning, 0 on success.
397 */
398static int ssl_parse_global_default_dh(char **args, int section_type, struct proxy *curpx,
399 struct proxy *defpx, const char *file, int line,
400 char **err)
401{
402 if (too_many_args(1, args, err, NULL))
403 return -1;
404
405 if (*(args[1]) == 0) {
406 memprintf(err, "'%s' expects an integer argument.", args[0]);
407 return -1;
408 }
409
410 global_ssl.default_dh_param = atoi(args[1]);
411 if (global_ssl.default_dh_param < 1024) {
412 memprintf(err, "'%s' expects a value >= 1024.", args[0]);
413 return -1;
414 }
415 return 0;
416}
417#endif
418
419
420/*
421 * parse "ssl-load-extra-files".
422 * multiple arguments are allowed: "bundle", "sctl", "ocsp", "issuer", "all", "none"
423 */
424static int ssl_parse_global_extra_files(char **args, int section_type, struct proxy *curpx,
425 struct proxy *defpx, const char *file, int line,
426 char **err)
427{
428 int i;
429 int gf = SSL_GF_NONE;
430
431 if (*(args[1]) == 0)
432 goto err_arg;
433
434 for (i = 1; *args[i]; i++) {
435
436 if (!strcmp("bundle", args[i])) {
437 gf |= SSL_GF_BUNDLE;
438
439 } else if (!strcmp("sctl", args[i])) {
440 gf |= SSL_GF_SCTL;
441
442 } else if (!strcmp("ocsp", args[i])){
443 gf |= SSL_GF_OCSP;
444
445 } else if (!strcmp("issuer", args[i])){
446 gf |= SSL_GF_OCSP_ISSUER;
447
448 } else if (!strcmp("key", args[i])) {
449 gf |= SSL_GF_KEY;
450
451 } else if (!strcmp("none", args[i])) {
452 if (gf != SSL_GF_NONE)
453 goto err_alone;
454 gf = SSL_GF_NONE;
455 i++;
456 break;
457
458 } else if (!strcmp("all", args[i])) {
459 if (gf != SSL_GF_NONE)
460 goto err_alone;
461 gf = SSL_GF_ALL;
462 i++;
463 break;
464 } else {
465 goto err_arg;
466 }
467 }
468 /* break from loop but there are still arguments */
469 if (*args[i])
470 goto err_alone;
471
472 global_ssl.extra_files = gf;
473
474 return 0;
475
476err_alone:
477 memprintf(err, "'%s' 'none' and 'all' can be only used alone", args[0]);
478 return -1;
479
480err_arg:
481 memprintf(err, "'%s' expects one or multiple arguments (none, all, bundle, sctl, ocsp, issuer).", args[0]);
482 return -1;
483}
484
485
486/***************************** Bind keyword Parsing ********************************************/
487
488/* for ca-file and ca-verify-file */
489static int ssl_bind_parse_ca_file_common(char **args, int cur_arg, char **ca_file_p, char **err)
490{
491 if (!*args[cur_arg + 1]) {
492 memprintf(err, "'%s' : missing CAfile path", args[cur_arg]);
493 return ERR_ALERT | ERR_FATAL;
494 }
495
496 if ((*args[cur_arg + 1] != '/') && global_ssl.ca_base)
497 memprintf(ca_file_p, "%s/%s", global_ssl.ca_base, args[cur_arg + 1]);
498 else
499 memprintf(ca_file_p, "%s", args[cur_arg + 1]);
500
501 if (!ssl_store_load_locations_file(*ca_file_p)) {
502 memprintf(err, "'%s' : unable to load %s", args[cur_arg], *ca_file_p);
503 return ERR_ALERT | ERR_FATAL;
504 }
505 return 0;
506}
507
508/* parse the "ca-file" bind keyword */
509static int ssl_bind_parse_ca_file(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
510{
511 return ssl_bind_parse_ca_file_common(args, cur_arg, &conf->ca_file, err);
512}
513static int bind_parse_ca_file(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
514{
515 return ssl_bind_parse_ca_file(args, cur_arg, px, &conf->ssl_conf, err);
516}
517
518/* parse the "ca-verify-file" bind keyword */
519static int ssl_bind_parse_ca_verify_file(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
520{
521 return ssl_bind_parse_ca_file_common(args, cur_arg, &conf->ca_verify_file, err);
522}
523static int bind_parse_ca_verify_file(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
524{
525 return ssl_bind_parse_ca_verify_file(args, cur_arg, px, &conf->ssl_conf, err);
526}
527
528/* parse the "ca-sign-file" bind keyword */
529static int bind_parse_ca_sign_file(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
530{
531 if (!*args[cur_arg + 1]) {
532 memprintf(err, "'%s' : missing CAfile path", args[cur_arg]);
533 return ERR_ALERT | ERR_FATAL;
534 }
535
536 if ((*args[cur_arg + 1] != '/') && global_ssl.ca_base)
537 memprintf(&conf->ca_sign_file, "%s/%s", global_ssl.ca_base, args[cur_arg + 1]);
538 else
539 memprintf(&conf->ca_sign_file, "%s", args[cur_arg + 1]);
540
541 return 0;
542}
543
544/* parse the "ca-sign-pass" bind keyword */
545static int bind_parse_ca_sign_pass(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
546{
547 if (!*args[cur_arg + 1]) {
548 memprintf(err, "'%s' : missing CAkey password", args[cur_arg]);
549 return ERR_ALERT | ERR_FATAL;
550 }
551 memprintf(&conf->ca_sign_pass, "%s", args[cur_arg + 1]);
552 return 0;
553}
554
555/* parse the "ciphers" bind keyword */
556static int ssl_bind_parse_ciphers(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
557{
558 if (!*args[cur_arg + 1]) {
559 memprintf(err, "'%s' : missing cipher suite", args[cur_arg]);
560 return ERR_ALERT | ERR_FATAL;
561 }
562
563 free(conf->ciphers);
564 conf->ciphers = strdup(args[cur_arg + 1]);
565 return 0;
566}
567static int bind_parse_ciphers(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
568{
569 return ssl_bind_parse_ciphers(args, cur_arg, px, &conf->ssl_conf, err);
570}
571
572#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
573/* parse the "ciphersuites" bind keyword */
574static int ssl_bind_parse_ciphersuites(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
575{
576 if (!*args[cur_arg + 1]) {
577 memprintf(err, "'%s' : missing cipher suite", args[cur_arg]);
578 return ERR_ALERT | ERR_FATAL;
579 }
580
581 free(conf->ciphersuites);
582 conf->ciphersuites = strdup(args[cur_arg + 1]);
583 return 0;
584}
585static int bind_parse_ciphersuites(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
586{
587 return ssl_bind_parse_ciphersuites(args, cur_arg, px, &conf->ssl_conf, err);
588}
589#endif
590
591/* parse the "crt" bind keyword. Returns a set of ERR_* flags possibly with an error in <err>. */
592static int bind_parse_crt(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
593{
594 char path[MAXPATHLEN];
595
596 if (!*args[cur_arg + 1]) {
597 memprintf(err, "'%s' : missing certificate location", args[cur_arg]);
598 return ERR_ALERT | ERR_FATAL;
599 }
600
601 if ((*args[cur_arg + 1] != '/' ) && global_ssl.crt_base) {
602 if ((strlen(global_ssl.crt_base) + 1 + strlen(args[cur_arg + 1]) + 1) > MAXPATHLEN) {
603 memprintf(err, "'%s' : path too long", args[cur_arg]);
604 return ERR_ALERT | ERR_FATAL;
605 }
606 snprintf(path, sizeof(path), "%s/%s", global_ssl.crt_base, args[cur_arg + 1]);
607 return ssl_sock_load_cert(path, conf, err);
608 }
609
610 return ssl_sock_load_cert(args[cur_arg + 1], conf, err);
611}
612
613/* parse the "crt-list" bind keyword. Returns a set of ERR_* flags possibly with an error in <err>. */
614static int bind_parse_crt_list(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
615{
616 int err_code;
617
618 if (!*args[cur_arg + 1]) {
619 memprintf(err, "'%s' : missing certificate location", args[cur_arg]);
620 return ERR_ALERT | ERR_FATAL;
621 }
622
623 err_code = ssl_sock_load_cert_list_file(args[cur_arg + 1], 0, conf, px, err);
624 if (err_code)
625 memprintf(err, "'%s' : %s", args[cur_arg], *err);
626
627 return err_code;
628}
629
630/* parse the "crl-file" bind keyword */
631static int ssl_bind_parse_crl_file(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
632{
633#ifndef X509_V_FLAG_CRL_CHECK
634 memprintf(err, "'%s' : library does not support CRL verify", args[cur_arg]);
635 return ERR_ALERT | ERR_FATAL;
636#else
637 if (!*args[cur_arg + 1]) {
638 memprintf(err, "'%s' : missing CRLfile path", args[cur_arg]);
639 return ERR_ALERT | ERR_FATAL;
640 }
641
642 if ((*args[cur_arg + 1] != '/') && global_ssl.ca_base)
643 memprintf(&conf->crl_file, "%s/%s", global_ssl.ca_base, args[cur_arg + 1]);
644 else
645 memprintf(&conf->crl_file, "%s", args[cur_arg + 1]);
646
647 if (!ssl_store_load_locations_file(conf->crl_file)) {
648 memprintf(err, "'%s' : unable to load %s", args[cur_arg], conf->crl_file);
649 return ERR_ALERT | ERR_FATAL;
650 }
651 return 0;
652#endif
653}
654static int bind_parse_crl_file(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
655{
656 return ssl_bind_parse_crl_file(args, cur_arg, px, &conf->ssl_conf, err);
657}
658
659/* parse the "curves" bind keyword keyword */
660static int ssl_bind_parse_curves(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
661{
662#if ((HA_OPENSSL_VERSION_NUMBER >= 0x1000200fL) || defined(LIBRESSL_VERSION_NUMBER))
663 if (!*args[cur_arg + 1]) {
664 memprintf(err, "'%s' : missing curve suite", args[cur_arg]);
665 return ERR_ALERT | ERR_FATAL;
666 }
667 conf->curves = strdup(args[cur_arg + 1]);
668 return 0;
669#else
670 memprintf(err, "'%s' : library does not support curve suite", args[cur_arg]);
671 return ERR_ALERT | ERR_FATAL;
672#endif
673}
674static int bind_parse_curves(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
675{
676 return ssl_bind_parse_curves(args, cur_arg, px, &conf->ssl_conf, err);
677}
678
679/* parse the "ecdhe" bind keyword keyword */
680static int ssl_bind_parse_ecdhe(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
681{
682#if HA_OPENSSL_VERSION_NUMBER < 0x0090800fL
683 memprintf(err, "'%s' : library does not support elliptic curve Diffie-Hellman (too old)", args[cur_arg]);
684 return ERR_ALERT | ERR_FATAL;
685#elif defined(OPENSSL_NO_ECDH)
686 memprintf(err, "'%s' : library does not support elliptic curve Diffie-Hellman (disabled via OPENSSL_NO_ECDH)", args[cur_arg]);
687 return ERR_ALERT | ERR_FATAL;
688#else
689 if (!*args[cur_arg + 1]) {
690 memprintf(err, "'%s' : missing named curve", args[cur_arg]);
691 return ERR_ALERT | ERR_FATAL;
692 }
693
694 conf->ecdhe = strdup(args[cur_arg + 1]);
695
696 return 0;
697#endif
698}
699static int bind_parse_ecdhe(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
700{
701 return ssl_bind_parse_ecdhe(args, cur_arg, px, &conf->ssl_conf, err);
702}
703
704/* parse the "crt-ignore-err" and "ca-ignore-err" bind keywords */
705static int bind_parse_ignore_err(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
706{
707 int code;
708 char *p = args[cur_arg + 1];
709 unsigned long long *ignerr = &conf->crt_ignerr;
710
711 if (!*p) {
712 memprintf(err, "'%s' : missing error IDs list", args[cur_arg]);
713 return ERR_ALERT | ERR_FATAL;
714 }
715
716 if (strcmp(args[cur_arg], "ca-ignore-err") == 0)
717 ignerr = &conf->ca_ignerr;
718
719 if (strcmp(p, "all") == 0) {
720 *ignerr = ~0ULL;
721 return 0;
722 }
723
724 while (p) {
725 code = atoi(p);
726 if ((code <= 0) || (code > 63)) {
727 memprintf(err, "'%s' : ID '%d' out of range (1..63) in error IDs list '%s'",
728 args[cur_arg], code, args[cur_arg + 1]);
729 return ERR_ALERT | ERR_FATAL;
730 }
731 *ignerr |= 1ULL << code;
732 p = strchr(p, ',');
733 if (p)
734 p++;
735 }
736
737 return 0;
738}
739
740/* parse tls_method_options "no-xxx" and "force-xxx" */
741static int parse_tls_method_options(char *arg, struct tls_version_filter *methods, char **err)
742{
743 uint16_t v;
744 char *p;
745 p = strchr(arg, '-');
746 if (!p)
747 goto fail;
748 p++;
749 if (!strcmp(p, "sslv3"))
750 v = CONF_SSLV3;
751 else if (!strcmp(p, "tlsv10"))
752 v = CONF_TLSV10;
753 else if (!strcmp(p, "tlsv11"))
754 v = CONF_TLSV11;
755 else if (!strcmp(p, "tlsv12"))
756 v = CONF_TLSV12;
757 else if (!strcmp(p, "tlsv13"))
758 v = CONF_TLSV13;
759 else
760 goto fail;
761 if (!strncmp(arg, "no-", 3))
762 methods->flags |= methodVersions[v].flag;
763 else if (!strncmp(arg, "force-", 6))
764 methods->min = methods->max = v;
765 else
766 goto fail;
767 return 0;
768 fail:
769 memprintf(err, "'%s' : option not implemented", arg);
770 return ERR_ALERT | ERR_FATAL;
771}
772
773static int bind_parse_tls_method_options(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
774{
775 return parse_tls_method_options(args[cur_arg], &conf->ssl_conf.ssl_methods, err);
776}
777
778static int srv_parse_tls_method_options(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
779{
780 return parse_tls_method_options(args[*cur_arg], &newsrv->ssl_ctx.methods, err);
781}
782
783/* parse tls_method min/max: "ssl-min-ver" and "ssl-max-ver" */
784static int parse_tls_method_minmax(char **args, int cur_arg, struct tls_version_filter *methods, char **err)
785{
786 uint16_t i, v = 0;
787 char *argv = args[cur_arg + 1];
788 if (!*argv) {
789 memprintf(err, "'%s' : missing the ssl/tls version", args[cur_arg]);
790 return ERR_ALERT | ERR_FATAL;
791 }
792 for (i = CONF_TLSV_MIN; i <= CONF_TLSV_MAX; i++)
793 if (!strcmp(argv, methodVersions[i].name))
794 v = i;
795 if (!v) {
796 memprintf(err, "'%s' : unknown ssl/tls version", args[cur_arg + 1]);
797 return ERR_ALERT | ERR_FATAL;
798 }
799 if (!strcmp("ssl-min-ver", args[cur_arg]))
800 methods->min = v;
801 else if (!strcmp("ssl-max-ver", args[cur_arg]))
802 methods->max = v;
803 else {
804 memprintf(err, "'%s' : option not implemented", args[cur_arg]);
805 return ERR_ALERT | ERR_FATAL;
806 }
807 return 0;
808}
809
810static int ssl_bind_parse_tls_method_minmax(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
811{
812#if (HA_OPENSSL_VERSION_NUMBER < 0x10101000L) && !defined(OPENSSL_IS_BORINGSSL)
813 ha_warning("crt-list: ssl-min-ver and ssl-max-ver are not supported with this Openssl version (skipped).\n");
814#endif
815 return parse_tls_method_minmax(args, cur_arg, &conf->ssl_methods, err);
816}
817
818static int bind_parse_tls_method_minmax(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
819{
820 return parse_tls_method_minmax(args, cur_arg, &conf->ssl_conf.ssl_methods, err);
821}
822
823static int srv_parse_tls_method_minmax(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
824{
825 return parse_tls_method_minmax(args, *cur_arg, &newsrv->ssl_ctx.methods, err);
826}
827
828/* parse the "no-tls-tickets" bind keyword */
829static int bind_parse_no_tls_tickets(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
830{
831 conf->ssl_options |= BC_SSL_O_NO_TLS_TICKETS;
832 return 0;
833}
834
835/* parse the "allow-0rtt" bind keyword */
836static int ssl_bind_parse_allow_0rtt(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
837{
838 conf->early_data = 1;
839 return 0;
840}
841
842static int bind_parse_allow_0rtt(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
843{
844 conf->ssl_conf.early_data = 1;
845 return 0;
846}
847
848/* parse the "npn" bind keyword */
849static int ssl_bind_parse_npn(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
850{
851#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG)
852 char *p1, *p2;
853
854 if (!*args[cur_arg + 1]) {
855 memprintf(err, "'%s' : missing the comma-delimited NPN protocol suite", args[cur_arg]);
856 return ERR_ALERT | ERR_FATAL;
857 }
858
859 free(conf->npn_str);
860
861 /* the NPN string is built as a suite of (<len> <name>)*,
862 * so we reuse each comma to store the next <len> and need
863 * one more for the end of the string.
864 */
865 conf->npn_len = strlen(args[cur_arg + 1]) + 1;
866 conf->npn_str = calloc(1, conf->npn_len + 1);
867 memcpy(conf->npn_str + 1, args[cur_arg + 1], conf->npn_len);
868
869 /* replace commas with the name length */
870 p1 = conf->npn_str;
871 p2 = p1 + 1;
872 while (1) {
873 p2 = memchr(p1 + 1, ',', conf->npn_str + conf->npn_len - (p1 + 1));
874 if (!p2)
875 p2 = p1 + 1 + strlen(p1 + 1);
876
877 if (p2 - (p1 + 1) > 255) {
878 *p2 = '\0';
879 memprintf(err, "'%s' : NPN protocol name too long : '%s'", args[cur_arg], p1 + 1);
880 return ERR_ALERT | ERR_FATAL;
881 }
882
883 *p1 = p2 - (p1 + 1);
884 p1 = p2;
885
886 if (!*p2)
887 break;
888
889 *(p2++) = '\0';
890 }
891 return 0;
892#else
893 memprintf(err, "'%s' : library does not support TLS NPN extension", args[cur_arg]);
894 return ERR_ALERT | ERR_FATAL;
895#endif
896}
897
898static int bind_parse_npn(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
899{
900 return ssl_bind_parse_npn(args, cur_arg, px, &conf->ssl_conf, err);
901}
902
903
904/* Parses a alpn string and converts it to the right format for the SSL api */
905int ssl_sock_parse_alpn(char *arg, char **alpn_str, int *alpn_len, char **err)
906{
907 char *p1, *p2, *alpn = NULL;
908 int len, ret = 0;
909
910 *alpn_str = NULL;
911 *alpn_len = 0;
912
913 if (!*arg) {
914 memprintf(err, "missing the comma-delimited ALPN protocol suite");
915 goto error;
916 }
917
918 /* the ALPN string is built as a suite of (<len> <name>)*,
919 * so we reuse each comma to store the next <len> and need
920 * one more for the end of the string.
921 */
922 len = strlen(arg) + 1;
923 alpn = calloc(1, len+1);
924 if (!alpn) {
925 memprintf(err, "'%s' : out of memory", arg);
926 goto error;
927 }
928 memcpy(alpn+1, arg, len);
929
930 /* replace commas with the name length */
931 p1 = alpn;
932 p2 = p1 + 1;
933 while (1) {
934 p2 = memchr(p1 + 1, ',', alpn + len - (p1 + 1));
935 if (!p2)
936 p2 = p1 + 1 + strlen(p1 + 1);
937
938 if (p2 - (p1 + 1) > 255) {
939 *p2 = '\0';
940 memprintf(err, "ALPN protocol name too long : '%s'", p1 + 1);
941 goto error;
942 }
943
944 *p1 = p2 - (p1 + 1);
945 p1 = p2;
946
947 if (!*p2)
948 break;
949
950 *(p2++) = '\0';
951 }
952
953 *alpn_str = alpn;
954 *alpn_len = len;
955
956 out:
957 return ret;
958
959 error:
960 free(alpn);
961 ret = ERR_ALERT | ERR_FATAL;
962 goto out;
963}
964
965/* parse the "alpn" bind keyword */
966static int ssl_bind_parse_alpn(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
967{
968#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
969 int ret;
970
971 free(conf->alpn_str);
972
973 ret = ssl_sock_parse_alpn(args[cur_arg + 1], &conf->alpn_str, &conf->alpn_len, err);
974 if (ret)
975 memprintf(err, "'%s' : %s", args[cur_arg], *err);
976 return ret;
977#else
978 memprintf(err, "'%s' : library does not support TLS ALPN extension", args[cur_arg]);
979 return ERR_ALERT | ERR_FATAL;
980#endif
981}
982
983static int bind_parse_alpn(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
984{
985 return ssl_bind_parse_alpn(args, cur_arg, px, &conf->ssl_conf, err);
986}
987
988/* parse the "ssl" bind keyword */
989static int bind_parse_ssl(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
990{
991 conf->xprt = &ssl_sock;
992 conf->is_ssl = 1;
993
994 if (global_ssl.listen_default_ciphers && !conf->ssl_conf.ciphers)
995 conf->ssl_conf.ciphers = strdup(global_ssl.listen_default_ciphers);
996#if ((HA_OPENSSL_VERSION_NUMBER >= 0x1000200fL) || defined(LIBRESSL_VERSION_NUMBER))
997 if (global_ssl.listen_default_curves && !conf->ssl_conf.curves)
998 conf->ssl_conf.curves = strdup(global_ssl.listen_default_curves);
999#endif
1000#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
1001 if (global_ssl.listen_default_ciphersuites && !conf->ssl_conf.ciphersuites)
1002 conf->ssl_conf.ciphersuites = strdup(global_ssl.listen_default_ciphersuites);
1003#endif
1004 conf->ssl_options |= global_ssl.listen_default_ssloptions;
1005 conf->ssl_conf.ssl_methods.flags |= global_ssl.listen_default_sslmethods.flags;
1006 if (!conf->ssl_conf.ssl_methods.min)
1007 conf->ssl_conf.ssl_methods.min = global_ssl.listen_default_sslmethods.min;
1008 if (!conf->ssl_conf.ssl_methods.max)
1009 conf->ssl_conf.ssl_methods.max = global_ssl.listen_default_sslmethods.max;
1010
1011 return 0;
1012}
1013
1014/* parse the "prefer-client-ciphers" bind keyword */
1015static int bind_parse_pcc(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1016{
1017 conf->ssl_options |= BC_SSL_O_PREF_CLIE_CIPH;
1018 return 0;
1019}
1020
1021/* parse the "generate-certificates" bind keyword */
1022static int bind_parse_generate_certs(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1023{
1024#if (defined SSL_CTRL_SET_TLSEXT_HOSTNAME && !defined SSL_NO_GENERATE_CERTIFICATES)
1025 conf->generate_certs = 1;
1026#else
1027 memprintf(err, "%sthis version of openssl cannot generate SSL certificates.\n",
1028 err && *err ? *err : "");
1029#endif
1030 return 0;
1031}
1032
1033/* parse the "strict-sni" bind keyword */
1034static int bind_parse_strict_sni(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1035{
1036 conf->strict_sni = 1;
1037 return 0;
1038}
1039
1040/* parse the "tls-ticket-keys" bind keyword */
1041static int bind_parse_tls_ticket_keys(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1042{
1043#if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0)
1044 FILE *f = NULL;
1045 int i = 0;
1046 char thisline[LINESIZE];
1047 struct tls_keys_ref *keys_ref = NULL;
1048
1049 if (!*args[cur_arg + 1]) {
1050 memprintf(err, "'%s' : missing TLS ticket keys file path", args[cur_arg]);
1051 goto fail;
1052 }
1053
1054 keys_ref = tlskeys_ref_lookup(args[cur_arg + 1]);
1055 if (keys_ref) {
1056 keys_ref->refcount++;
1057 conf->keys_ref = keys_ref;
1058 return 0;
1059 }
1060
1061 keys_ref = calloc(1, sizeof(*keys_ref));
1062 if (!keys_ref) {
1063 memprintf(err, "'%s' : allocation error", args[cur_arg+1]);
1064 goto fail;
1065 }
1066
1067 keys_ref->tlskeys = malloc(TLS_TICKETS_NO * sizeof(union tls_sess_key));
1068 if (!keys_ref->tlskeys) {
1069 memprintf(err, "'%s' : allocation error", args[cur_arg+1]);
1070 goto fail;
1071 }
1072
1073 if ((f = fopen(args[cur_arg + 1], "r")) == NULL) {
1074 memprintf(err, "'%s' : unable to load ssl tickets keys file", args[cur_arg+1]);
1075 goto fail;
1076 }
1077
1078 keys_ref->filename = strdup(args[cur_arg + 1]);
1079 if (!keys_ref->filename) {
1080 memprintf(err, "'%s' : allocation error", args[cur_arg+1]);
1081 goto fail;
1082 }
1083
1084 keys_ref->key_size_bits = 0;
1085 while (fgets(thisline, sizeof(thisline), f) != NULL) {
1086 int len = strlen(thisline);
1087 int dec_size;
1088
1089 /* Strip newline characters from the end */
1090 if(thisline[len - 1] == '\n')
1091 thisline[--len] = 0;
1092
1093 if(thisline[len - 1] == '\r')
1094 thisline[--len] = 0;
1095
1096 dec_size = base64dec(thisline, len, (char *) (keys_ref->tlskeys + i % TLS_TICKETS_NO), sizeof(union tls_sess_key));
1097 if (dec_size < 0) {
1098 memprintf(err, "'%s' : unable to decode base64 key on line %d", args[cur_arg+1], i + 1);
1099 goto fail;
1100 }
1101 else if (!keys_ref->key_size_bits && (dec_size == sizeof(struct tls_sess_key_128))) {
1102 keys_ref->key_size_bits = 128;
1103 }
1104 else if (!keys_ref->key_size_bits && (dec_size == sizeof(struct tls_sess_key_256))) {
1105 keys_ref->key_size_bits = 256;
1106 }
1107 else if (((dec_size != sizeof(struct tls_sess_key_128)) && (dec_size != sizeof(struct tls_sess_key_256)))
1108 || ((dec_size == sizeof(struct tls_sess_key_128) && (keys_ref->key_size_bits != 128)))
1109 || ((dec_size == sizeof(struct tls_sess_key_256) && (keys_ref->key_size_bits != 256)))) {
1110 memprintf(err, "'%s' : wrong sized key on line %d", args[cur_arg+1], i + 1);
1111 goto fail;
1112 }
1113 i++;
1114 }
1115
1116 if (i < TLS_TICKETS_NO) {
1117 memprintf(err, "'%s' : please supply at least %d keys in the tls-tickets-file", args[cur_arg+1], TLS_TICKETS_NO);
1118 goto fail;
1119 }
1120
1121 fclose(f);
1122
1123 /* Use penultimate key for encryption, handle when TLS_TICKETS_NO = 1 */
1124 i -= 2;
1125 keys_ref->tls_ticket_enc_index = i < 0 ? 0 : i % TLS_TICKETS_NO;
1126 keys_ref->unique_id = -1;
1127 keys_ref->refcount = 1;
1128 HA_RWLOCK_INIT(&keys_ref->lock);
1129 conf->keys_ref = keys_ref;
1130
1131 LIST_ADD(&tlskeys_reference, &keys_ref->list);
1132
1133 return 0;
1134
1135 fail:
1136 if (f)
1137 fclose(f);
1138 if (keys_ref) {
1139 free(keys_ref->filename);
1140 free(keys_ref->tlskeys);
1141 free(keys_ref);
1142 }
1143 return ERR_ALERT | ERR_FATAL;
1144
1145#else
1146 memprintf(err, "'%s' : TLS ticket callback extension not supported", args[cur_arg]);
1147 return ERR_ALERT | ERR_FATAL;
1148#endif /* SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB */
1149}
1150
1151/* parse the "verify" bind keyword */
1152static int ssl_bind_parse_verify(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
1153{
1154 if (!*args[cur_arg + 1]) {
1155 memprintf(err, "'%s' : missing verify method", args[cur_arg]);
1156 return ERR_ALERT | ERR_FATAL;
1157 }
1158
1159 if (strcmp(args[cur_arg + 1], "none") == 0)
1160 conf->verify = SSL_SOCK_VERIFY_NONE;
1161 else if (strcmp(args[cur_arg + 1], "optional") == 0)
1162 conf->verify = SSL_SOCK_VERIFY_OPTIONAL;
1163 else if (strcmp(args[cur_arg + 1], "required") == 0)
1164 conf->verify = SSL_SOCK_VERIFY_REQUIRED;
1165 else {
1166 memprintf(err, "'%s' : unknown verify method '%s', only 'none', 'optional', and 'required' are supported\n",
1167 args[cur_arg], args[cur_arg + 1]);
1168 return ERR_ALERT | ERR_FATAL;
1169 }
1170
1171 return 0;
1172}
1173static int bind_parse_verify(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1174{
1175 return ssl_bind_parse_verify(args, cur_arg, px, &conf->ssl_conf, err);
1176}
1177
1178/* parse the "no-ca-names" bind keyword */
1179static int ssl_bind_parse_no_ca_names(char **args, int cur_arg, struct proxy *px, struct ssl_bind_conf *conf, char **err)
1180{
1181 conf->no_ca_names = 1;
1182 return 0;
1183}
1184static int bind_parse_no_ca_names(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
1185{
1186 return ssl_bind_parse_no_ca_names(args, cur_arg, px, &conf->ssl_conf, err);
1187}
1188
1189/***************************** "server" keywords Parsing ********************************************/
1190
1191/* parse the "npn" bind keyword */
1192static int srv_parse_npn(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1193{
1194#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG)
1195 char *p1, *p2;
1196
1197 if (!*args[*cur_arg + 1]) {
1198 memprintf(err, "'%s' : missing the comma-delimited NPN protocol suite", args[*cur_arg]);
1199 return ERR_ALERT | ERR_FATAL;
1200 }
1201
1202 free(newsrv->ssl_ctx.npn_str);
1203
1204 /* the NPN string is built as a suite of (<len> <name>)*,
1205 * so we reuse each comma to store the next <len> and need
1206 * one more for the end of the string.
1207 */
1208 newsrv->ssl_ctx.npn_len = strlen(args[*cur_arg + 1]) + 1;
1209 newsrv->ssl_ctx.npn_str = calloc(1, newsrv->ssl_ctx.npn_len + 1);
1210 memcpy(newsrv->ssl_ctx.npn_str + 1, args[*cur_arg + 1],
1211 newsrv->ssl_ctx.npn_len);
1212
1213 /* replace commas with the name length */
1214 p1 = newsrv->ssl_ctx.npn_str;
1215 p2 = p1 + 1;
1216 while (1) {
1217 p2 = memchr(p1 + 1, ',', newsrv->ssl_ctx.npn_str +
1218 newsrv->ssl_ctx.npn_len - (p1 + 1));
1219 if (!p2)
1220 p2 = p1 + 1 + strlen(p1 + 1);
1221
1222 if (p2 - (p1 + 1) > 255) {
1223 *p2 = '\0';
1224 memprintf(err, "'%s' : NPN protocol name too long : '%s'", args[*cur_arg], p1 + 1);
1225 return ERR_ALERT | ERR_FATAL;
1226 }
1227
1228 *p1 = p2 - (p1 + 1);
1229 p1 = p2;
1230
1231 if (!*p2)
1232 break;
1233
1234 *(p2++) = '\0';
1235 }
1236 return 0;
1237#else
1238 memprintf(err, "'%s' : library does not support TLS NPN extension", args[*cur_arg]);
1239 return ERR_ALERT | ERR_FATAL;
1240#endif
1241}
1242
1243/* parse the "alpn" or the "check-alpn" server keyword */
1244static int srv_parse_alpn(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1245{
1246#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
1247 char **alpn_str;
1248 int *alpn_len;
1249 int ret;
1250
1251 if (*args[*cur_arg] == 'c') {
1252 alpn_str = &newsrv->check.alpn_str;
1253 alpn_len = &newsrv->check.alpn_len;
1254 } else {
1255 alpn_str = &newsrv->ssl_ctx.alpn_str;
1256 alpn_len = &newsrv->ssl_ctx.alpn_len;
1257
1258 }
1259
1260 free(*alpn_str);
1261 ret = ssl_sock_parse_alpn(args[*cur_arg + 1], alpn_str, alpn_len, err);
1262 if (ret)
1263 memprintf(err, "'%s' : %s", args[*cur_arg], *err);
1264 return ret;
1265#else
1266 memprintf(err, "'%s' : library does not support TLS ALPN extension", args[*cur_arg]);
1267 return ERR_ALERT | ERR_FATAL;
1268#endif
1269}
1270
1271/* parse the "ca-file" server keyword */
1272static int srv_parse_ca_file(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1273{
1274 if (!*args[*cur_arg + 1]) {
1275 memprintf(err, "'%s' : missing CAfile path", args[*cur_arg]);
1276 return ERR_ALERT | ERR_FATAL;
1277 }
1278
1279 if ((*args[*cur_arg + 1] != '/') && global_ssl.ca_base)
1280 memprintf(&newsrv->ssl_ctx.ca_file, "%s/%s", global_ssl.ca_base, args[*cur_arg + 1]);
1281 else
1282 memprintf(&newsrv->ssl_ctx.ca_file, "%s", args[*cur_arg + 1]);
1283
1284 if (!ssl_store_load_locations_file(newsrv->ssl_ctx.ca_file)) {
1285 memprintf(err, "'%s' : unable to load %s", args[*cur_arg], newsrv->ssl_ctx.ca_file);
1286 return ERR_ALERT | ERR_FATAL;
1287 }
1288 return 0;
1289}
1290
1291/* parse the "check-sni" server keyword */
1292static int srv_parse_check_sni(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1293{
1294 if (!*args[*cur_arg + 1]) {
1295 memprintf(err, "'%s' : missing SNI", args[*cur_arg]);
1296 return ERR_ALERT | ERR_FATAL;
1297 }
1298
1299 newsrv->check.sni = strdup(args[*cur_arg + 1]);
1300 if (!newsrv->check.sni) {
1301 memprintf(err, "'%s' : failed to allocate memory", args[*cur_arg]);
1302 return ERR_ALERT | ERR_FATAL;
1303 }
1304 return 0;
1305
1306}
1307
1308/* parse the "check-ssl" server keyword */
1309static int srv_parse_check_ssl(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1310{
1311 newsrv->check.use_ssl = 1;
1312 if (global_ssl.connect_default_ciphers && !newsrv->ssl_ctx.ciphers)
1313 newsrv->ssl_ctx.ciphers = strdup(global_ssl.connect_default_ciphers);
1314#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
1315 if (global_ssl.connect_default_ciphersuites && !newsrv->ssl_ctx.ciphersuites)
1316 newsrv->ssl_ctx.ciphersuites = strdup(global_ssl.connect_default_ciphersuites);
1317#endif
1318 newsrv->ssl_ctx.options |= global_ssl.connect_default_ssloptions;
1319 newsrv->ssl_ctx.methods.flags |= global_ssl.connect_default_sslmethods.flags;
1320 if (!newsrv->ssl_ctx.methods.min)
1321 newsrv->ssl_ctx.methods.min = global_ssl.connect_default_sslmethods.min;
1322 if (!newsrv->ssl_ctx.methods.max)
1323 newsrv->ssl_ctx.methods.max = global_ssl.connect_default_sslmethods.max;
1324
1325 return 0;
1326}
1327
1328/* parse the "ciphers" server keyword */
1329static int srv_parse_ciphers(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1330{
1331 if (!*args[*cur_arg + 1]) {
1332 memprintf(err, "'%s' : missing cipher suite", args[*cur_arg]);
1333 return ERR_ALERT | ERR_FATAL;
1334 }
1335
1336 free(newsrv->ssl_ctx.ciphers);
1337 newsrv->ssl_ctx.ciphers = strdup(args[*cur_arg + 1]);
1338 return 0;
1339}
1340
1341#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
1342/* parse the "ciphersuites" server keyword */
1343static int srv_parse_ciphersuites(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1344{
1345 if (!*args[*cur_arg + 1]) {
1346 memprintf(err, "'%s' : missing cipher suite", args[*cur_arg]);
1347 return ERR_ALERT | ERR_FATAL;
1348 }
1349
1350 free(newsrv->ssl_ctx.ciphersuites);
1351 newsrv->ssl_ctx.ciphersuites = strdup(args[*cur_arg + 1]);
1352 return 0;
1353}
1354#endif
1355
1356/* parse the "crl-file" server keyword */
1357static int srv_parse_crl_file(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1358{
1359#ifndef X509_V_FLAG_CRL_CHECK
1360 memprintf(err, "'%s' : library does not support CRL verify", args[*cur_arg]);
1361 return ERR_ALERT | ERR_FATAL;
1362#else
1363 if (!*args[*cur_arg + 1]) {
1364 memprintf(err, "'%s' : missing CRLfile path", args[*cur_arg]);
1365 return ERR_ALERT | ERR_FATAL;
1366 }
1367
1368 if ((*args[*cur_arg + 1] != '/') && global_ssl.ca_base)
1369 memprintf(&newsrv->ssl_ctx.crl_file, "%s/%s", global_ssl.ca_base, args[*cur_arg + 1]);
1370 else
1371 memprintf(&newsrv->ssl_ctx.crl_file, "%s", args[*cur_arg + 1]);
1372
1373 if (!ssl_store_load_locations_file(newsrv->ssl_ctx.crl_file)) {
1374 memprintf(err, "'%s' : unable to load %s", args[*cur_arg], newsrv->ssl_ctx.crl_file);
1375 return ERR_ALERT | ERR_FATAL;
1376 }
1377 return 0;
1378#endif
1379}
1380
1381/* parse the "crt" server keyword */
1382static int srv_parse_crt(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1383{
1384 if (!*args[*cur_arg + 1]) {
1385 memprintf(err, "'%s' : missing certificate file path", args[*cur_arg]);
1386 return ERR_ALERT | ERR_FATAL;
1387 }
1388
1389 if ((*args[*cur_arg + 1] != '/') && global_ssl.crt_base)
1390 memprintf(&newsrv->ssl_ctx.client_crt, "%s/%s", global_ssl.crt_base, args[*cur_arg + 1]);
1391 else
1392 memprintf(&newsrv->ssl_ctx.client_crt, "%s", args[*cur_arg + 1]);
1393
1394 return 0;
1395}
1396
1397/* parse the "no-check-ssl" server keyword */
1398static int srv_parse_no_check_ssl(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1399{
1400 newsrv->check.use_ssl = -1;
1401 free(newsrv->ssl_ctx.ciphers);
1402 newsrv->ssl_ctx.ciphers = NULL;
1403 newsrv->ssl_ctx.options &= ~global_ssl.connect_default_ssloptions;
1404 return 0;
1405}
1406
1407/* parse the "no-send-proxy-v2-ssl" server keyword */
1408static int srv_parse_no_send_proxy_ssl(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1409{
1410 newsrv->pp_opts &= ~SRV_PP_V2;
1411 newsrv->pp_opts &= ~SRV_PP_V2_SSL;
1412 return 0;
1413}
1414
1415/* parse the "no-send-proxy-v2-ssl-cn" server keyword */
1416static int srv_parse_no_send_proxy_cn(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1417{
1418 newsrv->pp_opts &= ~SRV_PP_V2;
1419 newsrv->pp_opts &= ~SRV_PP_V2_SSL;
1420 newsrv->pp_opts &= ~SRV_PP_V2_SSL_CN;
1421 return 0;
1422}
1423
1424/* parse the "no-ssl" server keyword */
1425static int srv_parse_no_ssl(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1426{
1427 newsrv->use_ssl = -1;
1428 free(newsrv->ssl_ctx.ciphers);
1429 newsrv->ssl_ctx.ciphers = NULL;
1430 return 0;
1431}
1432
1433/* parse the "allow-0rtt" server keyword */
1434static int srv_parse_allow_0rtt(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1435{
1436 newsrv->ssl_ctx.options |= SRV_SSL_O_EARLY_DATA;
1437 return 0;
1438}
1439
1440/* parse the "no-ssl-reuse" server keyword */
1441static int srv_parse_no_ssl_reuse(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1442{
1443 newsrv->ssl_ctx.options |= SRV_SSL_O_NO_REUSE;
1444 return 0;
1445}
1446
1447/* parse the "no-tls-tickets" server keyword */
1448static int srv_parse_no_tls_tickets(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1449{
1450 newsrv->ssl_ctx.options |= SRV_SSL_O_NO_TLS_TICKETS;
1451 return 0;
1452}
1453/* parse the "send-proxy-v2-ssl" server keyword */
1454static int srv_parse_send_proxy_ssl(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1455{
1456 newsrv->pp_opts |= SRV_PP_V2;
1457 newsrv->pp_opts |= SRV_PP_V2_SSL;
1458 return 0;
1459}
1460
1461/* parse the "send-proxy-v2-ssl-cn" server keyword */
1462static int srv_parse_send_proxy_cn(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1463{
1464 newsrv->pp_opts |= SRV_PP_V2;
1465 newsrv->pp_opts |= SRV_PP_V2_SSL;
1466 newsrv->pp_opts |= SRV_PP_V2_SSL_CN;
1467 return 0;
1468}
1469
1470/* parse the "sni" server keyword */
1471static int srv_parse_sni(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1472{
1473#ifndef SSL_CTRL_SET_TLSEXT_HOSTNAME
1474 memprintf(err, "'%s' : the current SSL library doesn't support the SNI TLS extension", args[*cur_arg]);
1475 return ERR_ALERT | ERR_FATAL;
1476#else
1477 char *arg;
1478
1479 arg = args[*cur_arg + 1];
1480 if (!*arg) {
1481 memprintf(err, "'%s' : missing sni expression", args[*cur_arg]);
1482 return ERR_ALERT | ERR_FATAL;
1483 }
1484
1485 free(newsrv->sni_expr);
1486 newsrv->sni_expr = strdup(arg);
1487
1488 return 0;
1489#endif
1490}
1491
1492/* parse the "ssl" server keyword */
1493static int srv_parse_ssl(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1494{
1495 newsrv->use_ssl = 1;
1496 if (global_ssl.connect_default_ciphers && !newsrv->ssl_ctx.ciphers)
1497 newsrv->ssl_ctx.ciphers = strdup(global_ssl.connect_default_ciphers);
1498#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
1499 if (global_ssl.connect_default_ciphersuites && !newsrv->ssl_ctx.ciphersuites)
1500 newsrv->ssl_ctx.ciphersuites = strdup(global_ssl.connect_default_ciphersuites);
1501#endif
1502 newsrv->ssl_ctx.options |= global_ssl.connect_default_ssloptions;
1503 newsrv->ssl_ctx.methods.flags |= global_ssl.connect_default_sslmethods.flags;
1504
1505 if (!newsrv->ssl_ctx.methods.min)
1506 newsrv->ssl_ctx.methods.min = global_ssl.connect_default_sslmethods.min;
1507
1508 if (!newsrv->ssl_ctx.methods.max)
1509 newsrv->ssl_ctx.methods.max = global_ssl.connect_default_sslmethods.max;
1510
1511
1512 return 0;
1513}
1514
1515/* parse the "ssl-reuse" server keyword */
1516static int srv_parse_ssl_reuse(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1517{
1518 newsrv->ssl_ctx.options &= ~SRV_SSL_O_NO_REUSE;
1519 return 0;
1520}
1521
1522/* parse the "tls-tickets" server keyword */
1523static int srv_parse_tls_tickets(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1524{
1525 newsrv->ssl_ctx.options &= ~SRV_SSL_O_NO_TLS_TICKETS;
1526 return 0;
1527}
1528
1529/* parse the "verify" server keyword */
1530static int srv_parse_verify(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1531{
1532 if (!*args[*cur_arg + 1]) {
1533 memprintf(err, "'%s' : missing verify method", args[*cur_arg]);
1534 return ERR_ALERT | ERR_FATAL;
1535 }
1536
1537 if (strcmp(args[*cur_arg + 1], "none") == 0)
1538 newsrv->ssl_ctx.verify = SSL_SOCK_VERIFY_NONE;
1539 else if (strcmp(args[*cur_arg + 1], "required") == 0)
1540 newsrv->ssl_ctx.verify = SSL_SOCK_VERIFY_REQUIRED;
1541 else {
1542 memprintf(err, "'%s' : unknown verify method '%s', only 'none' and 'required' are supported\n",
1543 args[*cur_arg], args[*cur_arg + 1]);
1544 return ERR_ALERT | ERR_FATAL;
1545 }
1546
1547 return 0;
1548}
1549
1550/* parse the "verifyhost" server keyword */
1551static int srv_parse_verifyhost(char **args, int *cur_arg, struct proxy *px, struct server *newsrv, char **err)
1552{
1553 if (!*args[*cur_arg + 1]) {
1554 memprintf(err, "'%s' : missing hostname to verify against", args[*cur_arg]);
1555 return ERR_ALERT | ERR_FATAL;
1556 }
1557
1558 free(newsrv->ssl_ctx.verify_host);
1559 newsrv->ssl_ctx.verify_host = strdup(args[*cur_arg + 1]);
1560
1561 return 0;
1562}
1563
1564/* parse the "ssl-default-bind-options" keyword in global section */
1565static int ssl_parse_default_bind_options(char **args, int section_type, struct proxy *curpx,
1566 struct proxy *defpx, const char *file, int line,
1567 char **err) {
1568 int i = 1;
1569
1570 if (*(args[i]) == 0) {
1571 memprintf(err, "global statement '%s' expects an option as an argument.", args[0]);
1572 return -1;
1573 }
1574 while (*(args[i])) {
1575 if (!strcmp(args[i], "no-tls-tickets"))
1576 global_ssl.listen_default_ssloptions |= BC_SSL_O_NO_TLS_TICKETS;
1577 else if (!strcmp(args[i], "prefer-client-ciphers"))
1578 global_ssl.listen_default_ssloptions |= BC_SSL_O_PREF_CLIE_CIPH;
1579 else if (!strcmp(args[i], "ssl-min-ver") || !strcmp(args[i], "ssl-max-ver")) {
1580 if (!parse_tls_method_minmax(args, i, &global_ssl.listen_default_sslmethods, err))
1581 i++;
1582 else {
1583 memprintf(err, "%s on global statement '%s'.", *err, args[0]);
1584 return -1;
1585 }
1586 }
1587 else if (parse_tls_method_options(args[i], &global_ssl.listen_default_sslmethods, err)) {
1588 memprintf(err, "unknown option '%s' on global statement '%s'.", args[i], args[0]);
1589 return -1;
1590 }
1591 i++;
1592 }
1593 return 0;
1594}
1595
1596/* parse the "ssl-default-server-options" keyword in global section */
1597static int ssl_parse_default_server_options(char **args, int section_type, struct proxy *curpx,
1598 struct proxy *defpx, const char *file, int line,
1599 char **err) {
1600 int i = 1;
1601
1602 if (*(args[i]) == 0) {
1603 memprintf(err, "global statement '%s' expects an option as an argument.", args[0]);
1604 return -1;
1605 }
1606 while (*(args[i])) {
1607 if (!strcmp(args[i], "no-tls-tickets"))
1608 global_ssl.connect_default_ssloptions |= SRV_SSL_O_NO_TLS_TICKETS;
1609 else if (!strcmp(args[i], "ssl-min-ver") || !strcmp(args[i], "ssl-max-ver")) {
1610 if (!parse_tls_method_minmax(args, i, &global_ssl.connect_default_sslmethods, err))
1611 i++;
1612 else {
1613 memprintf(err, "%s on global statement '%s'.", *err, args[0]);
1614 return -1;
1615 }
1616 }
1617 else if (parse_tls_method_options(args[i], &global_ssl.connect_default_sslmethods, err)) {
1618 memprintf(err, "unknown option '%s' on global statement '%s'.", args[i], args[0]);
1619 return -1;
1620 }
1621 i++;
1622 }
1623 return 0;
1624}
1625
1626/* parse the "ca-base" / "crt-base" keywords in global section.
1627 * Returns <0 on alert, >0 on warning, 0 on success.
1628 */
1629static int ssl_parse_global_ca_crt_base(char **args, int section_type, struct proxy *curpx,
1630 struct proxy *defpx, const char *file, int line,
1631 char **err)
1632{
1633 char **target;
1634
1635 target = (args[0][1] == 'a') ? &global_ssl.ca_base : &global_ssl.crt_base;
1636
1637 if (too_many_args(1, args, err, NULL))
1638 return -1;
1639
1640 if (*target) {
1641 memprintf(err, "'%s' already specified.", args[0]);
1642 return -1;
1643 }
1644
1645 if (*(args[1]) == 0) {
1646 memprintf(err, "global statement '%s' expects a directory path as an argument.", args[0]);
1647 return -1;
1648 }
1649 *target = strdup(args[1]);
1650 return 0;
1651}
1652
1653/* parse the "ssl-skip-self-issued-ca" keyword in global section. */
1654static int ssl_parse_skip_self_issued_ca(char **args, int section_type, struct proxy *curpx,
1655 struct proxy *defpx, const char *file, int line,
1656 char **err)
1657{
1658 global_ssl.skip_self_issued_ca = 1;
1659 return 0;
1660}
1661
1662
1663
1664
1665
1666/* Note: must not be declared <const> as its list will be overwritten.
1667 * Please take care of keeping this list alphabetically sorted, doing so helps
1668 * all code contributors.
1669 * Optional keywords are also declared with a NULL ->parse() function so that
1670 * the config parser can report an appropriate error when a known keyword was
1671 * not enabled.
1672 */
1673
1674/* the <ssl_bind_kws> keywords are used for crt-list parsing, they *MUST* be safe
1675 * with their proxy argument NULL and must only fill the ssl_bind_conf */
1676struct ssl_bind_kw ssl_bind_kws[] = {
1677 { "allow-0rtt", ssl_bind_parse_allow_0rtt, 0 }, /* allow 0-RTT */
1678 { "alpn", ssl_bind_parse_alpn, 1 }, /* set ALPN supported protocols */
1679 { "ca-file", ssl_bind_parse_ca_file, 1 }, /* set CAfile to process ca-names and verify on client cert */
1680 { "ca-verify-file", ssl_bind_parse_ca_verify_file, 1 }, /* set CAverify file to process verify on client cert */
1681 { "ciphers", ssl_bind_parse_ciphers, 1 }, /* set SSL cipher suite */
1682#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
1683 { "ciphersuites", ssl_bind_parse_ciphersuites, 1 }, /* set TLS 1.3 cipher suite */
1684#endif
1685 { "crl-file", ssl_bind_parse_crl_file, 1 }, /* set certificate revocation list file use on client cert verify */
1686 { "curves", ssl_bind_parse_curves, 1 }, /* set SSL curve suite */
1687 { "ecdhe", ssl_bind_parse_ecdhe, 1 }, /* defines named curve for elliptic curve Diffie-Hellman */
1688 { "no-ca-names", ssl_bind_parse_no_ca_names, 0 }, /* do not send ca names to clients (ca_file related) */
1689 { "npn", ssl_bind_parse_npn, 1 }, /* set NPN supported protocols */
1690 { "ssl-min-ver", ssl_bind_parse_tls_method_minmax,1 }, /* minimum version */
1691 { "ssl-max-ver", ssl_bind_parse_tls_method_minmax,1 }, /* maximum version */
1692 { "verify", ssl_bind_parse_verify, 1 }, /* set SSL verify method */
1693 { NULL, NULL, 0 },
1694};
1695
1696/* no initcall for ssl_bind_kws, these ones are parsed in the parser loop */
1697
1698static struct bind_kw_list bind_kws = { "SSL", { }, {
1699 { "allow-0rtt", bind_parse_allow_0rtt, 0 }, /* Allow 0RTT */
1700 { "alpn", bind_parse_alpn, 1 }, /* set ALPN supported protocols */
1701 { "ca-file", bind_parse_ca_file, 1 }, /* set CAfile to process ca-names and verify on client cert */
1702 { "ca-verify-file", bind_parse_ca_verify_file, 1 }, /* set CAverify file to process verify on client cert */
1703 { "ca-ignore-err", bind_parse_ignore_err, 1 }, /* set error IDs to ignore on verify depth > 0 */
1704 { "ca-sign-file", bind_parse_ca_sign_file, 1 }, /* set CAFile used to generate and sign server certs */
1705 { "ca-sign-pass", bind_parse_ca_sign_pass, 1 }, /* set CAKey passphrase */
1706 { "ciphers", bind_parse_ciphers, 1 }, /* set SSL cipher suite */
1707#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
1708 { "ciphersuites", bind_parse_ciphersuites, 1 }, /* set TLS 1.3 cipher suite */
1709#endif
1710 { "crl-file", bind_parse_crl_file, 1 }, /* set certificate revocation list file use on client cert verify */
1711 { "crt", bind_parse_crt, 1 }, /* load SSL certificates from this location */
1712 { "crt-ignore-err", bind_parse_ignore_err, 1 }, /* set error IDs to ignore on verify depth == 0 */
1713 { "crt-list", bind_parse_crt_list, 1 }, /* load a list of crt from this location */
1714 { "curves", bind_parse_curves, 1 }, /* set SSL curve suite */
1715 { "ecdhe", bind_parse_ecdhe, 1 }, /* defines named curve for elliptic curve Diffie-Hellman */
1716 { "force-sslv3", bind_parse_tls_method_options, 0 }, /* force SSLv3 */
1717 { "force-tlsv10", bind_parse_tls_method_options, 0 }, /* force TLSv10 */
1718 { "force-tlsv11", bind_parse_tls_method_options, 0 }, /* force TLSv11 */
1719 { "force-tlsv12", bind_parse_tls_method_options, 0 }, /* force TLSv12 */
1720 { "force-tlsv13", bind_parse_tls_method_options, 0 }, /* force TLSv13 */
1721 { "generate-certificates", bind_parse_generate_certs, 0 }, /* enable the server certificates generation */
1722 { "no-ca-names", bind_parse_no_ca_names, 0 }, /* do not send ca names to clients (ca_file related) */
1723 { "no-sslv3", bind_parse_tls_method_options, 0 }, /* disable SSLv3 */
1724 { "no-tlsv10", bind_parse_tls_method_options, 0 }, /* disable TLSv10 */
1725 { "no-tlsv11", bind_parse_tls_method_options, 0 }, /* disable TLSv11 */
1726 { "no-tlsv12", bind_parse_tls_method_options, 0 }, /* disable TLSv12 */
1727 { "no-tlsv13", bind_parse_tls_method_options, 0 }, /* disable TLSv13 */
1728 { "no-tls-tickets", bind_parse_no_tls_tickets, 0 }, /* disable session resumption tickets */
1729 { "ssl", bind_parse_ssl, 0 }, /* enable SSL processing */
1730 { "ssl-min-ver", bind_parse_tls_method_minmax, 1 }, /* minimum version */
1731 { "ssl-max-ver", bind_parse_tls_method_minmax, 1 }, /* maximum version */
1732 { "strict-sni", bind_parse_strict_sni, 0 }, /* refuse negotiation if sni doesn't match a certificate */
1733 { "tls-ticket-keys", bind_parse_tls_ticket_keys, 1 }, /* set file to load TLS ticket keys from */
1734 { "verify", bind_parse_verify, 1 }, /* set SSL verify method */
1735 { "npn", bind_parse_npn, 1 }, /* set NPN supported protocols */
1736 { "prefer-client-ciphers", bind_parse_pcc, 0 }, /* prefer client ciphers */
1737 { NULL, NULL, 0 },
1738}};
1739
1740INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws);
1741
1742/* Note: must not be declared <const> as its list will be overwritten.
1743 * Please take care of keeping this list alphabetically sorted, doing so helps
1744 * all code contributors.
1745 * Optional keywords are also declared with a NULL ->parse() function so that
1746 * the config parser can report an appropriate error when a known keyword was
1747 * not enabled.
1748 */
1749static struct srv_kw_list srv_kws = { "SSL", { }, {
1750 { "allow-0rtt", srv_parse_allow_0rtt, 0, 1 }, /* Allow using early data on this server */
1751 { "alpn", srv_parse_alpn, 1, 1 }, /* Set ALPN supported protocols */
1752 { "ca-file", srv_parse_ca_file, 1, 1 }, /* set CAfile to process verify server cert */
1753 { "check-alpn", srv_parse_alpn, 1, 1 }, /* Set ALPN used for checks */
1754 { "check-sni", srv_parse_check_sni, 1, 1 }, /* set SNI */
1755 { "check-ssl", srv_parse_check_ssl, 0, 1 }, /* enable SSL for health checks */
1756 { "ciphers", srv_parse_ciphers, 1, 1 }, /* select the cipher suite */
1757#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
1758 { "ciphersuites", srv_parse_ciphersuites, 1, 1 }, /* select the cipher suite */
1759#endif
1760 { "crl-file", srv_parse_crl_file, 1, 1 }, /* set certificate revocation list file use on server cert verify */
1761 { "crt", srv_parse_crt, 1, 1 }, /* set client certificate */
1762 { "force-sslv3", srv_parse_tls_method_options, 0, 1 }, /* force SSLv3 */
1763 { "force-tlsv10", srv_parse_tls_method_options, 0, 1 }, /* force TLSv10 */
1764 { "force-tlsv11", srv_parse_tls_method_options, 0, 1 }, /* force TLSv11 */
1765 { "force-tlsv12", srv_parse_tls_method_options, 0, 1 }, /* force TLSv12 */
1766 { "force-tlsv13", srv_parse_tls_method_options, 0, 1 }, /* force TLSv13 */
1767 { "no-check-ssl", srv_parse_no_check_ssl, 0, 1 }, /* disable SSL for health checks */
1768 { "no-send-proxy-v2-ssl", srv_parse_no_send_proxy_ssl, 0, 1 }, /* do not send PROXY protocol header v2 with SSL info */
1769 { "no-send-proxy-v2-ssl-cn", srv_parse_no_send_proxy_cn, 0, 1 }, /* do not send PROXY protocol header v2 with CN */
1770 { "no-ssl", srv_parse_no_ssl, 0, 1 }, /* disable SSL processing */
1771 { "no-ssl-reuse", srv_parse_no_ssl_reuse, 0, 1 }, /* disable session reuse */
1772 { "no-sslv3", srv_parse_tls_method_options, 0, 0 }, /* disable SSLv3 */
1773 { "no-tlsv10", srv_parse_tls_method_options, 0, 0 }, /* disable TLSv10 */
1774 { "no-tlsv11", srv_parse_tls_method_options, 0, 0 }, /* disable TLSv11 */
1775 { "no-tlsv12", srv_parse_tls_method_options, 0, 0 }, /* disable TLSv12 */
1776 { "no-tlsv13", srv_parse_tls_method_options, 0, 0 }, /* disable TLSv13 */
1777 { "no-tls-tickets", srv_parse_no_tls_tickets, 0, 1 }, /* disable session resumption tickets */
1778 { "npn", srv_parse_npn, 1, 1 }, /* Set NPN supported protocols */
1779 { "send-proxy-v2-ssl", srv_parse_send_proxy_ssl, 0, 1 }, /* send PROXY protocol header v2 with SSL info */
1780 { "send-proxy-v2-ssl-cn", srv_parse_send_proxy_cn, 0, 1 }, /* send PROXY protocol header v2 with CN */
1781 { "sni", srv_parse_sni, 1, 1 }, /* send SNI extension */
1782 { "ssl", srv_parse_ssl, 0, 1 }, /* enable SSL processing */
1783 { "ssl-min-ver", srv_parse_tls_method_minmax, 1, 1 }, /* minimum version */
1784 { "ssl-max-ver", srv_parse_tls_method_minmax, 1, 1 }, /* maximum version */
1785 { "ssl-reuse", srv_parse_ssl_reuse, 0, 1 }, /* enable session reuse */
1786 { "tls-tickets", srv_parse_tls_tickets, 0, 1 }, /* enable session resumption tickets */
1787 { "verify", srv_parse_verify, 1, 1 }, /* set SSL verify method */
1788 { "verifyhost", srv_parse_verifyhost, 1, 1 }, /* require that SSL cert verifies for hostname */
1789 { NULL, NULL, 0, 0 },
1790}};
1791
1792INITCALL1(STG_REGISTER, srv_register_keywords, &srv_kws);
1793
1794static struct cfg_kw_list cfg_kws = {ILH, {
1795 { CFG_GLOBAL, "ca-base", ssl_parse_global_ca_crt_base },
1796 { CFG_GLOBAL, "crt-base", ssl_parse_global_ca_crt_base },
1797 { CFG_GLOBAL, "issuers-chain-path", ssl_load_global_issuers_from_path },
1798 { CFG_GLOBAL, "maxsslconn", ssl_parse_global_int },
1799 { CFG_GLOBAL, "ssl-default-bind-options", ssl_parse_default_bind_options },
1800 { CFG_GLOBAL, "ssl-default-server-options", ssl_parse_default_server_options },
1801#ifndef OPENSSL_NO_DH
1802 { CFG_GLOBAL, "ssl-dh-param-file", ssl_parse_global_dh_param_file },
1803#endif
1804 { CFG_GLOBAL, "ssl-mode-async", ssl_parse_global_ssl_async },
1805#ifndef OPENSSL_NO_ENGINE
1806 { CFG_GLOBAL, "ssl-engine", ssl_parse_global_ssl_engine },
1807#endif
1808 { CFG_GLOBAL, "ssl-skip-self-issued-ca", ssl_parse_skip_self_issued_ca },
1809 { CFG_GLOBAL, "tune.ssl.cachesize", ssl_parse_global_int },
1810#ifndef OPENSSL_NO_DH
1811 { CFG_GLOBAL, "tune.ssl.default-dh-param", ssl_parse_global_default_dh },
1812#endif
1813 { CFG_GLOBAL, "tune.ssl.force-private-cache", ssl_parse_global_private_cache },
1814 { CFG_GLOBAL, "tune.ssl.lifetime", ssl_parse_global_lifetime },
1815 { CFG_GLOBAL, "tune.ssl.maxrecord", ssl_parse_global_int },
1816 { CFG_GLOBAL, "tune.ssl.ssl-ctx-cache-size", ssl_parse_global_int },
1817 { CFG_GLOBAL, "tune.ssl.capture-cipherlist-size", ssl_parse_global_capture_cipherlist },
1818 { CFG_GLOBAL, "ssl-default-bind-ciphers", ssl_parse_global_ciphers },
1819 { CFG_GLOBAL, "ssl-default-server-ciphers", ssl_parse_global_ciphers },
1820#if ((HA_OPENSSL_VERSION_NUMBER >= 0x1000200fL) || defined(LIBRESSL_VERSION_NUMBER))
1821 { CFG_GLOBAL, "ssl-default-bind-curves", ssl_parse_global_curves },
1822#endif
1823#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
1824 { CFG_GLOBAL, "ssl-default-bind-ciphersuites", ssl_parse_global_ciphersuites },
1825 { CFG_GLOBAL, "ssl-default-server-ciphersuites", ssl_parse_global_ciphersuites },
1826#endif
1827 { CFG_GLOBAL, "ssl-load-extra-files", ssl_parse_global_extra_files },
1828 { 0, NULL, NULL },
1829}};
1830
1831INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);