Skip to content

Commit 897ee5e

Browse files
committed
Merge branch 'ky/ssl-version-min-max'
* ky/ssl-version-min-max: ssl: fix conflict of options in SSLContext#set_params Use caller with length to reduce unused strings
2 parents 8ebac4a + 62af044 commit 897ee5e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/openssl/ssl.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def initialize(version = nil)
136136
# used.
137137
def set_params(params={})
138138
params = DEFAULT_PARAMS.merge(params)
139+
self.options = params.delete(:options) # set before min_version/max_version
139140
params.each{|name, value| self.__send__("#{name}=", value) }
140141
if self.verify_mode != OpenSSL::SSL::VERIFY_NONE
141142
unless self.ca_file or self.ca_path or self.cert_store
@@ -201,7 +202,7 @@ def ssl_version=(meth)
201202
if /(?<type>_client|_server)\z/ =~ meth
202203
meth = $`
203204
if $VERBOSE
204-
warn "#{caller(1)[0]}: method type #{type.inspect} is ignored"
205+
warn "#{caller(1, 1)[0]}: method type #{type.inspect} is ignored"
205206
end
206207
end
207208
version = METHODS_MAP[meth.intern] or

test/test_ssl.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,24 @@ def check_supported_protocol_versions
811811
supported
812812
end
813813

814+
def test_set_params_min_version
815+
supported = check_supported_protocol_versions
816+
store = OpenSSL::X509::Store.new
817+
store.add_cert(@ca_cert)
818+
819+
if supported.include?(OpenSSL::SSL::SSL3_VERSION)
820+
# SSLContext#set_params properly disables SSL 3.0 by default
821+
ctx_proc = proc { |ctx|
822+
ctx.min_version = ctx.max_version = OpenSSL::SSL::SSL3_VERSION
823+
}
824+
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
825+
ctx = OpenSSL::SSL::SSLContext.new
826+
ctx.set_params(cert_store: store, verify_hostname: false)
827+
assert_handshake_error { server_connect(port, ctx) { } }
828+
}
829+
end
830+
end
831+
814832
def test_minmax_version
815833
supported = check_supported_protocol_versions
816834

0 commit comments

Comments
 (0)