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.

49 lines
1.2KB

  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)
  10. idn = SimpleIDN.to_ascii host
  11. result = begin
  12. server = self.module::Server.new idn
  13. grade = self.module::Grade.new server
  14. result = {
  15. key: key_to_json(server.key),
  16. dh: server.dh.collect { |k| key_to_json k },
  17. protocols: server.supported_protocols,
  18. ciphers: server.supported_ciphers.collect { |c| { protocol: c.protocol, name: c.name, size: c.size, dh: key_to_json(c.dh) } },
  19. score: {
  20. rank: grade.grade,
  21. details: {
  22. score: grade.score,
  23. protocol: grade.protocol_score,
  24. key_exchange: grade.key_exchange_score,
  25. cipher_strengths: grade.cipher_strengths_score
  26. },
  27. error: grade.error,
  28. warning: grade.warning,
  29. success: grade.success
  30. }
  31. }
  32. self.result server, grade, result
  33. rescue CryptCheck::Tls::Server::TLSNotAvailableException
  34. { no_tls: true }
  35. end
  36. Datastore.post self.type, host, result
  37. end
  38. protected
  39. def result(_, _, result)
  40. result
  41. end
  42. end