开发者

HTTPS URL server certificate in Ruby

开发者 https://www.devze.com 2022-12-14 14:48 出处:网络
How to get https server cert开发者_开发问答ificate using Net::HTTP or HTTPClient Ruby lib?I found a solution using HTTPClient lib

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消