N3rd
N3rd

Reputation: 21

How to check SSL certificate encryption with ruby

i am new on Ruby and got the task to check the encryption of some SSL certificates to figure out if they use sha1 or sha256. I do not have any idea.

here a code snippet which checks for expiring date and has to be extended with encryption info:

  domains.each do |domain|
  domain_name = domain[:Name]

  begin
    uri = URI.parse("https://" + domain_name)

    http = Net::HTTP.new(uri.host,uri.port)
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    http.start do |h|
      @cert = h.peer_cert
  end

  expire_date = Date.parse(@cert.not_after.strftime("%Y-%m-%d")).to_s

  output('INFO', 'SSL expiry date is: ' + expire_date.to_s);

Upvotes: 1

Views: 1007

Answers (1)

Wand Maker
Wand Maker

Reputation: 18762

Look at OpenSSL::X509::Certificate#signature_algorithm

@cert.signature_algorithm
#=> sha1WithRSAEncryption

Upvotes: 1

Related Questions