ruby-sslyze 0.2.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -4
  3. data/.travis.yml +15 -7
  4. data/ChangeLog.md +29 -12
  5. data/Gemfile +3 -2
  6. data/LICENSE.txt +1 -1
  7. data/README.md +5 -5
  8. data/Rakefile +1 -1
  9. data/lib/sslyze/cipher_suites.rb +176 -0
  10. data/lib/sslyze/program.rb +8 -8
  11. data/lib/sslyze/task.rb +40 -33
  12. data/lib/sslyze/version.rb +1 -1
  13. data/lib/sslyze/{certificate/domain_name.rb → x509/domain.rb} +5 -3
  14. data/lib/sslyze/x509/extension.rb +15 -0
  15. data/lib/sslyze/x509/extension_set.rb +140 -0
  16. data/lib/sslyze/x509/extensions.rb +6 -0
  17. data/lib/sslyze/x509/extensions/basic_constraints.rb +41 -0
  18. data/lib/sslyze/x509/extensions/certificate_policies.rb +108 -0
  19. data/lib/sslyze/x509/extensions/crl_distribution_points.rb +47 -0
  20. data/lib/sslyze/x509/extensions/extended_key_usage.rb +58 -0
  21. data/lib/sslyze/x509/extensions/key_usage.rb +66 -0
  22. data/lib/sslyze/x509/extensions/subject_alt_name.rb +144 -0
  23. data/lib/sslyze/x509/name.rb +194 -0
  24. data/lib/sslyze/x509/public_key.rb +53 -0
  25. data/lib/sslyze/xml.rb +26 -37
  26. data/lib/sslyze/xml/attributes.rb +5 -0
  27. data/lib/sslyze/xml/attributes/error.rb +30 -0
  28. data/lib/sslyze/xml/attributes/exception.rb +30 -0
  29. data/lib/sslyze/xml/attributes/is_supported.rb +29 -0
  30. data/lib/sslyze/xml/attributes/is_vulnerable.rb +29 -0
  31. data/lib/sslyze/xml/attributes/title.rb +31 -0
  32. data/lib/sslyze/xml/certinfo.rb +67 -0
  33. data/lib/sslyze/xml/certinfo/certificate.rb +202 -0
  34. data/lib/sslyze/xml/certinfo/certificate_validation.rb +69 -0
  35. data/lib/sslyze/xml/certinfo/certificate_validation/hostname_validation.rb +54 -0
  36. data/lib/sslyze/xml/certinfo/certificate_validation/path_validation.rb +84 -0
  37. data/lib/sslyze/xml/certinfo/certificate_validation/verified_certificate_chain.rb +41 -0
  38. data/lib/sslyze/xml/certinfo/has_certificates.rb +102 -0
  39. data/lib/sslyze/xml/certinfo/ocsp_stapling.rb +45 -0
  40. data/lib/sslyze/xml/certinfo/ocsp_stapling/ocsp_response.rb +87 -0
  41. data/lib/sslyze/xml/certinfo/received_certificate_chain.rb +48 -0
  42. data/lib/sslyze/xml/compression.rb +33 -0
  43. data/lib/sslyze/xml/compression/compression_method.rb +38 -0
  44. data/lib/sslyze/xml/fallback.rb +34 -0
  45. data/lib/sslyze/xml/fallback/tls_fallback_scsv.rb +27 -0
  46. data/lib/sslyze/xml/heartbleed.rb +38 -0
  47. data/lib/sslyze/xml/heartbleed/openssl_heartbleed.rb +29 -0
  48. data/lib/sslyze/xml/http_headers.rb +42 -0
  49. data/lib/sslyze/xml/http_headers/http_public_key_pinning.rb +121 -0
  50. data/lib/sslyze/xml/http_headers/http_strict_transport_security.rb +59 -0
  51. data/lib/sslyze/xml/invalid_target.rb +33 -0
  52. data/lib/sslyze/xml/openssl_ccs.rb +34 -0
  53. data/lib/sslyze/xml/openssl_ccs/openssl_ccs_injection.rb +26 -0
  54. data/lib/sslyze/xml/plugin.rb +27 -0
  55. data/lib/sslyze/xml/protocol.rb +143 -0
  56. data/lib/sslyze/xml/protocol/cipher_suite.rb +93 -0
  57. data/lib/sslyze/xml/protocol/cipher_suite/key_exchange.rb +127 -0
  58. data/lib/sslyze/xml/reneg.rb +28 -0
  59. data/lib/sslyze/xml/reneg/session_renegotiation.rb +51 -0
  60. data/lib/sslyze/xml/resum.rb +42 -0
  61. data/lib/sslyze/xml/resum/session_resumption_with_session_ids.rb +94 -0
  62. data/lib/sslyze/xml/resum/session_resumption_with_tls_tickets.rb +69 -0
  63. data/lib/sslyze/xml/resum_rate.rb +30 -0
  64. data/lib/sslyze/xml/target.rb +371 -0
  65. data/lib/sslyze/xml/types.rb +19 -0
  66. data/ruby-sslyze.gemspec +3 -3
  67. data/spec/spec_helper.rb +2 -4
  68. data/spec/sslyze.xml +2356 -2580
  69. data/spec/x509/domain_spec.rb +125 -0
  70. data/spec/x509/extension_set_spec.rb +208 -0
  71. data/spec/x509/extension_spec.rb +58 -0
  72. data/spec/x509/extensions/basic_constraints_spec.rb +41 -0
  73. data/spec/x509/extensions/certificate_policies_spec.rb +38 -0
  74. data/spec/x509/extensions/crl_distribution_points_spec.rb +38 -0
  75. data/spec/x509/extensions/extended_key_usage_spec.rb +58 -0
  76. data/spec/x509/extensions/key_usage_spec.rb +84 -0
  77. data/spec/x509/extensions/subject_alt_name_spec.rb +146 -0
  78. data/spec/x509/name_spec.rb +85 -0
  79. data/spec/x509/public_key_spec.rb +113 -0
  80. data/spec/xml/certinfo/certificate_spec.rb +166 -0
  81. data/spec/xml/certinfo/certificate_validation/hostname_validation_spec.rb +23 -0
  82. data/spec/xml/certinfo/certificate_validation/path_validation_spec.rb +107 -0
  83. data/spec/xml/certinfo/certificate_validation/verified_certificate_chain_spec.rb +163 -0
  84. data/spec/xml/certinfo/certificate_validation_spec.rb +40 -0
  85. data/spec/xml/certinfo/ocsp_stapling/ocsp_response_spec.rb +61 -0
  86. data/spec/xml/certinfo/ocsp_stapling_spec.rb +31 -0
  87. data/spec/xml/certinfo/received_certificate_chain_spec.rb +165 -0
  88. data/spec/xml/certinfo_spec.rb +45 -0
  89. data/spec/xml/compression/compression_method_spec.rb +23 -0
  90. data/spec/xml/compression_spec.rb +23 -0
  91. data/spec/xml/heartbleed/openssl_heartbleed_spec.rb +17 -0
  92. data/spec/xml/heartbleed_spec.rb +37 -0
  93. data/spec/xml/http_headers/http_public_key_pinning_spec.rb +73 -0
  94. data/spec/xml/http_headers/http_strict_transport_security_spec.rb +107 -0
  95. data/spec/xml/http_headers_spec.rb +63 -0
  96. data/spec/xml/invalid_target_spec.rb +23 -0
  97. data/spec/xml/plugin_examples.rb +14 -0
  98. data/spec/{key_exchange_spec.rb → xml/protocol/cipher_suite/key_exchange_spec.rb} +9 -3
  99. data/spec/xml/protocol/cipher_suite_spec.rb +66 -0
  100. data/spec/xml/protocol_spec.rb +115 -0
  101. data/spec/xml/reneg/session_renegotiation_spec.rb +23 -0
  102. data/spec/xml/reneg_spec.rb +35 -0
  103. data/spec/xml/resum/session_resumption_with_session_ids_spec.rb +103 -0
  104. data/spec/xml/resum/session_resumption_with_tls_tickets_spec.rb +121 -0
  105. data/spec/xml/resum_rate_spec.rb +30 -0
  106. data/spec/xml/resum_spec.rb +47 -0
  107. data/spec/{target_spec.rb → xml/target_spec.rb} +73 -27
  108. data/spec/xml_spec.rb +13 -21
  109. metadata +138 -61
  110. data/lib/sslyze/cert_info.rb +0 -57
  111. data/lib/sslyze/certificate.rb +0 -139
  112. data/lib/sslyze/certificate/extensions.rb +0 -127
  113. data/lib/sslyze/certificate/extensions/authority_information_access.rb +0 -38
  114. data/lib/sslyze/certificate/extensions/extension.rb +0 -26
  115. data/lib/sslyze/certificate/extensions/x509v3_basic_constraints.rb +0 -60
  116. data/lib/sslyze/certificate/extensions/x509v3_certificate_policies.rb +0 -50
  117. data/lib/sslyze/certificate/extensions/x509v3_crl_distribution_points.rb +0 -32
  118. data/lib/sslyze/certificate/extensions/x509v3_extended_key_usage.rb +0 -32
  119. data/lib/sslyze/certificate/extensions/x509v3_key_usage.rb +0 -50
  120. data/lib/sslyze/certificate/extensions/x509v3_subject_alternative_name.rb +0 -71
  121. data/lib/sslyze/certificate/issuer.rb +0 -56
  122. data/lib/sslyze/certificate/public_key.rb +0 -9
  123. data/lib/sslyze/certificate/subject.rb +0 -117
  124. data/lib/sslyze/certificate/subject_public_key_info.rb +0 -53
  125. data/lib/sslyze/certificate/validity.rb +0 -9
  126. data/lib/sslyze/certificate_chain.rb +0 -89
  127. data/lib/sslyze/certificate_validation.rb +0 -70
  128. data/lib/sslyze/cipher_suite.rb +0 -237
  129. data/lib/sslyze/invalid_target.rb +0 -35
  130. data/lib/sslyze/key_exchange.rb +0 -106
  131. data/lib/sslyze/ocsp_response.rb +0 -87
  132. data/lib/sslyze/protocol.rb +0 -133
  133. data/lib/sslyze/target.rb +0 -312
  134. data/lib/sslyze/types.rb +0 -17
  135. data/spec/cert_info_spec.rb +0 -29
  136. data/spec/certificate/subject_name_spec.rb +0 -72
  137. data/spec/certificate_chain_spec.rb +0 -61
  138. data/spec/certificate_spec.rb +0 -330
  139. data/spec/certificate_validation_spec.rb +0 -39
  140. data/spec/cipher_suite_spec.rb +0 -50
  141. data/spec/invalid_target_spec.rb +0 -21
  142. data/spec/issuer_spec.rb +0 -33
  143. data/spec/ocsp_response_spec.rb +0 -59
  144. data/spec/protocol_spec.rb +0 -99
  145. data/spec/subject_public_key_info_spec.rb +0 -35
  146. data/spec/subject_spec.rb +0 -69
