18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/scanner/plugins/ssl/ssl_labs/analyze.rb', line 18
def self.scan(endpoint, target, start_new)
uri = endpoint.copy
uri.path = '/api/v3/analyze'
uri.query = if start_new
"host=#{target}&publish=off&startNew=on&all=done&ignoreMismatch=on"
else
"host=#{target}&publish=off&all=done&ignoreMismatch=on"
end
req = Yawast::Shared::Http.get_http(uri)
req.use_ssl = uri.scheme == 'https'
res = req.request_get(uri, {'User-Agent' => "YAWAST/#{Yawast::VERSION}"})
body = res.read_body
code = res.code.to_i
begin
json = JSON.parse body
rescue => e raise StandardError, "Invalid response from SSL Labs: '#{e.message}'"
end
raise InvocationError, "API returned: #{json['errors']}" if json.key?('errors')
Yawast::Shared::Output.log_json 'ssl', 'ssl_labs', body
if code != 200
case code
when 400
raise InvocationError, 'invalid parameters'
when 429
raise RequestRateTooHigh, 'request rate is too high, please slow down'
when 500
raise InternalError, 'service encountered an error, sleep 5 minutes'
when 503
raise ServiceNotAvailable, 'service is not available, sleep 15 minutes'
when 529
raise ServiceOverloaded, 'service is overloaded, sleep 30 minutes'
else
raise StandardError, "http error code #{r.code}"
end
end
body
end
|