Skip to content

Commit d9c2c68

Browse files
authored
Merge pull request #94 from bdewater/ssl-minmax-version
Allow setting min/max SSL version for a connection on Ruby 2.5
2 parents 0e5a8fb + d4a2667 commit d9c2c68

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

lib/net/http/persistent.rb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,26 @@ def self.detect_idle_timeout uri, max = 10
440440
# SSL version to use.
441441
#
442442
# By default, the version will be negotiated automatically between client
443-
# and server. Ruby 1.9 and newer only.
443+
# and server. Ruby 1.9 and newer only. Deprecated since Ruby 2.5.
444444

445445
attr_reader :ssl_version
446446

447+
##
448+
# Minimum SSL version to use, e.g. :TLS1_1
449+
#
450+
# By default, the version will be negotiated automatically between client
451+
# and server. Ruby 2.5 and newer only.
452+
453+
attr_reader :min_version
454+
455+
##
456+
# Maximum SSL version to use, e.g. :TLS1_2
457+
#
458+
# By default, the version will be negotiated automatically between client
459+
# and server. Ruby 2.5 and newer only.
460+
461+
attr_reader :max_version
462+
447463
##
448464
# Where this instance's last-use times live in the thread local variables
449465

@@ -533,6 +549,8 @@ def initialize name: nil, proxy: nil, pool_size: DEFAULT_POOL_SIZE
533549
@private_key = nil
534550
@ssl_timeout = nil
535551
@ssl_version = nil
552+
@min_version = nil
553+
@max_version = nil
536554
@verify_callback = nil
537555
@verify_depth = nil
538556
@verify_mode = nil
@@ -1044,6 +1062,8 @@ def ssl connection
10441062
connection.ciphers = @ciphers if @ciphers
10451063
connection.ssl_timeout = @ssl_timeout if @ssl_timeout
10461064
connection.ssl_version = @ssl_version if @ssl_version
1065+
connection.min_version = @min_version if @min_version
1066+
connection.max_version = @max_version if @max_version
10471067

10481068
connection.verify_depth = @verify_depth
10491069
connection.verify_mode = @verify_mode
@@ -1115,6 +1135,24 @@ def ssl_version= ssl_version
11151135
reconnect_ssl
11161136
end
11171137

1138+
##
1139+
# Minimum SSL version to use
1140+
1141+
def min_version= min_version
1142+
@min_version = min_version
1143+
1144+
reconnect_ssl
1145+
end
1146+
1147+
##
1148+
# maximum SSL version to use
1149+
1150+
def max_version= max_version
1151+
@max_version = max_version
1152+
1153+
reconnect_ssl
1154+
end
1155+
11181156
##
11191157
# Sets the depth of SSL certificate verification
11201158

test/test_net_http_persistent.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def teardown
7777
class BasicConnection
7878
attr_accessor :started, :finished, :address, :port, :use_ssl,
7979
:read_timeout, :open_timeout, :keep_alive_timeout
80-
attr_accessor :ciphers, :ssl_timeout, :ssl_version,
81-
:verify_depth, :verify_mode, :cert_store,
80+
attr_accessor :ciphers, :ssl_timeout, :ssl_version, :min_version,
81+
:max_version, :verify_depth, :verify_mode, :cert_store,
8282
:ca_file, :ca_path, :cert, :key
8383
attr_reader :req, :debug_output
8484
def initialize
@@ -1527,6 +1527,20 @@ def test_ssl_version_equals
15271527
assert_equal 1, @http.ssl_generation
15281528
end
15291529

1530+
def test_min_version_equals
1531+
@http.min_version = :min_version
1532+
1533+
assert_equal :min_version, @http.min_version
1534+
assert_equal 1, @http.ssl_generation
1535+
end
1536+
1537+
def test_max_version_equals
1538+
@http.max_version = :max_version
1539+
1540+
assert_equal :max_version, @http.max_version
1541+
assert_equal 1, @http.ssl_generation
1542+
end
1543+
15301544
def test_start
15311545
c = basic_connection
15321546
c = c.http

0 commit comments

Comments
 (0)