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.

check_worker.rb 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. require 'simpleidn'
  2. require 'cryptcheck'
  3. class CheckWorker
  4. include Sidekiq::Worker
  5. sidekiq_options retry: false
  6. def key_to_json(key)
  7. key.nil? ? nil : { type: key.type, size: key.size, rsa_size: key.rsa_equivalent_size }
  8. end
  9. def perform(host, port=nil)
  10. idn = SimpleIDN.to_ascii host
  11. host = "#{host}:#{port}" if port
  12. result = begin
  13. server = self.server.new *(port ? [idn, port] : [idn])
  14. grade = self.grade.new server
  15. result = {
  16. key: key_to_json(server.key),
  17. dh: server.dh.collect { |k| key_to_json k },
  18. protocols: server.supported_protocols,
  19. ciphers: server.supported_ciphers.collect { |c| { protocol: c.protocol, name: c.name, size: c.size, dh: key_to_json(c.dh) } },
  20. score: {
  21. rank: grade.grade,
  22. details: {
  23. score: grade.score,
  24. protocol: grade.protocol_score,
  25. key_exchange: grade.key_exchange_score,
  26. cipher_strengths: grade.cipher_strengths_score
  27. },
  28. error: grade.error,
  29. danger: grade.danger,
  30. warning: grade.warning,
  31. success: grade.success
  32. }
  33. }
  34. self.result server, grade, result
  35. rescue CryptCheck::Tls::Server::TLSNotAvailableException
  36. { no_tls: true }
  37. end
  38. Datastore.post self.type, host, result
  39. end
  40. protected
  41. def result(_, _, result)
  42. result
  43. end
  44. end