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