summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorjsing <>2020-11-11 18:20:10 +0000
committerjsing <>2020-11-11 18:20:10 +0000
commit9b0af8c264027d5934269d611c73f218e6533a95 (patch)
tree9db60455c379dcbf4e84964fd07b8ba3fe0ab8a9 /src/lib
parent439875db3ebc782d7dcb3cef801a22813bf8470e (diff)
downloadopenbsd-9b0af8c264027d5934269d611c73f218e6533a95.tar.gz
openbsd-9b0af8c264027d5934269d611c73f218e6533a95.tar.bz2
openbsd-9b0af8c264027d5934269d611c73f218e6533a95.zip
Implement auto chain for the TLSv1.3 server.
Apparently OpenLDAP relies on this craziness to provide intermediates, rather than specifying the chain directly like a normal TLS server would. Issue noted by sthen@ and Bernard Spil, who both also tested this diff. ok tb@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libssl/tls13_server.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/lib/libssl/tls13_server.c b/src/lib/libssl/tls13_server.c
index a5c03b610c..a638f00f5f 100644
--- a/src/lib/libssl/tls13_server.c
+++ b/src/lib/libssl/tls13_server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: tls13_server.c,v 1.61 2020/07/03 04:12:51 tb Exp $ */ 1/* $OpenBSD: tls13_server.c,v 1.62 2020/11/11 18:20:10 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2020 Bob Beck <beck@openbsd.org> 4 * Copyright (c) 2020 Bob Beck <beck@openbsd.org>
@@ -611,6 +611,7 @@ tls13_server_certificate_send(struct tls13_ctx *ctx, CBB *cbb)
611 SSL *s = ctx->ssl; 611 SSL *s = ctx->ssl;
612 CBB cert_request_context, cert_list; 612 CBB cert_request_context, cert_list;
613 const struct ssl_sigalg *sigalg; 613 const struct ssl_sigalg *sigalg;
614 X509_STORE_CTX *xsc = NULL;
614 STACK_OF(X509) *chain; 615 STACK_OF(X509) *chain;
615 CERT_PKEY *cpk; 616 CERT_PKEY *cpk;
616 X509 *cert; 617 X509 *cert;
@@ -633,6 +634,16 @@ tls13_server_certificate_send(struct tls13_ctx *ctx, CBB *cbb)
633 if ((chain = cpk->chain) == NULL) 634 if ((chain = cpk->chain) == NULL)
634 chain = s->ctx->extra_certs; 635 chain = s->ctx->extra_certs;
635 636
637 if (chain == NULL && !(s->internal->mode & SSL_MODE_NO_AUTO_CHAIN)) {
638 if ((xsc = X509_STORE_CTX_new()) == NULL)
639 goto err;
640 if (!X509_STORE_CTX_init(xsc, s->ctx->cert_store, cpk->x509, NULL))
641 goto err;
642 X509_verify_cert(xsc);
643 ERR_clear_error();
644 chain = xsc->chain;
645 }
646
636 if (!CBB_add_u8_length_prefixed(cbb, &cert_request_context)) 647 if (!CBB_add_u8_length_prefixed(cbb, &cert_request_context))
637 goto err; 648 goto err;
638 if (!CBB_add_u24_length_prefixed(cbb, &cert_list)) 649 if (!CBB_add_u24_length_prefixed(cbb, &cert_list))
@@ -643,6 +654,15 @@ tls13_server_certificate_send(struct tls13_ctx *ctx, CBB *cbb)
643 654
644 for (i = 0; i < sk_X509_num(chain); i++) { 655 for (i = 0; i < sk_X509_num(chain); i++) {
645 cert = sk_X509_value(chain, i); 656 cert = sk_X509_value(chain, i);
657
658 /*
659 * In the case of auto chain, the leaf certificate will be at
660 * the top of the chain - skip over it as we've already added
661 * it earlier.
662 */
663 if (i == 0 && cert == cpk->x509)
664 continue;
665
646 /* 666 /*
647 * XXX we don't send extensions with chain certs to avoid sending 667 * XXX we don't send extensions with chain certs to avoid sending
648 * a leaf ocsp stape with the chain certs. This needs to get 668 * a leaf ocsp stape with the chain certs. This needs to get
@@ -658,6 +678,8 @@ tls13_server_certificate_send(struct tls13_ctx *ctx, CBB *cbb)
658 ret = 1; 678 ret = 1;
659 679
660 err: 680 err:
681 X509_STORE_CTX_free(xsc);
682
661 return ret; 683 return ret;
662} 684}
663 685