Browse Source

Option to disable IPv4 (or IPv6)

master
aeris 1 month ago
parent
commit
92f00153dc
4 changed files with 56 additions and 33 deletions
  1. 1
    0
      .gitignore
  2. 7
    5
      cryptcheck.gemspec
  3. 39
    28
      lib/cryptcheck.rb
  4. 9
    0
      lib/cryptcheck/fixtures/hash.rb

+ 1
- 0
.gitignore View File

@@ -11,3 +11,4 @@ Gemfile.lock
/lib/**/*.so
/lib/**/*.so.1.0.0
/build/
/vendor/bundle/

+ 7
- 5
cryptcheck.gemspec View File

@@ -30,9 +30,11 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 11.2', '>= 11.2.2'
spec.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'

spec.add_dependency 'httparty', '~> 0.13', '>= 0.13.3'
spec.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.6'
spec.add_dependency 'parallel', '~> 1.3', '>= 1.3.4'
spec.add_dependency 'ruby-progressbar', '~> 1.7', '>= 1.7.1'
spec.add_dependency 'colorize', '~> 0.7', '>= 0.7.7'
spec.add_dependency 'httparty'
spec.add_dependency 'nokogiri'
spec.add_dependency 'parallel'
spec.add_dependency 'ruby-progressbar'
spec.add_dependency 'colorize'
spec.add_dependency 'awesome_print'
spec.add_dependency 'thor'
end

+ 39
- 28
lib/cryptcheck.rb View File

@@ -75,41 +75,52 @@ module CryptCheck

def self.addresses(host)
begin
ip = IPAddr.new host
return [[ip.family, ip.to_s, nil]]
rescue IPAddr::InvalidAddressError
begin
ip = IPAddr.new host
return [[ip.family, ip.to_s, nil]]
rescue IPAddr::InvalidAddressError
end
::Addrinfo.getaddrinfo(host, nil, nil, :STREAM)
.collect { |a| [a.afamily, a.ip_address, host] }
end.reject do |family, *_|
(ENV['DISABLE_IPv6'] && family == Socket::AF_INET6) ||
(ENV['DISABLE_IPv4'] && family == Socket::AF_INET)
end
end

def self.analyze_address(host, family, ip, port, server, grade, *args, **kargs)
a = [host, family, ip, port, *args]
::Timeout::timeout MAX_ANALYSIS_DURATION do
s = if kargs.empty?
server.new *a
else
server.new *a, **kargs
end
if grade
g = grade.new s
Logger.info { '' }
g.display
g
else
s
end
end
::Addrinfo.getaddrinfo(host, nil, nil, :STREAM)
.collect { |a| [a.afamily, a.ip_address, host] }
rescue ::Timeout::Error
e = "Too long analysis (max #{MAX_ANALYSIS_DURATION.humanize})"
Logger.error e
AnalysisFailure.new e
rescue => e
Logger.error e
AnalysisFailure.new e
end

def self.analyze_addresses(host, addresses, port, server, grade, *args, **kargs)
first = true
addresses.collect do |family, ip|
first ? (first = false) : Logger.info { '' }
key = [host, ip, port]
a = [host, family, ip, port, *args]
begin
::Timeout::timeout MAX_ANALYSIS_DURATION do
s = if kargs.empty?
server.new *a
else
server.new *a, **kargs
end
if grade
g = grade.new s
Logger.info { '' }
g.display
[key, g]
else
[key, s]
end
end
rescue => e
e = "Too long analysis (max #{MAX_ANALYSIS_DURATION.humanize})" if e.message == 'execution expired'
Logger.error e
[key, AnalysisFailure.new(e)]
end
key = [host, ip, port]
result = analyze_address host, family, ip, port, server, grade, *args, **kargs
[key, result]
end.to_h
end


+ 9
- 0
lib/cryptcheck/fixtures/hash.rb View File

@@ -0,0 +1,9 @@
class Hash
def compact
self.reject { |_, v| v.nil? }
end

def compact!
self.reject! { |_, v| v.nil? }
end
end

Loading…
Cancel
Save