Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

179 wiersze
2.5KB

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