summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2021-03-19 19:51:07 +0000
committertb <>2021-03-19 19:51:07 +0000
commitdb3f81fc27d7f2c4e5d57b3936d083fd094ebcfe (patch)
treee02960ea71ab17ada892c9c68a801148d14403dd /src
parentc240a6035f817bd2937ea304396fea4e7404f3ce (diff)
downloadopenbsd-db3f81fc27d7f2c4e5d57b3936d083fd094ebcfe.tar.gz
openbsd-db3f81fc27d7f2c4e5d57b3936d083fd094ebcfe.tar.bz2
openbsd-db3f81fc27d7f2c4e5d57b3936d083fd094ebcfe.zip
Prepare to provide SSL_use_certificate_chain_file()
This is the same as SSL_CTX_use_certificate_chain_file() but for an SSL object instead of an SSL_CTX object. remi found this in a recent librelp update, so we need to provide it. The function will be exposed in an upcoming library bump. ok inoguchi on an earlier version, input/ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/ssl.h5
-rw-r--r--src/lib/libssl/ssl_rsa.c50
2 files changed, 40 insertions, 15 deletions
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
index e7ff6cec2a..36c9ef02bd 100644
--- a/src/lib/libssl/ssl.h
+++ b/src/lib/libssl/ssl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl.h,v 1.182 2021/02/20 08:33:17 jsing Exp $ */ 1/* $OpenBSD: ssl.h,v 1.183 2021/03/19 19:51:07 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -1357,6 +1357,9 @@ int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
1357int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type); 1357int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
1358int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type); 1358int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
1359int SSL_use_certificate_file(SSL *ssl, const char *file, int type); 1359int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
1360#if defined(LIBRESSL_INTERNAL)
1361int SSL_use_certificate_chain_file(SSL *ssl, const char *file);
1362#endif
1360int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type); 1363int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
1361int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type); 1364int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
1362int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type); 1365int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c
index 0936c0bd4c..18ae5307d3 100644
--- a/src/lib/libssl/ssl_rsa.c
+++ b/src/lib/libssl/ssl_rsa.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssl_rsa.c,v 1.31 2019/03/25 16:46:48 jsing Exp $ */ 1/* $OpenBSD: ssl_rsa.c,v 1.32 2021/03/19 19:51:07 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -68,7 +68,10 @@
68 68
69static int ssl_set_cert(CERT *c, X509 *x509); 69static int ssl_set_cert(CERT *c, X509 *x509);
70static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey); 70static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey);
71static int ssl_ctx_use_certificate_chain_bio(SSL_CTX *, BIO *); 71static int use_certificate_chain_bio(BIO *in, CERT *cert,
72 pem_password_cb *passwd_cb, void *passwd_arg);
73static int use_certificate_chain_file(const char *file, CERT *cert,
74 pem_password_cb *passwd_cb, void *passwd_arg);
72 75
73int 76int
74SSL_use_certificate(SSL *ssl, X509 *x) 77SSL_use_certificate(SSL *ssl, X509 *x)
@@ -609,29 +612,29 @@ SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, const unsigned char *d,
609 * sent to the peer in the Certificate message. 612 * sent to the peer in the Certificate message.
610 */ 613 */
611static int 614static int
612ssl_ctx_use_certificate_chain_bio(SSL_CTX *ctx, BIO *in) 615use_certificate_chain_bio(BIO *in, CERT *cert, pem_password_cb *passwd_cb,
616 void *passwd_arg)
613{ 617{
614 X509 *ca, *x = NULL; 618 X509 *ca, *x = NULL;
615 unsigned long err; 619 unsigned long err;
616 int ret = 0; 620 int ret = 0;
617 621
618 if ((x = PEM_read_bio_X509_AUX(in, NULL, ctx->default_passwd_callback, 622 if ((x = PEM_read_bio_X509_AUX(in, NULL, passwd_cb, passwd_arg)) ==
619 ctx->default_passwd_callback_userdata)) == NULL) { 623 NULL) {
620 SSLerrorx(ERR_R_PEM_LIB); 624 SSLerrorx(ERR_R_PEM_LIB);
621 goto err; 625 goto err;
622 } 626 }
623 627
624 if (!SSL_CTX_use_certificate(ctx, x)) 628 if (!ssl_set_cert(cert, x))
625 goto err; 629 goto err;
626 630
627 if (!ssl_cert_set0_chain(ctx->internal->cert, NULL)) 631 if (!ssl_cert_set0_chain(cert, NULL))
628 goto err; 632 goto err;
629 633
630 /* Process any additional CA certificates. */ 634 /* Process any additional CA certificates. */
631 while ((ca = PEM_read_bio_X509(in, NULL, 635 while ((ca = PEM_read_bio_X509(in, NULL, passwd_cb, passwd_arg)) !=
632 ctx->default_passwd_callback, 636 NULL) {
633 ctx->default_passwd_callback_userdata)) != NULL) { 637 if (!ssl_cert_add0_chain_cert(cert, ca)) {
634 if (!ssl_cert_add0_chain_cert(ctx->internal->cert, ca)) {
635 X509_free(ca); 638 X509_free(ca);
636 goto err; 639 goto err;
637 } 640 }
@@ -652,7 +655,8 @@ ssl_ctx_use_certificate_chain_bio(SSL_CTX *ctx, BIO *in)
652} 655}
653 656
654int 657int
655SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) 658use_certificate_chain_file(const char *file, CERT *cert,
659 pem_password_cb *passwd_cb, void *passwd_arg)
656{ 660{
657 BIO *in; 661 BIO *in;
658 int ret = 0; 662 int ret = 0;
@@ -668,7 +672,7 @@ SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file)
668 goto end; 672 goto end;
669 } 673 }
670 674
671 ret = ssl_ctx_use_certificate_chain_bio(ctx, in); 675 ret = use_certificate_chain_bio(in, cert, passwd_cb, passwd_arg);
672 676
673end: 677end:
674 BIO_free(in); 678 BIO_free(in);
@@ -676,6 +680,22 @@ end:
676} 680}
677 681
678int 682int
683SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file)
684{
685 return use_certificate_chain_file(file, ctx->internal->cert,
686 ctx->default_passwd_callback,
687 ctx->default_passwd_callback_userdata);
688}
689
690int
691SSL_use_certificate_chain_file(SSL *ssl, const char *file)
692{
693 return use_certificate_chain_file(file, ssl->cert,
694 ssl->ctx->default_passwd_callback,
695 ssl->ctx->default_passwd_callback_userdata);
696}
697
698int
679SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len) 699SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len)
680{ 700{
681 BIO *in; 701 BIO *in;
@@ -687,7 +707,9 @@ SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len)
687 goto end; 707 goto end;
688 } 708 }
689 709
690 ret = ssl_ctx_use_certificate_chain_bio(ctx, in); 710 ret = use_certificate_chain_bio(in, ctx->internal->cert,
711 ctx->default_passwd_callback,
712 ctx->default_passwd_callback_userdata);
691 713
692end: 714end:
693 BIO_free(in); 715 BIO_free(in);