Created
February 26, 2014 20:59
-
-
Save macros/9238407 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'openssl' | |
cert = OpenSSL::X509::Certificate.new File.read(ARGV[0]) | |
cn = cert.subject.to_a.select{|oid, value| oid == "CN"}[0][1] | |
puts "Cert metadata" | |
puts cert.serial | |
puts cert.issuer | |
puts cert.not_before | |
puts cert.not_after | |
puts cert.signature_algorithm | |
puts cert.to_s | |
puts "Public key metadata" | |
puts cert.public_key.class | |
puts cert.public_key.to_s | |
sans = [] | |
cert.extensions.each do |ext| | |
next if ext.oid != "subjectAltName" | |
ostr = OpenSSL::ASN1.decode(ext.to_der).value.last | |
sequence = OpenSSL::ASN1.decode(ostr.value) | |
sequence.value.each do |san| | |
sans << san.value | |
end | |
end | |
puts "CN: #{cn}" | |
puts "SANS: #{sans.join(', ')}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment