diff options
Diffstat (limited to 'src/lib/libssl/s3_clnt.c')
-rw-r--r-- | src/lib/libssl/s3_clnt.c | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c index 7da9363ef5..d32bb1cb9c 100644 --- a/src/lib/libssl/s3_clnt.c +++ b/src/lib/libssl/s3_clnt.c | |||
@@ -145,18 +145,25 @@ SSL_METHOD *SSLv3_client_method(void) | |||
145 | 145 | ||
146 | if (init) | 146 | if (init) |
147 | { | 147 | { |
148 | init=0; | 148 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); |
149 | memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(), | 149 | |
150 | sizeof(SSL_METHOD)); | 150 | if (init) |
151 | SSLv3_client_data.ssl_connect=ssl3_connect; | 151 | { |
152 | SSLv3_client_data.get_ssl_method=ssl3_get_client_method; | 152 | memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(), |
153 | sizeof(SSL_METHOD)); | ||
154 | SSLv3_client_data.ssl_connect=ssl3_connect; | ||
155 | SSLv3_client_data.get_ssl_method=ssl3_get_client_method; | ||
156 | init=0; | ||
157 | } | ||
158 | |||
159 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
153 | } | 160 | } |
154 | return(&SSLv3_client_data); | 161 | return(&SSLv3_client_data); |
155 | } | 162 | } |
156 | 163 | ||
157 | int ssl3_connect(SSL *s) | 164 | int ssl3_connect(SSL *s) |
158 | { | 165 | { |
159 | BUF_MEM *buf; | 166 | BUF_MEM *buf=NULL; |
160 | unsigned long Time=time(NULL),l; | 167 | unsigned long Time=time(NULL),l; |
161 | long num1; | 168 | long num1; |
162 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | 169 | void (*cb)(const SSL *ssl,int type,int val)=NULL; |
@@ -217,6 +224,7 @@ int ssl3_connect(SSL *s) | |||
217 | goto end; | 224 | goto end; |
218 | } | 225 | } |
219 | s->init_buf=buf; | 226 | s->init_buf=buf; |
227 | buf=NULL; | ||
220 | } | 228 | } |
221 | 229 | ||
222 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } | 230 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } |
@@ -495,6 +503,8 @@ int ssl3_connect(SSL *s) | |||
495 | } | 503 | } |
496 | end: | 504 | end: |
497 | s->in_handshake--; | 505 | s->in_handshake--; |
506 | if (buf != NULL) | ||
507 | BUF_MEM_free(buf); | ||
498 | if (cb != NULL) | 508 | if (cb != NULL) |
499 | cb(s,SSL_CB_CONNECT_EXIT,ret); | 509 | cb(s,SSL_CB_CONNECT_EXIT,ret); |
500 | return(ret); | 510 | return(ret); |
@@ -637,6 +647,7 @@ static int ssl3_get_server_hello(SSL *s) | |||
637 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_LONG); | 647 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_LONG); |
638 | goto f_err; | 648 | goto f_err; |
639 | } | 649 | } |
650 | |||
640 | if (j != 0 && j == s->session->session_id_length | 651 | if (j != 0 && j == s->session->session_id_length |
641 | && memcmp(p,s->session->session_id,j) == 0) | 652 | && memcmp(p,s->session->session_id,j) == 0) |
642 | { | 653 | { |
@@ -687,7 +698,12 @@ static int ssl3_get_server_hello(SSL *s) | |||
687 | goto f_err; | 698 | goto f_err; |
688 | } | 699 | } |
689 | 700 | ||
690 | if (s->hit && (s->session->cipher != c)) | 701 | /* Depending on the session caching (internal/external), the cipher |
702 | and/or cipher_id values may not be set. Make sure that | ||
703 | cipher_id is set and use it for comparison. */ | ||
704 | if (s->session->cipher) | ||
705 | s->session->cipher_id = s->session->cipher->id; | ||
706 | if (s->hit && (s->session->cipher_id != c->id)) | ||
691 | { | 707 | { |
692 | if (!(s->options & | 708 | if (!(s->options & |
693 | SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)) | 709 | SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)) |
@@ -1445,16 +1461,16 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1445 | 1461 | ||
1446 | tmp_buf[0]=s->client_version>>8; | 1462 | tmp_buf[0]=s->client_version>>8; |
1447 | tmp_buf[1]=s->client_version&0xff; | 1463 | tmp_buf[1]=s->client_version&0xff; |
1448 | if (RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2) <= 0) | 1464 | if (RAND_bytes(&(tmp_buf[2]),sizeof tmp_buf-2) <= 0) |
1449 | goto err; | 1465 | goto err; |
1450 | 1466 | ||
1451 | s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; | 1467 | s->session->master_key_length=sizeof tmp_buf; |
1452 | 1468 | ||
1453 | q=p; | 1469 | q=p; |
1454 | /* Fix buf for TLS and beyond */ | 1470 | /* Fix buf for TLS and beyond */ |
1455 | if (s->version > SSL3_VERSION) | 1471 | if (s->version > SSL3_VERSION) |
1456 | p+=2; | 1472 | p+=2; |
1457 | n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH, | 1473 | n=RSA_public_encrypt(sizeof tmp_buf, |
1458 | tmp_buf,p,rsa,RSA_PKCS1_PADDING); | 1474 | tmp_buf,p,rsa,RSA_PKCS1_PADDING); |
1459 | #ifdef PKCS1_CHECK | 1475 | #ifdef PKCS1_CHECK |
1460 | if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++; | 1476 | if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++; |
@@ -1476,8 +1492,8 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1476 | s->session->master_key_length= | 1492 | s->session->master_key_length= |
1477 | s->method->ssl3_enc->generate_master_secret(s, | 1493 | s->method->ssl3_enc->generate_master_secret(s, |
1478 | s->session->master_key, | 1494 | s->session->master_key, |
1479 | tmp_buf,SSL_MAX_MASTER_KEY_LENGTH); | 1495 | tmp_buf,sizeof tmp_buf); |
1480 | memset(tmp_buf,0,SSL_MAX_MASTER_KEY_LENGTH); | 1496 | OPENSSL_cleanse(tmp_buf,sizeof tmp_buf); |
1481 | } | 1497 | } |
1482 | #endif | 1498 | #endif |
1483 | #ifndef OPENSSL_NO_KRB5 | 1499 | #ifndef OPENSSL_NO_KRB5 |
@@ -1573,7 +1589,7 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1573 | n+=2; | 1589 | n+=2; |
1574 | } | 1590 | } |
1575 | 1591 | ||
1576 | if (RAND_bytes(tmp_buf,SSL_MAX_MASTER_KEY_LENGTH) <= 0) | 1592 | if (RAND_bytes(tmp_buf,sizeof tmp_buf) <= 0) |
1577 | goto err; | 1593 | goto err; |
1578 | 1594 | ||
1579 | /* 20010420 VRS. Tried it this way; failed. | 1595 | /* 20010420 VRS. Tried it this way; failed. |
@@ -1583,11 +1599,11 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1583 | ** EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv); | 1599 | ** EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv); |
1584 | */ | 1600 | */ |
1585 | 1601 | ||
1586 | memset(iv, 0, EVP_MAX_IV_LENGTH); /* per RFC 1510 */ | 1602 | memset(iv, 0, sizeof iv); /* per RFC 1510 */ |
1587 | EVP_EncryptInit_ex(&ciph_ctx,enc, NULL, | 1603 | EVP_EncryptInit_ex(&ciph_ctx,enc, NULL, |
1588 | kssl_ctx->key,iv); | 1604 | kssl_ctx->key,iv); |
1589 | EVP_EncryptUpdate(&ciph_ctx,epms,&outl,tmp_buf, | 1605 | EVP_EncryptUpdate(&ciph_ctx,epms,&outl,tmp_buf, |
1590 | SSL_MAX_MASTER_KEY_LENGTH); | 1606 | sizeof tmp_buf); |
1591 | EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl); | 1607 | EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl); |
1592 | outl += padl; | 1608 | outl += padl; |
1593 | if (outl > sizeof epms) | 1609 | if (outl > sizeof epms) |
@@ -1606,10 +1622,10 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1606 | s->session->master_key_length= | 1622 | s->session->master_key_length= |
1607 | s->method->ssl3_enc->generate_master_secret(s, | 1623 | s->method->ssl3_enc->generate_master_secret(s, |
1608 | s->session->master_key, | 1624 | s->session->master_key, |
1609 | tmp_buf, SSL_MAX_MASTER_KEY_LENGTH); | 1625 | tmp_buf, sizeof tmp_buf); |
1610 | 1626 | ||
1611 | memset(tmp_buf, 0, SSL_MAX_MASTER_KEY_LENGTH); | 1627 | OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); |
1612 | memset(epms, 0, outl); | 1628 | OPENSSL_cleanse(epms, outl); |
1613 | } | 1629 | } |
1614 | #endif | 1630 | #endif |
1615 | #ifndef OPENSSL_NO_DH | 1631 | #ifndef OPENSSL_NO_DH |