diff options
author | reyk <> | 2014-09-28 14:45:48 +0000 |
---|---|---|
committer | reyk <> | 2014-09-28 14:45:48 +0000 |
commit | 86dd9a4f816c164cfa45e157991a16f15badb4a3 (patch) | |
tree | 2558f6bbdff94c43a1f9a53c84ba5f0ffa3ea8c0 /src/lib/libssl/ssl_rsa.c | |
parent | 091f5c3e6dfe57ebde616bd69bdc1866949e19a4 (diff) | |
download | openbsd-86dd9a4f816c164cfa45e157991a16f15badb4a3.tar.gz openbsd-86dd9a4f816c164cfa45e157991a16f15badb4a3.tar.bz2 openbsd-86dd9a4f816c164cfa45e157991a16f15badb4a3.zip |
Add a new API function SSL_CTX_use_certificate_chain() that allows to
read the PEM-encoded certificate chain from memory instead of a file.
This idea is derived from an older implementation in relayd that was
needed to use the function with a privep'ed process in a chroot. Now
it is time to get it into LibreSSL to make the API more privsep-
friendly and to make it available for other programs and the ressl
library.
ok jsing@ miod@
Diffstat (limited to 'src/lib/libssl/ssl_rsa.c')
-rw-r--r-- | src/lib/libssl/ssl_rsa.c | 64 |
1 files changed, 48 insertions, 16 deletions
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c index d4d14bad35..e8b72f016e 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.16 2014/07/12 16:03:37 miod Exp $ */ | 1 | /* $OpenBSD: ssl_rsa.c,v 1.17 2014/09/28 14:45:48 reyk 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 | * |
@@ -66,6 +66,8 @@ | |||
66 | 66 | ||
67 | static int ssl_set_cert(CERT *c, X509 *x509); | 67 | static int ssl_set_cert(CERT *c, X509 *x509); |
68 | static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey); | 68 | static int ssl_set_pkey(CERT *c, EVP_PKEY *pkey); |
69 | static int ssl_ctx_use_certificate_chain_bio(SSL_CTX *, BIO *); | ||
70 | |||
69 | int | 71 | int |
70 | SSL_use_certificate(SSL *ssl, X509 *x) | 72 | SSL_use_certificate(SSL *ssl, X509 *x) |
71 | { | 73 | { |
@@ -637,30 +639,18 @@ SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, const unsigned char *d, | |||
637 | 639 | ||
638 | 640 | ||
639 | /* | 641 | /* |
640 | * Read a file that contains our certificate in "PEM" format, | 642 | * Read a bio that contains our certificate in "PEM" format, |
641 | * possibly followed by a sequence of CA certificates that should be | 643 | * possibly followed by a sequence of CA certificates that should be |
642 | * sent to the peer in the Certificate message. | 644 | * sent to the peer in the Certificate message. |
643 | */ | 645 | */ |
644 | int | 646 | static int |
645 | SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) | 647 | ssl_ctx_use_certificate_chain_bio(SSL_CTX *ctx, BIO *in) |
646 | { | 648 | { |
647 | BIO *in; | ||
648 | int ret = 0; | 649 | int ret = 0; |
649 | X509 *x = NULL; | 650 | X509 *x = NULL; |
650 | 651 | ||
651 | ERR_clear_error(); /* clear error stack for SSL_CTX_use_certificate() */ | 652 | ERR_clear_error(); /* clear error stack for SSL_CTX_use_certificate() */ |
652 | 653 | ||
653 | in = BIO_new(BIO_s_file_internal()); | ||
654 | if (in == NULL) { | ||
655 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_BUF_LIB); | ||
656 | goto end; | ||
657 | } | ||
658 | |||
659 | if (BIO_read_filename(in, file) <= 0) { | ||
660 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_SYS_LIB); | ||
661 | goto end; | ||
662 | } | ||
663 | |||
664 | x = PEM_read_bio_X509_AUX(in, NULL, ctx->default_passwd_callback, | 654 | x = PEM_read_bio_X509_AUX(in, NULL, ctx->default_passwd_callback, |
665 | ctx->default_passwd_callback_userdata); | 655 | ctx->default_passwd_callback_userdata); |
666 | if (x == NULL) { | 656 | if (x == NULL) { |
@@ -716,6 +706,48 @@ SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) | |||
716 | end: | 706 | end: |
717 | if (x != NULL) | 707 | if (x != NULL) |
718 | X509_free(x); | 708 | X509_free(x); |
709 | return (ret); | ||
710 | } | ||
711 | |||
712 | int | ||
713 | SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) | ||
714 | { | ||
715 | BIO *in; | ||
716 | int ret = 0; | ||
717 | |||
718 | in = BIO_new(BIO_s_file_internal()); | ||
719 | if (in == NULL) { | ||
720 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_BUF_LIB); | ||
721 | goto end; | ||
722 | } | ||
723 | |||
724 | if (BIO_read_filename(in, file) <= 0) { | ||
725 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_SYS_LIB); | ||
726 | goto end; | ||
727 | } | ||
728 | |||
729 | ret = ssl_ctx_use_certificate_chain_bio(ctx, in); | ||
730 | |||
731 | end: | ||
732 | BIO_free(in); | ||
733 | return (ret); | ||
734 | } | ||
735 | |||
736 | int | ||
737 | SSL_CTX_use_certificate_chain(SSL_CTX *ctx, void *buf, int len) | ||
738 | { | ||
739 | BIO *in; | ||
740 | int ret = 0; | ||
741 | |||
742 | in = BIO_new_mem_buf(buf, len); | ||
743 | if (in == NULL) { | ||
744 | SSLerr(SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE, ERR_R_BUF_LIB); | ||
745 | goto end; | ||
746 | } | ||
747 | |||
748 | ret = ssl_ctx_use_certificate_chain_bio(ctx, in); | ||
749 | |||
750 | end: | ||
719 | BIO_free(in); | 751 | BIO_free(in); |
720 | return (ret); | 752 | return (ret); |
721 | } | 753 | } |