Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

server.rb 858B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. require 'httparty'
  2. module CryptCheck
  3. module Tls
  4. module Https
  5. class Server < Tls::TcpServer
  6. attr_reader :hsts
  7. def initialize(hostname, port=443)
  8. super
  9. fetch_hsts
  10. end
  11. def fetch_hsts
  12. port = @port == 443 ? '' : ":#{@port}"
  13. response = ::HTTParty.head "https://#{@hostname}#{port}/", { follow_redirects: false, verify: false, timeout: SSL_TIMEOUT }
  14. if header = response.headers['strict-transport-security']
  15. name, value = header.split '='
  16. if name == 'max-age'
  17. @hsts = value.to_i
  18. Logger.info { "HSTS : #{@hsts.to_s.colorize hsts_long? ? :green : nil}" }
  19. return
  20. end
  21. end
  22. Logger.info { 'No HSTS'.colorize :yellow }
  23. @hsts = nil
  24. end
  25. def hsts?
  26. !@hsts.nil?
  27. end
  28. def hsts_long?
  29. hsts? and @hsts >= 6*30*24*60*60
  30. end
  31. end
  32. end
  33. end
  34. end