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 918B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. begin
  14. response = ::HTTParty.head "https://#{@hostname}#{port}/", { follow_redirects: false, verify: false, timeout: SSL_TIMEOUT }
  15. if header = response.headers['strict-transport-security']
  16. name, value = header.split '='
  17. if name == 'max-age'
  18. @hsts = value.to_i
  19. Logger.info { "HSTS : #{@hsts.to_s.colorize hsts_long? ? :green : nil}" }
  20. return
  21. end
  22. end
  23. rescue ::Net::OpenTimeout
  24. end
  25. Logger.info { 'No HSTS'.colorize :yellow }
  26. @hsts = nil
  27. end
  28. def hsts?
  29. !@hsts.nil?
  30. end
  31. def hsts_long?
  32. hsts? and @hsts >= 6*30*24*60*60
  33. end
  34. end
  35. end
  36. end
  37. end