Skip to content

Instantly share code, notes, and snippets.

@skeptomai
Forked from macros/gist:9238407
Created March 26, 2014 18:13
Show Gist options
  • Save skeptomai/9789705 to your computer and use it in GitHub Desktop.
Save skeptomai/9789705 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'openssl'
pathglob = File.join(ARGV[0], "*.crt")
sans = []
Dir.glob(pathglob).each do |cert_filename|
cert = OpenSSL::X509::Certificate.new File.read(cert_filename)
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{|san|
case san.tag
when 2 # dNSName in GeneralName (RFC5280)
sans << san.value
end
}
end
end
puts sans.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment