Skip to content

Commit 87d8693

Browse files
committed
ssl: initialize verify_mode and verify_hostname with default values
SSLContext's verify_mode expects an SSL_VERIFY_* constant (an integer) and verify_hostname expects either true or false. However, they are set to nil after calling OpenSSL::SSL::SSLContext.new, which is surprising. Set a proper value to them by default: verify_mode is set to OpenSSL::SSL::VERIFY_NONE and verify_hostname is set to false by default. Note that this does not change the default behavior. The certificate verification was never performed unless verify_mode is set to OpenSSL::SSL::VERIFY_PEER by a user. The same applies to verify_hostname.
1 parent 1ccdc05 commit 87d8693

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/openssl/ssl.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class SSLContext
122122
def initialize(version = nil)
123123
self.options |= OpenSSL::SSL::OP_ALL
124124
self.ssl_version = version if version
125+
self.verify_mode = OpenSSL::SSL::VERIFY_NONE
126+
self.verify_hostname = false
125127
end
126128

127129
##

test/openssl/test_ssl.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ def test_copy_stream
246246
end
247247
end
248248

249+
def test_verify_mode_default
250+
ctx = OpenSSL::SSL::SSLContext.new
251+
assert_equal OpenSSL::SSL::VERIFY_NONE, ctx.verify_mode
252+
end
253+
249254
def test_verify_mode_server_cert
250255
start_server(ignore_listener_error: true) { |port|
251256
populated_store = OpenSSL::X509::Store.new
@@ -919,6 +924,7 @@ def test_verify_hostname_on_connect
919924

920925
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
921926
ctx = OpenSSL::SSL::SSLContext.new
927+
assert_equal false, ctx.verify_hostname
922928
ctx.verify_hostname = true
923929
ctx.cert_store = OpenSSL::X509::Store.new
924930
ctx.cert_store.add_cert(@ca_cert)

0 commit comments

Comments
 (0)