Skip to content

Commit 3e5a009

Browse files
committed
ssl: remove unsupported TLS versions from SSLContext::METHODS
Check for all version-specific SSL methods. We do check for existence of TLSv1_1_method() and TLSv1_2_method(), but not for TLSv1_method(). This fixes compile error when OpenSSL is configured with no-tls1-method. Also check the OPENSSL_NO_TLS{1,1_1,1_2} macros for whether OpenSSL supports the corresponding versions or not. This prevents :TLSv1 from being in SSLContext::METHODS when OpenSSL is compiled with no-tls1. In particular, Debian sid has disabled TLS 1.0/1.1 support recently. The changes in ext/openssl are partial backport of 4eb4b32 ("Remove support for OpenSSL 0.9.8 and 1.0.0", 2016-11-30).
1 parent 579afc4 commit 3e5a009

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

ext/openssl/extconf.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,10 @@ def find_openssl_library
109109
Logging::message "=== Checking for OpenSSL features... ===\n"
110110
# compile options
111111

112-
# check OPENSSL_NO_{SSL2,SSL3_METHOD} macro: on some environment, these symbols
113-
# exist even if compiled with no-ssl2 or no-ssl3-method.
114-
unless have_macro("OPENSSL_NO_SSL2", "openssl/opensslconf.h")
115-
have_func("SSLv2_method")
116-
end
117-
unless have_macro("OPENSSL_NO_SSL3_METHOD", "openssl/opensslconf.h")
118-
have_func("SSLv3_method")
119-
end
120-
have_func("TLSv1_1_method")
121-
have_func("TLSv1_2_method")
112+
# SSLv2 and SSLv3 may be removed in future versions of OpenSSL, and even macros
113+
# like OPENSSL_NO_SSL2 may not be defined.
114+
have_func("SSLv2_method")
115+
have_func("SSLv3_method")
122116
have_func("RAND_egd")
123117
engines = %w{builtin_engines openbsd_dev_crypto dynamic 4758cca aep atalla chil
124118
cswift nuron sureware ubsec padlock capi gmp gost cryptodev aesni}

ext/openssl/ossl_ssl.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,19 @@ static const struct {
6565
{ #name"_server", (SSL_METHOD *(*)(void))name##_server_method, version }, \
6666
{ #name"_client", (SSL_METHOD *(*)(void))name##_client_method, version }
6767
#endif
68-
#if defined(HAVE_SSLV2_METHOD)
68+
#if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL2_METHOD) && defined(HAVE_SSLV2_METHOD)
6969
OSSL_SSL_METHOD_ENTRY(SSLv2, SSL2_VERSION),
7070
#endif
71-
#if defined(HAVE_SSLV3_METHOD)
71+
#if !defined(OPENSSL_NO_SSL3) && !defined(OPENSSL_NO_SSL3_METHOD) && defined(HAVE_SSLV3_METHOD)
7272
OSSL_SSL_METHOD_ENTRY(SSLv3, SSL3_VERSION),
7373
#endif
74+
#if !defined(OPENSSL_NO_TLS1) && !defined(OPENSSL_NO_TLS1_METHOD)
7475
OSSL_SSL_METHOD_ENTRY(TLSv1, TLS1_VERSION),
75-
#if defined(HAVE_TLSV1_1_METHOD)
76+
#endif
77+
#if !defined(OPENSSL_NO_TLS1_1) && !defined(OPENSSL_NO_TLS1_1_METHOD)
7678
OSSL_SSL_METHOD_ENTRY(TLSv1_1, TLS1_1_VERSION),
7779
#endif
78-
#if defined(HAVE_TLSV1_2_METHOD)
80+
#if !defined(OPENSSL_NO_TLS1_2) && !defined(OPENSSL_NO_TLS1_2_METHOD)
7981
OSSL_SSL_METHOD_ENTRY(TLSv1_2, TLS1_2_VERSION),
8082
#endif
8183
OSSL_SSL_METHOD_ENTRY(SSLv23, 0),

test/test_ssl.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ def test_forbid_ssl_v3_from_server
810810

811811
end
812812

813-
if OpenSSL::SSL::SSLContext::METHODS.include? :TLSv1_1
813+
if OpenSSL::SSL::SSLContext::METHODS.include?(:TLSv1_1) && OpenSSL::SSL::SSLContext::METHODS.include?(:TLSv1)
814814

815815
def test_tls_v1_1
816816
start_server_version(:TLSv1_1) { |server, port|
@@ -837,7 +837,7 @@ def test_forbid_tls_v1_from_server
837837

838838
end
839839

840-
if OpenSSL::SSL::SSLContext::METHODS.include? :TLSv1_2
840+
if OpenSSL::SSL::SSLContext::METHODS.include?(:TLSv1_2) && OpenSSL::SSL::SSLContext::METHODS.include?(:TLSv1_1)
841841

842842
def test_tls_v1_2
843843
start_server_version(:TLSv1_2) { |server, port|

test/test_ssl_session.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_session
4848
Timeout.timeout(5) do
4949
start_server do |server, port|
5050
sock = TCPSocket.new("127.0.0.1", port)
51-
ctx = OpenSSL::SSL::SSLContext.new("TLSv1")
51+
ctx = OpenSSL::SSL::SSLContext.new
5252
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
5353
ssl.sync_close = true
5454
ssl.connect
@@ -157,9 +157,7 @@ def test_client_session
157157
start_server do |server, port|
158158
2.times do
159159
sock = TCPSocket.new("127.0.0.1", port)
160-
# Debian's openssl 0.9.8g-13 failed at assert(ssl.session_reused?),
161-
# when use default SSLContext. [ruby-dev:36167]
162-
ctx = OpenSSL::SSL::SSLContext.new("TLSv1")
160+
ctx = OpenSSL::SSL::SSLContext.new
163161
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
164162
ssl.sync_close = true
165163
ssl.session = last_session if last_session

0 commit comments

Comments
 (0)