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.

xmpp.rb 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. require 'erb'
  2. require 'parallel'
  3. module CryptCheck
  4. module Tls
  5. module Xmpp
  6. MAX_ANALYSIS_DURATION = 600
  7. PARALLEL_ANALYSIS = 10
  8. def self.grade(hostname, type=:s2s)
  9. timeout MAX_ANALYSIS_DURATION do
  10. Grade.new Server.new hostname, type
  11. end
  12. rescue ::Exception => e
  13. Logger.error { "Error during #{hostname}:#{type} analysis : #{e}" }
  14. TlsNotSupportedGrade.new TlsNotSupportedServer.new hostname, type
  15. end
  16. def self.analyze(hosts, output)
  17. servers = []
  18. semaphore = ::Mutex.new
  19. ::Parallel.each hosts, progress: 'Analysing', in_threads: PARALLEL_ANALYSIS, finish: lambda { |item, _, _| puts item } do |host|
  20. result = grade host.strip
  21. semaphore.synchronize { servers << result }
  22. end
  23. servers.sort! do |a, b|
  24. cmp = score(a) <=> score(b)
  25. if cmp == 0
  26. cmp = b.score <=> a.score
  27. if cmp == 0
  28. cmp = a.server.hostname <=> b.server.hostname
  29. end
  30. end
  31. cmp
  32. end
  33. ::File.write output, ::ERB.new(::File.read('output/xmpp.erb')).result(binding)
  34. end
  35. def self.analyze_from_file(file, output)
  36. hosts = ::YAML.load_file file
  37. self.analyze hosts, output
  38. end
  39. private
  40. SCORES = %w(A+ A A- B C D E F T M X)
  41. def self.score(a)
  42. SCORES.index a.grade
  43. end
  44. end
  45. end
  46. end