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.

57 lines
1.2KB

  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. def to_h
  25. { protocol: self.to_sym, states: self.states }
  26. end
  27. alias to_sym __getobj__
  28. def <=>(other)
  29. EXISTING.find_index(self) <=> EXISTING.find_index(other)
  30. end
  31. include State
  32. CHECKS = [
  33. [:sslv2, :critical, -> (s) { s == :SSLv2 }],
  34. [:sslv3, :critical, -> (s) { s == :SSLv3 }],
  35. [:tlsv1_0, :error, -> (s) { s == :TLSv1 }],
  36. [:tlsv1_1, :error, -> (s) { s == :TLSv1_1 }]
  37. ].freeze
  38. protected
  39. def available_checks
  40. CHECKS
  41. end
  42. end
  43. end
  44. end