diff options
| author | jsing <> | 2020-09-17 15:23:29 +0000 |
|---|---|---|
| committer | jsing <> | 2020-09-17 15:23:29 +0000 |
| commit | ac608c91af9de9141849165d1599e500cf7010cc (patch) | |
| tree | ab0f21a1d37a85215ffbd688a792523e6b1b6726 /src/lib/libssl/ssl_methods.c | |
| parent | 27421011021040c269ef365f2083f1c5233c7307 (diff) | |
| download | openbsd-ac608c91af9de9141849165d1599e500cf7010cc.tar.gz openbsd-ac608c91af9de9141849165d1599e500cf7010cc.tar.bz2 openbsd-ac608c91af9de9141849165d1599e500cf7010cc.zip | |
Simplify SSL method lookups.
There are three places where we call tls1_get_{client,server}_method() and
if that returns NULL, call dtls1_get_{client,server}_method(). Simplify
this by combining the lookup into a single function. While here also use
uint16_t for version types.
ok inoguchi@ millert@
Diffstat (limited to 'src/lib/libssl/ssl_methods.c')
| -rw-r--r-- | src/lib/libssl/ssl_methods.c | 84 |
1 files changed, 35 insertions, 49 deletions
diff --git a/src/lib/libssl/ssl_methods.c b/src/lib/libssl/ssl_methods.c index c500d7ac06..ff8d17af06 100644 --- a/src/lib/libssl/ssl_methods.c +++ b/src/lib/libssl/ssl_methods.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ssl_methods.c,v 1.15 2020/09/15 09:41:24 jsing Exp $ */ | 1 | /* $OpenBSD: ssl_methods.c,v 1.16 2020/09/17 15:23:29 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 | * |
| @@ -98,14 +98,6 @@ DTLS_client_method(void) | |||
| 98 | return DTLSv1_client_method(); | 98 | return DTLSv1_client_method(); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | const SSL_METHOD * | ||
| 102 | dtls1_get_client_method(int ver) | ||
| 103 | { | ||
| 104 | if (ver == DTLS1_VERSION) | ||
| 105 | return (DTLSv1_client_method()); | ||
| 106 | return (NULL); | ||
| 107 | } | ||
| 108 | |||
| 109 | static const SSL_METHOD_INTERNAL DTLSv1_method_internal_data = { | 101 | static const SSL_METHOD_INTERNAL DTLSv1_method_internal_data = { |
| 110 | .version = DTLS1_VERSION, | 102 | .version = DTLS1_VERSION, |
| 111 | .min_version = DTLS1_VERSION, | 103 | .min_version = DTLS1_VERSION, |
| @@ -184,14 +176,6 @@ DTLS_server_method(void) | |||
| 184 | return DTLSv1_server_method(); | 176 | return DTLSv1_server_method(); |
| 185 | } | 177 | } |
| 186 | 178 | ||
| 187 | const SSL_METHOD * | ||
| 188 | dtls1_get_server_method(int ver) | ||
| 189 | { | ||
| 190 | if (ver == DTLS1_VERSION) | ||
| 191 | return (DTLSv1_server_method()); | ||
| 192 | return (NULL); | ||
| 193 | } | ||
| 194 | |||
| 195 | #ifdef LIBRESSL_HAS_TLS1_3_CLIENT | 179 | #ifdef LIBRESSL_HAS_TLS1_3_CLIENT |
| 196 | static const SSL_METHOD_INTERNAL TLS_client_method_internal_data = { | 180 | static const SSL_METHOD_INTERNAL TLS_client_method_internal_data = { |
| 197 | .version = TLS1_3_VERSION, | 181 | .version = TLS1_3_VERSION, |
| @@ -330,22 +314,6 @@ static const SSL_METHOD TLSv1_2_client_method_data = { | |||
| 330 | }; | 314 | }; |
| 331 | 315 | ||
| 332 | const SSL_METHOD * | 316 | const SSL_METHOD * |
| 333 | tls1_get_client_method(int ver) | ||
| 334 | { | ||
| 335 | #ifdef LIBRESSL_HAS_TLS1_3_CLIENT | ||
| 336 | if (ver == TLS1_3_VERSION) | ||
| 337 | return (TLS_client_method()); | ||
| 338 | #endif | ||
| 339 | if (ver == TLS1_2_VERSION) | ||
| 340 | return (TLSv1_2_client_method()); | ||
| 341 | if (ver == TLS1_1_VERSION) | ||
| 342 | return (TLSv1_1_client_method()); | ||
| 343 | if (ver == TLS1_VERSION) | ||
| 344 | return (TLSv1_client_method()); | ||
| 345 | return (NULL); | ||
| 346 | } | ||
| 347 | |||
| 348 | const SSL_METHOD * | ||
| 349 | SSLv23_client_method(void) | 317 | SSLv23_client_method(void) |
| 350 | { | 318 | { |
| 351 | return (TLS_client_method()); | 319 | return (TLS_client_method()); |
| @@ -700,22 +668,6 @@ static const SSL_METHOD TLSv1_2_server_method_data = { | |||
| 700 | }; | 668 | }; |
| 701 | 669 | ||
| 702 | const SSL_METHOD * | 670 | const SSL_METHOD * |
| 703 | tls1_get_server_method(int ver) | ||
| 704 | { | ||
| 705 | #ifdef LIBRESSL_HAS_TLS1_3_SERVER | ||
| 706 | if (ver == TLS1_3_VERSION) | ||
| 707 | return (TLS_server_method()); | ||
| 708 | #endif | ||
| 709 | if (ver == TLS1_2_VERSION) | ||
| 710 | return (TLSv1_2_server_method()); | ||
| 711 | if (ver == TLS1_1_VERSION) | ||
| 712 | return (TLSv1_1_server_method()); | ||
| 713 | if (ver == TLS1_VERSION) | ||
| 714 | return (TLSv1_server_method()); | ||
| 715 | return (NULL); | ||
| 716 | } | ||
| 717 | |||
| 718 | const SSL_METHOD * | ||
| 719 | SSLv23_server_method(void) | 671 | SSLv23_server_method(void) |
| 720 | { | 672 | { |
| 721 | return (TLS_server_method()); | 673 | return (TLS_server_method()); |
| @@ -754,3 +706,37 @@ TLSv1_2_server_method(void) | |||
| 754 | { | 706 | { |
| 755 | return (&TLSv1_2_server_method_data); | 707 | return (&TLSv1_2_server_method_data); |
| 756 | } | 708 | } |
| 709 | |||
| 710 | const SSL_METHOD * | ||
| 711 | ssl_get_client_method(uint16_t version) | ||
| 712 | { | ||
| 713 | if (version == TLS1_3_VERSION) | ||
| 714 | return (TLS_client_method()); | ||
| 715 | if (version == TLS1_2_VERSION) | ||
| 716 | return (TLSv1_2_client_method()); | ||
| 717 | if (version == TLS1_1_VERSION) | ||
| 718 | return (TLSv1_1_client_method()); | ||
| 719 | if (version == TLS1_VERSION) | ||
| 720 | return (TLSv1_client_method()); | ||
| 721 | if (version == DTLS1_VERSION) | ||
| 722 | return (DTLSv1_client_method()); | ||
| 723 | |||
| 724 | return (NULL); | ||
| 725 | } | ||
| 726 | |||
| 727 | const SSL_METHOD * | ||
| 728 | ssl_get_server_method(uint16_t version) | ||
| 729 | { | ||
| 730 | if (version == TLS1_3_VERSION) | ||
| 731 | return (TLS_server_method()); | ||
| 732 | if (version == TLS1_2_VERSION) | ||
| 733 | return (TLSv1_2_server_method()); | ||
| 734 | if (version == TLS1_1_VERSION) | ||
| 735 | return (TLSv1_1_server_method()); | ||
| 736 | if (version == TLS1_VERSION) | ||
| 737 | return (TLSv1_server_method()); | ||
| 738 | if (version == DTLS1_VERSION) | ||
| 739 | return (DTLSv1_server_method()); | ||
| 740 | |||
| 741 | return (NULL); | ||
| 742 | } | ||
