Skip to content

Commit

Permalink
Resolve peer verification issues when using TLS over a proxy (#351)
Browse files Browse the repository at this point in the history
Co-authored-by: Ilya Grigorik <[email protected]>
  • Loading branch information
dariushoule-stripe and igrigorik authored Nov 10, 2024
1 parent 91cee59 commit ce363a7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/em-http/http_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def ssl_verify_peer(cert_string)
rescue OpenSSL::X509::StoreError => e
raise e unless e.message == 'cert already in hash table'
end
else
raise OpenSSL::SSL::SSLError.new(%(unable to verify the server certificate for "#{sni_hostname}"))
end

true
Expand All @@ -68,8 +70,8 @@ def ssl_handshake_completed
end

unless certificate_store.verify(@last_seen_cert) &&
OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, host)
raise OpenSSL::SSL::SSLError.new(%(host "#{host}" does not match the server certificate))
OpenSSL::SSL.verify_certificate_identity(@last_seen_cert, sni_hostname)
raise OpenSSL::SSL::SSLError.new(%(host "#{sni_hostname}" does not match the server certificate))
else
true
end
Expand All @@ -83,6 +85,10 @@ def host
parent.connopts.host
end

def sni_hostname
parent.connopts.tls[:sni_hostname]
end

def certificate_store
@certificate_store ||= begin
store = OpenSSL::X509::Store.new
Expand Down

0 comments on commit ce363a7

Please sign in to comment.