diff options
author | guenther <> | 2014-04-16 15:10:07 +0000 |
---|---|---|
committer | guenther <> | 2014-04-16 15:10:07 +0000 |
commit | 07d70e2f624616050545c4fb6f6ba748c12b342e (patch) | |
tree | cd6b7bd17edfb25d9928b1c38f811f45391e4e97 /src/lib/libssl/ssl_lib.c | |
parent | 0e08f2db38e867e26107d9826aa489a211882fb1 (diff) | |
download | openbsd-07d70e2f624616050545c4fb6f6ba748c12b342e.tar.gz openbsd-07d70e2f624616050545c4fb6f6ba748c12b342e.tar.bz2 openbsd-07d70e2f624616050545c4fb6f6ba748c12b342e.zip |
Kill the bogus "send an SSLv3/TLS hello in SSLv2 format" crap from
the SSLv23_* client code. The server continues to accept it. It
also kills the bits for SSL2 SESSIONs; even when the server gets
an SSLv2-style compat handshake, the session that it creates has
the correct version internally.
ok tedu@ beck@
Diffstat (limited to 'src/lib/libssl/ssl_lib.c')
-rw-r--r-- | src/lib/libssl/ssl_lib.c | 84 |
1 files changed, 32 insertions, 52 deletions
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index b5ba0f4aac..a0882e4521 100644 --- a/src/lib/libssl/ssl_lib.c +++ b/src/lib/libssl/ssl_lib.c | |||
@@ -250,7 +250,7 @@ SSL_clear(SSL *s) | |||
250 | return (1); | 250 | return (1); |
251 | } | 251 | } |
252 | 252 | ||
253 | /** Used to change an SSL_CTXs default SSL method type */ | 253 | /* Used to change an SSL_CTXs default SSL method type */ |
254 | int | 254 | int |
255 | SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth) | 255 | SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth) |
256 | { | 256 | { |
@@ -259,8 +259,7 @@ SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth) | |||
259 | ctx->method = meth; | 259 | ctx->method = meth; |
260 | 260 | ||
261 | sk = ssl_create_cipher_list(ctx->method, &(ctx->cipher_list), | 261 | sk = ssl_create_cipher_list(ctx->method, &(ctx->cipher_list), |
262 | &(ctx->cipher_list_by_id), | 262 | &(ctx->cipher_list_by_id), SSL_DEFAULT_CIPHER_LIST); |
263 | meth->version == SSL2_VERSION ? "SSLv2" : SSL_DEFAULT_CIPHER_LIST); | ||
264 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) { | 263 | if ((sk == NULL) || (sk_SSL_CIPHER_num(sk) <= 0)) { |
265 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION, SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); | 264 | SSLerr(SSL_F_SSL_CTX_SET_SSL_VERSION, SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS); |
266 | return (0); | 265 | return (0); |
@@ -437,11 +436,13 @@ int | |||
437 | SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, | 436 | SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, |
438 | unsigned int id_len) | 437 | unsigned int id_len) |
439 | { | 438 | { |
440 | /* A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp shows how | 439 | /* |
441 | * we can "construct" a session to give us the desired check - ie. to | 440 | * A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp |
442 | * find if there's a session in the hash table that would conflict with | 441 | * shows how we can "construct" a session to give us the desired |
443 | * any new session built out of this id/id_len and the ssl_version in | 442 | * check - ie. to find if there's a session in the hash table |
444 | * use by this SSL. */ | 443 | * that would conflict with any new session built out of this |
444 | * id/id_len and the ssl_version in use by this SSL. | ||
445 | */ | ||
445 | SSL_SESSION r, *p; | 446 | SSL_SESSION r, *p; |
446 | 447 | ||
447 | if (id_len > sizeof r.session_id) | 448 | if (id_len > sizeof r.session_id) |
@@ -450,16 +451,6 @@ SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, | |||
450 | r.ssl_version = ssl->version; | 451 | r.ssl_version = ssl->version; |
451 | r.session_id_length = id_len; | 452 | r.session_id_length = id_len; |
452 | memcpy(r.session_id, id, id_len); | 453 | memcpy(r.session_id, id, id_len); |
453 | /* NB: SSLv2 always uses a fixed 16-byte session ID, so even if a | ||
454 | * callback is calling us to check the uniqueness of a shorter ID, it | ||
455 | * must be compared as a padded-out ID because that is what it will be | ||
456 | * converted to when the callback has finished choosing it. */ | ||
457 | if ((r.ssl_version == SSL2_VERSION) && | ||
458 | (id_len < SSL2_SSL_SESSION_ID_LENGTH)) { | ||
459 | memset(r.session_id + id_len, 0, | ||
460 | SSL2_SSL_SESSION_ID_LENGTH - id_len); | ||
461 | r.session_id_length = SSL2_SSL_SESSION_ID_LENGTH; | ||
462 | } | ||
463 | 454 | ||
464 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); | 455 | CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX); |
465 | p = lh_SSL_SESSION_retrieve(ssl->ctx->sessions, &r); | 456 | p = lh_SSL_SESSION_retrieve(ssl->ctx->sessions, &r); |
@@ -1777,11 +1768,10 @@ SSL_CTX | |||
1777 | if (ret->cert_store == NULL) | 1768 | if (ret->cert_store == NULL) |
1778 | goto err; | 1769 | goto err; |
1779 | 1770 | ||
1780 | ssl_create_cipher_list(ret->method, | 1771 | ssl_create_cipher_list(ret->method, &ret->cipher_list, |
1781 | &ret->cipher_list, &ret->cipher_list_by_id, | 1772 | &ret->cipher_list_by_id, SSL_DEFAULT_CIPHER_LIST); |
1782 | meth->version == SSL2_VERSION ? "SSLv2" : SSL_DEFAULT_CIPHER_LIST); | 1773 | if (ret->cipher_list == NULL || |
1783 | if (ret->cipher_list == NULL | 1774 | sk_SSL_CIPHER_num(ret->cipher_list) <= 0) { |
1784 | || sk_SSL_CIPHER_num(ret->cipher_list) <= 0) { | ||
1785 | SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_LIBRARY_HAS_NO_CIPHERS); | 1775 | SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_LIBRARY_HAS_NO_CIPHERS); |
1786 | goto err2; | 1776 | goto err2; |
1787 | } | 1777 | } |
@@ -1790,10 +1780,6 @@ SSL_CTX | |||
1790 | if (!ret->param) | 1780 | if (!ret->param) |
1791 | goto err; | 1781 | goto err; |
1792 | 1782 | ||
1793 | if ((ret->rsa_md5 = EVP_get_digestbyname("ssl2-md5")) == NULL) { | ||
1794 | SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES); | ||
1795 | goto err2; | ||
1796 | } | ||
1797 | if ((ret->md5 = EVP_get_digestbyname("ssl3-md5")) == NULL) { | 1783 | if ((ret->md5 = EVP_get_digestbyname("ssl3-md5")) == NULL) { |
1798 | SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES); | 1784 | SSLerr(SSL_F_SSL_CTX_NEW, SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES); |
1799 | goto err2; | 1785 | goto err2; |
@@ -2483,15 +2469,16 @@ SSL_get_error(const SSL *s, int i) | |||
2483 | if (BIO_should_read(bio)) | 2469 | if (BIO_should_read(bio)) |
2484 | return (SSL_ERROR_WANT_READ); | 2470 | return (SSL_ERROR_WANT_READ); |
2485 | else if (BIO_should_write(bio)) | 2471 | else if (BIO_should_write(bio)) |
2486 | /* This one doesn't make too much sense ... We never try | 2472 | /* |
2487 | * to write to the rbio, and an application program where | 2473 | * This one doesn't make too much sense... We never |
2488 | * rbio and wbio are separate couldn't even know what it | 2474 | * try to write to the rbio, and an application |
2489 | * should wait for. | 2475 | * program where rbio and wbio are separate couldn't |
2490 | * However if we ever set s->rwstate incorrectly | 2476 | * even know what it should wait for. However if we |
2491 | * (so that we have SSL_want_read(s) instead of | 2477 | * ever set s->rwstate incorrectly (so that we have |
2492 | * SSL_want_write(s)) and rbio and wbio *are* the same, | 2478 | * SSL_want_read(s) instead of SSL_want_write(s)) |
2493 | * this test works around that bug; so it might be safer | 2479 | * and rbio and wbio *are* the same, this test works |
2494 | * to keep it. */ | 2480 | * around that bug; so it might be safer to keep it. |
2481 | */ | ||
2495 | return (SSL_ERROR_WANT_WRITE); | 2482 | return (SSL_ERROR_WANT_WRITE); |
2496 | else if (BIO_should_io_special(bio)) { | 2483 | else if (BIO_should_io_special(bio)) { |
2497 | reason = BIO_get_retry_reason(bio); | 2484 | reason = BIO_get_retry_reason(bio); |
@@ -2526,14 +2513,9 @@ SSL_get_error(const SSL *s, int i) | |||
2526 | } | 2513 | } |
2527 | 2514 | ||
2528 | if (i == 0) { | 2515 | if (i == 0) { |
2529 | if (s->version == SSL2_VERSION) { | 2516 | if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) && |
2530 | /* assume it is the socket being closed */ | 2517 | (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY)) |
2531 | return (SSL_ERROR_ZERO_RETURN); | 2518 | return (SSL_ERROR_ZERO_RETURN); |
2532 | } else { | ||
2533 | if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) && | ||
2534 | (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY)) | ||
2535 | return (SSL_ERROR_ZERO_RETURN); | ||
2536 | } | ||
2537 | } | 2519 | } |
2538 | return (SSL_ERROR_SYSCALL); | 2520 | return (SSL_ERROR_SYSCALL); |
2539 | } | 2521 | } |
@@ -2605,15 +2587,15 @@ ssl_undefined_const_function(const SSL *s) | |||
2605 | return (0); | 2587 | return (0); |
2606 | } | 2588 | } |
2607 | 2589 | ||
2608 | SSL_METHOD | 2590 | SSL_METHOD * |
2609 | *ssl_bad_method(int ver) | 2591 | ssl_bad_method(int ver) |
2610 | { | 2592 | { |
2611 | SSLerr(SSL_F_SSL_BAD_METHOD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 2593 | SSLerr(SSL_F_SSL_BAD_METHOD, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
2612 | return (NULL); | 2594 | return (NULL); |
2613 | } | 2595 | } |
2614 | 2596 | ||
2615 | const char | 2597 | const char * |
2616 | *SSL_get_version(const SSL *s) | 2598 | SSL_get_version(const SSL *s) |
2617 | { | 2599 | { |
2618 | if (s->version == TLS1_2_VERSION) | 2600 | if (s->version == TLS1_2_VERSION) |
2619 | return("TLSv1.2"); | 2601 | return("TLSv1.2"); |
@@ -2623,14 +2605,12 @@ const char | |||
2623 | return("TLSv1"); | 2605 | return("TLSv1"); |
2624 | else if (s->version == SSL3_VERSION) | 2606 | else if (s->version == SSL3_VERSION) |
2625 | return("SSLv3"); | 2607 | return("SSLv3"); |
2626 | else if (s->version == SSL2_VERSION) | ||
2627 | return("SSLv2"); | ||
2628 | else | 2608 | else |
2629 | return("unknown"); | 2609 | return("unknown"); |
2630 | } | 2610 | } |
2631 | 2611 | ||
2632 | SSL | 2612 | SSL * |
2633 | *SSL_dup(SSL *s) | 2613 | SSL_dup(SSL *s) |
2634 | { | 2614 | { |
2635 | STACK_OF(X509_NAME) *sk; | 2615 | STACK_OF(X509_NAME) *sk; |
2636 | X509_NAME *xn; | 2616 | X509_NAME *xn; |