@@ -0,0 +1,69 @@
1
+ require 'sslyze/xml/plugin'
2
+ require 'sslyze/xml/certinfo/certificate_validation/hostname_validation'
3
+ require 'sslyze/xml/certinfo/certificate_validation/path_validation'
4
+
5
+ module SSLyze
6
+ class XML
7
+ class Certinfo < Plugin
8
+ #
9
+ # Represents the `<certificateValidation>` XML element.
10
+ #
11
+ # @since 1.0.0
12
+ #
13
+ class CertificateValidation
14
+
15
+ #
16
+ # Initializes the {CertificateValidation} object.
17
+ #
18
+ # @param [Nokogiri::XML::Element] node
19
+ # The `<certificateValidation>` XML element.
20
+ #
21
+ def initialize(node)
22
+ @node = node
23
+ end
24
+
25
+ #
26
+ # Hostname based validation information.
27
+ #
28
+ # @return [HostnameValidation]
29
+ #
30
+ def hostname_validation
31
+ @hostname_validation ||= HostnameValidation.new(
32
+ @node.at_xpath('hostnameValidation')
33
+ )
34
+ end
35
+
36
+ alias hostname hostname_validation
37
+
38
+ #
39
+ # Enumerates over the path-based validation information.
40
+ #
41
+ # @yield [path_validation]
42
+ #
43
+ # @yieldparam [PathValidation] path_validation
44
+ #
45
+ # @return [Enumerator]
46
+ #
47
+ def each_path_validation
48
+ return enum_for(__method__) unless block_given?
49
+
50
+ @node.xpath('pathValidation').each do |element|
51
+ yield PathValidation.new(element)
52
+ end
53
+ end
54
+
55
+ #
56
+ # @return [Array<PathValidation>]
57
+ #
58
+ # @see #each_path_validation
59
+ #
60
+ def path_validations
61
+ each_path_validation.to_a
62
+ end
63
+
64
+ alias path path_validations
65
+
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,54 @@
1
+ require 'sslyze/xml/plugin'
2
+ require 'sslyze/xml/types'
3
+
4
+ module SSLyze
5
+ class XML
6
+ class Certinfo < Plugin
7
+ class CertificateValidation
8
+ #
9
+ # Represents the `<hostnameValidation>` XML element.
10
+ #
11
+ # @since 1.0.0
12
+ #
13
+ class HostnameValidation
14
+
15
+ include Types
16
+
17
+ #
18
+ # Initializes the element.
19
+ #
20
+ # @param [Nokogiri::XML::Element] node
21
+ # The `<hostnameValidation>` XML element.
22
+ #
23
+ def initialize(node)
24
+ @node = node
25
+ end
26
+
27
+ #
28
+ # Determines if the certificate Common Name matches the target domain
29
+ # name.
30
+ #
31
+ # @return [Boolean]
32
+ #
33
+ def certificate_matches_server_hostname?
34
+ Boolean[@node['certificateMatchesServerHostname']]
35
+ end
36
+
37
+ alias matches_server_hostname? certificate_matches_server_hostname?
38
+
39
+ #
40
+ # The server's domain name.
41
+ #
42
+ # @return [String]
43
+ #
44
+ def server_hostname
45
+ @node['serverHostname']
46
+ end
47
+
48
+ alias to_s server_hostname
49
+
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,84 @@
1
+ require 'sslyze/xml/plugin'
2
+ require 'sslyze/xml/types'
3
+ require 'sslyze/xml/attributes/error'
4
+
5
+ module SSLyze
6
+ class XML
7
+ class Certinfo < Plugin
8
+ class CertificateValidation
9
+ #
10
+ # Represents the `<pathValidation>` XML element.
11
+ #
12
+ # @since 1.0.0
13
+ #
14
+ class PathValidation
15
+
16
+ include Types
17
+ include Attributes::Error
18
+
19
+ #
20
+ # Initializes the element.
21
+ #
22
+ # @param [Nokogiri::XML::Element] node
23
+ # The `<pathValidation>` XML element.
24
+ #
25
+ def initialize(node)
26
+ @node = node
27
+ end
28
+
29
+ #
30
+ # @return [Boolean, nil]
31
+ #
32
+ def is_extended_validation_certificate?
33
+ Boolean[@node['isExtendedValidationCertificate']]
34
+ end
35
+
36
+ alias is_extended_validation_cert? is_extended_validation_certificate?
37
+
38
+ #
39
+ # @return [String]
40
+ #
41
+ def trust_store_version
42
+ @trust_store_version ||= @node['trustStoreVersion']
43
+ end
44
+
45
+ #
46
+ # @return [String]
47
+ #
48
+ def using_trust_store
49
+ @using_trust_store ||= @node['usingTrustStore']
50
+ end
51
+
52
+ alias trust_store using_trust_store
53
+
54
+ #
55
+ # The validation result.
56
+ #
57
+ # @return [Symbol, nil]
58
+ #
59
+ def validation_result
60
+ @validation_result ||= if (value = @node['validationResult'])
61
+ value.to_sym
62
+ end
63
+ end
64
+
65
+ alias result validation_result
66
+
67
+ #
68
+ # Determines if the {#validation_result} was `:ok`.
69
+ #
70
+ # @return [Boolean, nil]
71
+ #
72
+ def ok?
73
+ if validation_result
74
+ validation_result == :ok
75
+ end
76
+ end
77
+
78
+ alias valid? ok?
79
+
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,41 @@
1
+ require 'sslyze/xml/plugin'
2
+ require 'sslyze/xml/certinfo/has_certificates'
3
+
4
+ module SSLyze
5
+ class XML
6
+ class Certinfo < Plugin
7
+ class CertificateValidation
8
+ #
9
+ # Represents the `<verifiedCertificateChain>` XML element.
10
+ #
11
+ # @since 1.0.0
12
+ #
13
+ class VerifiedCertificateChain
14
+
15
+ include Types
16
+ include HasCertificates
17
+
18
+ #
19
+ # Initializes the {VerifiedCertificateChain} object.
20
+ #
21
+ # @param [Nokogiri::XML::Element] node
22
+ # The `<verifiedCertificateChain>` XML element.
23
+ #
24
+ def initialize(node)
25
+ @node = node
26
+ end
27
+
28
+ #
29
+ # Parses the `hasSha1SignedCertificate` XML attribute.
30
+ #
31
+ # @return [Boolean]
32
+ #
33
+ def has_sha1_signed_certificate?
34
+ Boolean[@node['hasSha1SignedCertificate']]
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,102 @@
1
+ require 'sslyze/xml/plugin'
2
+ require 'sslyze/xml/types'
3
+ require 'sslyze/xml/certinfo/certificate'
4
+
5
+ module SSLyze
6
+ class XML
7
+ class Certinfo < Plugin
8
+ #
9
+ # @since 1.0.0
10
+ #
11
+ module HasCertificates
12
+ include Enumerable
13
+
14
+ #
15
+ # Enumerates over each certificate in the chain.
16
+ #
17
+ # @yield [cert]
18
+ # The given block will be passed each certificate.
19
+ #
20
+ # @yieldparam [Certificate] cert
21
+ # A certificate in the chain.
22
+ #
23
+ # @return [Enumerator]
24
+ # If no block was given, an Enumerator will be returned.
25
+ #
26
+ def each_certificate
27
+ return enum_for(__method__) unless block_given?
28
+
29
+ @node.xpath('certificate').each do |element|
30
+ yield Certificate.new(element)
31
+ end
32
+ end
33
+
34
+ alias each_cert each_certificate
35
+ alias each each_certificate
36
+
37
+ #
38
+ # Returns all certificates in the chain.
39
+ #
40
+ # @return [Array<Certificate>]
41
+ #
42
+ def certificates
43
+ each_certificate.to_a
44
+ end
45
+
46
+ alias certs certificates
47
+
48
+ #
49
+ # The leaf certificate.
50
+ #
51
+ # @return [Certificate, nil]
52
+ #
53
+ def leaf
54
+ if (element = @node.at_xpath('certificate[1]'))
55
+ Certificate.new(element)
56
+ end
57
+ end
58
+
59
+ #
60
+ # Enumerates over any intermediate certificates in the chain.
61
+ #
62
+ # @yield [cert]
63
+ # The given block will be passed each intermediate certificate.
64
+ #
65
+ # @yieldparam [Certificate] cert
66
+ # An intermediate certificate in the chain.
67
+ #
68
+ # @return [Enumerator]
69
+ # If no block was given, an Enumerator will be returned.
70
+ #
71
+ def each_intermediate
72
+ return enum_for(__method__) unless block_given?
73
+
74
+ @node.xpath('certificate[position() > 1 and position() < last()]').each do |element|
75
+ yield Certificate.new(element)
76
+ end
77
+ end
78
+
79
+ #
80
+ # Returns all intermediate certificates in the chain.
81
+ #
82
+ # @return [Array<Certificate>]
83
+ #
84
+ def intermediates
85
+ each_intermediate.to_a
86
+ end
87
+
88
+ #
89
+ # The root certificate.
90
+ #
91
+ # @return [Certificate, nil]
92
+ #
93
+ def root
94
+ if (element = @node.at_xpath('certificate[last()]'))
95
+ Certificate.new(element)
96
+ end
97
+ end
98
+
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,45 @@
1
+ require 'sslyze/xml/plugin'
2
+ require 'sslyze/xml/attributes/is_supported'
3
+ require 'sslyze/xml/certinfo/ocsp_stapling/ocsp_response'
4
+
5
+ module SSLyze
6
+ class XML
7
+ class Certinfo < Plugin
8
+ #
9
+ # Represents the `<ocspStapling>` XML element.
10
+ #
11
+ # @since 1.0.0
12
+ #
13
+ class OCSPStapling
14
+
15
+ include Attributes::IsSupported
16
+
17
+ #
18
+ # Initializes the {OCSPStapling} object.
19
+ #
20
+ # @param [Nokogiri::XML::Element] node
21
+ # The `<ocspStapling>` XML element.
22
+ #
23
+ def initialize(node)
24
+ @node = node
25
+ end
26
+
27
+ #
28
+ # The OCSP Response.
29
+ #
30
+ # @return [OCSPResponse, nil]
31
+ #
32
+ # @note Parses the `<ocspResponse>` XML element.
33
+ #
34
+ def ocsp_response
35
+ @ocsp_response ||= if (element = @node.at_xpath('ocspResponse'))
36
+ OCSPResponse.new(element)
37
+ end
38
+ end
39
+
40
+ alias response ocsp_response
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,87 @@
1
+ require 'sslyze/xml/plugin'
2
+ require 'sslyze/xml/types'
3
+
4
+ require 'time'
5
+
6
+ module SSLyze
7
+ class XML
8
+ class Certinfo < Plugin
9
+ class OCSPStapling
10
+ #
11
+ # Represents the `<ocspResponse>` XML element.
12
+ #
13
+ # @since 1.0.0
14
+ #
15
+ class OCSPResponse
16
+
17
+ include Types
18
+
19
+ #
20
+ # Initializes the {OCSPResponse} object.
21
+ #
22
+ # @param [Nokogiri::XML::Element] node
23
+ # The `<ocspResponse>` XML element.
24
+ #
25
+ def initialize(node)
26
+ @node = node
27
+ end
28
+
29
+ #
30
+ # The responder's ID.
31
+ #
32
+ # @return [String]
33
+ #
34
+ # @note Parses the `responderID` attribute.
35
+ #
36
+ def responder_id
37
+ @responder_id ||= @node.at_xpath('responderID').inner_text
38
+ end
39
+
40
+ alias id responder_id
41
+
42
+ #
43
+ # When the response was produced at.
44
+ #
45
+ # @return [Time]
46
+ #
47
+ def produced_at
48
+ @produced_at ||= Time.parse(@node.at_xpath('producedAt').inner_text)
49
+ end
50
+
51
+ alias to_time produced_at
52
+
53
+ #
54
+ # The status.
55
+ #
56
+ # @return [:successful]
57
+ #
58
+ def status
59
+ @status ||= @node['status'].downcase.to_sym
60
+ end
61
+
62
+ #
63
+ # Determines if the response status was successful.
64
+ #
65
+ # @return [Boolean]
66
+ #
67
+ def successful?
68
+ status == :successful
69
+ end
70
+
71
+ #
72
+ # Specifies whether the OCSP Response is trusted by Mozilla's CA
73
+ # Store.
74
+ #
75
+ # @return [Boolean]
76
+ #
77
+ def is_trusted_by_mozilla_ca_store?
78
+ Boolean[@node['isTrustedByMozillaCAStore']]
79
+ end
80
+
81
+ alias trusted? is_trusted_by_mozilla_ca_store?
82
+
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end