Class: Yawast::Scanner::Plugins::SSL::SSLLabs::Analyze

Inherits:
Object
  • Object
show all
Defined in:
lib/scanner/plugins/ssl/ssl_labs/analyze.rb

Class Method Summary collapse

Class Method Details

.extract_status(body) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/scanner/plugins/ssl/ssl_labs/analyze.rb', line 66

def self.extract_status(body)
  begin
    json = JSON.parse body
  rescue => e # rubocop:disable Style/RescueStandardError
    raise StandardError, "Invalid response from SSL Labs: '#{e.message}'"
  end

  json['status']
end

.scan(endpoint, target, start_new) ⇒ Object

Raises:



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

  # check for error in the response - if we don't, we'll wait forever for nothing
  begin
    json = JSON.parse body
  rescue => e # rubocop:disable Style/RescueStandardError
    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

  # check the response code, make sure it's 200 - otherwise, we should stop now
  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