Created
December 6, 2015 03:34
-
-
Save pzb/f0888d140eb299f94b03 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 'nokogiri' | |
require 'curb' | |
require 'openssl' | |
doc = File.open("publiclyDisclosedSubCACerts"){|f| Nokogiri::HTML(f)} | |
certurls = {} | |
# The page as almost no metadata, so we are doing this by index | |
subtbl = doc.css("body table")[1] | |
subtbl.css("tr").each do |row| | |
links = row.css("td")[2] | |
if links.nil? | |
next | |
end | |
hrefs = links.css("a") | |
# Audit links suggest external subordinate | |
if hrefs.any?{|a|a.children[0].to_s == "Audit"} | |
next | |
end | |
certurl = hrefs.select{|a|a.children[0].to_s == "Certificate"}.first["href"] | |
if !certurl.nil? | |
certurls[certurl] = true | |
end | |
end | |
certurls.keys.each do |u| | |
http = Curl.get(u) | |
if http.response_code >= 200 && http.response_code < 300 | |
der = http.body_str | |
begin | |
crt = OpenSSL::X509::Certificate.new(der) | |
subj = crt.subject.to_s(OpenSSL::X509::Name::RFC2253 & ~4).force_encoding("UTF-8") | |
spki = OpenSSL::Digest::SHA256.hexdigest(crt.public_key.to_der) | |
puts "#{subj}\t#{spki}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment