Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

check_helper.rb 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. module CheckHelper
  2. private def __label(value, color, state=true)
  3. color = :default unless color
  4. color = "state-#{color}" if state
  5. "<span class=\"label label-#{color}\">#{value}</span>"
  6. end
  7. def label(value, color, state=true)
  8. __label(value, color, state).html_safe
  9. end
  10. def cell(value, color, state=true)
  11. "<td class=\"label-state-#{color}\">#{value}</td>".html_safe
  12. end
  13. def labels(level, states, state=true)
  14. states.each_pair.collect do |name, value|
  15. color = if value.nil?
  16. :default
  17. elsif ::CryptCheck::State.bad? level
  18. value ? :danger : :success
  19. else
  20. value ? :success : :danger
  21. end
  22. __label name, color, state
  23. end.join(' ').html_safe
  24. end
  25. def states(states)
  26. ::CryptCheck::State.collect do |level|
  27. states[level].each_pair
  28. .select { |_, v| v == true }
  29. .collect { |name, _| __label name, level }
  30. end.flatten(1).join(' ').html_safe
  31. end
  32. def rank_color(rank)
  33. case rank
  34. when :'A+', :A
  35. :great
  36. when :'B+', :B
  37. :best
  38. when :'C+', :C
  39. :good
  40. when :D
  41. nil
  42. when :E
  43. :warning
  44. when :F
  45. :error
  46. else
  47. :critical
  48. end
  49. end
  50. def rank_label(rank)
  51. label rank, rank_color(rank)
  52. end
  53. def protocol_label(protocol)
  54. label protocol.to_sym, protocol.status
  55. end
  56. def protocol_labels(protocols)
  57. protocols.collect { |p| protocol_label p }.join("\n").html_safe
  58. end
  59. def key_label(key)
  60. return label('Aucune', :error) unless key
  61. label "#{key[:type].upcase} #{key[:size]} bits", key_color(key)
  62. end
  63. def key_labels(keys)
  64. return label('Aucune', :error) if keys.empty?
  65. keys.sort { |a, b| -1 * (a[:size] <=> b[:size]) }.collect { |k| key_label k }.join("\n").html_safe
  66. end
  67. def cipher_size_label(cipher)
  68. size = cipher.size if cipher.is_a? CryptCheck::Tls::Cipher
  69. label "#{size} bits", cipher_color(size)
  70. end
  71. def key_color(key)
  72. case key[:size]
  73. when nil then
  74. :default
  75. when 0...1024 then
  76. :error
  77. when 1024...2048 then
  78. :danger
  79. when 2048...4096 then
  80. :warning
  81. else
  82. :success
  83. end
  84. end
  85. def cipher_color(key)
  86. case key
  87. when nil then
  88. :default
  89. when 0...128 then
  90. :error
  91. when 112...128 then
  92. :danger
  93. when 128...256 then
  94. :success
  95. else
  96. :primary
  97. end
  98. end
  99. def cipher_name_label(cipher)
  100. status = cipher.status
  101. status = :success if status == :good
  102. label("&nbsp;", status) + "&nbsp;#{cipher.name}".html_safe
  103. end
  104. def cipher_labels(cipher)
  105. cipher.state.collect { |c, ls| ls.collect { |l| label l.upcase, c } }
  106. .flatten(1).join("\n").html_safe
  107. end
  108. def cipher_kex_type_cell(kex)
  109. color = case kex
  110. when :ecdh then
  111. nil
  112. when :dh then
  113. :warning
  114. when :rsa then
  115. :error
  116. else
  117. :critical
  118. end
  119. kex ||= 'None'
  120. cell kex.to_s.upcase, color
  121. end
  122. def cipher_kex_size_cell(kex)
  123. color = key_color kex
  124. cell kex&.[](:size), color
  125. end
  126. def cipher_auth_type_cell(auth)
  127. color = case auth
  128. when :ecdsa, :rsa then
  129. nil
  130. else
  131. :critical
  132. end
  133. auth ||= 'None'
  134. cell auth.to_s.upcase, color
  135. end
  136. def cipher_auth_size_cell(auth)
  137. color = key_color auth
  138. cell auth&.[](:size), color
  139. end
  140. def cipher_enc_type_cell(enc)
  141. color = case enc
  142. when :chacha20
  143. :success
  144. when nil, :rc4
  145. :critical
  146. end
  147. enc ||= 'NONE'
  148. cell enc.to_s.upcase, color
  149. end
  150. def cipher_enc_block_size_cell(enc)
  151. color = case
  152. when enc == :stream
  153. nil
  154. when enc.nil?
  155. nil
  156. when enc <= 64
  157. :critical
  158. when enc < 128
  159. :error
  160. end
  161. cell enc, color
  162. end
  163. def cipher_enc_key_size_cell(enc)
  164. color = case
  165. when enc.nil?
  166. nil
  167. when enc < 128
  168. :critical
  169. end
  170. cell enc, color
  171. end
  172. def cipher_enc_mode_cell(enc)
  173. color = case enc
  174. when :gcm, :ccm, :aead
  175. :success
  176. end
  177. cell enc.to_s.upcase, color
  178. end
  179. def cipher_mac_type_cell(mac)
  180. color = case mac
  181. when :poly1305 then
  182. :success
  183. when :sha384, :sha256 then
  184. nil
  185. when :sha1 then
  186. :warning
  187. else
  188. :critical
  189. end
  190. cell mac.to_s.upcase, color
  191. end
  192. def cipher_mac_size_cell(mac)
  193. cell mac, nil
  194. end
  195. def cipher_pfs_cell(pfs)
  196. return cell 'PFS', nil if pfs
  197. cell 'No PFS', :error
  198. end
  199. end