Browse Source

Better way to manager TLS methods as symbol

new-scoring
aeris 2 years ago
parent
commit
4fa17e724f
2 changed files with 6 additions and 7 deletions
  1. 2
    1
      lib/cryptcheck/tls/cipher.rb
  2. 4
    6
      lib/cryptcheck/tls/server.rb

+ 2
- 1
lib/cryptcheck/tls/cipher.rb View File

@@ -273,8 +273,9 @@ module CryptCheck
273 273
 
274 274
 			ALL       = 'ALL:COMPLEMENTOFALL'
275 275
 			SUPPORTED = Method.collect do |m|
276
-				context         = ::OpenSSL::SSL::SSLContext.new m.name
276
+				context         = ::OpenSSL::SSL::SSLContext.new m.to_sym
277 277
 				context.ciphers = ALL
278
+
278 279
 				[m, context.ciphers.collect { |c| Cipher.new m, c.first }.sort ]
279 280
 			end.to_h.freeze
280 281
 		end

+ 4
- 6
lib/cryptcheck/tls/server.rb View File

@@ -28,7 +28,7 @@ module CryptCheck
28 28
 			class ConnectionError < ::StandardError
29 29
 			end
30 30
 
31
-			attr_reader :certs, :keys, :dh, :supported_methods, :supported_curves, :curves_preference
31
+			attr_reader :certs, :keys, :dh, :supported_methods, :supported_ciphers, :supported_curves, :curves_preference
32 32
 
33 33
 			def initialize(hostname, family, ip, port)
34 34
 				@hostname, @family, @ip, @port = hostname, family, ip, port
@@ -283,10 +283,9 @@ module CryptCheck
283 283
 			end
284 284
 
285 285
 			Method.each do |method|
286
-				method = method.name
287 286
 				class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
288
-					def #{method.to_s.downcase}?
289
-						@supported_methods.detect { |m| m.name == method }
287
+					def #{method.to_sym.downcase}?
288
+						@supported_methods.detect { |m| m == method }
290 289
 					end
291 290
 				RUBY_EVAL
292 291
 			end
@@ -421,8 +420,7 @@ module CryptCheck
421 420
 			end
422 421
 
423 422
 			def ssl_client(method, ciphers = nil, curves: nil, fallback: false, &block)
424
-				method      = method.name
425
-				ssl_context = ::OpenSSL::SSL::SSLContext.new method
423
+				ssl_context = ::OpenSSL::SSL::SSLContext.new method.to_sym
426 424
 				ssl_context.enable_fallback_scsv if fallback
427 425
 
428 426
 				if ciphers

Loading…
Cancel
Save