diff options
author | tb <> | 2022-06-29 21:12:19 +0000 |
---|---|---|
committer | tb <> | 2022-06-29 21:12:19 +0000 |
commit | 2b3a4ac6b2c9caeb459033fe8bc839fd93ad24f4 (patch) | |
tree | f4a91403dd87275ae461df32912d6bed233c1b67 | |
parent | 607440e43ab60de5b766fe1c327fee120629c3e5 (diff) | |
download | openbsd-2b3a4ac6b2c9caeb459033fe8bc839fd93ad24f4.tar.gz openbsd-2b3a4ac6b2c9caeb459033fe8bc839fd93ad24f4.tar.bz2 openbsd-2b3a4ac6b2c9caeb459033fe8bc839fd93ad24f4.zip |
Refactor use_certificate_chain_* to take ssl/ctx instead of a cert
ok beck jsing
-rw-r--r-- | src/lib/libssl/ssl_cert.c | 11 | ||||
-rw-r--r-- | src/lib/libssl/ssl_locl.h | 3 | ||||
-rw-r--r-- | src/lib/libssl/ssl_rsa.c | 52 |
3 files changed, 45 insertions, 21 deletions
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c index ecf8179d51..21937f8513 100644 --- a/src/lib/libssl/ssl_cert.c +++ b/src/lib/libssl/ssl_cert.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_cert.c,v 1.98 2022/06/29 21:08:07 tb Exp $ */ | 1 | /* $OpenBSD: ssl_cert.c,v 1.99 2022/06/29 21:12:19 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 | * |
@@ -302,6 +302,15 @@ ssl_cert_free(SSL_CERT *c) | |||
302 | free(c); | 302 | free(c); |
303 | } | 303 | } |
304 | 304 | ||
305 | SSL_CERT * | ||
306 | ssl_get0_cert(SSL_CTX *ctx, SSL *ssl) | ||
307 | { | ||
308 | if (ssl != NULL) | ||
309 | return ssl->cert; | ||
310 | |||
311 | return ctx->internal->cert; | ||
312 | } | ||
313 | |||
305 | int | 314 | int |
306 | ssl_cert_set0_chain(SSL_CERT *c, STACK_OF(X509) *chain) | 315 | ssl_cert_set0_chain(SSL_CERT *c, STACK_OF(X509) *chain) |
307 | { | 316 | { |
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index 161a8407af..83374fa69f 100644 --- a/src/lib/libssl/ssl_locl.h +++ b/src/lib/libssl/ssl_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_locl.h,v 1.404 2022/06/29 21:10:20 tb Exp $ */ | 1 | /* $OpenBSD: ssl_locl.h,v 1.405 2022/06/29 21:12:19 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 | * |
@@ -1285,6 +1285,7 @@ void ssl_msg_callback(SSL *s, int is_write, int content_type, | |||
1285 | SSL_CERT *ssl_cert_new(void); | 1285 | SSL_CERT *ssl_cert_new(void); |
1286 | SSL_CERT *ssl_cert_dup(SSL_CERT *cert); | 1286 | SSL_CERT *ssl_cert_dup(SSL_CERT *cert); |
1287 | void ssl_cert_free(SSL_CERT *c); | 1287 | void ssl_cert_free(SSL_CERT *c); |
1288 | SSL_CERT *ssl_get0_cert(SSL_CTX *ctx, SSL *ssl); | ||
1288 | int ssl_cert_set0_chain(SSL_CERT *c, STACK_OF(X509) *chain); | 1289 | int ssl_cert_set0_chain(SSL_CERT *c, STACK_OF(X509) *chain); |
1289 | int ssl_cert_set1_chain(SSL_CERT *c, STACK_OF(X509) *chain); | 1290 | int ssl_cert_set1_chain(SSL_CERT *c, STACK_OF(X509) *chain); |
1290 | int ssl_cert_add0_chain_cert(SSL_CERT *c, X509 *cert); | 1291 | int ssl_cert_add0_chain_cert(SSL_CERT *c, X509 *cert); |
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c index f5c90fca8b..f2d3b8dd00 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.39 2022/02/03 16:33:12 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_rsa.c,v 1.40 2022/06/29 21:12:19 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 | * |
@@ -66,12 +66,12 @@ | |||
66 | 66 | ||
67 | #include "ssl_locl.h" | 67 | #include "ssl_locl.h" |
68 | 68 | ||
69 | static int ssl_get_password_cb_and_arg(SSL_CTX *ctx, SSL *ssl, | ||
70 | pem_password_cb **passwd_cb, void **passwd_arg); | ||
69 | static int ssl_set_cert(SSL_CERT *c, X509 *x509); | 71 | static int ssl_set_cert(SSL_CERT *c, X509 *x509); |
70 | static int ssl_set_pkey(SSL_CERT *c, EVP_PKEY *pkey); | 72 | static int ssl_set_pkey(SSL_CERT *c, EVP_PKEY *pkey); |
71 | static int use_certificate_chain_bio(BIO *in, SSL_CERT *cert, | 73 | static int use_certificate_chain_bio(SSL_CTX *ctx, SSL *ssl, BIO *in); |
72 | pem_password_cb *passwd_cb, void *passwd_arg); | 74 | static int use_certificate_chain_file(SSL_CTX *ctx, SSL *ssl, const char *file); |
73 | static int use_certificate_chain_file(const char *file, SSL_CERT *cert, | ||
74 | pem_password_cb *passwd_cb, void *passwd_arg); | ||
75 | 75 | ||
76 | int | 76 | int |
77 | SSL_use_certificate(SSL *ssl, X509 *x) | 77 | SSL_use_certificate(SSL *ssl, X509 *x) |
@@ -343,6 +343,19 @@ SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x) | |||
343 | } | 343 | } |
344 | 344 | ||
345 | static int | 345 | static int |
346 | ssl_get_password_cb_and_arg(SSL_CTX *ctx, SSL *ssl, | ||
347 | pem_password_cb **passwd_cb, void **passwd_arg) | ||
348 | { | ||
349 | if (ssl != NULL) | ||
350 | ctx = ssl->ctx; | ||
351 | |||
352 | *passwd_cb = ctx->default_passwd_callback; | ||
353 | *passwd_arg = ctx->default_passwd_callback_userdata; | ||
354 | |||
355 | return 1; | ||
356 | } | ||
357 | |||
358 | static int | ||
346 | ssl_set_cert(SSL_CERT *c, X509 *x) | 359 | ssl_set_cert(SSL_CERT *c, X509 *x) |
347 | { | 360 | { |
348 | EVP_PKEY *pkey; | 361 | EVP_PKEY *pkey; |
@@ -610,19 +623,27 @@ SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, const unsigned char *d, | |||
610 | * sent to the peer in the Certificate message. | 623 | * sent to the peer in the Certificate message. |
611 | */ | 624 | */ |
612 | static int | 625 | static int |
613 | use_certificate_chain_bio(BIO *in, SSL_CERT *cert, pem_password_cb *passwd_cb, | 626 | use_certificate_chain_bio(SSL_CTX *ctx, SSL *ssl, BIO *in) |
614 | void *passwd_arg) | ||
615 | { | 627 | { |
628 | pem_password_cb *passwd_cb; | ||
629 | void *passwd_arg; | ||
630 | SSL_CERT *cert; | ||
616 | X509 *ca, *x = NULL; | 631 | X509 *ca, *x = NULL; |
617 | unsigned long err; | 632 | unsigned long err; |
618 | int ret = 0; | 633 | int ret = 0; |
619 | 634 | ||
635 | if (!ssl_get_password_cb_and_arg(ctx, ssl, &passwd_cb, &passwd_arg)) | ||
636 | goto err; | ||
637 | |||
620 | if ((x = PEM_read_bio_X509_AUX(in, NULL, passwd_cb, passwd_arg)) == | 638 | if ((x = PEM_read_bio_X509_AUX(in, NULL, passwd_cb, passwd_arg)) == |
621 | NULL) { | 639 | NULL) { |
622 | SSLerrorx(ERR_R_PEM_LIB); | 640 | SSLerrorx(ERR_R_PEM_LIB); |
623 | goto err; | 641 | goto err; |
624 | } | 642 | } |
625 | 643 | ||
644 | if ((cert = ssl_get0_cert(ctx, ssl)) == NULL) | ||
645 | goto err; | ||
646 | |||
626 | if (!ssl_set_cert(cert, x)) | 647 | if (!ssl_set_cert(cert, x)) |
627 | goto err; | 648 | goto err; |
628 | 649 | ||
@@ -653,8 +674,7 @@ use_certificate_chain_bio(BIO *in, SSL_CERT *cert, pem_password_cb *passwd_cb, | |||
653 | } | 674 | } |
654 | 675 | ||
655 | int | 676 | int |
656 | use_certificate_chain_file(const char *file, SSL_CERT *cert, | 677 | use_certificate_chain_file(SSL_CTX *ctx, SSL *ssl, const char *file) |
657 | pem_password_cb *passwd_cb, void *passwd_arg) | ||
658 | { | 678 | { |
659 | BIO *in; | 679 | BIO *in; |
660 | int ret = 0; | 680 | int ret = 0; |
@@ -670,7 +690,7 @@ use_certificate_chain_file(const char *file, SSL_CERT *cert, | |||
670 | goto end; | 690 | goto end; |
671 | } | 691 | } |
672 | 692 | ||
673 | ret = use_certificate_chain_bio(in, cert, passwd_cb, passwd_arg); | 693 | ret = use_certificate_chain_bio(ctx, ssl, in); |
674 | 694 | ||
675 | end: | 695 | end: |
676 | BIO_free(in); | 696 | BIO_free(in); |
@@ -680,17 +700,13 @@ use_certificate_chain_file(const char *file, SSL_CERT *cert, | |||
680 | int | 700 | int |
681 | SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) | 701 | SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) |
682 | { | 702 | { |
683 | return use_certificate_chain_file(file, ctx->internal->cert, | 703 | return use_certificate_chain_file(ctx, NULL, file); |
684 | ctx->default_passwd_callback, | ||
685 | ctx->default_passwd_callback_userdata); | ||
686 | } | 704 | } |
687 | 705 | ||
688 | int | 706 | int |
689 | SSL_use_certificate_chain_file(SSL *ssl, const char *file) | 707 | SSL_use_certificate_chain_file(SSL *ssl, const char *file) |
690 | { | 708 | { |
691 | return use_certificate_chain_file(file, ssl->cert, | 709 | return use_certificate_chain_file(NULL, ssl, file); |
692 | ssl->ctx->default_passwd_callback, | ||
693 | ssl->ctx->default_passwd_callback_userdata); | ||
694 | } | 710 | } |
695 | 711 | ||
696 | int | 712 | int |
@@ -705,9 +721,7 @@ SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len) | |||
705 | goto end; | 721 | goto end; |
706 | } | 722 | } |
707 | 723 | ||
708 | ret = use_certificate_chain_bio(in, ctx->internal->cert, | 724 | ret = use_certificate_chain_bio(ctx, NULL, in); |
709 | ctx->default_passwd_callback, | ||
710 | ctx->default_passwd_callback_userdata); | ||
711 | 725 | ||
712 | end: | 726 | end: |
713 | BIO_free(in); | 727 | BIO_free(in); |