Browse Source

Manage host

new-scoring
aeris 5 years ago
parent
commit
366a078dee
  1. 13
      lib/cryptcheck.rb
  2. 47
      lib/cryptcheck/tls/host.rb
  3. 31
      lib/cryptcheck/tls/https/host.rb
  4. 2
      lib/cryptcheck/tls/https/server.rb

13
lib/cryptcheck.rb

@ -4,20 +4,9 @@ require 'timeout'
require 'yaml'
module CryptCheck
MAX_ANALYSIS_DURATION = 600
PARALLEL_ANALYSIS = 10
class AnalysisFailure
attr_reader :error
def initialize(error)
@error = error
end
def to_s
@error.to_s
end
end
class NoTLSAvailableServer
attr_reader :server
@ -43,11 +32,13 @@ module CryptCheck
autoload :TcpServer, 'cryptcheck/tls/server'
autoload :UdpServer, 'cryptcheck/tls/server'
autoload :Grade, 'cryptcheck/tls/grade'
autoload :Host, 'cryptcheck/tls/host'
autoload :Https, 'cryptcheck/tls/https'
module Https
autoload :Server, 'cryptcheck/tls/https/server'
autoload :Grade, 'cryptcheck/tls/https/grade'
autoload :Host, 'cryptcheck/tls/https/host'
end
autoload :Xmpp, 'cryptcheck/tls/xmpp'

47
lib/cryptcheck/tls/host.rb

@ -0,0 +1,47 @@
require 'timeout'
module CryptCheck
module Tls
class AnalysisFailure
attr_reader :error
def initialize(error)
@error = error
end
def to_s
@error.to_s
end
end
class TooLongAnalysis < AnalysisFailure
def initialize
super "Too long analysis (max #{Host::MAX_ANALYSIS_DURATION.humanize})"
end
end
class Host
MAX_ANALYSIS_DURATION = 600
attr_reader :servers
def initialize
first = true
@servers = resolve.collect do |args|
first ? (first = false) : Logger.info { '' }
result = begin
server = ::Timeout.timeout MAX_ANALYSIS_DURATION do
server(*args)
end
grade(server)
rescue Engine::TLSException => e
AnalysisFailure.new e
rescue ::Timeout::Error
TooLongAnalysis.new
end
[args, result]
end.to_h
end
end
end
end

31
lib/cryptcheck/tls/https/host.rb

@ -0,0 +1,31 @@
module CryptCheck
module Tls
module Https
class Host < Tls::Host
def initialize(hostname, port=443)
@hostname, @port = hostname, port
super()
end
private
def resolve
begin
ip = IPAddr.new @hostname
return [[nil, ip.to_s, ip.family]]
rescue IPAddr::InvalidAddressError
end
::Addrinfo.getaddrinfo(@hostname, nil, nil, :STREAM)
.collect { |a| [@hostname, a.ip_address, a.afamily] }
end
def server(hostname, ip, family)
Https::Server.new hostname, ip, family, @port
end
def grade(server)
Https::Grade.new server
end
end
end
end
end

2
lib/cryptcheck/tls/https/server.rb

@ -6,7 +6,7 @@ module CryptCheck
class Server < Tls::TcpServer
attr_reader :hsts
def initialize(hostname, family, ip, port=443)
def initialize(hostname, ip, family, port=443)
super
fetch_hsts
end

Loading…
Cancel
Save