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.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. class CheckWorker
  2. include Sidekiq::Worker
  3. sidekiq_options retry: false
  4. def key_to_json(key)
  5. key.nil? ? nil : { type: key.type, size: key.size, rsa_size: key.rsa_equivalent_size }
  6. end
  7. def perform(host, port=nil)
  8. host = SimpleIDN.to_ascii host.downcase
  9. result = begin
  10. grade = self.analyze *(port ? [host, port] : [host])
  11. raise CryptCheck::Tls::Server::TLSNotAvailableException if grade.is_a? CryptCheck::Tls::TlsNotSupportedGrade
  12. server = grade.server
  13. result = {
  14. key: key_to_json(server.key),
  15. dh: server.dh.collect { |k| key_to_json k },
  16. protocols: server.supported_protocols,
  17. ciphers: server.supported_ciphers.collect { |c| { protocol: c.protocol, name: c.name, size: c.size, dh: key_to_json(c.dh) } },
  18. score: {
  19. rank: grade.grade,
  20. details: {
  21. score: grade.score,
  22. protocol: grade.protocol_score,
  23. key_exchange: grade.key_exchange_score,
  24. cipher_strengths: grade.cipher_strengths_score
  25. },
  26. error: grade.error,
  27. danger: grade.danger,
  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, port, result
  37. end
  38. protected
  39. def result(_, _, result)
  40. result
  41. end
  42. end