Class: SSLyze::XML

Inherits:
Object
  • Object
show all
Includes:
Types
Defined in:
lib/sslyze/xml.rb

Overview

Represents the XML output from sslyze.

Constant Summary

Constants included from Types

Types::Boolean, Types::None

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ XML

Initializes the XML.

Parameters:

  • doc (Nokogiri::XML::Document)

    The XML document.



20
21
22
# File 'lib/sslyze/xml.rb', line 20

def initialize(doc)
  @doc = doc
end

Class Method Details

.open(path) ⇒ XML

Opens the XML file.

Parameters:

  • path (String)

    Path to the XML file.

Returns:



44
45
46
# File 'lib/sslyze/xml.rb', line 44

def self.open(path)
  new(File.open(path) { |file| Nokogiri::XML(file) })
end

.parse(xml) ⇒ XML

Parses the XML.

Parameters:

  • xml (String)

    The raw XML.

Returns:



32
33
34
# File 'lib/sslyze/xml.rb', line 32

def self.parse(xml)
  new(Nokogiri::XML.parse(xml))
end

Instance Method Details

#default_timeoutInteger

The default timeout used.

Returns:

  • (Integer)


62
63
64
# File 'lib/sslyze/xml.rb', line 62

def default_timeout
  @default_time ||= @doc.at('/document/results/@defaultTimeout').value.to_i
end

#each_invalid_target {|invalidtarget| ... } ⇒ Enumerator

Enumerates over each invalid target.

Yields:

  • (invalidtarget)

Yield Parameters:

Returns:

  • (Enumerator)

Since:

  • 0.2.0



114
115
116
117
118
119
120
# File 'lib/sslyze/xml.rb', line 114

def each_invalid_target
  return enum_for(__method__) unless block_given?

  @doc.search('invalidTargets/invalidTarget').each do |inval|
    yield InvalidTarget.new(inval)
  end
end

#each_target {|target| ... } ⇒ Enumerator Also known as: each

Enumerates over each target.

Yields:

Yield Parameters:

Returns:

  • (Enumerator)


131
132
133
134
135
136
137
# File 'lib/sslyze/xml.rb', line 131

def each_target
  return enum_for(__method__) unless block_given?

  @doc.search('/document/results/target').each do |target|
    yield Target.new(target)
  end
end

#https_tunnelBoolean

Whether an HTTPS tunnel was used.

Returns:



71
72
73
# File 'lib/sslyze/xml.rb', line 71

def https_tunnel
  @https_tunnel ||= Boolean[@doc.at('/document/results/@httpsTunnel').value]
end

#invalid_targetsArray<InvalidTarget>

Returns:

See Also:

Since:

  • 0.2.0



100
101
102
# File 'lib/sslyze/xml.rb', line 100

def invalid_targets
  each_invalid_target.to_a
end

#start_tlsBoolean

Specifies whether STARTTLS was enabled.

Returns:



80
81
82
# File 'lib/sslyze/xml.rb', line 80

def start_tls
  @start_tls ||= Boolean[@doc.at('/document/results/@startTLS').value]
end

#targetTarget?

The first target.

Returns:



155
156
157
# File 'lib/sslyze/xml.rb', line 155

def target
  each_target.first
end

#targetsArray<Target>

Returns:

See Also:



146
147
148
# File 'lib/sslyze/xml.rb', line 146

def targets
  each_target.to_a
end

#total_scan_timeFloat

Duration of the scan.

Returns:

  • (Float)


89
90
91
# File 'lib/sslyze/xml.rb', line 89

def total_scan_time
  @start_tls ||= @doc.at('/document/results/@totalScanTime').value.to_f
end

#versionString

The version of the XML output.

Returns:

  • (String)


53
54
55
# File 'lib/sslyze/xml.rb', line 53

def version
  @version ||= @doc.at('/document/@SSLyzeVersion').value.split(' ',2).last
end