Skip to content

Instantly share code, notes, and snippets.

@ravage
Created June 5, 2022 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravage/700ecd4786fbc31b9f6c9e1e2a7bf772 to your computer and use it in GitHub Desktop.
Save ravage/700ecd4786fbc31b9f6c9e1e2a7bf772 to your computer and use it in GitHub Desktop.
Fetch expiry date and other info from certificate
#!/usr/bin/env ruby
# frozen_string_literal: true
require "time"
require "openssl"
def get_expiry_date(host)
ctx = OpenSSL::SSL::SSLContext.new
sock = TCPSocket.new(host, 443)
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
ssl.hostname = host
ssl.connect
cert = ssl.peer_cert
{
hostname: host,
expires_in_days: (cert.not_after - Time.now).to_i / (24 * 60 * 60),
vertion: cert.version,
not_before: cert.not_before,
not_after: cert.not_after
}
end
p get_expiry_date(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment