views:

285

answers:

2

How to get https server certificate using Net::HTTP or HTTPClient Ruby lib?

A: 

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.

morhekil
+1  A: 

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
Chandra Patni