@@ -22,7 +22,7 @@ def cert
22
22
23
23
def cert = ( input )
24
24
unless input . kind_of? OpenSSL ::X509 ::Certificate or input . nil?
25
- raise ArgumentError , "Must be an X509 Cert!"
25
+ raise ArgumentError , "Must be an X509 Cert!"
26
26
end
27
27
@cert = input
28
28
end
@@ -53,26 +53,7 @@ def strong_ciphers
53
53
# @raise [ArgumentError] if the version supplied is invalid
54
54
# @return [Array] An array of accepted cipher details matching the supplied versions
55
55
def accepted ( version = :all )
56
- case version
57
- when Symbol
58
- case version
59
- when :all
60
- return @ciphers . reject { |cipher | cipher [ :status ] == :rejected }
61
- when :SSLv2 , :SSLv3 , :TLSv1
62
- return @ciphers . reject { |cipher | cipher [ :status ] == :rejected or cipher [ :version ] != version }
63
- else
64
- raise ArgumentError , "Invalid SSL Version Supplied: #{ version } "
65
- end
66
- when Array
67
- version = version . reject { |v | !( @supported_versions . include? v ) }
68
- if version . empty?
69
- return @ciphers . reject { |cipher | cipher [ :status ] == :rejected }
70
- else
71
- return @ciphers . reject { |cipher | cipher [ :status ] == :rejected or !( version . include? cipher [ :version ] ) }
72
- end
73
- else
74
- raise ArgumentError , "Was expecting Symbol or Array and got #{ version . class } "
75
- end
56
+ enum_ciphers ( :accepted , version )
76
57
end
77
58
78
59
# Returns all rejected ciphers matching the supplied version
@@ -81,26 +62,7 @@ def accepted(version = :all)
81
62
# @raise [ArgumentError] if the version supplied is invalid
82
63
# @return [Array] An array of rejected cipher details matching the supplied versions
83
64
def rejected ( version = :all )
84
- case version
85
- when Symbol
86
- case version
87
- when :all
88
- return @ciphers . reject { |cipher | cipher [ :status ] == :accepted }
89
- when :SSLv2 , :SSLv3 , :TLSv1
90
- return @ciphers . reject { |cipher | cipher [ :status ] == :accepted or cipher [ :version ] != version }
91
- else
92
- raise ArgumentError , "Invalid SSL Version Supplied: #{ version } "
93
- end
94
- when Array
95
- version = version . reject { |v | !( @supported_versions . include? v ) }
96
- if version . empty?
97
- return @ciphers . reject { |cipher | cipher [ :status ] == :accepted }
98
- else
99
- return @ciphers . reject { |cipher | cipher [ :status ] == :accepted or !( version . include? cipher [ :version ] ) }
100
- end
101
- else
102
- raise ArgumentError , "Was expecting Symbol or Array and got #{ version . class } "
103
- end
65
+ enum_ciphers ( :rejected , version )
104
66
end
105
67
106
68
def each_accepted ( version = :all )
@@ -166,7 +128,7 @@ def add_cipher(version, cipher, key_length, status)
166
128
# OpenSSL Directive For Strong Ciphers
167
129
# See: http://www.rapid7.com/vulndb/lookup/ssl-weak-ciphers
168
130
strong_cipher_ctx . ciphers = "ALL:!aNULL:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM"
169
-
131
+
170
132
if strong_cipher_ctx . ciphers . flatten . include? cipher
171
133
weak = false
172
134
else
@@ -178,7 +140,7 @@ def add_cipher(version, cipher, key_length, status)
178
140
end
179
141
180
142
def to_s
181
- unless supports_ssl?
143
+ unless supports_ssl?
182
144
return "Server does not appear to support SSL on this port!"
183
145
end
184
146
table = Rex ::Ui ::Text ::Table . new (
@@ -206,6 +168,36 @@ def to_s
206
168
text << "\n \n *** WARNING: Your OS hates freedom! Your OpenSSL libs are compiled without SSLv2 support!"
207
169
end
208
170
text
209
- end
171
+ end
172
+
173
+ protected
174
+
175
+ # @param [Symbol] state Either :accepted or :rejected
176
+ # @param [Symbol] version The SSL Version to filter on (:SSLv2:SSLv3,:TLSv1)
177
+ # @param [Array] version An array of SSL Versions to filter on
178
+ # @return [Set] The Set of cipher results matching the filter criteria
179
+ def enum_ciphers(state, version = :all)
180
+ case version
181
+ when Symbol
182
+ case version
183
+ when :all
184
+ return @ciphers.select{|cipher| cipher[:status] == state}
185
+ when :SSLv2, :SSLv3, :TLSv1
186
+ return @ciphers.select{|cipher| cipher[:status] == state and cipher[:version] == version}
187
+ else
188
+ raise ArgumentError, "Invalid SSL Version Supplied: #{ version } "
189
+ end
190
+ when Array
191
+ version = version.reject{|v| !(@supported_versions.include? v)}
192
+ if version.empty?
193
+ return @ciphers.select{|cipher| cipher[:status] == state}
194
+ else
195
+ return @ciphers.select{|cipher| cipher[:status] == state and version.include? cipher[:version]}
196
+ end
197
+ else
198
+ raise ArgumentError, "Was expecting Symbol or Array and got #{ version . class } "
199
+ end
200
+ end
201
+
210
202
end
211
203
end
0 commit comments