简体   繁体   中英

How do I get the peer_cert for a https request using Ruby?

How can I get access to the peer_cert when making a SSL request?

I've updated my ruby ssl certs with rvm osx-ssl-certs update all

What I'm trying is

require 'httpclient'
c = HTTPClient.new
r = c.get( "https://gmail.com" )
puts r.peer_cert

But I keep getting either OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server hello A: sslv3 alert handshake failure

or

OpenSSL::SSL::SSLError: hostname "gmail.com" does not match the server certificate

What does the first error mean? Is there a way to get it to set the property version automatically?

I'm able to load up the data on the URL using HTTParty and Farday, but in that case I don't know here to access the actual SSL cert that was used.

You can't get the peer cert until you succesfully make the connection, and you're getting an error in succesfully making the connection. Have you upgraded to the latest httpclient? Many servers changed their SSL handshake configurations in response to recent vulnerabilties, and a new httpclient was released in response to same, which perhaps is neccesary to be compatible with new server configurations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM