9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/shadowserver/whitelist.rb', line 9
def Whitelist::by_hash(hash)
url = @@baseurl
if hash.length == 32
url += "?md5=#{hash.upcase}"
elsif hash.length == 40
url += "?sha1=#{hash.upcase}"
else
raise "The hash must be either 32 or 40 characters long"
end
url = URI.parse(url)
request = Net::HTTP::Get.new(url.path+"?"+url.query)
request.add_field("User-Agent", "Ruby/#{RUBY_VERSION} shadowserver rubygem (https://github.com/chrislee35/shadowserver)")
http = Net::HTTP.new(url.host, url.port)
if url.scheme == 'https'
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.verify_depth = 5
end
resp = http.request(request)
if resp.body =~ /^[0-9A-F]{32,40} (.+)/
JSON.parse($1)
else
nil
end
end
|