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.

fixture.rb 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. require 'openssl'
  2. class ::OpenSSL::PKey::EC
  3. def type
  4. :ecc
  5. end
  6. def size
  7. self.group.degree
  8. end
  9. def curve
  10. self.group.curve_name
  11. end
  12. def to_s
  13. "ECC #{self.size} bits"
  14. end
  15. include ::CryptCheck::Statused
  16. CHECKS = [
  17. [:weak_key, -> (s) do
  18. case s.size
  19. when 0...160
  20. :critical
  21. when 160...192
  22. :error
  23. when 192...256
  24. :warning
  25. end
  26. end]
  27. ].freeze
  28. def checks
  29. CHECKS
  30. end
  31. end
  32. class ::OpenSSL::PKey::RSA
  33. def type
  34. :rsa
  35. end
  36. def size
  37. self.n.num_bits
  38. end
  39. def to_s
  40. "RSA #{self.size} bits"
  41. end
  42. include ::CryptCheck::Statused
  43. CHECKS = [
  44. [:weak_key, -> (s) do
  45. case s.size
  46. when 0...1024
  47. :critical
  48. when 1024...2048
  49. :error
  50. end
  51. end]
  52. ].freeze
  53. def checks
  54. CHECKS
  55. end
  56. end
  57. class ::OpenSSL::PKey::DSA
  58. def type
  59. :dsa
  60. end
  61. def size
  62. self.p.num_bits
  63. end
  64. def to_s
  65. "DSA #{self.size} bits"
  66. end
  67. include ::CryptCheck::Statused
  68. CHECKS = [
  69. [:weak_key, -> (_) { :critical }]
  70. ].freeze
  71. def checks
  72. CHECKS
  73. end
  74. end
  75. class ::OpenSSL::PKey::DH
  76. def type
  77. :dh
  78. end
  79. def size
  80. self.p.num_bits
  81. end
  82. def to_s
  83. "DH #{self.size} bits"
  84. end
  85. include ::CryptCheck::Statused
  86. CHECKS = [
  87. [:weak_dh, -> (s) do
  88. case s.size
  89. when 0...1024
  90. :critical
  91. when 1024...2048
  92. :error
  93. else
  94. :warning
  95. end
  96. end]
  97. ].freeze
  98. def checks
  99. CHECKS
  100. end
  101. end
  102. class ::OpenSSL::X509::Store
  103. def add_chains(chains)
  104. chains = [chains] unless chains.is_a? Enumerable
  105. chains.each do |chain|
  106. case chain
  107. when ::OpenSSL::X509::Certificate
  108. self.add_cert chain
  109. else
  110. if File.directory?(chain)
  111. Dir.entries(chain)
  112. .collect { |e| File.join chain, e }
  113. .select { |e| File.file? e }
  114. .each { |f| self.add_file f }
  115. else
  116. self.add_file chain
  117. end
  118. end
  119. end
  120. end
  121. end