summaryrefslogtreecommitdiff
path: root/crtsh-getcerts
blob: 0191e2e1d4db000edbef60fbf4ca560abbd31613 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'

certs = {}
ARGV.each do |domain|
	[ domain, "%.#{domain}" ].each do |pattern|
		Nokogiri::XML(open("https://crt.sh/atom?identity=#{pattern}&exclude=expired")).css('feed > entry').each do |entry|
			url = entry.css('id').first.text.split("#").first

			updated = entry.css('updated').first.text

			html = Nokogiri::HTML(entry.css('summary').first.text)
			html.css('br').each{|br| br.replace("\n")}
			pem = html.css('div').first.text

			lines = pem.split("\n")
			lines.insert(1, "X-Crt-Sh-Url: #{url}", "X-Crt-Sh-Updated: #{updated}")
			pem = lines.join("\n")+"\n"

			certs[url] = pem
		end
	end
end

certs.each do |url, pem|
	print pem
end