You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

method.rb 927B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. require 'delegate'
  2. module CryptCheck
  3. module Tls
  4. class Method < SimpleDelegator
  5. EXISTING = %i(TLSv1_2 TLSv1_1 TLSv1 SSLv3 SSLv2).freeze
  6. SUPPORTED = (EXISTING & ::OpenSSL::SSL::SSLContext::METHODS)
  7. .collect { |m| [m, self.new(m)] }.to_h.freeze
  8. def self.[](method)
  9. SUPPORTED[method]
  10. end
  11. extend Enumerable
  12. def self.each(&block)
  13. SUPPORTED.values.each &block
  14. end
  15. def to_s
  16. colors = case self.to_sym
  17. when *%i(SSLv3 SSLv2)
  18. :critical
  19. when :TLSv1_2
  20. :good
  21. end
  22. super.colorize colors
  23. end
  24. alias :to_sym :__getobj__
  25. def <=>(other)
  26. EXISTING.find_index(self) <=> EXISTING.find_index(other)
  27. end
  28. include State
  29. CHECKS = [
  30. [:sslv2, -> (s) { s == :SSLv2 }, :critical],
  31. [:sslv3, -> (s) { s == :SSLv3 }, :critical],
  32. [:tlsv1_2, -> (s) { s == :TLSv1_2 }, :good]
  33. ]
  34. def checks
  35. CHECKS
  36. end
  37. end
  38. end
  39. end