diff options
Diffstat (limited to 'src/lib/libssl/s3_clnt.c')
-rw-r--r-- | src/lib/libssl/s3_clnt.c | 363 |
1 files changed, 207 insertions, 156 deletions
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c index 940c6a458f..d3e6b4d1e5 100644 --- a/src/lib/libssl/s3_clnt.c +++ b/src/lib/libssl/s3_clnt.c | |||
@@ -57,23 +57,15 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "buffer.h" | 60 | #include <openssl/buffer.h> |
61 | #include "rand.h" | 61 | #include <openssl/rand.h> |
62 | #include "objects.h" | 62 | #include <openssl/objects.h> |
63 | #include "evp.h" | 63 | #include <openssl/md5.h> |
64 | #include <openssl/sha.h> | ||
65 | #include <openssl/evp.h> | ||
64 | #include "ssl_locl.h" | 66 | #include "ssl_locl.h" |
65 | 67 | ||
66 | #define BREAK break | 68 | static SSL_METHOD *ssl3_get_client_method(int ver); |
67 | /* SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,ERR_R_MALLOC_FAILURE); | ||
68 | * SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); | ||
69 | * SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,ERR_R_MALLOC_FAILURE); | ||
70 | * SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,ERR_R_MALLOC_FAILURE); | ||
71 | * SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); | ||
72 | * SSLerr(SSL_F_SSL3_GET_SERVER_DONE,ERR_R_MALLOC_FAILURE); | ||
73 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT); | ||
74 | */ | ||
75 | |||
76 | #ifndef NOPROTO | ||
77 | static int ssl3_client_hello(SSL *s); | 69 | static int ssl3_client_hello(SSL *s); |
78 | static int ssl3_get_server_hello(SSL *s); | 70 | static int ssl3_get_server_hello(SSL *s); |
79 | static int ssl3_get_certificate_request(SSL *s); | 71 | static int ssl3_get_certificate_request(SSL *s); |
@@ -85,22 +77,7 @@ static int ssl3_send_client_key_exchange(SSL *s); | |||
85 | static int ssl3_get_key_exchange(SSL *s); | 77 | static int ssl3_get_key_exchange(SSL *s); |
86 | static int ssl3_get_server_certificate(SSL *s); | 78 | static int ssl3_get_server_certificate(SSL *s); |
87 | static int ssl3_check_cert_and_algorithm(SSL *s); | 79 | static int ssl3_check_cert_and_algorithm(SSL *s); |
88 | #else | 80 | static SSL_METHOD *ssl3_get_client_method(int ver) |
89 | static int ssl3_client_hello(); | ||
90 | static int ssl3_get_server_hello(); | ||
91 | static int ssl3_get_certificate_request(); | ||
92 | static int ca_dn_cmp(); | ||
93 | static int ssl3_get_server_done(); | ||
94 | static int ssl3_send_client_verify(); | ||
95 | static int ssl3_send_client_certificate(); | ||
96 | static int ssl3_send_client_key_exchange(); | ||
97 | static int ssl3_get_key_exchange(); | ||
98 | static int ssl3_get_server_certificate(); | ||
99 | static int ssl3_check_cert_and_algorithm(); | ||
100 | #endif | ||
101 | |||
102 | static SSL_METHOD *ssl3_get_client_method(ver) | ||
103 | int ver; | ||
104 | { | 81 | { |
105 | if (ver == SSL3_VERSION) | 82 | if (ver == SSL3_VERSION) |
106 | return(SSLv3_client_method()); | 83 | return(SSLv3_client_method()); |
@@ -108,7 +85,7 @@ int ver; | |||
108 | return(NULL); | 85 | return(NULL); |
109 | } | 86 | } |
110 | 87 | ||
111 | SSL_METHOD *SSLv3_client_method() | 88 | SSL_METHOD *SSLv3_client_method(void) |
112 | { | 89 | { |
113 | static int init=1; | 90 | static int init=1; |
114 | static SSL_METHOD SSLv3_client_data; | 91 | static SSL_METHOD SSLv3_client_data; |
@@ -124,18 +101,16 @@ SSL_METHOD *SSLv3_client_method() | |||
124 | return(&SSLv3_client_data); | 101 | return(&SSLv3_client_data); |
125 | } | 102 | } |
126 | 103 | ||
127 | int ssl3_connect(s) | 104 | int ssl3_connect(SSL *s) |
128 | SSL *s; | ||
129 | { | 105 | { |
130 | BUF_MEM *buf; | 106 | BUF_MEM *buf; |
131 | unsigned long Time=time(NULL),l; | 107 | unsigned long Time=time(NULL),l; |
132 | long num1; | 108 | long num1; |
133 | void (*cb)()=NULL; | 109 | void (*cb)()=NULL; |
134 | int ret= -1; | 110 | int ret= -1; |
135 | BIO *under; | ||
136 | int new_state,state,skip=0;; | 111 | int new_state,state,skip=0;; |
137 | 112 | ||
138 | RAND_seed((unsigned char *)&Time,sizeof(Time)); | 113 | RAND_seed(&Time,sizeof(Time)); |
139 | ERR_clear_error(); | 114 | ERR_clear_error(); |
140 | clear_sys_error(); | 115 | clear_sys_error(); |
141 | 116 | ||
@@ -156,13 +131,14 @@ SSL *s; | |||
156 | case SSL_ST_RENEGOTIATE: | 131 | case SSL_ST_RENEGOTIATE: |
157 | s->new_session=1; | 132 | s->new_session=1; |
158 | s->state=SSL_ST_CONNECT; | 133 | s->state=SSL_ST_CONNECT; |
159 | s->ctx->sess_connect_renegotiate++; | 134 | s->ctx->stats.sess_connect_renegotiate++; |
160 | /* break */ | 135 | /* break */ |
161 | case SSL_ST_BEFORE: | 136 | case SSL_ST_BEFORE: |
162 | case SSL_ST_CONNECT: | 137 | case SSL_ST_CONNECT: |
163 | case SSL_ST_BEFORE|SSL_ST_CONNECT: | 138 | case SSL_ST_BEFORE|SSL_ST_CONNECT: |
164 | case SSL_ST_OK|SSL_ST_CONNECT: | 139 | case SSL_ST_OK|SSL_ST_CONNECT: |
165 | 140 | ||
141 | s->server=0; | ||
166 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); | 142 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_START,1); |
167 | 143 | ||
168 | if ((s->version & 0xff00 ) != 0x0300) | 144 | if ((s->version & 0xff00 ) != 0x0300) |
@@ -195,7 +171,7 @@ SSL *s; | |||
195 | ssl3_init_finished_mac(s); | 171 | ssl3_init_finished_mac(s); |
196 | 172 | ||
197 | s->state=SSL3_ST_CW_CLNT_HELLO_A; | 173 | s->state=SSL3_ST_CW_CLNT_HELLO_A; |
198 | s->ctx->sess_connect++; | 174 | s->ctx->stats.sess_connect++; |
199 | s->init_num=0; | 175 | s->init_num=0; |
200 | break; | 176 | break; |
201 | 177 | ||
@@ -278,6 +254,7 @@ SSL *s; | |||
278 | case SSL3_ST_CW_CERT_A: | 254 | case SSL3_ST_CW_CERT_A: |
279 | case SSL3_ST_CW_CERT_B: | 255 | case SSL3_ST_CW_CERT_B: |
280 | case SSL3_ST_CW_CERT_C: | 256 | case SSL3_ST_CW_CERT_C: |
257 | case SSL3_ST_CW_CERT_D: | ||
281 | ret=ssl3_send_client_certificate(s); | 258 | ret=ssl3_send_client_certificate(s); |
282 | if (ret <= 0) goto end; | 259 | if (ret <= 0) goto end; |
283 | s->state=SSL3_ST_CW_KEY_EXCH_A; | 260 | s->state=SSL3_ST_CW_KEY_EXCH_A; |
@@ -324,6 +301,11 @@ SSL *s; | |||
324 | s->init_num=0; | 301 | s->init_num=0; |
325 | 302 | ||
326 | s->session->cipher=s->s3->tmp.new_cipher; | 303 | s->session->cipher=s->s3->tmp.new_cipher; |
304 | if (s->s3->tmp.new_compression == NULL) | ||
305 | s->session->compress_meth=0; | ||
306 | else | ||
307 | s->session->compress_meth= | ||
308 | s->s3->tmp.new_compression->id; | ||
327 | if (!s->method->ssl3_enc->setup_key_block(s)) | 309 | if (!s->method->ssl3_enc->setup_key_block(s)) |
328 | { | 310 | { |
329 | ret= -1; | 311 | ret= -1; |
@@ -399,38 +381,33 @@ SSL *s; | |||
399 | /* clean a few things up */ | 381 | /* clean a few things up */ |
400 | ssl3_cleanup_key_block(s); | 382 | ssl3_cleanup_key_block(s); |
401 | 383 | ||
402 | BUF_MEM_free(s->init_buf); | 384 | if (s->init_buf != NULL) |
403 | s->init_buf=NULL; | ||
404 | |||
405 | if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER)) | ||
406 | { | 385 | { |
407 | /* remove buffering */ | 386 | BUF_MEM_free(s->init_buf); |
408 | under=BIO_pop(s->wbio); | 387 | s->init_buf=NULL; |
409 | if (under != NULL) | ||
410 | s->wbio=under; | ||
411 | else | ||
412 | abort(); /* ok */ | ||
413 | |||
414 | BIO_free(s->bbio); | ||
415 | s->bbio=NULL; | ||
416 | } | 388 | } |
417 | /* else do it later */ | 389 | |
390 | /* If we are not 'joining' the last two packets, | ||
391 | * remove the buffering now */ | ||
392 | if (!(s->s3->flags & SSL3_FLAGS_POP_BUFFER)) | ||
393 | ssl_free_wbio_buffer(s); | ||
394 | /* else do it later in ssl3_write */ | ||
418 | 395 | ||
419 | s->init_num=0; | 396 | s->init_num=0; |
420 | s->new_session=0; | 397 | s->new_session=0; |
421 | 398 | ||
422 | ssl_update_cache(s,SSL_SESS_CACHE_CLIENT); | 399 | ssl_update_cache(s,SSL_SESS_CACHE_CLIENT); |
423 | if (s->hit) s->ctx->sess_hit++; | 400 | if (s->hit) s->ctx->stats.sess_hit++; |
424 | 401 | ||
425 | ret=1; | 402 | ret=1; |
426 | /* s->server=0; */ | 403 | /* s->server=0; */ |
427 | s->handshake_func=ssl3_connect; | 404 | s->handshake_func=ssl3_connect; |
428 | s->ctx->sess_connect_good++; | 405 | s->ctx->stats.sess_connect_good++; |
429 | 406 | ||
430 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1); | 407 | if (cb != NULL) cb(s,SSL_CB_HANDSHAKE_DONE,1); |
431 | 408 | ||
432 | goto end; | 409 | goto end; |
433 | break; | 410 | /* break; */ |
434 | 411 | ||
435 | default: | 412 | default: |
436 | SSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE); | 413 | SSLerr(SSL_F_SSL3_CONNECT,SSL_R_UNKNOWN_STATE); |
@@ -466,19 +443,20 @@ end: | |||
466 | } | 443 | } |
467 | 444 | ||
468 | 445 | ||
469 | static int ssl3_client_hello(s) | 446 | static int ssl3_client_hello(SSL *s) |
470 | SSL *s; | ||
471 | { | 447 | { |
472 | unsigned char *buf; | 448 | unsigned char *buf; |
473 | unsigned char *p,*d; | 449 | unsigned char *p,*d; |
474 | int i; | 450 | int i,j; |
475 | unsigned long Time,l; | 451 | unsigned long Time,l; |
452 | SSL_COMP *comp; | ||
476 | 453 | ||
477 | buf=(unsigned char *)s->init_buf->data; | 454 | buf=(unsigned char *)s->init_buf->data; |
478 | if (s->state == SSL3_ST_CW_CLNT_HELLO_A) | 455 | if (s->state == SSL3_ST_CW_CLNT_HELLO_A) |
479 | { | 456 | { |
480 | if ((s->session == NULL) || | 457 | if ((s->session == NULL) || |
481 | (s->session->ssl_version != s->version)) | 458 | (s->session->ssl_version != s->version) || |
459 | (s->session->not_resumable)) | ||
482 | { | 460 | { |
483 | if (!ssl_get_new_session(s,0)) | 461 | if (!ssl_get_new_session(s,0)) |
484 | goto err; | 462 | goto err; |
@@ -488,13 +466,14 @@ SSL *s; | |||
488 | p=s->s3->client_random; | 466 | p=s->s3->client_random; |
489 | Time=time(NULL); /* Time */ | 467 | Time=time(NULL); /* Time */ |
490 | l2n(Time,p); | 468 | l2n(Time,p); |
491 | RAND_bytes(&(p[4]),SSL3_RANDOM_SIZE-sizeof(Time)); | 469 | RAND_bytes(p,SSL3_RANDOM_SIZE-sizeof(Time)); |
492 | 470 | ||
493 | /* Do the message type and length last */ | 471 | /* Do the message type and length last */ |
494 | d=p= &(buf[4]); | 472 | d=p= &(buf[4]); |
495 | 473 | ||
496 | *(p++)=s->version>>8; | 474 | *(p++)=s->version>>8; |
497 | *(p++)=s->version&0xff; | 475 | *(p++)=s->version&0xff; |
476 | s->client_version=s->version; | ||
498 | 477 | ||
499 | /* Random stuff */ | 478 | /* Random stuff */ |
500 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); | 479 | memcpy(p,s->s3->client_random,SSL3_RANDOM_SIZE); |
@@ -522,9 +501,18 @@ SSL *s; | |||
522 | s2n(i,p); | 501 | s2n(i,p); |
523 | p+=i; | 502 | p+=i; |
524 | 503 | ||
525 | /* hardwire in the NULL compression algorithm. */ | 504 | /* COMPRESSION */ |
526 | *(p++)=1; | 505 | if (s->ctx->comp_methods == NULL) |
527 | *(p++)=0; | 506 | j=0; |
507 | else | ||
508 | j=sk_SSL_COMP_num(s->ctx->comp_methods); | ||
509 | *(p++)=1+j; | ||
510 | for (i=0; i<j; i++) | ||
511 | { | ||
512 | comp=sk_SSL_COMP_value(s->ctx->comp_methods,i); | ||
513 | *(p++)=comp->id; | ||
514 | } | ||
515 | *(p++)=0; /* Add the NULL method */ | ||
528 | 516 | ||
529 | l=(p-d); | 517 | l=(p-d); |
530 | d=buf; | 518 | d=buf; |
@@ -543,15 +531,15 @@ err: | |||
543 | return(-1); | 531 | return(-1); |
544 | } | 532 | } |
545 | 533 | ||
546 | static int ssl3_get_server_hello(s) | 534 | static int ssl3_get_server_hello(SSL *s) |
547 | SSL *s; | ||
548 | { | 535 | { |
549 | STACK *sk; | 536 | STACK_OF(SSL_CIPHER) *sk; |
550 | SSL_CIPHER *c; | 537 | SSL_CIPHER *c; |
551 | unsigned char *p,*d; | 538 | unsigned char *p,*d; |
552 | int i,al,ok; | 539 | int i,al,ok; |
553 | unsigned int j; | 540 | unsigned int j; |
554 | long n; | 541 | long n; |
542 | SSL_COMP *comp; | ||
555 | 543 | ||
556 | n=ssl3_get_message(s, | 544 | n=ssl3_get_message(s, |
557 | SSL3_ST_CR_SRVR_HELLO_A, | 545 | SSL3_ST_CR_SRVR_HELLO_A, |
@@ -590,9 +578,18 @@ SSL *s; | |||
590 | goto f_err; | 578 | goto f_err; |
591 | } | 579 | } |
592 | } | 580 | } |
593 | if ((j != 0) && (j == s->session->session_id_length) && | 581 | if (j != 0 && j == s->session->session_id_length |
594 | (memcmp(p,s->session->session_id,j) == 0)) | 582 | && memcmp(p,s->session->session_id,j) == 0) |
595 | s->hit=1; | 583 | { |
584 | if(s->sid_ctx_length != s->session->sid_ctx_length | ||
585 | || memcmp(s->session->sid_ctx,s->sid_ctx,s->sid_ctx_length)) | ||
586 | { | ||
587 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
588 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT); | ||
589 | goto f_err; | ||
590 | } | ||
591 | s->hit=1; | ||
592 | } | ||
596 | else /* a miss or crap from the other end */ | 593 | else /* a miss or crap from the other end */ |
597 | { | 594 | { |
598 | /* If we were trying for session-id reuse, make a new | 595 | /* If we were trying for session-id reuse, make a new |
@@ -621,7 +618,7 @@ SSL *s; | |||
621 | p+=ssl_put_cipher_by_char(s,NULL,NULL); | 618 | p+=ssl_put_cipher_by_char(s,NULL,NULL); |
622 | 619 | ||
623 | sk=ssl_get_ciphers_by_id(s); | 620 | sk=ssl_get_ciphers_by_id(s); |
624 | i=sk_find(sk,(char *)c); | 621 | i=sk_SSL_CIPHER_find(sk,c); |
625 | if (i < 0) | 622 | if (i < 0) |
626 | { | 623 | { |
627 | /* we did not say we would use this cipher */ | 624 | /* we did not say we would use this cipher */ |
@@ -643,13 +640,23 @@ SSL *s; | |||
643 | s->s3->tmp.new_cipher=c; | 640 | s->s3->tmp.new_cipher=c; |
644 | 641 | ||
645 | /* lets get the compression algorithm */ | 642 | /* lets get the compression algorithm */ |
643 | /* COMPRESSION */ | ||
646 | j= *(p++); | 644 | j= *(p++); |
647 | if (j != 0) | 645 | if (j == 0) |
646 | comp=NULL; | ||
647 | else | ||
648 | comp=ssl3_comp_find(s->ctx->comp_methods,j); | ||
649 | |||
650 | if ((j != 0) && (comp == NULL)) | ||
648 | { | 651 | { |
649 | al=SSL_AD_ILLEGAL_PARAMETER; | 652 | al=SSL_AD_ILLEGAL_PARAMETER; |
650 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM); | 653 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM); |
651 | goto f_err; | 654 | goto f_err; |
652 | } | 655 | } |
656 | else | ||
657 | { | ||
658 | s->s3->tmp.new_compression=comp; | ||
659 | } | ||
653 | 660 | ||
654 | if (p != (d+n)) | 661 | if (p != (d+n)) |
655 | { | 662 | { |
@@ -666,15 +673,14 @@ err: | |||
666 | return(-1); | 673 | return(-1); |
667 | } | 674 | } |
668 | 675 | ||
669 | static int ssl3_get_server_certificate(s) | 676 | static int ssl3_get_server_certificate(SSL *s) |
670 | SSL *s; | ||
671 | { | 677 | { |
672 | int al,i,ok,ret= -1; | 678 | int al,i,ok,ret= -1; |
673 | unsigned long n,nc,llen,l; | 679 | unsigned long n,nc,llen,l; |
674 | X509 *x=NULL; | 680 | X509 *x=NULL; |
675 | unsigned char *p,*d,*q; | 681 | unsigned char *p,*d,*q; |
676 | STACK *sk=NULL; | 682 | STACK_OF(X509) *sk=NULL; |
677 | CERT *c; | 683 | SESS_CERT *sc; |
678 | EVP_PKEY *pkey=NULL; | 684 | EVP_PKEY *pkey=NULL; |
679 | 685 | ||
680 | n=ssl3_get_message(s, | 686 | n=ssl3_get_message(s, |
@@ -704,7 +710,7 @@ SSL *s; | |||
704 | } | 710 | } |
705 | d=p=(unsigned char *)s->init_buf->data; | 711 | d=p=(unsigned char *)s->init_buf->data; |
706 | 712 | ||
707 | if ((sk=sk_new_null()) == NULL) | 713 | if ((sk=sk_X509_new_null()) == NULL) |
708 | { | 714 | { |
709 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); | 715 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); |
710 | goto err; | 716 | goto err; |
@@ -741,7 +747,7 @@ SSL *s; | |||
741 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); | 747 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERT_LENGTH_MISMATCH); |
742 | goto f_err; | 748 | goto f_err; |
743 | } | 749 | } |
744 | if (!sk_push(sk,(char *)x)) | 750 | if (!sk_X509_push(sk,x)) |
745 | { | 751 | { |
746 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); | 752 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,ERR_R_MALLOC_FAILURE); |
747 | goto err; | 753 | goto err; |
@@ -752,26 +758,26 @@ SSL *s; | |||
752 | } | 758 | } |
753 | 759 | ||
754 | i=ssl_verify_cert_chain(s,sk); | 760 | i=ssl_verify_cert_chain(s,sk); |
755 | if ((s->verify_mode != SSL_VERIFY_NONE) && (!i)) | 761 | if ((s->verify_mode != SSL_VERIFY_NONE) && (!i)) |
756 | { | 762 | { |
757 | al=ssl_verify_alarm_type(s->verify_result); | 763 | al=ssl_verify_alarm_type(s->verify_result); |
758 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED); | 764 | SSLerr(SSL_F_SSL3_GET_SERVER_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED); |
759 | goto f_err; | 765 | goto f_err; |
760 | } | 766 | } |
761 | 767 | ||
762 | c=ssl_cert_new(); | 768 | sc=ssl_sess_cert_new(); |
763 | if (c == NULL) goto err; | 769 | if (sc == NULL) goto err; |
764 | 770 | ||
765 | if (s->session->cert) ssl_cert_free(s->session->cert); | 771 | if (s->session->sess_cert) ssl_sess_cert_free(s->session->sess_cert); |
766 | s->session->cert=c; | 772 | s->session->sess_cert=sc; |
767 | 773 | ||
768 | c->cert_chain=sk; | 774 | sc->cert_chain=sk; |
769 | x=(X509 *)sk_value(sk,0); | 775 | x=sk_X509_value(sk,0); |
770 | sk=NULL; | 776 | sk=NULL; |
771 | 777 | ||
772 | pkey=X509_get_pubkey(x); | 778 | pkey=X509_get_pubkey(x); |
773 | 779 | ||
774 | if (EVP_PKEY_missing_parameters(pkey)) | 780 | if ((pkey == NULL) || EVP_PKEY_missing_parameters(pkey)) |
775 | { | 781 | { |
776 | x=NULL; | 782 | x=NULL; |
777 | al=SSL3_AL_FATAL; | 783 | al=SSL3_AL_FATAL; |
@@ -788,14 +794,16 @@ SSL *s; | |||
788 | goto f_err; | 794 | goto f_err; |
789 | } | 795 | } |
790 | 796 | ||
791 | c->cert_type=i; | 797 | sc->peer_cert_type=i; |
792 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | 798 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); |
793 | if (c->pkeys[i].x509 != NULL) | 799 | if (sc->peer_pkeys[i].x509 != NULL) /* Why would this ever happen? |
794 | X509_free(c->pkeys[i].x509); | 800 | * We just created sc a couple of |
795 | c->pkeys[i].x509=x; | 801 | * lines ago. */ |
796 | c->key= &(c->pkeys[i]); | 802 | X509_free(sc->peer_pkeys[i].x509); |
797 | 803 | sc->peer_pkeys[i].x509=x; | |
798 | if ((s->session != NULL) && (s->session->peer != NULL)) | 804 | sc->peer_key= &(sc->peer_pkeys[i]); |
805 | |||
806 | if (s->session->peer != NULL) | ||
799 | X509_free(s->session->peer); | 807 | X509_free(s->session->peer); |
800 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); | 808 | CRYPTO_add(&x->references,1,CRYPTO_LOCK_X509); |
801 | s->session->peer=x; | 809 | s->session->peer=x; |
@@ -809,13 +817,13 @@ f_err: | |||
809 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | 817 | ssl3_send_alert(s,SSL3_AL_FATAL,al); |
810 | } | 818 | } |
811 | err: | 819 | err: |
812 | if (x != NULL) X509_free(x); | 820 | EVP_PKEY_free(pkey); |
813 | if (sk != NULL) sk_pop_free(sk,X509_free); | 821 | X509_free(x); |
822 | sk_X509_pop_free(sk,X509_free); | ||
814 | return(ret); | 823 | return(ret); |
815 | } | 824 | } |
816 | 825 | ||
817 | static int ssl3_get_key_exchange(s) | 826 | static int ssl3_get_key_exchange(SSL *s) |
818 | SSL *s; | ||
819 | { | 827 | { |
820 | #ifndef NO_RSA | 828 | #ifndef NO_RSA |
821 | unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2]; | 829 | unsigned char *q,md_buf[EVP_MAX_MD_SIZE*2]; |
@@ -825,7 +833,9 @@ SSL *s; | |||
825 | int al,i,j,param_len,ok; | 833 | int al,i,j,param_len,ok; |
826 | long n,alg; | 834 | long n,alg; |
827 | EVP_PKEY *pkey=NULL; | 835 | EVP_PKEY *pkey=NULL; |
836 | #ifndef NO_RSA | ||
828 | RSA *rsa=NULL; | 837 | RSA *rsa=NULL; |
838 | #endif | ||
829 | #ifndef NO_DH | 839 | #ifndef NO_DH |
830 | DH *dh=NULL; | 840 | DH *dh=NULL; |
831 | #endif | 841 | #endif |
@@ -847,26 +857,26 @@ SSL *s; | |||
847 | 857 | ||
848 | param=p=(unsigned char *)s->init_buf->data; | 858 | param=p=(unsigned char *)s->init_buf->data; |
849 | 859 | ||
850 | if (s->session->cert != NULL) | 860 | if (s->session->sess_cert != NULL) |
851 | { | 861 | { |
852 | #ifndef NO_RSA | 862 | #ifndef NO_RSA |
853 | if (s->session->cert->rsa_tmp != NULL) | 863 | if (s->session->sess_cert->peer_rsa_tmp != NULL) |
854 | { | 864 | { |
855 | RSA_free(s->session->cert->rsa_tmp); | 865 | RSA_free(s->session->sess_cert->peer_rsa_tmp); |
856 | s->session->cert->rsa_tmp=NULL; | 866 | s->session->sess_cert->peer_rsa_tmp=NULL; |
857 | } | 867 | } |
858 | #endif | 868 | #endif |
859 | #ifndef NO_DH | 869 | #ifndef NO_DH |
860 | if (s->session->cert->dh_tmp) | 870 | if (s->session->sess_cert->peer_dh_tmp) |
861 | { | 871 | { |
862 | DH_free(s->session->cert->dh_tmp); | 872 | DH_free(s->session->sess_cert->peer_dh_tmp); |
863 | s->session->cert->dh_tmp=NULL; | 873 | s->session->sess_cert->peer_dh_tmp=NULL; |
864 | } | 874 | } |
865 | #endif | 875 | #endif |
866 | } | 876 | } |
867 | else | 877 | else |
868 | { | 878 | { |
869 | s->session->cert=ssl_cert_new(); | 879 | s->session->sess_cert=ssl_sess_cert_new(); |
870 | } | 880 | } |
871 | 881 | ||
872 | param_len=0; | 882 | param_len=0; |
@@ -911,16 +921,16 @@ SSL *s; | |||
911 | p+=i; | 921 | p+=i; |
912 | n-=param_len; | 922 | n-=param_len; |
913 | 923 | ||
914 | /* s->session->cert->rsa_tmp=rsa;*/ | ||
915 | /* this should be because we are using an export cipher */ | 924 | /* this should be because we are using an export cipher */ |
916 | if (alg & SSL_aRSA) | 925 | if (alg & SSL_aRSA) |
917 | pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509); | 926 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); |
918 | else | 927 | else |
919 | { | 928 | { |
920 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); | 929 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_INTERNAL_ERROR); |
921 | goto err; | 930 | goto err; |
922 | } | 931 | } |
923 | s->session->cert->rsa_tmp=rsa; | 932 | s->session->sess_cert->peer_rsa_tmp=rsa; |
933 | rsa=NULL; | ||
924 | } | 934 | } |
925 | else | 935 | else |
926 | #endif | 936 | #endif |
@@ -980,16 +990,17 @@ SSL *s; | |||
980 | 990 | ||
981 | #ifndef NO_RSA | 991 | #ifndef NO_RSA |
982 | if (alg & SSL_aRSA) | 992 | if (alg & SSL_aRSA) |
983 | pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509); | 993 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); |
984 | else | 994 | else |
985 | #endif | 995 | #endif |
986 | #ifndef NO_DSA | 996 | #ifndef NO_DSA |
987 | if (alg & SSL_aDSS) | 997 | if (alg & SSL_aDSS) |
988 | pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_DSA_SIGN].x509); | 998 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_DSA_SIGN].x509); |
989 | #endif | 999 | #endif |
990 | /* else anonymous DH, so no certificate or pkey. */ | 1000 | /* else anonymous DH, so no certificate or pkey. */ |
991 | 1001 | ||
992 | s->session->cert->dh_tmp=dh; | 1002 | s->session->sess_cert->peer_dh_tmp=dh; |
1003 | dh=NULL; | ||
993 | } | 1004 | } |
994 | else if ((alg & SSL_kDHr) || (alg & SSL_kDHd)) | 1005 | else if ((alg & SSL_kDHr) || (alg & SSL_kDHd)) |
995 | { | 1006 | { |
@@ -998,6 +1009,13 @@ SSL *s; | |||
998 | goto f_err; | 1009 | goto f_err; |
999 | } | 1010 | } |
1000 | #endif | 1011 | #endif |
1012 | if (alg & SSL_aFZA) | ||
1013 | { | ||
1014 | al=SSL_AD_HANDSHAKE_FAILURE; | ||
1015 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER); | ||
1016 | goto f_err; | ||
1017 | } | ||
1018 | |||
1001 | 1019 | ||
1002 | /* p points to the next byte, there are 'n' bytes left */ | 1020 | /* p points to the next byte, there are 'n' bytes left */ |
1003 | 1021 | ||
@@ -1014,7 +1032,7 @@ SSL *s; | |||
1014 | /* wrong packet length */ | 1032 | /* wrong packet length */ |
1015 | al=SSL_AD_DECODE_ERROR; | 1033 | al=SSL_AD_DECODE_ERROR; |
1016 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH); | 1034 | SSLerr(SSL_F_SSL3_GET_KEY_EXCHANGE,SSL_R_WRONG_SIGNATURE_LENGTH); |
1017 | goto err; | 1035 | goto f_err; |
1018 | } | 1036 | } |
1019 | 1037 | ||
1020 | #ifndef NO_RSA | 1038 | #ifndef NO_RSA |
@@ -1091,23 +1109,31 @@ SSL *s; | |||
1091 | goto f_err; | 1109 | goto f_err; |
1092 | } | 1110 | } |
1093 | } | 1111 | } |
1094 | 1112 | EVP_PKEY_free(pkey); | |
1095 | return(1); | 1113 | return(1); |
1096 | f_err: | 1114 | f_err: |
1097 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | 1115 | ssl3_send_alert(s,SSL3_AL_FATAL,al); |
1098 | err: | 1116 | err: |
1117 | EVP_PKEY_free(pkey); | ||
1118 | #ifndef NO_RSA | ||
1119 | if (rsa != NULL) | ||
1120 | RSA_free(rsa); | ||
1121 | #endif | ||
1122 | #ifndef NO_DH | ||
1123 | if (dh != NULL) | ||
1124 | DH_free(dh); | ||
1125 | #endif | ||
1099 | return(-1); | 1126 | return(-1); |
1100 | } | 1127 | } |
1101 | 1128 | ||
1102 | static int ssl3_get_certificate_request(s) | 1129 | static int ssl3_get_certificate_request(SSL *s) |
1103 | SSL *s; | ||
1104 | { | 1130 | { |
1105 | int ok,ret=0; | 1131 | int ok,ret=0; |
1106 | unsigned long n,nc,l; | 1132 | unsigned long n,nc,l; |
1107 | unsigned int llen,ctype_num,i; | 1133 | unsigned int llen,ctype_num,i; |
1108 | X509_NAME *xn=NULL; | 1134 | X509_NAME *xn=NULL; |
1109 | unsigned char *p,*d,*q; | 1135 | unsigned char *p,*d,*q; |
1110 | STACK *ca_sk=NULL; | 1136 | STACK_OF(X509_NAME) *ca_sk=NULL; |
1111 | 1137 | ||
1112 | n=ssl3_get_message(s, | 1138 | n=ssl3_get_message(s, |
1113 | SSL3_ST_CR_CERT_REQ_A, | 1139 | SSL3_ST_CR_CERT_REQ_A, |
@@ -1151,7 +1177,7 @@ SSL *s; | |||
1151 | 1177 | ||
1152 | d=p=(unsigned char *)s->init_buf->data; | 1178 | d=p=(unsigned char *)s->init_buf->data; |
1153 | 1179 | ||
1154 | if ((ca_sk=sk_new(ca_dn_cmp)) == NULL) | 1180 | if ((ca_sk=sk_X509_NAME_new(ca_dn_cmp)) == NULL) |
1155 | { | 1181 | { |
1156 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); | 1182 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); |
1157 | goto err; | 1183 | goto err; |
@@ -1167,6 +1193,15 @@ SSL *s; | |||
1167 | 1193 | ||
1168 | /* get the CA RDNs */ | 1194 | /* get the CA RDNs */ |
1169 | n2s(p,llen); | 1195 | n2s(p,llen); |
1196 | #if 0 | ||
1197 | { | ||
1198 | FILE *out; | ||
1199 | out=fopen("/tmp/vsign.der","w"); | ||
1200 | fwrite(p,1,llen,out); | ||
1201 | fclose(out); | ||
1202 | } | ||
1203 | #endif | ||
1204 | |||
1170 | if ((llen+ctype_num+2+1) != n) | 1205 | if ((llen+ctype_num+2+1) != n) |
1171 | { | 1206 | { |
1172 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); | 1207 | ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECODE_ERROR); |
@@ -1207,7 +1242,7 @@ SSL *s; | |||
1207 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH); | 1242 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,SSL_R_CA_DN_LENGTH_MISMATCH); |
1208 | goto err; | 1243 | goto err; |
1209 | } | 1244 | } |
1210 | if (!sk_push(ca_sk,(char *)xn)) | 1245 | if (!sk_X509_NAME_push(ca_sk,xn)) |
1211 | { | 1246 | { |
1212 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); | 1247 | SSLerr(SSL_F_SSL3_GET_CERTIFICATE_REQUEST,ERR_R_MALLOC_FAILURE); |
1213 | goto err; | 1248 | goto err; |
@@ -1227,24 +1262,22 @@ cont: | |||
1227 | s->s3->tmp.cert_req=1; | 1262 | s->s3->tmp.cert_req=1; |
1228 | s->s3->tmp.ctype_num=ctype_num; | 1263 | s->s3->tmp.ctype_num=ctype_num; |
1229 | if (s->s3->tmp.ca_names != NULL) | 1264 | if (s->s3->tmp.ca_names != NULL) |
1230 | sk_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | 1265 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); |
1231 | s->s3->tmp.ca_names=ca_sk; | 1266 | s->s3->tmp.ca_names=ca_sk; |
1232 | ca_sk=NULL; | 1267 | ca_sk=NULL; |
1233 | 1268 | ||
1234 | ret=1; | 1269 | ret=1; |
1235 | err: | 1270 | err: |
1236 | if (ca_sk != NULL) sk_pop_free(ca_sk,X509_NAME_free); | 1271 | if (ca_sk != NULL) sk_X509_NAME_pop_free(ca_sk,X509_NAME_free); |
1237 | return(ret); | 1272 | return(ret); |
1238 | } | 1273 | } |
1239 | 1274 | ||
1240 | static int ca_dn_cmp(a,b) | 1275 | static int ca_dn_cmp(X509_NAME **a, X509_NAME **b) |
1241 | X509_NAME **a,**b; | ||
1242 | { | 1276 | { |
1243 | return(X509_NAME_cmp(*a,*b)); | 1277 | return(X509_NAME_cmp(*a,*b)); |
1244 | } | 1278 | } |
1245 | 1279 | ||
1246 | static int ssl3_get_server_done(s) | 1280 | static int ssl3_get_server_done(SSL *s) |
1247 | SSL *s; | ||
1248 | { | 1281 | { |
1249 | int ok,ret=0; | 1282 | int ok,ret=0; |
1250 | long n; | 1283 | long n; |
@@ -1267,13 +1300,15 @@ SSL *s; | |||
1267 | return(ret); | 1300 | return(ret); |
1268 | } | 1301 | } |
1269 | 1302 | ||
1270 | static int ssl3_send_client_key_exchange(s) | 1303 | static int ssl3_send_client_key_exchange(SSL *s) |
1271 | SSL *s; | ||
1272 | { | 1304 | { |
1273 | unsigned char *p,*q,*d; | 1305 | unsigned char *p,*d; |
1274 | int n; | 1306 | int n; |
1275 | unsigned long l; | 1307 | unsigned long l; |
1308 | #ifndef NO_RSA | ||
1309 | unsigned char *q; | ||
1276 | EVP_PKEY *pkey=NULL; | 1310 | EVP_PKEY *pkey=NULL; |
1311 | #endif | ||
1277 | 1312 | ||
1278 | if (s->state == SSL3_ST_CW_KEY_EXCH_A) | 1313 | if (s->state == SSL3_ST_CW_KEY_EXCH_A) |
1279 | { | 1314 | { |
@@ -1286,13 +1321,13 @@ SSL *s; | |||
1286 | if (l & SSL_kRSA) | 1321 | if (l & SSL_kRSA) |
1287 | { | 1322 | { |
1288 | RSA *rsa; | 1323 | RSA *rsa; |
1289 | unsigned char tmp_buf[48]; | 1324 | unsigned char tmp_buf[SSL_MAX_MASTER_KEY_LENGTH]; |
1290 | 1325 | ||
1291 | if (s->session->cert->rsa_tmp != NULL) | 1326 | if (s->session->sess_cert->peer_rsa_tmp != NULL) |
1292 | rsa=s->session->cert->rsa_tmp; | 1327 | rsa=s->session->sess_cert->peer_rsa_tmp; |
1293 | else | 1328 | else |
1294 | { | 1329 | { |
1295 | pkey=X509_get_pubkey(s->session->cert->pkeys[SSL_PKEY_RSA_ENC].x509); | 1330 | pkey=X509_get_pubkey(s->session->sess_cert->peer_pkeys[SSL_PKEY_RSA_ENC].x509); |
1296 | if ((pkey == NULL) || | 1331 | if ((pkey == NULL) || |
1297 | (pkey->type != EVP_PKEY_RSA) || | 1332 | (pkey->type != EVP_PKEY_RSA) || |
1298 | (pkey->pkey.rsa == NULL)) | 1333 | (pkey->pkey.rsa == NULL)) |
@@ -1301,10 +1336,11 @@ SSL *s; | |||
1301 | goto err; | 1336 | goto err; |
1302 | } | 1337 | } |
1303 | rsa=pkey->pkey.rsa; | 1338 | rsa=pkey->pkey.rsa; |
1339 | EVP_PKEY_free(pkey); | ||
1304 | } | 1340 | } |
1305 | 1341 | ||
1306 | tmp_buf[0]=s->version>>8; | 1342 | tmp_buf[0]=s->client_version>>8; |
1307 | tmp_buf[1]=s->version&0xff; | 1343 | tmp_buf[1]=s->client_version&0xff; |
1308 | RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2); | 1344 | RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2); |
1309 | 1345 | ||
1310 | s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; | 1346 | s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; |
@@ -1315,6 +1351,10 @@ SSL *s; | |||
1315 | p+=2; | 1351 | p+=2; |
1316 | n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH, | 1352 | n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH, |
1317 | tmp_buf,p,rsa,RSA_PKCS1_PADDING); | 1353 | tmp_buf,p,rsa,RSA_PKCS1_PADDING); |
1354 | #ifdef PKCS1_CHECK | ||
1355 | if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++; | ||
1356 | if (s->options & SSL_OP_PKCS1_CHECK_2) tmp_buf[0]=0x70; | ||
1357 | #endif | ||
1318 | if (n <= 0) | 1358 | if (n <= 0) |
1319 | { | 1359 | { |
1320 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT); | 1360 | SSLerr(SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_ENCRYPT); |
@@ -1331,8 +1371,8 @@ SSL *s; | |||
1331 | s->session->master_key_length= | 1371 | s->session->master_key_length= |
1332 | s->method->ssl3_enc->generate_master_secret(s, | 1372 | s->method->ssl3_enc->generate_master_secret(s, |
1333 | s->session->master_key, | 1373 | s->session->master_key, |
1334 | tmp_buf,48); | 1374 | tmp_buf,SSL_MAX_MASTER_KEY_LENGTH); |
1335 | memset(tmp_buf,0,48); | 1375 | memset(tmp_buf,0,SSL_MAX_MASTER_KEY_LENGTH); |
1336 | } | 1376 | } |
1337 | else | 1377 | else |
1338 | #endif | 1378 | #endif |
@@ -1341,8 +1381,8 @@ SSL *s; | |||
1341 | { | 1381 | { |
1342 | DH *dh_srvr,*dh_clnt; | 1382 | DH *dh_srvr,*dh_clnt; |
1343 | 1383 | ||
1344 | if (s->session->cert->dh_tmp != NULL) | 1384 | if (s->session->sess_cert->peer_dh_tmp != NULL) |
1345 | dh_srvr=s->session->cert->dh_tmp; | 1385 | dh_srvr=s->session->sess_cert->peer_dh_tmp; |
1346 | else | 1386 | else |
1347 | { | 1387 | { |
1348 | /* we get them from the cert */ | 1388 | /* we get them from the cert */ |
@@ -1414,13 +1454,14 @@ err: | |||
1414 | return(-1); | 1454 | return(-1); |
1415 | } | 1455 | } |
1416 | 1456 | ||
1417 | static int ssl3_send_client_verify(s) | 1457 | static int ssl3_send_client_verify(SSL *s) |
1418 | SSL *s; | ||
1419 | { | 1458 | { |
1420 | unsigned char *p,*d; | 1459 | unsigned char *p,*d; |
1421 | unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; | 1460 | unsigned char data[MD5_DIGEST_LENGTH+SHA_DIGEST_LENGTH]; |
1422 | EVP_PKEY *pkey; | 1461 | EVP_PKEY *pkey; |
1462 | #ifndef NO_RSA | ||
1423 | int i=0; | 1463 | int i=0; |
1464 | #endif | ||
1424 | unsigned long n; | 1465 | unsigned long n; |
1425 | #ifndef NO_DSA | 1466 | #ifndef NO_DSA |
1426 | int j; | 1467 | int j; |
@@ -1485,8 +1526,7 @@ err: | |||
1485 | return(-1); | 1526 | return(-1); |
1486 | } | 1527 | } |
1487 | 1528 | ||
1488 | static int ssl3_send_client_certificate(s) | 1529 | static int ssl3_send_client_certificate(SSL *s) |
1489 | SSL *s; | ||
1490 | { | 1530 | { |
1491 | X509 *x509=NULL; | 1531 | X509 *x509=NULL; |
1492 | EVP_PKEY *pkey=NULL; | 1532 | EVP_PKEY *pkey=NULL; |
@@ -1565,19 +1605,22 @@ SSL *s; | |||
1565 | 1605 | ||
1566 | #define has_bits(i,m) (((i)&(m)) == (m)) | 1606 | #define has_bits(i,m) (((i)&(m)) == (m)) |
1567 | 1607 | ||
1568 | static int ssl3_check_cert_and_algorithm(s) | 1608 | static int ssl3_check_cert_and_algorithm(SSL *s) |
1569 | SSL *s; | ||
1570 | { | 1609 | { |
1571 | int i,idx; | 1610 | int i,idx; |
1572 | long algs; | 1611 | long algs; |
1573 | EVP_PKEY *pkey=NULL; | 1612 | EVP_PKEY *pkey=NULL; |
1574 | CERT *c; | 1613 | SESS_CERT *sc; |
1614 | #ifndef NO_RSA | ||
1575 | RSA *rsa; | 1615 | RSA *rsa; |
1616 | #endif | ||
1617 | #ifndef NO_DH | ||
1576 | DH *dh; | 1618 | DH *dh; |
1619 | #endif | ||
1577 | 1620 | ||
1578 | c=s->session->cert; | 1621 | sc=s->session->sess_cert; |
1579 | 1622 | ||
1580 | if (c == NULL) | 1623 | if (sc == NULL) |
1581 | { | 1624 | { |
1582 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR); | 1625 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_INTERNAL_ERROR); |
1583 | goto err; | 1626 | goto err; |
@@ -1589,14 +1632,19 @@ SSL *s; | |||
1589 | if (algs & (SSL_aDH|SSL_aNULL)) | 1632 | if (algs & (SSL_aDH|SSL_aNULL)) |
1590 | return(1); | 1633 | return(1); |
1591 | 1634 | ||
1592 | rsa=s->session->cert->rsa_tmp; | 1635 | #ifndef NO_RSA |
1593 | dh=s->session->cert->dh_tmp; | 1636 | rsa=s->session->sess_cert->peer_rsa_tmp; |
1637 | #endif | ||
1638 | #ifndef NO_DH | ||
1639 | dh=s->session->sess_cert->peer_dh_tmp; | ||
1640 | #endif | ||
1594 | 1641 | ||
1595 | /* This is the passed certificate */ | 1642 | /* This is the passed certificate */ |
1596 | 1643 | ||
1597 | idx=c->cert_type; | 1644 | idx=sc->peer_cert_type; |
1598 | pkey=X509_get_pubkey(c->pkeys[idx].x509); | 1645 | pkey=X509_get_pubkey(sc->peer_pkeys[idx].x509); |
1599 | i=X509_certificate_type(c->pkeys[idx].x509,pkey); | 1646 | i=X509_certificate_type(sc->peer_pkeys[idx].x509,pkey); |
1647 | EVP_PKEY_free(pkey); | ||
1600 | 1648 | ||
1601 | 1649 | ||
1602 | /* Check that we have a certificate if we require one */ | 1650 | /* Check that we have a certificate if we require one */ |
@@ -1612,15 +1660,16 @@ SSL *s; | |||
1612 | goto f_err; | 1660 | goto f_err; |
1613 | } | 1661 | } |
1614 | #endif | 1662 | #endif |
1615 | 1663 | #ifndef NO_RSA | |
1616 | if ((algs & SSL_kRSA) && | 1664 | if ((algs & SSL_kRSA) && |
1617 | !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL))) | 1665 | !(has_bits(i,EVP_PK_RSA|EVP_PKT_ENC) || (rsa != NULL))) |
1618 | { | 1666 | { |
1619 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT); | 1667 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_RSA_ENCRYPTING_CERT); |
1620 | goto f_err; | 1668 | goto f_err; |
1621 | } | 1669 | } |
1670 | #endif | ||
1622 | #ifndef NO_DH | 1671 | #ifndef NO_DH |
1623 | else if ((algs & SSL_kEDH) && | 1672 | if ((algs & SSL_kEDH) && |
1624 | !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL))) | 1673 | !(has_bits(i,EVP_PK_DH|EVP_PKT_EXCH) || (dh != NULL))) |
1625 | { | 1674 | { |
1626 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY); | 1675 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_DH_KEY); |
@@ -1640,12 +1689,13 @@ SSL *s; | |||
1640 | #endif | 1689 | #endif |
1641 | #endif | 1690 | #endif |
1642 | 1691 | ||
1643 | if ((algs & SSL_EXP) && !has_bits(i,EVP_PKT_EXP)) | 1692 | if (SSL_IS_EXPORT(algs) && !has_bits(i,EVP_PKT_EXP)) |
1644 | { | 1693 | { |
1645 | #ifndef NO_RSA | 1694 | #ifndef NO_RSA |
1646 | if (algs & SSL_kRSA) | 1695 | if (algs & SSL_kRSA) |
1647 | { | 1696 | { |
1648 | if ((rsa == NULL) || (RSA_size(rsa) > 512)) | 1697 | if (rsa == NULL |
1698 | || RSA_size(rsa) > SSL_EXPORT_PKEYLENGTH(algs)) | ||
1649 | { | 1699 | { |
1650 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY); | 1700 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_RSA_KEY); |
1651 | goto f_err; | 1701 | goto f_err; |
@@ -1655,8 +1705,9 @@ SSL *s; | |||
1655 | #endif | 1705 | #endif |
1656 | #ifndef NO_DH | 1706 | #ifndef NO_DH |
1657 | if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) | 1707 | if (algs & (SSL_kEDH|SSL_kDHr|SSL_kDHd)) |
1658 | { | 1708 | { |
1659 | if ((dh == NULL) || (DH_size(dh) > 512)) | 1709 | if (dh == NULL |
1710 | || DH_size(dh) > SSL_EXPORT_PKEYLENGTH(algs)) | ||
1660 | { | 1711 | { |
1661 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY); | 1712 | SSLerr(SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM,SSL_R_MISSING_EXPORT_TMP_DH_KEY); |
1662 | goto f_err; | 1713 | goto f_err; |