summaryrefslogtreecommitdiff
path: root/src/lib/libssl/ssl_rsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libssl/ssl_rsa.c')
-rw-r--r--src/lib/libssl/ssl_rsa.c104
1 files changed, 52 insertions, 52 deletions
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c
index facb8ac274..e99ce1e3ae 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.27 2017/01/26 12:16:13 beck Exp $ */ 1/* $OpenBSD: ssl_rsa.c,v 1.28 2017/02/07 02:08:38 beck 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 *
@@ -74,11 +74,11 @@ int
74SSL_use_certificate(SSL *ssl, X509 *x) 74SSL_use_certificate(SSL *ssl, X509 *x)
75{ 75{
76 if (x == NULL) { 76 if (x == NULL) {
77 SSLerror(ERR_R_PASSED_NULL_PARAMETER); 77 SSLerror(ssl, ERR_R_PASSED_NULL_PARAMETER);
78 return (0); 78 return (0);
79 } 79 }
80 if (!ssl_cert_inst(&ssl->cert)) { 80 if (!ssl_cert_inst(&ssl->cert)) {
81 SSLerror(ERR_R_MALLOC_FAILURE); 81 SSLerror(ssl, ERR_R_MALLOC_FAILURE);
82 return (0); 82 return (0);
83 } 83 }
84 return (ssl_set_cert(ssl->cert, x)); 84 return (ssl_set_cert(ssl->cert, x));
@@ -94,12 +94,12 @@ SSL_use_certificate_file(SSL *ssl, const char *file, int type)
94 94
95 in = BIO_new(BIO_s_file_internal()); 95 in = BIO_new(BIO_s_file_internal());
96 if (in == NULL) { 96 if (in == NULL) {
97 SSLerror(ERR_R_BUF_LIB); 97 SSLerror(ssl, ERR_R_BUF_LIB);
98 goto end; 98 goto end;
99 } 99 }
100 100
101 if (BIO_read_filename(in, file) <= 0) { 101 if (BIO_read_filename(in, file) <= 0) {
102 SSLerror(ERR_R_SYS_LIB); 102 SSLerror(ssl, ERR_R_SYS_LIB);
103 goto end; 103 goto end;
104 } 104 }
105 if (type == SSL_FILETYPE_ASN1) { 105 if (type == SSL_FILETYPE_ASN1) {
@@ -111,12 +111,12 @@ SSL_use_certificate_file(SSL *ssl, const char *file, int type)
111 ssl->ctx->default_passwd_callback, 111 ssl->ctx->default_passwd_callback,
112 ssl->ctx->default_passwd_callback_userdata); 112 ssl->ctx->default_passwd_callback_userdata);
113 } else { 113 } else {
114 SSLerror(SSL_R_BAD_SSL_FILETYPE); 114 SSLerror(ssl, SSL_R_BAD_SSL_FILETYPE);
115 goto end; 115 goto end;
116 } 116 }
117 117
118 if (x == NULL) { 118 if (x == NULL) {
119 SSLerror(j); 119 SSLerror(ssl, j);
120 goto end; 120 goto end;
121 } 121 }
122 122
@@ -135,7 +135,7 @@ SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len)
135 135
136 x = d2i_X509(NULL, &d,(long)len); 136 x = d2i_X509(NULL, &d,(long)len);
137 if (x == NULL) { 137 if (x == NULL) {
138 SSLerror(ERR_R_ASN1_LIB); 138 SSLerror(ssl, ERR_R_ASN1_LIB);
139 return (0); 139 return (0);
140 } 140 }
141 141
@@ -151,15 +151,15 @@ SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa)
151 int ret; 151 int ret;
152 152
153 if (rsa == NULL) { 153 if (rsa == NULL) {
154 SSLerror(ERR_R_PASSED_NULL_PARAMETER); 154 SSLerror(ssl, ERR_R_PASSED_NULL_PARAMETER);
155 return (0); 155 return (0);
156 } 156 }
157 if (!ssl_cert_inst(&ssl->cert)) { 157 if (!ssl_cert_inst(&ssl->cert)) {
158 SSLerror(ERR_R_MALLOC_FAILURE); 158 SSLerror(ssl, ERR_R_MALLOC_FAILURE);
159 return (0); 159 return (0);
160 } 160 }
161 if ((pkey = EVP_PKEY_new()) == NULL) { 161 if ((pkey = EVP_PKEY_new()) == NULL) {
162 SSLerror(ERR_R_EVP_LIB); 162 SSLerror(ssl, ERR_R_EVP_LIB);
163 return (0); 163 return (0);
164 } 164 }
165 165
@@ -178,7 +178,7 @@ ssl_set_pkey(CERT *c, EVP_PKEY *pkey)
178 178
179 i = ssl_cert_type(NULL, pkey); 179 i = ssl_cert_type(NULL, pkey);
180 if (i < 0) { 180 if (i < 0) {
181 SSLerror(SSL_R_UNKNOWN_CERTIFICATE_TYPE); 181 SSLerrorx(SSL_R_UNKNOWN_CERTIFICATE_TYPE);
182 return (0); 182 return (0);
183 } 183 }
184 184
@@ -222,12 +222,12 @@ SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type)
222 222
223 in = BIO_new(BIO_s_file_internal()); 223 in = BIO_new(BIO_s_file_internal());
224 if (in == NULL) { 224 if (in == NULL) {
225 SSLerror(ERR_R_BUF_LIB); 225 SSLerror(ssl, ERR_R_BUF_LIB);
226 goto end; 226 goto end;
227 } 227 }
228 228
229 if (BIO_read_filename(in, file) <= 0) { 229 if (BIO_read_filename(in, file) <= 0) {
230 SSLerror(ERR_R_SYS_LIB); 230 SSLerror(ssl, ERR_R_SYS_LIB);
231 goto end; 231 goto end;
232 } 232 }
233 if (type == SSL_FILETYPE_ASN1) { 233 if (type == SSL_FILETYPE_ASN1) {
@@ -239,11 +239,11 @@ SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type)
239 ssl->ctx->default_passwd_callback, 239 ssl->ctx->default_passwd_callback,
240 ssl->ctx->default_passwd_callback_userdata); 240 ssl->ctx->default_passwd_callback_userdata);
241 } else { 241 } else {
242 SSLerror(SSL_R_BAD_SSL_FILETYPE); 242 SSLerror(ssl, SSL_R_BAD_SSL_FILETYPE);
243 goto end; 243 goto end;
244 } 244 }
245 if (rsa == NULL) { 245 if (rsa == NULL) {
246 SSLerror(j); 246 SSLerror(ssl, j);
247 goto end; 247 goto end;
248 } 248 }
249 ret = SSL_use_RSAPrivateKey(ssl, rsa); 249 ret = SSL_use_RSAPrivateKey(ssl, rsa);
@@ -262,7 +262,7 @@ SSL_use_RSAPrivateKey_ASN1(SSL *ssl, unsigned char *d, long len)
262 262
263 p = d; 263 p = d;
264 if ((rsa = d2i_RSAPrivateKey(NULL, &p,(long)len)) == NULL) { 264 if ((rsa = d2i_RSAPrivateKey(NULL, &p,(long)len)) == NULL) {
265 SSLerror(ERR_R_ASN1_LIB); 265 SSLerror(ssl, ERR_R_ASN1_LIB);
266 return (0); 266 return (0);
267 } 267 }
268 268
@@ -277,11 +277,11 @@ SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey)
277 int ret; 277 int ret;
278 278
279 if (pkey == NULL) { 279 if (pkey == NULL) {
280 SSLerror(ERR_R_PASSED_NULL_PARAMETER); 280 SSLerror(ssl, ERR_R_PASSED_NULL_PARAMETER);
281 return (0); 281 return (0);
282 } 282 }
283 if (!ssl_cert_inst(&ssl->cert)) { 283 if (!ssl_cert_inst(&ssl->cert)) {
284 SSLerror(ERR_R_MALLOC_FAILURE); 284 SSLerror(ssl, ERR_R_MALLOC_FAILURE);
285 return (0); 285 return (0);
286 } 286 }
287 ret = ssl_set_pkey(ssl->cert, pkey); 287 ret = ssl_set_pkey(ssl->cert, pkey);
@@ -297,12 +297,12 @@ SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type)
297 297
298 in = BIO_new(BIO_s_file_internal()); 298 in = BIO_new(BIO_s_file_internal());
299 if (in == NULL) { 299 if (in == NULL) {
300 SSLerror(ERR_R_BUF_LIB); 300 SSLerror(ssl, ERR_R_BUF_LIB);
301 goto end; 301 goto end;
302 } 302 }
303 303
304 if (BIO_read_filename(in, file) <= 0) { 304 if (BIO_read_filename(in, file) <= 0) {
305 SSLerror(ERR_R_SYS_LIB); 305 SSLerror(ssl, ERR_R_SYS_LIB);
306 goto end; 306 goto end;
307 } 307 }
308 if (type == SSL_FILETYPE_PEM) { 308 if (type == SSL_FILETYPE_PEM) {
@@ -314,11 +314,11 @@ SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type)
314 j = ERR_R_ASN1_LIB; 314 j = ERR_R_ASN1_LIB;
315 pkey = d2i_PrivateKey_bio(in, NULL); 315 pkey = d2i_PrivateKey_bio(in, NULL);
316 } else { 316 } else {
317 SSLerror(SSL_R_BAD_SSL_FILETYPE); 317 SSLerror(ssl, SSL_R_BAD_SSL_FILETYPE);
318 goto end; 318 goto end;
319 } 319 }
320 if (pkey == NULL) { 320 if (pkey == NULL) {
321 SSLerror(j); 321 SSLerror(ssl, j);
322 goto end; 322 goto end;
323 } 323 }
324 ret = SSL_use_PrivateKey(ssl, pkey); 324 ret = SSL_use_PrivateKey(ssl, pkey);
@@ -337,7 +337,7 @@ SSL_use_PrivateKey_ASN1(int type, SSL *ssl, const unsigned char *d, long len)
337 337
338 p = d; 338 p = d;
339 if ((pkey = d2i_PrivateKey(type, NULL, &p,(long)len)) == NULL) { 339 if ((pkey = d2i_PrivateKey(type, NULL, &p,(long)len)) == NULL) {
340 SSLerror(ERR_R_ASN1_LIB); 340 SSLerror(ssl, ERR_R_ASN1_LIB);
341 return (0); 341 return (0);
342 } 342 }
343 343
@@ -350,11 +350,11 @@ int
350SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x) 350SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x)
351{ 351{
352 if (x == NULL) { 352 if (x == NULL) {
353 SSLerror(ERR_R_PASSED_NULL_PARAMETER); 353 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER);
354 return (0); 354 return (0);
355 } 355 }
356 if (!ssl_cert_inst(&ctx->internal->cert)) { 356 if (!ssl_cert_inst(&ctx->internal->cert)) {
357 SSLerror(ERR_R_MALLOC_FAILURE); 357 SSLerrorx(ERR_R_MALLOC_FAILURE);
358 return (0); 358 return (0);
359 } 359 }
360 return (ssl_set_cert(ctx->internal->cert, x)); 360 return (ssl_set_cert(ctx->internal->cert, x));
@@ -368,13 +368,13 @@ ssl_set_cert(CERT *c, X509 *x)
368 368
369 pkey = X509_get_pubkey(x); 369 pkey = X509_get_pubkey(x);
370 if (pkey == NULL) { 370 if (pkey == NULL) {
371 SSLerror(SSL_R_X509_LIB); 371 SSLerrorx(SSL_R_X509_LIB);
372 return (0); 372 return (0);
373 } 373 }
374 374
375 i = ssl_cert_type(x, pkey); 375 i = ssl_cert_type(x, pkey);
376 if (i < 0) { 376 if (i < 0) {
377 SSLerror(SSL_R_UNKNOWN_CERTIFICATE_TYPE); 377 SSLerrorx(SSL_R_UNKNOWN_CERTIFICATE_TYPE);
378 EVP_PKEY_free(pkey); 378 EVP_PKEY_free(pkey);
379 return (0); 379 return (0);
380 } 380 }
@@ -427,12 +427,12 @@ SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type)
427 427
428 in = BIO_new(BIO_s_file_internal()); 428 in = BIO_new(BIO_s_file_internal());
429 if (in == NULL) { 429 if (in == NULL) {
430 SSLerror(ERR_R_BUF_LIB); 430 SSLerrorx(ERR_R_BUF_LIB);
431 goto end; 431 goto end;
432 } 432 }
433 433
434 if (BIO_read_filename(in, file) <= 0) { 434 if (BIO_read_filename(in, file) <= 0) {
435 SSLerror(ERR_R_SYS_LIB); 435 SSLerrorx(ERR_R_SYS_LIB);
436 goto end; 436 goto end;
437 } 437 }
438 if (type == SSL_FILETYPE_ASN1) { 438 if (type == SSL_FILETYPE_ASN1) {
@@ -443,12 +443,12 @@ SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type)
443 x = PEM_read_bio_X509(in, NULL, ctx->default_passwd_callback, 443 x = PEM_read_bio_X509(in, NULL, ctx->default_passwd_callback,
444 ctx->default_passwd_callback_userdata); 444 ctx->default_passwd_callback_userdata);
445 } else { 445 } else {
446 SSLerror(SSL_R_BAD_SSL_FILETYPE); 446 SSLerrorx(SSL_R_BAD_SSL_FILETYPE);
447 goto end; 447 goto end;
448 } 448 }
449 449
450 if (x == NULL) { 450 if (x == NULL) {
451 SSLerror(j); 451 SSLerrorx(j);
452 goto end; 452 goto end;
453 } 453 }
454 454
@@ -467,7 +467,7 @@ SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d)
467 467
468 x = d2i_X509(NULL, &d,(long)len); 468 x = d2i_X509(NULL, &d,(long)len);
469 if (x == NULL) { 469 if (x == NULL) {
470 SSLerror(ERR_R_ASN1_LIB); 470 SSLerrorx(ERR_R_ASN1_LIB);
471 return (0); 471 return (0);
472 } 472 }
473 473
@@ -483,15 +483,15 @@ SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa)
483 EVP_PKEY *pkey; 483 EVP_PKEY *pkey;
484 484
485 if (rsa == NULL) { 485 if (rsa == NULL) {
486 SSLerror(ERR_R_PASSED_NULL_PARAMETER); 486 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER);
487 return (0); 487 return (0);
488 } 488 }
489 if (!ssl_cert_inst(&ctx->internal->cert)) { 489 if (!ssl_cert_inst(&ctx->internal->cert)) {
490 SSLerror(ERR_R_MALLOC_FAILURE); 490 SSLerrorx(ERR_R_MALLOC_FAILURE);
491 return (0); 491 return (0);
492 } 492 }
493 if ((pkey = EVP_PKEY_new()) == NULL) { 493 if ((pkey = EVP_PKEY_new()) == NULL) {
494 SSLerror(ERR_R_EVP_LIB); 494 SSLerrorx(ERR_R_EVP_LIB);
495 return (0); 495 return (0);
496 } 496 }
497 497
@@ -512,12 +512,12 @@ SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type)
512 512
513 in = BIO_new(BIO_s_file_internal()); 513 in = BIO_new(BIO_s_file_internal());
514 if (in == NULL) { 514 if (in == NULL) {
515 SSLerror(ERR_R_BUF_LIB); 515 SSLerrorx(ERR_R_BUF_LIB);
516 goto end; 516 goto end;
517 } 517 }
518 518
519 if (BIO_read_filename(in, file) <= 0) { 519 if (BIO_read_filename(in, file) <= 0) {
520 SSLerror(ERR_R_SYS_LIB); 520 SSLerrorx(ERR_R_SYS_LIB);
521 goto end; 521 goto end;
522 } 522 }
523 if (type == SSL_FILETYPE_ASN1) { 523 if (type == SSL_FILETYPE_ASN1) {
@@ -529,11 +529,11 @@ SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type)
529 ctx->default_passwd_callback, 529 ctx->default_passwd_callback,
530 ctx->default_passwd_callback_userdata); 530 ctx->default_passwd_callback_userdata);
531 } else { 531 } else {
532 SSLerror(SSL_R_BAD_SSL_FILETYPE); 532 SSLerrorx(SSL_R_BAD_SSL_FILETYPE);
533 goto end; 533 goto end;
534 } 534 }
535 if (rsa == NULL) { 535 if (rsa == NULL) {
536 SSLerror(j); 536 SSLerrorx(j);
537 goto end; 537 goto end;
538 } 538 }
539 ret = SSL_CTX_use_RSAPrivateKey(ctx, rsa); 539 ret = SSL_CTX_use_RSAPrivateKey(ctx, rsa);
@@ -552,7 +552,7 @@ SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len)
552 552
553 p = d; 553 p = d;
554 if ((rsa = d2i_RSAPrivateKey(NULL, &p,(long)len)) == NULL) { 554 if ((rsa = d2i_RSAPrivateKey(NULL, &p,(long)len)) == NULL) {
555 SSLerror(ERR_R_ASN1_LIB); 555 SSLerrorx(ERR_R_ASN1_LIB);
556 return (0); 556 return (0);
557 } 557 }
558 558
@@ -565,11 +565,11 @@ int
565SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey) 565SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey)
566{ 566{
567 if (pkey == NULL) { 567 if (pkey == NULL) {
568 SSLerror(ERR_R_PASSED_NULL_PARAMETER); 568 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER);
569 return (0); 569 return (0);
570 } 570 }
571 if (!ssl_cert_inst(&ctx->internal->cert)) { 571 if (!ssl_cert_inst(&ctx->internal->cert)) {
572 SSLerror(ERR_R_MALLOC_FAILURE); 572 SSLerrorx(ERR_R_MALLOC_FAILURE);
573 return (0); 573 return (0);
574 } 574 }
575 return (ssl_set_pkey(ctx->internal->cert, pkey)); 575 return (ssl_set_pkey(ctx->internal->cert, pkey));
@@ -584,12 +584,12 @@ SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type)
584 584
585 in = BIO_new(BIO_s_file_internal()); 585 in = BIO_new(BIO_s_file_internal());
586 if (in == NULL) { 586 if (in == NULL) {
587 SSLerror(ERR_R_BUF_LIB); 587 SSLerrorx(ERR_R_BUF_LIB);
588 goto end; 588 goto end;
589 } 589 }
590 590
591 if (BIO_read_filename(in, file) <= 0) { 591 if (BIO_read_filename(in, file) <= 0) {
592 SSLerror(ERR_R_SYS_LIB); 592 SSLerrorx(ERR_R_SYS_LIB);
593 goto end; 593 goto end;
594 } 594 }
595 if (type == SSL_FILETYPE_PEM) { 595 if (type == SSL_FILETYPE_PEM) {
@@ -601,11 +601,11 @@ SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type)
601 j = ERR_R_ASN1_LIB; 601 j = ERR_R_ASN1_LIB;
602 pkey = d2i_PrivateKey_bio(in, NULL); 602 pkey = d2i_PrivateKey_bio(in, NULL);
603 } else { 603 } else {
604 SSLerror(SSL_R_BAD_SSL_FILETYPE); 604 SSLerrorx(SSL_R_BAD_SSL_FILETYPE);
605 goto end; 605 goto end;
606 } 606 }
607 if (pkey == NULL) { 607 if (pkey == NULL) {
608 SSLerror(j); 608 SSLerrorx(j);
609 goto end; 609 goto end;
610 } 610 }
611 ret = SSL_CTX_use_PrivateKey(ctx, pkey); 611 ret = SSL_CTX_use_PrivateKey(ctx, pkey);
@@ -625,7 +625,7 @@ SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, const unsigned char *d,
625 625
626 p = d; 626 p = d;
627 if ((pkey = d2i_PrivateKey(type, NULL, &p,(long)len)) == NULL) { 627 if ((pkey = d2i_PrivateKey(type, NULL, &p,(long)len)) == NULL) {
628 SSLerror(ERR_R_ASN1_LIB); 628 SSLerrorx(ERR_R_ASN1_LIB);
629 return (0); 629 return (0);
630 } 630 }
631 631
@@ -651,7 +651,7 @@ ssl_ctx_use_certificate_chain_bio(SSL_CTX *ctx, BIO *in)
651 x = PEM_read_bio_X509_AUX(in, NULL, ctx->default_passwd_callback, 651 x = PEM_read_bio_X509_AUX(in, NULL, ctx->default_passwd_callback,
652 ctx->default_passwd_callback_userdata); 652 ctx->default_passwd_callback_userdata);
653 if (x == NULL) { 653 if (x == NULL) {
654 SSLerror(ERR_R_PEM_LIB); 654 SSLerrorx(ERR_R_PEM_LIB);
655 goto end; 655 goto end;
656 } 656 }
657 657
@@ -711,12 +711,12 @@ SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file)
711 711
712 in = BIO_new(BIO_s_file_internal()); 712 in = BIO_new(BIO_s_file_internal());
713 if (in == NULL) { 713 if (in == NULL) {
714 SSLerror(ERR_R_BUF_LIB); 714 SSLerrorx(ERR_R_BUF_LIB);
715 goto end; 715 goto end;
716 } 716 }
717 717
718 if (BIO_read_filename(in, file) <= 0) { 718 if (BIO_read_filename(in, file) <= 0) {
719 SSLerror(ERR_R_SYS_LIB); 719 SSLerrorx(ERR_R_SYS_LIB);
720 goto end; 720 goto end;
721 } 721 }
722 722
@@ -735,7 +735,7 @@ SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len)
735 735
736 in = BIO_new_mem_buf(buf, len); 736 in = BIO_new_mem_buf(buf, len);
737 if (in == NULL) { 737 if (in == NULL) {
738 SSLerror(ERR_R_BUF_LIB); 738 SSLerrorx(ERR_R_BUF_LIB);
739 goto end; 739 goto end;
740 } 740 }
741 741