diff options
author | jsing <> | 2017-01-25 10:54:23 +0000 |
---|---|---|
committer | jsing <> | 2017-01-25 10:54:23 +0000 |
commit | 9c630e61dcded74cfa27eb586f9410dd7bf99358 (patch) | |
tree | 2f63538a996d3eb1b9f5ed2648f750a11966a5b3 /src | |
parent | 091d543c37fec7ed9a3ce3c5302e6f42190856d4 (diff) | |
download | openbsd-9c630e61dcded74cfa27eb586f9410dd7bf99358.tar.gz openbsd-9c630e61dcded74cfa27eb586f9410dd7bf99358.tar.bz2 openbsd-9c630e61dcded74cfa27eb586f9410dd7bf99358.zip |
Limit enabled version range by the versions configured on the SSL_CTX/SSL,
provide an ssl_supported_versions_range() function which also limits the
versions to those supported by the current method.
ok beck@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libssl/s23_clnt.c | 5 | ||||
-rw-r--r-- | src/lib/libssl/ssl_lib.c | 99 | ||||
-rw-r--r-- | src/lib/libssl/ssl_locl.h | 3 |
3 files changed, 84 insertions, 23 deletions
diff --git a/src/lib/libssl/s23_clnt.c b/src/lib/libssl/s23_clnt.c index b2dc912a9c..4a7641b818 100644 --- a/src/lib/libssl/s23_clnt.c +++ b/src/lib/libssl/s23_clnt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: s23_clnt.c,v 1.56 2017/01/23 14:35:42 jsing Exp $ */ | 1 | /* $OpenBSD: s23_clnt.c,v 1.57 2017/01/25 10:54:23 jsing 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 | * |
@@ -239,12 +239,11 @@ ssl23_client_hello(SSL *s) | |||
239 | if (s->internal->state == SSL23_ST_CW_CLNT_HELLO_A) { | 239 | if (s->internal->state == SSL23_ST_CW_CLNT_HELLO_A) { |
240 | arc4random_buf(s->s3->client_random, SSL3_RANDOM_SIZE); | 240 | arc4random_buf(s->s3->client_random, SSL3_RANDOM_SIZE); |
241 | 241 | ||
242 | if (ssl_enabled_version_range(s, NULL, &version) != 1) { | 242 | if (ssl_supported_version_range(s, NULL, &version) != 1) { |
243 | SSLerr(SSL_F_SSL23_CLIENT_HELLO, | 243 | SSLerr(SSL_F_SSL23_CLIENT_HELLO, |
244 | SSL_R_NO_PROTOCOLS_AVAILABLE); | 244 | SSL_R_NO_PROTOCOLS_AVAILABLE); |
245 | return (-1); | 245 | return (-1); |
246 | } | 246 | } |
247 | |||
248 | s->client_version = version; | 247 | s->client_version = version; |
249 | 248 | ||
250 | /* create Client Hello in SSL 3.0/TLS 1.0 format */ | 249 | /* create Client Hello in SSL 3.0/TLS 1.0 format */ |
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index 29bce5414a..8afb4909c3 100644 --- a/src/lib/libssl/ssl_lib.c +++ b/src/lib/libssl/ssl_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_lib.c,v 1.149 2017/01/24 15:11:55 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_lib.c,v 1.150 2017/01/25 10:54:23 jsing 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 | * |
@@ -284,6 +284,9 @@ SSL_new(SSL_CTX *ctx) | |||
284 | return (NULL); | 284 | return (NULL); |
285 | } | 285 | } |
286 | 286 | ||
287 | s->internal->min_version = ctx->internal->min_version; | ||
288 | s->internal->max_version = ctx->internal->max_version; | ||
289 | |||
287 | s->internal->options = ctx->internal->options; | 290 | s->internal->options = ctx->internal->options; |
288 | s->internal->mode = ctx->internal->mode; | 291 | s->internal->mode = ctx->internal->mode; |
289 | s->internal->max_cert_list = ctx->internal->max_cert_list; | 292 | s->internal->max_cert_list = ctx->internal->max_cert_list; |
@@ -1842,6 +1845,8 @@ SSL_CTX_new(const SSL_METHOD *meth) | |||
1842 | } | 1845 | } |
1843 | 1846 | ||
1844 | ret->method = meth; | 1847 | ret->method = meth; |
1848 | ret->internal->min_version = meth->internal->min_version; | ||
1849 | ret->internal->max_version = meth->internal->max_version; | ||
1845 | 1850 | ||
1846 | ret->cert_store = NULL; | 1851 | ret->cert_store = NULL; |
1847 | ret->internal->session_cache_mode = SSL_SESS_CACHE_SERVER; | 1852 | ret->internal->session_cache_mode = SSL_SESS_CACHE_SERVER; |
@@ -2514,6 +2519,23 @@ SSL_get_version(const SSL *s) | |||
2514 | return ssl_version_string(s->version); | 2519 | return ssl_version_string(s->version); |
2515 | } | 2520 | } |
2516 | 2521 | ||
2522 | static int | ||
2523 | ssl_clamp_version_range(uint16_t *min_ver, uint16_t *max_ver, | ||
2524 | uint16_t clamp_min, uint16_t clamp_max) | ||
2525 | { | ||
2526 | if (clamp_min > clamp_max || *min_ver > *max_ver) | ||
2527 | return 0; | ||
2528 | if (clamp_max < *min_ver || clamp_min > *max_ver) | ||
2529 | return 0; | ||
2530 | |||
2531 | if (*min_ver < clamp_min) | ||
2532 | *min_ver = clamp_min; | ||
2533 | if (*max_ver > clamp_max) | ||
2534 | *max_ver = clamp_max; | ||
2535 | |||
2536 | return 1; | ||
2537 | } | ||
2538 | |||
2517 | int | 2539 | int |
2518 | ssl_enabled_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver) | 2540 | ssl_enabled_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver) |
2519 | { | 2541 | { |
@@ -2548,6 +2570,40 @@ ssl_enabled_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver) | |||
2548 | if (min_version == 0 || max_version == 0) | 2570 | if (min_version == 0 || max_version == 0) |
2549 | return 0; | 2571 | return 0; |
2550 | 2572 | ||
2573 | /* Limit to configured version range. */ | ||
2574 | if (!ssl_clamp_version_range(&min_version, &max_version, | ||
2575 | s->internal->min_version, s->internal->max_version)) | ||
2576 | return 0; | ||
2577 | |||
2578 | if (min_ver != NULL) | ||
2579 | *min_ver = min_version; | ||
2580 | if (max_ver != NULL) | ||
2581 | *max_ver = max_version; | ||
2582 | |||
2583 | return 1; | ||
2584 | } | ||
2585 | |||
2586 | int | ||
2587 | ssl_supported_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver) | ||
2588 | { | ||
2589 | uint16_t min_version, max_version; | ||
2590 | |||
2591 | /* DTLS cannot currently be disabled... */ | ||
2592 | if (SSL_IS_DTLS(s)) { | ||
2593 | min_version = max_version = DTLS1_VERSION; | ||
2594 | goto done; | ||
2595 | } | ||
2596 | |||
2597 | if (!ssl_enabled_version_range(s, &min_version, &max_version)) | ||
2598 | return 0; | ||
2599 | |||
2600 | /* Limit to the versions supported by this method. */ | ||
2601 | if (!ssl_clamp_version_range(&min_version, &max_version, | ||
2602 | s->method->internal->min_version, | ||
2603 | s->method->internal->max_version)) | ||
2604 | return 0; | ||
2605 | |||
2606 | done: | ||
2551 | if (min_ver != NULL) | 2607 | if (min_ver != NULL) |
2552 | *min_ver = min_version; | 2608 | *min_ver = min_version; |
2553 | if (max_ver != NULL) | 2609 | if (max_ver != NULL) |
@@ -2563,6 +2619,14 @@ ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver) | |||
2563 | 2619 | ||
2564 | *max_ver = 0; | 2620 | *max_ver = 0; |
2565 | 2621 | ||
2622 | if (SSL_IS_DTLS(s)) { | ||
2623 | if (peer_ver >= DTLS1_VERSION) { | ||
2624 | *max_ver = DTLS1_VERSION; | ||
2625 | return 1; | ||
2626 | } | ||
2627 | return 0; | ||
2628 | } | ||
2629 | |||
2566 | if (peer_ver >= TLS1_2_VERSION) | 2630 | if (peer_ver >= TLS1_2_VERSION) |
2567 | shared_version = TLS1_2_VERSION; | 2631 | shared_version = TLS1_2_VERSION; |
2568 | else if (peer_ver >= TLS1_1_VERSION) | 2632 | else if (peer_ver >= TLS1_1_VERSION) |
@@ -2572,7 +2636,7 @@ ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver) | |||
2572 | else | 2636 | else |
2573 | return 0; | 2637 | return 0; |
2574 | 2638 | ||
2575 | if (!ssl_enabled_version_range(s, &min_version, &max_version)) | 2639 | if (!ssl_supported_version_range(s, &min_version, &max_version)) |
2576 | return 0; | 2640 | return 0; |
2577 | 2641 | ||
2578 | if (shared_version < min_version) | 2642 | if (shared_version < min_version) |
@@ -2589,28 +2653,25 @@ ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver) | |||
2589 | uint16_t | 2653 | uint16_t |
2590 | ssl_max_server_version(SSL *s) | 2654 | ssl_max_server_version(SSL *s) |
2591 | { | 2655 | { |
2592 | uint16_t max_version; | 2656 | uint16_t max_version, min_version = 0; |
2593 | |||
2594 | /* | ||
2595 | * The SSL method will be changed during version negotiation, as such | ||
2596 | * we want to use the SSL method from the context. | ||
2597 | */ | ||
2598 | max_version = s->ctx->method->internal->version; | ||
2599 | 2657 | ||
2600 | if (SSL_IS_DTLS(s)) | 2658 | if (SSL_IS_DTLS(s)) |
2601 | return (DTLS1_VERSION); | 2659 | return (DTLS1_VERSION); |
2602 | 2660 | ||
2603 | if ((s->internal->options & SSL_OP_NO_TLSv1_2) == 0 && | 2661 | if (!ssl_enabled_version_range(s, &min_version, &max_version)) |
2604 | max_version >= TLS1_2_VERSION) | 2662 | return 0; |
2605 | return (TLS1_2_VERSION); | ||
2606 | if ((s->internal->options & SSL_OP_NO_TLSv1_1) == 0 && | ||
2607 | max_version >= TLS1_1_VERSION) | ||
2608 | return (TLS1_1_VERSION); | ||
2609 | if ((s->internal->options & SSL_OP_NO_TLSv1) == 0 && | ||
2610 | max_version >= TLS1_VERSION) | ||
2611 | return (TLS1_VERSION); | ||
2612 | 2663 | ||
2613 | return (0); | 2664 | /* |
2665 | * Limit to the versions supported by this method. The SSL method | ||
2666 | * will be changed during version negotiation, as such we want to | ||
2667 | * use the SSL method from the context. | ||
2668 | */ | ||
2669 | if (!ssl_clamp_version_range(&min_version, &max_version, | ||
2670 | s->ctx->method->internal->min_version, | ||
2671 | s->ctx->method->internal->max_version)) | ||
2672 | return 0; | ||
2673 | |||
2674 | return (max_version); | ||
2614 | } | 2675 | } |
2615 | 2676 | ||
2616 | SSL * | 2677 | SSL * |
diff --git a/src/lib/libssl/ssl_locl.h b/src/lib/libssl/ssl_locl.h index 64725a7b23..7c3fb4f5e4 100644 --- a/src/lib/libssl/ssl_locl.h +++ b/src/lib/libssl/ssl_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl_locl.h,v 1.166 2017/01/25 06:38:01 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_locl.h,v 1.167 2017/01/25 10:54:23 jsing 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 | * |
@@ -1079,6 +1079,7 @@ extern SSL_CIPHER ssl3_ciphers[]; | |||
1079 | 1079 | ||
1080 | const char *ssl_version_string(int ver); | 1080 | const char *ssl_version_string(int ver); |
1081 | int ssl_enabled_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver); | 1081 | int ssl_enabled_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver); |
1082 | int ssl_supported_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver); | ||
1082 | int ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver); | 1083 | int ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver); |
1083 | uint16_t ssl_max_server_version(SSL *s); | 1084 | uint16_t ssl_max_server_version(SSL *s); |
1084 | 1085 | ||