Browse Source

Refactor fixtures

master
aeris 1 month ago
parent
commit
73fe4559cc

+ 7
- 5
lib/cryptcheck.rb View File

@@ -2,7 +2,7 @@ require 'colorize'
require 'ipaddr'
require 'timeout'
require 'yaml'
require 'cryptcheck/tls/fixture'
Dir[File.join __dir__, 'cryptcheck', 'fixtures', '*.rb'].each { |f| require f }

module CryptCheck
MAX_ANALYSIS_DURATION = 120
@@ -72,6 +72,7 @@ module CryptCheck
end

private

def self.addresses(host)
begin
ip = IPAddr.new host
@@ -116,8 +117,8 @@ module CryptCheck
addresses = begin
addresses host
rescue ::SocketError => e
Logger::error e
key = [host, nil, port]
Logger.error e
key = [host, nil, port]
error = AnalysisFailure.new "Unable to resolve #{host}"
return { key => error }
end
@@ -146,9 +147,9 @@ module CryptCheck
results.each do |d, _|
results[d].sort! do |a, b|
cmp = score(a) <=> score(b)
if cmp == 0
if cmp.zero?
cmp = b.score <=> a.score
if cmp == 0
if cmp.zero?
cmp = a.server.hostname <=> b.server.hostname
end
end
@@ -174,6 +175,7 @@ module CryptCheck
end

private

SCORES = %w(A+ A A- B C D E F T M X)

def self.score(a)

+ 12
- 0
lib/cryptcheck/fixtures/integer.rb View File

@@ -0,0 +1,12 @@
class Integer
def humanize
secs = self
[[60, :second], [60, :minute], [24, :hour], [30, :day], [12, :month]].map do |count, name|
if secs > 0
secs, n = secs.divmod count
n = n.to_i
n > 0 ? "#{n} #{name}#{n > 1 ? 's' : ''}" : nil
end
end.compact.reverse.join(' ')
end
end

lib/cryptcheck/tls/fixture.rb → lib/cryptcheck/fixtures/openssl.rb View File

@@ -1,18 +1,5 @@
require 'openssl'

class Integer
def humanize
secs = self
[[60, :second], [60, :minute], [24, :hour], [30, :day], [12, :month]].map { |count, name|
if secs > 0
secs, n = secs.divmod count
n = n.to_i
n > 0 ? "#{n} #{name}#{n > 1 ? 's' : ''}" : nil
end
}.compact.reverse.join(' ')
end
end

class ::OpenSSL::PKey::EC
def type
:ecc
@@ -24,12 +11,33 @@ class ::OpenSSL::PKey::EC

def rsa_equivalent_size
case self.size
when 160 then 1024
when 224 then 2048
when 256 then 3072
when 384 then 7680
when 521 then 15360
when 571 then 21000
when 160 then
1024
when 224 then
2048
when 256 then
3072
when 384 then
7680
when 521 then
15360
when 571 then
21000
end
end

def to_s
"ECC #{self.size} bits"
end

def status
case self.size
when 160 then 1024
when 224 then 2048
when 256 then 3072
when 384 then 7680
when 521 then 15360
when 571 then 21000
end
end


+ 16
- 0
lib/cryptcheck/fixtures/openstruct.rb View File

@@ -0,0 +1,16 @@
require 'ostruct'

class OpenStruct
def self.deep(hash)
hash = hash.collect do |k, v|
v = case v
when Hash
self.deep v
else
v
end
[k, v]
end.to_h
self.new hash
end
end

Loading…
Cancel
Save