How to get https server cert开发者_开发问答ificate using Net::HTTP or HTTPClient Ruby lib?
I found a solution using HTTPClient lib
require 'rubygems'
require 'httpclient'
client = HTTPClient.new
response = client.get("https://gmail.google.com")
cert = response.peer_cert
Make sure you have httpclient gem installed
sudo gem install httpclient
I don't think that you can do it with either of these libraries, or even with much more advanced libcurl and it's wrappers. But as an alternative - if you have openssl
command line tool available, you can invoke it and parse the output, the command you need is as follows:
openssl s_client -connect my.server.name:443
It will give you a full dump of the certificate as well as some parsed information - subject, issuer, etc.
精彩评论