Browse Source

Dead code

aeris 1 year ago
parent
commit
c640e26674
1 changed files with 3 additions and 124 deletions
  1. 3
    124
      lib/cryptcheck.rb

+ 3
- 124
lib/cryptcheck.rb View File

@@ -4,20 +4,6 @@ require 'timeout'
4 4
 require 'yaml'
5 5
 
6 6
 module CryptCheck
7
-	PARALLEL_ANALYSIS = 10
8
-
9
-	class NoTLSAvailableServer
10
-		attr_reader :server
11
-
12
-		def initialize(server)
13
-			@server = OpenStruct.new hostname: server
14
-		end
15
-
16
-		def grade
17
-			'X'
18
-		end
19
-	end
20
-
21 7
 	autoload :State, 'cryptcheck/state'
22 8
 	autoload :Grade, 'cryptcheck/grade'
23 9
 	autoload :Logger, 'cryptcheck/logger'
@@ -39,14 +25,16 @@ module CryptCheck
39 25
 			autoload :Host, 'cryptcheck/tls/https/host'
40 26
 		end
41 27
 
42
-		autoload :Xmpp, 'cryptcheck/tls/xmpp'
28
+		autoload :Xmpp, 'cryptcheck/tls/xmpp.rb'
43 29
 		module Xmpp
44 30
 			autoload :Server, 'cryptcheck/tls/xmpp/server'
31
+			autoload :Host, 'cryptcheck/tls/xmpp/host'
45 32
 		end
46 33
 
47 34
 		autoload :Smtp, 'cryptcheck/tls/smtp'
48 35
 		module Smtp
49 36
 			autoload :Server, 'cryptcheck/tls/smtp/server'
37
+			autoload :Host, 'cryptcheck/tls/smtp/host'
50 38
 		end
51 39
 	end
52 40
 
@@ -56,115 +44,6 @@ module CryptCheck
56 44
 		autoload :Server, 'cryptcheck/ssh/server'
57 45
 		autoload :SshNotSupportedServer, 'cryptcheck/ssh/server'
58 46
 	end
59
-
60
-	private
61
-	def self.addresses(host)
62
-		begin
63
-			ip = IPAddr.new host
64
-			return [[ip.family, ip.to_s, nil]]
65
-		rescue IPAddr::InvalidAddressError
66
-		end
67
-		::Addrinfo.getaddrinfo(host, nil, nil, :STREAM)
68
-				.collect { |a| [a.afamily, a.ip_address, host] }
69
-	end
70
-
71
-	def self.analyze_addresses(host, addresses, port, server, grade, *args, **kargs)
72
-		first = true
73
-		addresses.collect do |family, ip|
74
-			first ? (first = false) : Logger.info { '' }
75
-			key = [host, ip, port]
76
-			a   = [host, family, ip, port, *args]
77
-			begin
78
-				::Timeout::timeout MAX_ANALYSIS_DURATION do
79
-					s = if kargs.empty?
80
-							server.new *a
81
-						else
82
-							server.new *a, **kargs
83
-						end
84
-					ap s.states
85
-					if grade
86
-						g = grade.new s
87
-						Logger.info { '' }
88
-						g.display
89
-						[key, g]
90
-					else
91
-						[key, s]
92
-					end
93
-				end
94
-			rescue => e
95
-				e = Tls::Server::TLSException.new "Too long analysis (max #{MAX_ANALYSIS_DURATION.humanize})" \
96
- 						  if e.message == 'execution expired'
97
-				raise unless e.is_a? Tls::Server::TLSException
98
-				Logger.error e
99
-				[key, AnalysisFailure.new(e)]
100
-			end
101
-		end.to_h
102
-	end
103
-
104
-	def self.analyze(host, port, server, *args, **kargs)
105
-		addresses = begin
106
-			addresses host
107
-		rescue ::SocketError => e
108
-			Logger::error e
109
-			key   = [host, nil, port]
110
-			error = AnalysisFailure.new "Unable to resolve #{host}"
111
-			return { key => error }
112
-		end
113
-		analyze_addresses host, addresses, port, server, *args, **kargs
114
-	end
115
-
116
-	def self.analyze_hosts(hosts, template, output, groups: nil, &block)
117
-		results   = {}
118
-		semaphore = ::Mutex.new
119
-		::Parallel.each hosts, progress: 'Analysing', in_threads: PARALLEL_ANALYSIS, finish: lambda { |item, _, _| puts item[1] } do |description, host|
120
-			#hosts.each do |description, host|
121
-			result = block.call host.strip
122
-			result = result.values.first
123
-			result = NoTLSAvailableServer.new(host) if result.is_a? AnalysisFailure
124
-			semaphore.synchronize do
125
-				if results.include? description
126
-					results[description] << result
127
-				else
128
-					results[description] = [result]
129
-				end
130
-			end
131
-		end
132
-
133
-		results = ::Hash[groups.collect { |g| [g, results[g]] }] if groups
134
-
135
-		results.each do |d, _|
136
-			results[d].sort! do |a, b|
137
-				cmp = score(a) <=> score(b)
138
-				if cmp == 0
139
-					cmp = a.server.hostname <=> b.server.hostname
140
-				end
141
-				cmp
142
-			end
143
-		end
144
-
145
-		::File.write output, ::ERB.new(::File.read template).result(binding)
146
-	end
147
-
148
-	def self.analyze_file(input, template, output, &block)
149
-		config = ::YAML.load_file input
150
-		hosts  = []
151
-		groups = []
152
-
153
-		config.each do |c|
154
-			d, hs = c['description'], c['hostnames']
155
-			groups << d
156
-			hs.each { |host| hosts << [d, host] }
157
-		end
158
-
159
-		self.analyze_hosts hosts, template, output, groups: groups, &block
160
-	end
161
-
162
-	private
163
-	SCORES = %w(A+ A B+ B C+ C D E F G M T X)
164
-
165
-	def self.score(a)
166
-		SCORES.index a.grade
167
-	end
168 47
 end
169 48
 
170 49
 require 'cryptcheck/fixture'

Loading…
Cancel
Save