Skip to content

Initial approach to allowing SSL context option passing #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
/pkg/
/spec/reports/
/tmp/
/.tool-versions
/Gemfile.lock
14 changes: 14 additions & 0 deletions lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,14 @@ def HTTP.https_default_port
443
end

def HTTP.default_ssl_options
defined?(@@default_ssl_options) ? @@default_ssl_options : nil
end

def HTTP.default_ssl_options=(opt)
@@default_ssl_options = opt
end

def HTTP.socket_type #:nodoc: obsolete
BufferedIO
end
Expand Down Expand Up @@ -1032,6 +1040,7 @@ def HTTP.socket_type #:nodoc: obsolete
# - #open_timeout
# - #read_timeout
# - #ssl_timeout
# - #ssl_options
# - #ssl_version
# - +use_ssl+ (calls #use_ssl=)
# - #verify_callback
Expand Down Expand Up @@ -1190,6 +1199,7 @@ def initialize(address, port = nil) # :nodoc:

@use_ssl = false
@ssl_context = nil
@ssl_options = HTTP.default_ssl_options
@ssl_session = nil
@sspi_enabled = false
SSL_IVNAMES.each do |ivname|
Expand Down Expand Up @@ -1520,6 +1530,7 @@ def use_ssl=(flag)
:extra_chain_cert,
:key,
:ssl_timeout,
:options,
:ssl_version,
:min_version,
:max_version,
Expand Down Expand Up @@ -1559,6 +1570,9 @@ def use_ssl=(flag)
# Sets or returns the SSL timeout seconds.
attr_accessor :ssl_timeout

# Sets the SSL options. See OpenSSL::SSL::SSLContext#ssl_options=
attr_accessor :ssl_options

# Sets or returns the SSL version.
# See {OpenSSL::SSL::SSLContext#ssl_version=}[OpenSSL::SSL::SSL::Context#ssl_version=].
attr_accessor :ssl_version
Expand Down
10 changes: 10 additions & 0 deletions test/net/http/test_https.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ def test_max_version
assert_match(re_msg, ex.message)
end

def test_ssl_options
http = Net::HTTP.new(HOST, config("port"))
http.use_ssl = true
http.ssl_options = OpenSSL::SSL::OP_LEGACY_SERVER_CONNECT
http.cert_store = TEST_STORE
http.request_get("/") {|res|
assert_equal($test_net_http_data, res.body)
}
end

end if defined?(OpenSSL::SSL)

class TestNetHTTPSIdentityVerifyFailure < Test::Unit::TestCase
Expand Down