Skip to content

Commit ce363a7

Browse files
Resolve peer verification issues when using TLS over a proxy (#351)
Co-authored-by: Ilya Grigorik <ilya@igvita.com>
1 parent 91cee59 commit ce363a7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/em-http/http_connection.rb

+8-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def ssl_verify_peer(cert_string)
5555
rescue OpenSSL::X509::StoreError => e
5656
raise e unless e.message == 'cert already in hash table'
5757
end
58+
else
59+
raise OpenSSL::SSL::SSLError.new(%(unable to verify the server certificate for "#{sni_hostname}"))
5860
end
5961

6062
true
@@ -68,8 +70,8 @@ def ssl_handshake_completed
6870
end
6971

7072
unless certificate_store.verify(@last_seen_cert) &&
71-
OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
72-
raise OpenSSL::SSL::SSLError.new(%(host "#{host}" does not match the server certificate))
73+
OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, sni_hostname)
74+
raise OpenSSL::SSL::SSLError.new(%(host "#{sni_hostname}" does not match the server certificate))
7375
else
7476
true
7577
end
@@ -83,6 +85,10 @@ def host
8385
parent.connopts.host
8486
end
8587

88+
def sni_hostname
89+
parent.connopts.tls[:sni_hostname]
90+
end
91+
8692
def certificate_store
8793
@certificate_store ||= begin
8894
store = OpenSSL::X509::Store.new

0 commit comments

Comments
 (0)