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

ALL = 'ALL:COMPLEMENTOFALL'
SUPPORTED = Method.collect do |m|
context = ::OpenSSL::SSL::SSLContext.new m.name
context = ::OpenSSL::SSL::SSLContext.new m.to_sym
context.ciphers = ALL

[m, context.ciphers.collect { |c| Cipher.new m, c.first }.sort ]
end.to_h.freeze
end

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

@@ -28,7 +28,7 @@ module CryptCheck
class ConnectionError < ::StandardError
end

attr_reader :certs, :keys, :dh, :supported_methods, :supported_curves, :curves_preference
attr_reader :certs, :keys, :dh, :supported_methods, :supported_ciphers, :supported_curves, :curves_preference

def initialize(hostname, family, ip, port)
@hostname, @family, @ip, @port = hostname, family, ip, port
@@ -283,10 +283,9 @@ module CryptCheck
end

Method.each do |method|
method = method.name
class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
def #{method.to_s.downcase}?
@supported_methods.detect { |m| m.name == method }
def #{method.to_sym.downcase}?
@supported_methods.detect { |m| m == method }
end
RUBY_EVAL
end
@@ -421,8 +420,7 @@ module CryptCheck
end

def ssl_client(method, ciphers = nil, curves: nil, fallback: false, &block)
method = method.name
ssl_context = ::OpenSSL::SSL::SSLContext.new method
ssl_context = ::OpenSSL::SSL::SSLContext.new method.to_sym
ssl_context.enable_fallback_scsv if fallback

if ciphers

Loading…
Cancel
Save