Skip to content
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
14 changes: 13 additions & 1 deletion lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ class HTTPHeaderSyntaxError < StandardError; end
# - {:min_version=}[rdoc-ref:Net::HTTP#min_version=]:
# Sets the minimum SSL version.
# - {#peer_cert}[rdoc-ref:Net::HTTP#peer_cert]:
# Returns the X509 certificate for the session's socket peer.
# - {#peer_cert_chain}[rdoc-ref:Net::HTTP#peer_cert_chain]:
# Returns the X509 certificate chain for the session's socket peer.
# - {:ssl_version}[rdoc-ref:Net::HTTP#ssl_version]:
# Returns the SSL version.
Expand Down Expand Up @@ -1591,7 +1593,7 @@ def use_ssl=(flag)
# See {OpenSSL::SSL::SSLContext#verify_hostname=}[OpenSSL::SSL::SSL::Context#verify_hostname=].
attr_accessor :verify_hostname

# Returns the X509 certificate chain (an array of strings)
# Returns the X509 certificate (an OpenSSL::X509::Certificate)
# for the session's socket peer,
# or +nil+ if none.
def peer_cert
Expand All @@ -1601,6 +1603,16 @@ def peer_cert
@socket.io.peer_cert
end

# Returns the X509 certificate chain (an array of OpenSSL::X509::Certificate)
# for the session's socket peer,
# or +nil+ if none.
def peer_cert_chain
if not use_ssl? or not @socket
return nil
end
@socket.io.peer_cert_chain
end

# Starts an \HTTP session.
#
# Without a block, returns +self+:
Expand Down
2 changes: 2 additions & 0 deletions test/net/http/test_https.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_get
http.request_get("/") {|res|
assert_equal($test_net_http_data, res.body)
assert_equal(SERVER_CERT.to_der, http.peer_cert.to_der)
assert_equal(SERVER_CERT.to_der, http.peer_cert_chain.first.to_der)
}
end

Expand All @@ -50,6 +51,7 @@ def test_get_SNI
http.request_get("/") {|res|
assert_equal($test_net_http_data, res.body)
assert_equal(SERVER_CERT.to_der, http.peer_cert.to_der)
assert_equal(SERVER_CERT.to_der, http.peer_cert_chain.first.to_der)
}
end

Expand Down