summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2022-06-29 21:13:34 +0000
committertb <>2022-06-29 21:13:34 +0000
commitd609c8ec719b355164a9fd97465715761d05c0a4 (patch)
tree637d65d5081ad0182c5b3c8869695309c14be7e6 /src
parent2b3a4ac6b2c9caeb459033fe8bc839fd93ad24f4 (diff)
downloadopenbsd-d609c8ec719b355164a9fd97465715761d05c0a4.tar.gz
openbsd-d609c8ec719b355164a9fd97465715761d05c0a4.tar.bz2
openbsd-d609c8ec719b355164a9fd97465715761d05c0a4.zip
Make ssl_set_{cert,pkey} take an ssl/ctx
ok beck jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libssl/ssl_rsa.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c
index f2d3b8dd00..11edb6f76e 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.40 2022/06/29 21:12:19 tb Exp $ */ 1/* $OpenBSD: ssl_rsa.c,v 1.41 2022/06/29 21:13:34 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,8 +68,8 @@
68 68
69static int ssl_get_password_cb_and_arg(SSL_CTX *ctx, SSL *ssl, 69static int ssl_get_password_cb_and_arg(SSL_CTX *ctx, SSL *ssl,
70 pem_password_cb **passwd_cb, void **passwd_arg); 70 pem_password_cb **passwd_cb, void **passwd_arg);
71static int ssl_set_cert(SSL_CERT *c, X509 *x509); 71static int ssl_set_cert(SSL_CTX *ctx, SSL *ssl, X509 *x509);
72static int ssl_set_pkey(SSL_CERT *c, EVP_PKEY *pkey); 72static int ssl_set_pkey(SSL_CTX *ctx, SSL *ssl, EVP_PKEY *pkey);
73static int use_certificate_chain_bio(SSL_CTX *ctx, SSL *ssl, BIO *in); 73static int use_certificate_chain_bio(SSL_CTX *ctx, SSL *ssl, BIO *in);
74static int use_certificate_chain_file(SSL_CTX *ctx, SSL *ssl, const char *file); 74static int use_certificate_chain_file(SSL_CTX *ctx, SSL *ssl, const char *file);
75 75
@@ -80,7 +80,7 @@ SSL_use_certificate(SSL *ssl, X509 *x)
80 SSLerror(ssl, ERR_R_PASSED_NULL_PARAMETER); 80 SSLerror(ssl, ERR_R_PASSED_NULL_PARAMETER);
81 return (0); 81 return (0);
82 } 82 }
83 return (ssl_set_cert(ssl->cert, x)); 83 return ssl_set_cert(NULL, ssl, x);
84} 84}
85 85
86int 86int
@@ -161,14 +161,15 @@ SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa)
161 RSA_up_ref(rsa); 161 RSA_up_ref(rsa);
162 EVP_PKEY_assign_RSA(pkey, rsa); 162 EVP_PKEY_assign_RSA(pkey, rsa);
163 163
164 ret = ssl_set_pkey(ssl->cert, pkey); 164 ret = ssl_set_pkey(NULL, ssl, pkey);
165 EVP_PKEY_free(pkey); 165 EVP_PKEY_free(pkey);
166 return (ret); 166 return (ret);
167} 167}
168 168
169static int 169static int
170ssl_set_pkey(SSL_CERT *c, EVP_PKEY *pkey) 170ssl_set_pkey(SSL_CTX *ctx, SSL *ssl, EVP_PKEY *pkey)
171{ 171{
172 SSL_CERT *c;
172 int i; 173 int i;
173 174
174 i = ssl_cert_type(pkey); 175 i = ssl_cert_type(pkey);
@@ -177,6 +178,9 @@ ssl_set_pkey(SSL_CERT *c, EVP_PKEY *pkey)
177 return (0); 178 return (0);
178 } 179 }
179 180
181 if ((c = ssl_get0_cert(ctx, ssl)) == NULL)
182 return (0);
183
180 if (c->pkeys[i].x509 != NULL) { 184 if (c->pkeys[i].x509 != NULL) {
181 EVP_PKEY *pktmp; 185 EVP_PKEY *pktmp;
182 pktmp = X509_get_pubkey(c->pkeys[i].x509); 186 pktmp = X509_get_pubkey(c->pkeys[i].x509);
@@ -272,7 +276,7 @@ SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey)
272 SSLerror(ssl, ERR_R_PASSED_NULL_PARAMETER); 276 SSLerror(ssl, ERR_R_PASSED_NULL_PARAMETER);
273 return (0); 277 return (0);
274 } 278 }
275 ret = ssl_set_pkey(ssl->cert, pkey); 279 ret = ssl_set_pkey(NULL, ssl, pkey);
276 return (ret); 280 return (ret);
277} 281}
278 282
@@ -339,7 +343,7 @@ SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x)
339 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER); 343 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER);
340 return (0); 344 return (0);
341 } 345 }
342 return (ssl_set_cert(ctx->internal->cert, x)); 346 return ssl_set_cert(ctx, NULL, x);
343} 347}
344 348
345static int 349static int
@@ -356,11 +360,15 @@ ssl_get_password_cb_and_arg(SSL_CTX *ctx, SSL *ssl,
356} 360}
357 361
358static int 362static int
359ssl_set_cert(SSL_CERT *c, X509 *x) 363ssl_set_cert(SSL_CTX *ctx, SSL *ssl, X509 *x)
360{ 364{
365 SSL_CERT *c;
361 EVP_PKEY *pkey; 366 EVP_PKEY *pkey;
362 int i; 367 int i;
363 368
369 if ((c = ssl_get0_cert(ctx, ssl)) == NULL)
370 return (0);
371
364 pkey = X509_get_pubkey(x); 372 pkey = X509_get_pubkey(x);
365 if (pkey == NULL) { 373 if (pkey == NULL) {
366 SSLerrorx(SSL_R_X509_LIB); 374 SSLerrorx(SSL_R_X509_LIB);
@@ -488,7 +496,7 @@ SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa)
488 RSA_up_ref(rsa); 496 RSA_up_ref(rsa);
489 EVP_PKEY_assign_RSA(pkey, rsa); 497 EVP_PKEY_assign_RSA(pkey, rsa);
490 498
491 ret = ssl_set_pkey(ctx->internal->cert, pkey); 499 ret = ssl_set_pkey(ctx, NULL, pkey);
492 EVP_PKEY_free(pkey); 500 EVP_PKEY_free(pkey);
493 return (ret); 501 return (ret);
494} 502}
@@ -556,7 +564,7 @@ SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey)
556 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER); 564 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER);
557 return (0); 565 return (0);
558 } 566 }
559 return (ssl_set_pkey(ctx->internal->cert, pkey)); 567 return ssl_set_pkey(ctx, NULL, pkey);
560} 568}
561 569
562int 570int
@@ -644,7 +652,7 @@ use_certificate_chain_bio(SSL_CTX *ctx, SSL *ssl, BIO *in)
644 if ((cert = ssl_get0_cert(ctx, ssl)) == NULL) 652 if ((cert = ssl_get0_cert(ctx, ssl)) == NULL)
645 goto err; 653 goto err;
646 654
647 if (!ssl_set_cert(cert, x)) 655 if (!ssl_set_cert(ctx, ssl, x))
648 goto err; 656 goto err;
649 657
650 if (!ssl_cert_set0_chain(cert, NULL)) 658 if (!ssl_cert_set0_chain(cert, NULL))