Skip to content

Add Net::HTTP#security_level attribute #217

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 1 commit 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
10 changes: 10 additions & 0 deletions lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,10 @@ class HTTPHeaderSyntaxError < StandardError; end
# Sets the minimum SSL version.
# - {#peer_cert}[rdoc-ref:Net::HTTP#peer_cert]:
# Returns the X509 certificate chain for the session's socket peer.
# - {:security_level}[rdoc-ref:Net::HTTP#security_level]:
# Returns the SSL security level.
# - {:security_level=}[rdoc-ref:Net::HTTP#security_level=]:
# Sets the SSL security level.
# - {:ssl_version}[rdoc-ref:Net::HTTP#ssl_version]:
# Returns the SSL version.
# - {:ssl_version=}[rdoc-ref:Net::HTTP#ssl_version=]:
Expand Down Expand Up @@ -1031,6 +1035,7 @@ def HTTP.socket_type #:nodoc: obsolete
# - #key
# - #open_timeout
# - #read_timeout
# - #security_level
# - #ssl_timeout
# - #ssl_version
# - +use_ssl+ (calls #use_ssl=)
Expand Down Expand Up @@ -1519,6 +1524,7 @@ def use_ssl=(flag)
:ciphers,
:extra_chain_cert,
:key,
:security_level,
:ssl_timeout,
:ssl_version,
:min_version,
Expand Down Expand Up @@ -1556,6 +1562,10 @@ def use_ssl=(flag)
# Sets or returns the OpenSSL::PKey::RSA or OpenSSL::PKey::DSA object.
attr_accessor :key

# Sets or returns the SSL security level.
# See {OpenSSL::SSL::SSLContext#security_level=}[OpenSSL::SSL::SSL::Context#security_level=].
attr_accessor :security_level

# Sets or returns the SSL timeout seconds.
attr_accessor :ssl_timeout

Expand Down
11 changes: 11 additions & 0 deletions test/net/http/test_https.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,17 @@ def test_max_version
assert_match(re_msg, ex.message)
end

def test_security_level
http = Net::HTTP.new(HOST, config("port"))
http.use_ssl = true
http.security_level = 3
http.cert_store = TEST_STORE
ex = assert_raise(OpenSSL::SSL::SSLError){
http.request_get("/") {|res| }
}
assert_match(/certificate verify failed/, ex.message)
end

end if defined?(OpenSSL::SSL)

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