blob: d70e2ab91d646e7ff72514c9fd4ad718e8e4a329 [file] [log] [blame]
William Lallemand6e9556b2020-05-12 17:52:44 +02001/*
2 *
3 * Copyright (C) 2020 HAProxy Technologies, William Lallemand <wlallemand@haproxy.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
9 *
10 */
Willy Tarreaub2551052020-06-09 09:07:15 +020011#include <sys/stat.h>
12#include <sys/types.h>
William Lallemand6e9556b2020-05-12 17:52:44 +020013
Willy Tarreaub2551052020-06-09 09:07:15 +020014#include <dirent.h>
William Lallemand212e9932020-05-18 08:33:09 +020015#include <errno.h>
William Lallemand6e9556b2020-05-12 17:52:44 +020016#include <stdlib.h>
17#include <string.h>
Willy Tarreauaeed4a82020-06-04 22:01:04 +020018#include <syslog.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020019
20#include <import/ebpttree.h>
21#include <import/ebsttree.h>
William Lallemand6e9556b2020-05-12 17:52:44 +020022
Willy Tarreauf1d32c42020-06-04 21:07:02 +020023#include <haproxy/channel.h>
Willy Tarreau83487a82020-06-04 20:19:54 +020024#include <haproxy/cli.h>
Willy Tarreau8d366972020-05-27 16:10:29 +020025#include <haproxy/errors.h>
Willy Tarreau47d7f902020-06-04 14:25:47 +020026#include <haproxy/ssl_ckch.h>
Willy Tarreau52d88722020-06-04 14:29:23 +020027#include <haproxy/ssl_crtlist.h>
Willy Tarreau209108d2020-06-04 20:30:20 +020028#include <haproxy/ssl_sock.h>
Willy Tarreau5e539c92020-06-04 20:45:39 +020029#include <haproxy/stream_interface.h>
Willy Tarreau48fbcae2020-06-03 18:09:46 +020030#include <haproxy/tools.h>
William Lallemand6e9556b2020-05-12 17:52:44 +020031
William Lallemand6e9556b2020-05-12 17:52:44 +020032
William Lallemand6e9556b2020-05-12 17:52:44 +020033/* release ssl bind conf */
34void ssl_sock_free_ssl_conf(struct ssl_bind_conf *conf)
35{
36 if (conf) {
37#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG)
38 free(conf->npn_str);
39 conf->npn_str = NULL;
40#endif
41#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
42 free(conf->alpn_str);
43 conf->alpn_str = NULL;
44#endif
45 free(conf->ca_file);
46 conf->ca_file = NULL;
47 free(conf->ca_verify_file);
48 conf->ca_verify_file = NULL;
49 free(conf->crl_file);
50 conf->crl_file = NULL;
51 free(conf->ciphers);
52 conf->ciphers = NULL;
53#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
54 free(conf->ciphersuites);
55 conf->ciphersuites = NULL;
56#endif
57 free(conf->curves);
58 conf->curves = NULL;
59 free(conf->ecdhe);
60 conf->ecdhe = NULL;
61 }
62}
63
William Lallemand82f2d2f2020-09-10 19:06:43 +020064/*
65 * Allocate and copy a ssl_bind_conf structure
66 */
67struct ssl_bind_conf *crtlist_dup_ssl_conf(struct ssl_bind_conf *src)
68{
69 struct ssl_bind_conf *dst;
70
71 if (!src)
72 return NULL;
73
74 dst = calloc(1, sizeof(*dst));
75 if (!dst)
76 return NULL;
77
78#if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG)
79 if (src->npn_str) {
80 dst->npn_str = strdup(src->npn_str);
81 if (!dst->npn_str)
82 goto error;
83 }
84#endif
85#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
86 if (src->alpn_str) {
87 dst->alpn_str = strdup(src->alpn_str);
88 if (!dst->alpn_str)
89 goto error;
90 }
91#endif
92 if (src->ca_file) {
93 dst->ca_file = strdup(src->ca_file);
94 if (!dst->ca_file)
95 goto error;
96 }
97 if (src->ca_verify_file) {
98 dst->ca_verify_file = strdup(src->ca_verify_file);
99 if (!dst->ca_verify_file)
100 goto error;
101 }
102 if (src->crl_file) {
103 dst->crl_file = strdup(src->crl_file);
104 if (!dst->crl_file)
105 goto error;
106 }
107 if (src->ciphers) {
108 dst->ciphers = strdup(src->ciphers);
109 if (!dst->ciphers)
110 goto error;
111 }
112#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L)
113 if (src->ciphersuites) {
114 dst->ciphersuites = strdup(src->ciphersuites);
115 if (!dst->ciphersuites)
116 goto error;
117 }
118#endif
119 if (src->curves) {
120 dst->curves = strdup(src->curves);
121 if (!dst->curves)
122 goto error;
123 }
124 if (src->ecdhe) {
125 dst->ecdhe = strdup(src->ecdhe);
126 if (!dst->ecdhe)
127 goto error;
128 }
129 return dst;
130
131error:
132 ssl_sock_free_ssl_conf(dst);
133 free(dst);
134
135 return NULL;
136}
William Lallemand6e9556b2020-05-12 17:52:44 +0200137
138/* free sni filters */
139void crtlist_free_filters(char **args)
140{
141 int i;
142
143 if (!args)
144 return;
145
146 for (i = 0; args[i]; i++)
147 free(args[i]);
148
149 free(args);
150}
151
152/* Alloc and duplicate a char ** array */
153char **crtlist_dup_filters(char **args, int fcount)
154{
155 char **dst;
156 int i;
157
158 if (fcount == 0)
159 return NULL;
160
161 dst = calloc(fcount + 1, sizeof(*dst));
162 if (!dst)
163 return NULL;
164
165 for (i = 0; i < fcount; i++) {
166 dst[i] = strdup(args[i]);
167 if (!dst[i])
168 goto error;
169 }
170 return dst;
171
172error:
173 crtlist_free_filters(dst);
174 return NULL;
175}
176
177/*
178 * Detach and free a crtlist_entry.
179 * Free the filters, the ssl_conf and call ckch_inst_free() for each ckch_inst
180 */
181void crtlist_entry_free(struct crtlist_entry *entry)
182{
183 struct ckch_inst *inst, *inst_s;
184
185 if (entry == NULL)
186 return;
187
188 ebpt_delete(&entry->node);
189 LIST_DEL(&entry->by_crtlist);
190 LIST_DEL(&entry->by_ckch_store);
191 crtlist_free_filters(entry->filters);
192 ssl_sock_free_ssl_conf(entry->ssl_conf);
193 free(entry->ssl_conf);
194 list_for_each_entry_safe(inst, inst_s, &entry->ckch_inst, by_crtlist_entry) {
195 ckch_inst_free(inst);
196 }
197 free(entry);
198}
199
200/*
201 * Allocate and initialize a crtlist_entry
202 */
203struct crtlist_entry *crtlist_entry_new()
204{
205 struct crtlist_entry *entry;
206
207 entry = calloc(1, sizeof(*entry));
208 if (entry == NULL)
209 return NULL;
210
211 LIST_INIT(&entry->ckch_inst);
212
213 /* initialize the nodes so we can LIST_DEL in any cases */
214 LIST_INIT(&entry->by_crtlist);
215 LIST_INIT(&entry->by_ckch_store);
216
217 return entry;
218}
219
220/* Free a crtlist, from the crt_entry to the content of the ssl_conf */
221void crtlist_free(struct crtlist *crtlist)
222{
223 struct crtlist_entry *entry, *s_entry;
William Lallemand6a3168a2020-06-23 11:43:35 +0200224 struct bind_conf_list *bind_conf_node;
William Lallemand6e9556b2020-05-12 17:52:44 +0200225
226 if (crtlist == NULL)
227 return;
228
William Lallemand6a3168a2020-06-23 11:43:35 +0200229 bind_conf_node = crtlist->bind_conf;
230 while (bind_conf_node) {
231 struct bind_conf_list *next = bind_conf_node->next;
232 free(bind_conf_node);
233 bind_conf_node = next;
234 }
235
William Lallemand6e9556b2020-05-12 17:52:44 +0200236 list_for_each_entry_safe(entry, s_entry, &crtlist->ord_entries, by_crtlist) {
237 crtlist_entry_free(entry);
238 }
239 ebmb_delete(&crtlist->node);
240 free(crtlist);
241}
242
243/* Alloc and initialize a struct crtlist
244 * <filename> is the key of the ebmb_node
245 * <unique> initialize the list of entries to be unique (1) or not (0)
246 */
247struct crtlist *crtlist_new(const char *filename, int unique)
248{
249 struct crtlist *newlist;
250
251 newlist = calloc(1, sizeof(*newlist) + strlen(filename) + 1);
252 if (newlist == NULL)
253 return NULL;
254
255 memcpy(newlist->node.key, filename, strlen(filename) + 1);
256 if (unique)
257 newlist->entries = EB_ROOT_UNIQUE;
258 else
259 newlist->entries = EB_ROOT;
260
261 LIST_INIT(&newlist->ord_entries);
262
263 return newlist;
264}
265
266/*
267 * Read a single crt-list line. /!\ alter the <line> string.
268 * Fill <crt_path> and <crtlist_entry>
269 * <crtlist_entry> must be alloc and free by the caller
270 * <crtlist_entry->ssl_conf> is alloc by the function
271 * <crtlist_entry->filters> is alloc by the function
272 * <crt_path> is a ptr in <line>
273 * Return an error code
274 */
275int crtlist_parse_line(char *line, char **crt_path, struct crtlist_entry *entry, const char *file, int linenum, char **err)
276{
277 int cfgerr = 0;
278 int arg, newarg, cur_arg, i, ssl_b = 0, ssl_e = 0;
279 char *end;
280 char *args[MAX_CRT_ARGS + 1];
281 struct ssl_bind_conf *ssl_conf = NULL;
282
283 if (!line || !crt_path || !entry)
284 return ERR_ALERT | ERR_FATAL;
285
286 end = line + strlen(line);
287 if (end-line >= CRT_LINESIZE-1 && *(end-1) != '\n') {
288 /* Check if we reached the limit and the last char is not \n.
289 * Watch out for the last line without the terminating '\n'!
290 */
291 memprintf(err, "line %d too long in file '%s', limit is %d characters",
292 linenum, file, CRT_LINESIZE-1);
293 cfgerr |= ERR_ALERT | ERR_FATAL;
294 goto error;
295 }
296 arg = 0;
297 newarg = 1;
298 while (*line) {
299 if (isspace((unsigned char)*line)) {
300 newarg = 1;
301 *line = 0;
302 } else if (*line == '[') {
303 if (ssl_b) {
304 memprintf(err, "too many '[' on line %d in file '%s'.", linenum, file);
305 cfgerr |= ERR_ALERT | ERR_FATAL;
306 goto error;
307 }
308 if (!arg) {
309 memprintf(err, "file must start with a cert on line %d in file '%s'", linenum, file);
310 cfgerr |= ERR_ALERT | ERR_FATAL;
311 goto error;
312 }
313 ssl_b = arg;
314 newarg = 1;
315 *line = 0;
316 } else if (*line == ']') {
317 if (ssl_e) {
318 memprintf(err, "too many ']' on line %d in file '%s'.", linenum, file);
319 cfgerr |= ERR_ALERT | ERR_FATAL;
320 goto error;
321 }
322 if (!ssl_b) {
323 memprintf(err, "missing '[' in line %d in file '%s'.", linenum, file);
324 cfgerr |= ERR_ALERT | ERR_FATAL;
325 goto error;
326 }
327 ssl_e = arg;
328 newarg = 1;
329 *line = 0;
330 } else if (newarg) {
331 if (arg == MAX_CRT_ARGS) {
332 memprintf(err, "too many args on line %d in file '%s'.", linenum, file);
333 cfgerr |= ERR_ALERT | ERR_FATAL;
334 goto error;
335 }
336 newarg = 0;
337 args[arg++] = line;
338 }
339 line++;
340 }
341 args[arg++] = line;
342
343 /* empty line */
344 if (!*args[0]) {
345 cfgerr |= ERR_NONE;
346 goto error;
347 }
348
349 *crt_path = args[0];
350
351 if (ssl_b) {
352 ssl_conf = calloc(1, sizeof *ssl_conf);
353 if (!ssl_conf) {
354 memprintf(err, "not enough memory!");
355 cfgerr |= ERR_ALERT | ERR_FATAL;
356 goto error;
357 }
358 }
359 cur_arg = ssl_b ? ssl_b : 1;
360 while (cur_arg < ssl_e) {
361 newarg = 0;
362 for (i = 0; ssl_bind_kws[i].kw != NULL; i++) {
363 if (strcmp(ssl_bind_kws[i].kw, args[cur_arg]) == 0) {
364 newarg = 1;
365 cfgerr |= ssl_bind_kws[i].parse(args, cur_arg, NULL, ssl_conf, err);
366 if (cur_arg + 1 + ssl_bind_kws[i].skip > ssl_e) {
367 memprintf(err, "ssl args out of '[]' for %s on line %d in file '%s'",
368 args[cur_arg], linenum, file);
369 cfgerr |= ERR_ALERT | ERR_FATAL;
370 goto error;
371 }
372 cur_arg += 1 + ssl_bind_kws[i].skip;
373 break;
374 }
375 }
376 if (!cfgerr && !newarg) {
377 memprintf(err, "unknown ssl keyword %s on line %d in file '%s'.",
378 args[cur_arg], linenum, file);
379 cfgerr |= ERR_ALERT | ERR_FATAL;
380 goto error;
381 }
382 }
383 entry->linenum = linenum;
384 entry->ssl_conf = ssl_conf;
385 entry->filters = crtlist_dup_filters(&args[cur_arg], arg - cur_arg - 1);
386 entry->fcount = arg - cur_arg - 1;
387
388 return cfgerr;
389
390error:
391 crtlist_free_filters(entry->filters);
392 entry->filters = NULL;
393 ssl_sock_free_ssl_conf(entry->ssl_conf);
394 free(entry->ssl_conf);
395 entry->ssl_conf = NULL;
396 return cfgerr;
397}
398
399
400
401/* This function parse a crt-list file and store it in a struct crtlist, each line is a crtlist_entry structure
402 * Fill the <crtlist> argument with a pointer to a new crtlist struct
403 *
404 * This function tries to open and store certificate files.
405 */
406int crtlist_parse_file(char *file, struct bind_conf *bind_conf, struct proxy *curproxy, struct crtlist **crtlist, char **err)
407{
408 struct crtlist *newlist;
409 struct crtlist_entry *entry = NULL;
410 char thisline[CRT_LINESIZE];
411 char path[MAXPATHLEN+1];
412 FILE *f;
413 struct stat buf;
414 int linenum = 0;
415 int cfgerr = 0;
416
417 if ((f = fopen(file, "r")) == NULL) {
418 memprintf(err, "cannot open file '%s' : %s", file, strerror(errno));
419 return ERR_ALERT | ERR_FATAL;
420 }
421
422 newlist = crtlist_new(file, 0);
423 if (newlist == NULL) {
424 memprintf(err, "Not enough memory!");
425 cfgerr |= ERR_ALERT | ERR_FATAL;
426 goto error;
427 }
428
429 while (fgets(thisline, sizeof(thisline), f) != NULL) {
430 char *end;
431 char *line = thisline;
432 char *crt_path;
433 struct ckch_store *ckchs;
434
435 linenum++;
436 end = line + strlen(line);
437 if (end-line == sizeof(thisline)-1 && *(end-1) != '\n') {
438 /* Check if we reached the limit and the last char is not \n.
439 * Watch out for the last line without the terminating '\n'!
440 */
441 memprintf(err, "line %d too long in file '%s', limit is %d characters",
442 linenum, file, (int)sizeof(thisline)-1);
443 cfgerr |= ERR_ALERT | ERR_FATAL;
444 break;
445 }
446
447 if (*line == '#' || *line == '\n' || *line == '\r')
448 continue;
449
450 entry = crtlist_entry_new();
451 if (entry == NULL) {
452 memprintf(err, "Not enough memory!");
453 cfgerr |= ERR_ALERT | ERR_FATAL;
454 goto error;
455 }
William Lallemand0354b652020-09-16 11:55:09 +0200456 if (*(end - 1) == '\n')
457 *(end - 1) = '\0'; /* line parser mustn't receive any \n */
William Lallemand6e9556b2020-05-12 17:52:44 +0200458 cfgerr |= crtlist_parse_line(thisline, &crt_path, entry, file, linenum, err);
459 if (cfgerr)
460 goto error;
461
462 /* empty line */
463 if (!crt_path || !*crt_path) {
464 crtlist_entry_free(entry);
465 entry = NULL;
466 continue;
467 }
468
469 if (*crt_path != '/' && global_ssl.crt_base) {
470 if ((strlen(global_ssl.crt_base) + 1 + strlen(crt_path)) > MAXPATHLEN) {
471 memprintf(err, "'%s' : path too long on line %d in file '%s'",
472 crt_path, linenum, file);
473 cfgerr |= ERR_ALERT | ERR_FATAL;
474 goto error;
475 }
476 snprintf(path, sizeof(path), "%s/%s", global_ssl.crt_base, crt_path);
477 crt_path = path;
478 }
479
480 /* Look for a ckch_store or create one */
481 ckchs = ckchs_lookup(crt_path);
482 if (ckchs == NULL) {
483 if (stat(crt_path, &buf) == 0)
484 ckchs = ckchs_load_cert_file(crt_path, 0, err);
485 else
486 ckchs = ckchs_load_cert_file(crt_path, 1, err);
487 }
488 if (ckchs == NULL)
489 cfgerr |= ERR_ALERT | ERR_FATAL;
490
491 if (cfgerr & ERR_CODE)
492 goto error;
493
494 entry->node.key = ckchs;
495 entry->crtlist = newlist;
496 ebpt_insert(&newlist->entries, &entry->node);
497 LIST_ADDQ(&newlist->ord_entries, &entry->by_crtlist);
498 LIST_ADDQ(&ckchs->crtlist_entry, &entry->by_ckch_store);
499
500 entry = NULL;
501 }
502 if (cfgerr & ERR_CODE)
503 goto error;
504
505 newlist->linecount = linenum;
506
507 fclose(f);
508 *crtlist = newlist;
509
510 return cfgerr;
511error:
512 crtlist_entry_free(entry);
513
514 fclose(f);
515 crtlist_free(newlist);
516 return cfgerr;
517}
518
519/* This function reads a directory and stores it in a struct crtlist, each file is a crtlist_entry structure
520 * Fill the <crtlist> argument with a pointer to a new crtlist struct
521 *
522 * This function tries to open and store certificate files.
523 */
524int crtlist_load_cert_dir(char *path, struct bind_conf *bind_conf, struct crtlist **crtlist, char **err)
525{
526 struct crtlist *dir;
527 struct dirent **de_list;
528 int i, n;
529 struct stat buf;
530 char *end;
531 char fp[MAXPATHLEN+1];
532 int cfgerr = 0;
533 struct ckch_store *ckchs;
William Lallemand6e9556b2020-05-12 17:52:44 +0200534
535 dir = crtlist_new(path, 1);
536 if (dir == NULL) {
537 memprintf(err, "not enough memory");
538 return ERR_ALERT | ERR_FATAL;
539 }
540
541 n = scandir(path, &de_list, 0, alphasort);
542 if (n < 0) {
543 memprintf(err, "%sunable to scan directory '%s' : %s.\n",
544 err && *err ? *err : "", path, strerror(errno));
545 cfgerr |= ERR_ALERT | ERR_FATAL;
546 }
547 else {
548 for (i = 0; i < n; i++) {
549 struct crtlist_entry *entry;
550 struct dirent *de = de_list[i];
551
552 end = strrchr(de->d_name, '.');
553 if (end && (!strcmp(end, ".issuer") || !strcmp(end, ".ocsp") || !strcmp(end, ".sctl") || !strcmp(end, ".key")))
554 goto ignore_entry;
555
556 snprintf(fp, sizeof(fp), "%s/%s", path, de->d_name);
557 if (stat(fp, &buf) != 0) {
558 memprintf(err, "%sunable to stat SSL certificate from file '%s' : %s.\n",
559 err && *err ? *err : "", fp, strerror(errno));
560 cfgerr |= ERR_ALERT | ERR_FATAL;
561 goto ignore_entry;
562 }
563 if (!S_ISREG(buf.st_mode))
564 goto ignore_entry;
565
566 entry = crtlist_entry_new();
567 if (entry == NULL) {
568 memprintf(err, "not enough memory '%s'", fp);
569 cfgerr |= ERR_ALERT | ERR_FATAL;
570 goto ignore_entry;
571 }
572
William Lallemand6e9556b2020-05-12 17:52:44 +0200573 ckchs = ckchs_lookup(fp);
574 if (ckchs == NULL)
575 ckchs = ckchs_load_cert_file(fp, 0, err);
576 if (ckchs == NULL) {
577 free(de);
578 free(entry);
579 cfgerr |= ERR_ALERT | ERR_FATAL;
580 goto end;
581 }
582 entry->node.key = ckchs;
583 entry->crtlist = dir;
584 LIST_ADDQ(&ckchs->crtlist_entry, &entry->by_ckch_store);
585 LIST_ADDQ(&dir->ord_entries, &entry->by_crtlist);
586 ebpt_insert(&dir->entries, &entry->node);
587
588ignore_entry:
589 free(de);
590 }
591end:
592 free(de_list);
593 }
594
595 if (cfgerr & ERR_CODE) {
596 /* free the dir and entries on error */
597 crtlist_free(dir);
598 } else {
599 *crtlist = dir;
600 }
601 return cfgerr;
602
603}
604
William Lallemandc756bbd2020-05-13 17:23:59 +0200605/*
606 * Take an ssl_bind_conf structure and append the configuration line used to
607 * create it in the buffer
608 */
609static void dump_crtlist_sslconf(struct buffer *buf, const struct ssl_bind_conf *conf)
610{
611 int space = 0;
612
613 if (conf == NULL)
614 return;
615
616 chunk_appendf(buf, " [");
617#ifdef OPENSSL_NPN_NEGOTIATED
618 if (conf->npn_str) {
619 int len = conf->npn_len;
620 char *ptr = conf->npn_str;
621 int comma = 0;
622
623 if (space) chunk_appendf(buf, " ");
624 chunk_appendf(buf, "npn ");
625 while (len) {
626 unsigned short size;
627
628 size = *ptr;
629 ptr++;
630 if (comma)
631 chunk_memcat(buf, ",", 1);
632 chunk_memcat(buf, ptr, size);
633 ptr += size;
634 len -= size + 1;
635 comma = 1;
636 }
637 chunk_memcat(buf, "", 1); /* finish with a \0 */
638 space++;
639 }
640#endif
641#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
642 if (conf->alpn_str) {
643 int len = conf->alpn_len;
644 char *ptr = conf->alpn_str;
645 int comma = 0;
646
647 if (space) chunk_appendf(buf, " ");
648 chunk_appendf(buf, "alpn ");
649 while (len) {
650 unsigned short size;
651
652 size = *ptr;
653 ptr++;
654 if (comma)
655 chunk_memcat(buf, ",", 1);
656 chunk_memcat(buf, ptr, size);
657 ptr += size;
658 len -= size + 1;
659 comma = 1;
660 }
661 chunk_memcat(buf, "", 1); /* finish with a \0 */
662 space++;
663 }
664#endif
665 /* verify */
666 {
667 if (conf->verify == SSL_SOCK_VERIFY_NONE) {
668 if (space) chunk_appendf(buf, " ");
669 chunk_appendf(buf, "verify none");
670 space++;
671 } else if (conf->verify == SSL_SOCK_VERIFY_OPTIONAL) {
672 if (space) chunk_appendf(buf, " ");
673 chunk_appendf(buf, "verify optional");
674 space++;
675 } else if (conf->verify == SSL_SOCK_VERIFY_REQUIRED) {
676 if (space) chunk_appendf(buf, " ");
677 chunk_appendf(buf, "verify required");
678 space++;
679 }
680 }
681
682 if (conf->no_ca_names) {
683 if (space) chunk_appendf(buf, " ");
684 chunk_appendf(buf, "no-ca-names");
685 space++;
686 }
687
688 if (conf->early_data) {
689 if (space) chunk_appendf(buf, " ");
690 chunk_appendf(buf, "allow-0rtt");
691 space++;
692 }
693 if (conf->ca_file) {
694 if (space) chunk_appendf(buf, " ");
695 chunk_appendf(buf, "ca-file %s", conf->ca_file);
696 space++;
697 }
698 if (conf->crl_file) {
699 if (space) chunk_appendf(buf, " ");
700 chunk_appendf(buf, "crl-file %s", conf->crl_file);
701 space++;
702 }
703 if (conf->ciphers) {
704 if (space) chunk_appendf(buf, " ");
705 chunk_appendf(buf, "ciphers %s", conf->ciphers);
706 space++;
707 }
708#if (HA_OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined OPENSSL_IS_BORINGSSL && !defined LIBRESSL_VERSION_NUMBER)
709 if (conf->ciphersuites) {
710 if (space) chunk_appendf(buf, " ");
711 chunk_appendf(buf, "ciphersuites %s", conf->ciphersuites);
712 space++;
713 }
714#endif
715 if (conf->curves) {
716 if (space) chunk_appendf(buf, " ");
717 chunk_appendf(buf, "curves %s", conf->curves);
718 space++;
719 }
720 if (conf->ecdhe) {
721 if (space) chunk_appendf(buf, " ");
722 chunk_appendf(buf, "ecdhe %s", conf->ecdhe);
723 space++;
724 }
725
726 /* the crt-lists only support ssl-min-ver and ssl-max-ver */
William Lallemand8177ad92020-05-20 16:49:02 +0200727 if (conf->ssl_methods_cfg.min) {
William Lallemandc756bbd2020-05-13 17:23:59 +0200728 if (space) chunk_appendf(buf, " ");
William Lallemand8177ad92020-05-20 16:49:02 +0200729 chunk_appendf(buf, "ssl-min-ver %s", methodVersions[conf->ssl_methods_cfg.min].name);
William Lallemandc756bbd2020-05-13 17:23:59 +0200730 space++;
731 }
732
William Lallemand8177ad92020-05-20 16:49:02 +0200733 if (conf->ssl_methods_cfg.max) {
William Lallemandc756bbd2020-05-13 17:23:59 +0200734 if (space) chunk_appendf(buf, " ");
William Lallemand8177ad92020-05-20 16:49:02 +0200735 chunk_appendf(buf, "ssl-max-ver %s", methodVersions[conf->ssl_methods_cfg.max].name);
William Lallemandc756bbd2020-05-13 17:23:59 +0200736 space++;
737 }
738
739 chunk_appendf(buf, "]");
740
741 return;
742}
743
744/* dump a list of filters */
745static void dump_crtlist_filters(struct buffer *buf, struct crtlist_entry *entry)
746{
747 int i;
748
749 if (!entry->fcount)
750 return;
751
752 for (i = 0; i < entry->fcount; i++) {
753 chunk_appendf(buf, " %s", entry->filters[i]);
754 }
755 return;
756}
757
758/************************** CLI functions ****************************/
759
760
761/* CLI IO handler for '(show|dump) ssl crt-list' */
762static int cli_io_handler_dump_crtlist(struct appctx *appctx)
763{
764 struct buffer *trash = alloc_trash_chunk();
765 struct stream_interface *si = appctx->owner;
766 struct ebmb_node *lnode;
767
768 if (trash == NULL)
769 return 1;
770
771 /* dump the list of crt-lists */
772 lnode = appctx->ctx.cli.p1;
773 if (lnode == NULL)
774 lnode = ebmb_first(&crtlists_tree);
775 while (lnode) {
776 chunk_appendf(trash, "%s\n", lnode->key);
777 if (ci_putchk(si_ic(si), trash) == -1) {
778 si_rx_room_blk(si);
779 goto yield;
780 }
781 lnode = ebmb_next(lnode);
782 }
783 free_trash_chunk(trash);
784 return 1;
785yield:
786 appctx->ctx.cli.p1 = lnode;
787 free_trash_chunk(trash);
788 return 0;
789}
790
791/* CLI IO handler for '(show|dump) ssl crt-list <filename>' */
792static int cli_io_handler_dump_crtlist_entries(struct appctx *appctx)
793{
794 struct buffer *trash = alloc_trash_chunk();
795 struct crtlist *crtlist;
796 struct stream_interface *si = appctx->owner;
797 struct crtlist_entry *entry;
798
799 if (trash == NULL)
800 return 1;
801
802 crtlist = ebmb_entry(appctx->ctx.cli.p0, struct crtlist, node);
803
804 entry = appctx->ctx.cli.p1;
805 if (entry == NULL) {
806 entry = LIST_ELEM((crtlist->ord_entries).n, typeof(entry), by_crtlist);
807 chunk_appendf(trash, "# %s\n", crtlist->node.key);
808 if (ci_putchk(si_ic(si), trash) == -1) {
809 si_rx_room_blk(si);
810 goto yield;
811 }
812 }
813
814 list_for_each_entry_from(entry, &crtlist->ord_entries, by_crtlist) {
815 struct ckch_store *store;
816 const char *filename;
817
818 store = entry->node.key;
819 filename = store->path;
820 chunk_appendf(trash, "%s", filename);
821 if (appctx->ctx.cli.i0 == 's') /* show */
822 chunk_appendf(trash, ":%d", entry->linenum);
823 dump_crtlist_sslconf(trash, entry->ssl_conf);
824 dump_crtlist_filters(trash, entry);
825 chunk_appendf(trash, "\n");
826
827 if (ci_putchk(si_ic(si), trash) == -1) {
828 si_rx_room_blk(si);
829 goto yield;
830 }
831 }
832 free_trash_chunk(trash);
833 return 1;
834yield:
835 appctx->ctx.cli.p1 = entry;
836 free_trash_chunk(trash);
837 return 0;
838}
839
840/* CLI argument parser for '(show|dump) ssl crt-list' */
841static int cli_parse_dump_crtlist(char **args, char *payload, struct appctx *appctx, void *private)
842{
843 struct ebmb_node *lnode;
844 char *filename = NULL;
845 int mode;
William Lallemand99cc2182020-06-25 15:19:51 +0200846 char *end;
William Lallemandc756bbd2020-05-13 17:23:59 +0200847
848 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
849 return 1;
850
851 appctx->ctx.cli.p0 = NULL;
852 appctx->ctx.cli.p1 = NULL;
853
854 if (*args[3] && !strcmp(args[3], "-n")) {
855 mode = 's';
856 filename = args[4];
857 } else {
858 mode = 'd';
859 filename = args[3];
860 }
861
862 if (mode == 's' && !*args[4])
863 return cli_err(appctx, "'show ssl crt-list -n' expects a filename or a directory\n");
864
865 if (filename && *filename) {
William Lallemand99cc2182020-06-25 15:19:51 +0200866
867
868 /* strip trailing slashes, including first one */
869 for (end = filename + strlen(filename) - 1; end >= filename && *end == '/'; end--)
870 *end = 0;
871
William Lallemandc756bbd2020-05-13 17:23:59 +0200872 lnode = ebst_lookup(&crtlists_tree, filename);
873 if (lnode == NULL)
874 return cli_err(appctx, "didn't find the specified filename\n");
875
876 appctx->ctx.cli.p0 = lnode;
877 appctx->io_handler = cli_io_handler_dump_crtlist_entries;
878 }
879 appctx->ctx.cli.i0 = mode;
880
881 return 0;
882}
883
884/* release function of the "add ssl crt-list' command, free things and unlock
885 the spinlock */
886static void cli_release_add_crtlist(struct appctx *appctx)
887{
888 struct crtlist_entry *entry = appctx->ctx.cli.p1;
889
890 if (appctx->st2 != SETCERT_ST_FIN) {
891 struct ckch_inst *inst, *inst_s;
892 /* upon error free the ckch_inst and everything inside */
893 ebpt_delete(&entry->node);
894 LIST_DEL(&entry->by_crtlist);
895 LIST_DEL(&entry->by_ckch_store);
896
897 list_for_each_entry_safe(inst, inst_s, &entry->ckch_inst, by_ckchs) {
898 ckch_inst_free(inst);
899 }
900 crtlist_free_filters(entry->filters);
901 ssl_sock_free_ssl_conf(entry->ssl_conf);
902 free(entry->ssl_conf);
903 free(entry);
904 }
905
906 HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);
907}
908
909
910/* IO Handler for the "add ssl crt-list" command It adds a new entry in the
911 * crt-list and generates the ckch_insts for each bind_conf that uses this crt-list
912 *
913 * The logic is the same as the "commit ssl cert" command but without the
914 * freeing of the old structures, because there are none.
915 */
916static int cli_io_handler_add_crtlist(struct appctx *appctx)
917{
918 struct bind_conf_list *bind_conf_node;
919 struct stream_interface *si = appctx->owner;
920 struct crtlist *crtlist = appctx->ctx.cli.p0;
921 struct crtlist_entry *entry = appctx->ctx.cli.p1;
922 struct ckch_store *store = entry->node.key;
923 struct buffer *trash = alloc_trash_chunk();
924 struct ckch_inst *new_inst;
925 char *err = NULL;
926 int i = 0;
927 int errcode = 0;
928
929 if (trash == NULL)
930 goto error;
931
932 /* for each bind_conf which use the crt-list, a new ckch_inst must be
933 * created.
934 */
935 if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
936 goto error;
937
938 while (1) {
939 switch (appctx->st2) {
940 case SETCERT_ST_INIT:
941 /* This state just print the update message */
942 chunk_printf(trash, "Inserting certificate '%s' in crt-list '%s'", store->path, crtlist->node.key);
943 if (ci_putchk(si_ic(si), trash) == -1) {
944 si_rx_room_blk(si);
945 goto yield;
946 }
947 appctx->st2 = SETCERT_ST_GEN;
948 /* fallthrough */
949 case SETCERT_ST_GEN:
950 bind_conf_node = appctx->ctx.cli.p2; /* get the previous ptr from the yield */
951 if (bind_conf_node == NULL)
952 bind_conf_node = crtlist->bind_conf;
953 for (; bind_conf_node; bind_conf_node = bind_conf_node->next) {
954 struct bind_conf *bind_conf = bind_conf_node->bind_conf;
955 struct sni_ctx *sni;
956
957 /* yield every 10 generations */
958 if (i > 10) {
959 appctx->ctx.cli.p2 = bind_conf_node;
960 goto yield;
961 }
962
963 /* we don't support multi-cert bundles, only simple ones */
964 errcode |= ckch_inst_new_load_store(store->path, store, bind_conf, entry->ssl_conf, entry->filters, entry->fcount, &new_inst, &err);
965 if (errcode & ERR_CODE)
966 goto error;
967
968 /* we need to initialize the SSL_CTX generated */
969 /* this iterate on the newly generated SNIs in the new instance to prepare their SSL_CTX */
970 list_for_each_entry(sni, &new_inst->sni_ctx, by_ckch_inst) {
971 if (!sni->order) { /* we initialized only the first SSL_CTX because it's the same in the other sni_ctx's */
972 errcode |= ssl_sock_prepare_ctx(bind_conf, new_inst->ssl_conf, sni->ctx, &err);
973 if (errcode & ERR_CODE)
974 goto error;
975 }
976 }
977 /* display one dot for each new instance */
978 chunk_appendf(trash, ".");
979 i++;
980 LIST_ADDQ(&store->ckch_inst, &new_inst->by_ckchs);
William Lallemand9ab8f8d2020-06-24 01:00:52 +0200981 LIST_ADDQ(&entry->ckch_inst, &new_inst->by_crtlist_entry);
982 new_inst->crtlist_entry = entry;
William Lallemandc756bbd2020-05-13 17:23:59 +0200983 }
984 appctx->st2 = SETCERT_ST_INSERT;
985 /* fallthrough */
986 case SETCERT_ST_INSERT:
987 /* insert SNIs in bind_conf */
988 list_for_each_entry(new_inst, &store->ckch_inst, by_ckchs) {
989 HA_RWLOCK_WRLOCK(SNI_LOCK, &new_inst->bind_conf->sni_lock);
990 ssl_sock_load_cert_sni(new_inst, new_inst->bind_conf);
991 HA_RWLOCK_WRUNLOCK(SNI_LOCK, &new_inst->bind_conf->sni_lock);
992 }
993 entry->linenum = ++crtlist->linecount;
994 appctx->st2 = SETCERT_ST_FIN;
995 goto end;
996 }
997 }
998
999end:
1000 chunk_appendf(trash, "\n");
1001 if (errcode & ERR_WARN)
1002 chunk_appendf(trash, "%s", err);
1003 chunk_appendf(trash, "Success!\n");
1004 if (ci_putchk(si_ic(si), trash) == -1)
1005 si_rx_room_blk(si);
1006 free_trash_chunk(trash);
1007 /* success: call the release function and don't come back */
1008 return 1;
1009yield:
1010 /* store the state */
1011 if (ci_putchk(si_ic(si), trash) == -1)
1012 si_rx_room_blk(si);
1013 free_trash_chunk(trash);
1014 si_rx_endp_more(si); /* let's come back later */
1015 return 0; /* should come back */
1016
1017error:
1018 /* spin unlock and free are done in the release function */
1019 if (trash) {
1020 chunk_appendf(trash, "\n%sFailed!\n", err);
1021 if (ci_putchk(si_ic(si), trash) == -1)
1022 si_rx_room_blk(si);
1023 free_trash_chunk(trash);
1024 }
1025 /* error: call the release function and don't come back */
1026 return 1;
1027}
1028
1029
1030/*
1031 * Parse a "add ssl crt-list <crt-list> <certfile>" line.
1032 * Filters and option must be passed through payload:
1033 */
1034static int cli_parse_add_crtlist(char **args, char *payload, struct appctx *appctx, void *private)
1035{
1036 int cfgerr = 0;
1037 struct ckch_store *store;
1038 char *err = NULL;
1039 char path[MAXPATHLEN+1];
1040 char *crtlist_path;
1041 char *cert_path = NULL;
1042 struct ebmb_node *eb;
1043 struct ebpt_node *inserted;
1044 struct crtlist *crtlist;
1045 struct crtlist_entry *entry = NULL;
William Lallemand99cc2182020-06-25 15:19:51 +02001046 char *end;
William Lallemandc756bbd2020-05-13 17:23:59 +02001047
1048 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
1049 return 1;
1050
1051 if (!*args[3] || (!payload && !*args[4]))
1052 return cli_err(appctx, "'add ssl crtlist' expects a filename and a certificate name\n");
1053
1054 crtlist_path = args[3];
1055
William Lallemand99cc2182020-06-25 15:19:51 +02001056 /* strip trailing slashes, including first one */
1057 for (end = crtlist_path + strlen(crtlist_path) - 1; end >= crtlist_path && *end == '/'; end--)
1058 *end = 0;
1059
William Lallemandc756bbd2020-05-13 17:23:59 +02001060 if (HA_SPIN_TRYLOCK(CKCH_LOCK, &ckch_lock))
1061 return cli_err(appctx, "Operations on certificates are currently locked!\n");
1062
1063 eb = ebst_lookup(&crtlists_tree, crtlist_path);
1064 if (!eb) {
1065 memprintf(&err, "crt-list '%s' does not exist!", crtlist_path);
1066 goto error;
1067 }
1068 crtlist = ebmb_entry(eb, struct crtlist, node);
1069
1070 entry = crtlist_entry_new();
1071 if (entry == NULL) {
1072 memprintf(&err, "Not enough memory!");
1073 goto error;
1074 }
1075
1076 if (payload) {
1077 char *lf;
1078
1079 lf = strrchr(payload, '\n');
1080 if (lf) {
1081 memprintf(&err, "only one line of payload is supported!");
1082 goto error;
1083 }
1084 /* cert_path is filled here */
1085 cfgerr |= crtlist_parse_line(payload, &cert_path, entry, "CLI", 1, &err);
1086 if (cfgerr & ERR_CODE)
1087 goto error;
1088 } else {
1089 cert_path = args[4];
1090 }
1091
1092 if (!cert_path) {
1093 memprintf(&err, "'add ssl crtlist' should contain the certificate name in the payload");
1094 cfgerr |= ERR_ALERT | ERR_FATAL;
1095 goto error;
1096 }
1097
1098 if (eb_gettag(crtlist->entries.b[EB_RGHT])) {
1099 char *slash;
1100
1101 slash = strrchr(cert_path, '/');
1102 if (!slash) {
1103 memprintf(&err, "'%s' is a directory, certificate path '%s' must contain the directory path", (char *)crtlist->node.key, cert_path);
1104 goto error;
1105 }
1106 /* temporary replace / by 0 to do an strcmp */
1107 *slash = '\0';
1108 if (strcmp(cert_path, (char*)crtlist->node.key) != 0) {
1109 *slash = '/';
1110 memprintf(&err, "'%s' is a directory, certificate path '%s' must contain the directory path", (char *)crtlist->node.key, cert_path);
1111 goto error;
1112 }
1113 *slash = '/';
1114 }
1115
1116 if (*cert_path != '/' && global_ssl.crt_base) {
1117 if ((strlen(global_ssl.crt_base) + 1 + strlen(cert_path)) > MAXPATHLEN) {
1118 memprintf(&err, "'%s' : path too long", cert_path);
1119 cfgerr |= ERR_ALERT | ERR_FATAL;
1120 goto error;
1121 }
1122 snprintf(path, sizeof(path), "%s/%s", global_ssl.crt_base, cert_path);
1123 cert_path = path;
1124 }
1125
1126 store = ckchs_lookup(cert_path);
1127 if (store == NULL) {
1128 memprintf(&err, "certificate '%s' does not exist!", cert_path);
1129 goto error;
1130 }
William Lallemandc756bbd2020-05-13 17:23:59 +02001131 if (store->ckch == NULL || store->ckch->cert == NULL) {
1132 memprintf(&err, "certificate '%s' is empty!", cert_path);
1133 goto error;
1134 }
1135
1136 /* check if it's possible to insert this new crtlist_entry */
1137 entry->node.key = store;
1138 inserted = ebpt_insert(&crtlist->entries, &entry->node);
1139 if (inserted != &entry->node) {
1140 memprintf(&err, "file already exists in this directory!");
1141 goto error;
1142 }
1143
1144 /* this is supposed to be a directory (EB_ROOT_UNIQUE), so no ssl_conf are allowed */
1145 if ((entry->ssl_conf || entry->filters) && eb_gettag(crtlist->entries.b[EB_RGHT])) {
1146 memprintf(&err, "this is a directory, SSL configuration and filters are not allowed");
1147 goto error;
1148 }
1149
1150 LIST_ADDQ(&crtlist->ord_entries, &entry->by_crtlist);
1151 entry->crtlist = crtlist;
1152 LIST_ADDQ(&store->crtlist_entry, &entry->by_ckch_store);
1153
1154 appctx->st2 = SETCERT_ST_INIT;
1155 appctx->ctx.cli.p0 = crtlist;
1156 appctx->ctx.cli.p1 = entry;
1157
1158 /* unlock is done in the release handler */
1159 return 0;
1160
1161error:
1162 crtlist_entry_free(entry);
1163 HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);
1164 err = memprintf(&err, "Can't edit the crt-list: %s\n", err ? err : "");
1165 return cli_dynerr(appctx, err);
1166}
1167
1168/* Parse a "del ssl crt-list <crt-list> <certfile>" line. */
1169static int cli_parse_del_crtlist(char **args, char *payload, struct appctx *appctx, void *private)
1170{
1171 struct ckch_store *store;
1172 char *err = NULL;
1173 char *crtlist_path, *cert_path;
1174 struct ebmb_node *ebmb;
1175 struct ebpt_node *ebpt;
1176 struct crtlist *crtlist;
1177 struct crtlist_entry *entry = NULL;
1178 struct ckch_inst *inst, *inst_s;
1179 int linenum = 0;
1180 char *colons;
William Lallemand99cc2182020-06-25 15:19:51 +02001181 char *end;
William Lallemandc756bbd2020-05-13 17:23:59 +02001182
1183 if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
1184 return 1;
1185
1186 if (!*args[3] || !*args[4])
1187 return cli_err(appctx, "'del ssl crtlist' expects a filename and a certificate name\n");
1188
1189 if (HA_SPIN_TRYLOCK(CKCH_LOCK, &ckch_lock))
1190 return cli_err(appctx, "Can't delete!\nOperations on certificates are currently locked!\n");
1191
1192 crtlist_path = args[3];
1193 cert_path = args[4];
1194
1195 colons = strchr(cert_path, ':');
1196 if (colons) {
1197 char *endptr;
1198
1199 linenum = strtol(colons + 1, &endptr, 10);
1200 if (colons + 1 == endptr || *endptr != '\0') {
1201 memprintf(&err, "wrong line number after colons in '%s'!", cert_path);
1202 goto error;
1203 }
1204 *colons = '\0';
1205 }
William Lallemand99cc2182020-06-25 15:19:51 +02001206
1207 /* strip trailing slashes, including first one */
1208 for (end = crtlist_path + strlen(crtlist_path) - 1; end >= crtlist_path && *end == '/'; end--)
1209 *end = 0;
1210
William Lallemandc756bbd2020-05-13 17:23:59 +02001211 /* look for crtlist */
1212 ebmb = ebst_lookup(&crtlists_tree, crtlist_path);
1213 if (!ebmb) {
1214 memprintf(&err, "crt-list '%s' does not exist!", crtlist_path);
1215 goto error;
1216 }
1217 crtlist = ebmb_entry(ebmb, struct crtlist, node);
1218
1219 /* look for store */
1220 store = ckchs_lookup(cert_path);
1221 if (store == NULL) {
1222 memprintf(&err, "certificate '%s' does not exist!", cert_path);
1223 goto error;
1224 }
William Lallemandc756bbd2020-05-13 17:23:59 +02001225 if (store->ckch == NULL || store->ckch->cert == NULL) {
1226 memprintf(&err, "certificate '%s' is empty!", cert_path);
1227 goto error;
1228 }
1229
1230 ebpt = ebpt_lookup(&crtlist->entries, store);
1231 if (!ebpt) {
1232 memprintf(&err, "certificate '%s' can't be found in crt-list '%s'!", cert_path, crtlist_path);
1233 goto error;
1234 }
1235
1236 /* list the line number of entries for errors in err, and select the right ebpt */
1237 for (; ebpt; ebpt = ebpt_next_dup(ebpt)) {
1238 struct crtlist_entry *tmp;
1239
1240 tmp = ebpt_entry(ebpt, struct crtlist_entry, node);
1241 memprintf(&err, "%s%s%d", err ? err : "", err ? ", " : "", tmp->linenum);
1242
1243 /* select the entry we wanted */
1244 if (linenum == 0 || tmp->linenum == linenum) {
1245 if (!entry)
1246 entry = tmp;
1247 }
1248 }
1249
1250 /* we didn't found the specified entry */
1251 if (!entry) {
1252 memprintf(&err, "found a certificate '%s' but the line number is incorrect, please specify a correct line number preceded by colons (%s)!", cert_path, err ? err : NULL);
1253 goto error;
1254 }
1255
1256 /* we didn't specified a line number but there were several entries */
1257 if (linenum == 0 && ebpt_next_dup(&entry->node)) {
1258 memprintf(&err, "found the certificate '%s' in several entries, please specify a line number preceded by colons (%s)!", cert_path, err ? err : NULL);
1259 goto error;
1260 }
1261
1262 /* upon error free the ckch_inst and everything inside */
1263
1264 ebpt_delete(&entry->node);
1265 LIST_DEL(&entry->by_crtlist);
1266 LIST_DEL(&entry->by_ckch_store);
1267
1268 list_for_each_entry_safe(inst, inst_s, &entry->ckch_inst, by_crtlist_entry) {
1269 struct sni_ctx *sni, *sni_s;
1270
1271 HA_RWLOCK_WRLOCK(SNI_LOCK, &inst->bind_conf->sni_lock);
1272 list_for_each_entry_safe(sni, sni_s, &inst->sni_ctx, by_ckch_inst) {
1273 ebmb_delete(&sni->name);
1274 LIST_DEL(&sni->by_ckch_inst);
1275 SSL_CTX_free(sni->ctx);
1276 free(sni);
1277 }
1278 HA_RWLOCK_WRUNLOCK(SNI_LOCK, &inst->bind_conf->sni_lock);
1279 LIST_DEL(&inst->by_ckchs);
1280 free(inst);
1281 }
1282
1283 crtlist_free_filters(entry->filters);
1284 ssl_sock_free_ssl_conf(entry->ssl_conf);
1285 free(entry->ssl_conf);
1286 free(entry);
1287
1288 HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);
1289 err = memprintf(&err, "Entry '%s' deleted in crtlist '%s'!\n", cert_path, crtlist_path);
1290 return cli_dynmsg(appctx, LOG_NOTICE, err);
1291
1292error:
1293 HA_SPIN_UNLOCK(CKCH_LOCK, &ckch_lock);
1294 err = memprintf(&err, "Can't delete the entry: %s\n", err ? err : "");
1295 return cli_dynerr(appctx, err);
1296}
1297
1298
William Lallemandee8530c2020-06-23 18:19:42 +02001299/* unlink and free all crt-list and crt-list entries */
1300void crtlist_deinit()
1301{
1302 struct eb_node *node, *next;
1303 struct crtlist *crtlist;
1304
1305 node = eb_first(&crtlists_tree);
1306 while (node) {
1307 next = eb_next(node);
1308 crtlist = ebmb_entry(node, struct crtlist, node);
1309 crtlist_free(crtlist);
1310 node = next;
1311 }
1312}
1313
William Lallemandc756bbd2020-05-13 17:23:59 +02001314
1315/* register cli keywords */
1316static struct cli_kw_list cli_kws = {{ },{
1317 { { "add", "ssl", "crt-list", NULL }, "add ssl crt-list <filename> <certfile> [options] : add a line <certfile> to a crt-list <filename>", cli_parse_add_crtlist, cli_io_handler_add_crtlist, cli_release_add_crtlist },
1318 { { "del", "ssl", "crt-list", NULL }, "del ssl crt-list <filename> <certfile[:line]> : delete a line <certfile> in a crt-list <filename>", cli_parse_del_crtlist, NULL, NULL },
1319 { { "show", "ssl", "crt-list", NULL }, "show ssl crt-list [-n] [<filename>] : show the list of crt-lists or the content of a crt-list <filename>", cli_parse_dump_crtlist, cli_io_handler_dump_crtlist, NULL },
1320 { { NULL }, NULL, NULL, NULL } }
1321};
1322
1323INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
1324