Class: SslscanWrapper::Report
- Inherits:
-
Object
- Object
- SslscanWrapper::Report
- Defined in:
- lib/sslscan_wrapper/report.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
The content body of the report.
-
#doc ⇒ Object
readonly
The nokogiri document object.
Class Method Summary collapse
- .all_attr_values_accessor(name, xpath) ⇒ Object
- .attr_first_value_accessor(name, xpath) ⇒ Object
- .attr_first_value_boolean_true?(name, xpath) ⇒ Boolean
- .content_first_node_accessor(name, xpath) ⇒ Object
- .content_first_node_boolean_true?(name, xpath) ⇒ Boolean
Instance Method Summary collapse
-
#certificate ⇒ Object
Return the parsed certificate blob as OpenSSL::X509::Certificate.
-
#heartbleed_vulnerable? ⇒ Boolean
Are there any heartblead vulnerable SSL/TLS protocol versions?.
-
#initialize(output) ⇒ Report
constructor
Initialize a new report object.
-
#not_after ⇒ Object
Time the certificate is no longer valid.
-
#not_before ⇒ Object
Time the certificate starts to be valid.
-
#sslversions ⇒ Object
Returns a list of supported SSL protocol versions.
-
#support_cipher?(cipher) ⇒ Boolean
Is the cipher supported?.
-
#support_sslversion?(version) ⇒ Boolean
Check if a SSL protocol version is supported.
Constructor Details
#initialize(output) ⇒ Report
Initialize a new report object
Examples
content = File.read('report.xml')
SslscanWrapper::Report.new(content)
Returns a new SslscanWrapper::Report
19 20 21 22 |
# File 'lib/sslscan_wrapper/report.rb', line 19 def initialize(output) @body = output @doc = Nokogiri::XML(@body) end |
Instance Attribute Details
#body ⇒ Object (readonly)
The content body of the report
8 9 10 |
# File 'lib/sslscan_wrapper/report.rb', line 8 def body @body end |
#doc ⇒ Object (readonly)
The nokogiri document object
10 11 12 |
# File 'lib/sslscan_wrapper/report.rb', line 10 def doc @doc end |
Class Method Details
.all_attr_values_accessor(name, xpath) ⇒ Object
52 53 54 55 56 |
# File 'lib/sslscan_wrapper/report.rb', line 52 def self.all_attr_values_accessor(name, xpath) define_method(name) do @doc.xpath(xpath).map(&:value) end end |
.attr_first_value_accessor(name, xpath) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/sslscan_wrapper/report.rb', line 24 def self.attr_first_value_accessor(name, xpath) define_method(name) do node = @doc.xpath(xpath).first node.value unless node.nil? end end |
.attr_first_value_boolean_true?(name, xpath) ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/sslscan_wrapper/report.rb', line 31 def self.attr_first_value_boolean_true?(name, xpath) define_method(name) do node = @doc.xpath(xpath).first node.value.to_i == 1 unless node.nil? end end |
.content_first_node_accessor(name, xpath) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/sslscan_wrapper/report.rb', line 38 def self.content_first_node_accessor(name, xpath) define_method(name) do node = @doc.xpath(xpath).first node.content unless node.nil? end end |
.content_first_node_boolean_true?(name, xpath) ⇒ Boolean
45 46 47 48 49 50 |
# File 'lib/sslscan_wrapper/report.rb', line 45 def self.content_first_node_boolean_true?(name, xpath) define_method(name) do node = @doc.xpath(xpath).first node.content == 'true' unless node.nil? end end |
Instance Method Details
#certificate ⇒ Object
Return the parsed certificate blob as OpenSSL::X509::Certificate
133 134 135 136 |
# File 'lib/sslscan_wrapper/report.rb', line 133 def certificate node = @doc.xpath('//certificate/certificate-blob').first OpenSSL::X509::Certificate.new(node.content) unless node.nil? end |
#heartbleed_vulnerable? ⇒ Boolean
Are there any heartblead vulnerable SSL/TLS protocol versions?
118 119 120 |
# File 'lib/sslscan_wrapper/report.rb', line 118 def heartbleed_vulnerable? @doc.xpath('//heartbleed[@vulnerable="1"]').count > 0 end |
#not_after ⇒ Object
Time the certificate is no longer valid
98 99 100 101 |
# File 'lib/sslscan_wrapper/report.rb', line 98 def not_after time_str = @doc.xpath('//certificate/not-valid-after').first.content Time.parse(time_str) end |
#not_before ⇒ Object
Time the certificate starts to be valid
92 93 94 95 |
# File 'lib/sslscan_wrapper/report.rb', line 92 def not_before time_str = @doc.xpath('//certificate/not-valid-before').first.content Time.parse(time_str) end |
#sslversions ⇒ Object
Returns a list of supported SSL protocol versions
123 124 125 |
# File 'lib/sslscan_wrapper/report.rb', line 123 def sslversions @doc.xpath('//cipher/@sslversion').map(&:value).uniq end |
#support_cipher?(cipher) ⇒ Boolean
Is the cipher supported?
107 108 109 |
# File 'lib/sslscan_wrapper/report.rb', line 107 def support_cipher?(cipher) @doc.xpath("//cipher[@cipher=$cipher]", nil, { cipher: cipher }).count > 0 end |
#support_sslversion?(version) ⇒ Boolean
Check if a SSL protocol version is supported
128 129 130 |
# File 'lib/sslscan_wrapper/report.rb', line 128 def support_sslversion?(version) @doc.xpath("//cipher[@sslversion=$version]", nil, { version: version }).count > 0 end |