Browse Source

Handle IDN cleanly

Aeris 3 years ago
parent
commit
972526af46

+ 8
- 10
app/controllers/check_controller.rb View File

@@ -2,11 +2,9 @@ class CheckController < ApplicationController
2 2
 	before_action :check_host, except: %i(index)
3 3
 	helper_method :tls_type, :type
4 4
 
5
-	def index
6
-	end
7
-
8 5
 	def show
9 6
 		enqueue_host unless @result
7
+		@host = SimpleIDN.to_unicode @host
10 8
 		return render :processing if @result.pending
11 9
 		return render :no_tls if @result.no_tls
12 10
 	end
@@ -25,20 +23,20 @@ class CheckController < ApplicationController
25 23
 
26 24
 	protected
27 25
 	def enqueue_host
28
-		Datastore.pending self.type, @host
29
-		self.worker.perform_async *(@port ? [@idn, @port] : [@idn])
26
+		Datastore.pending self.type, @id
27
+		self.worker.perform_async *(@port.blank? ? [@host] : [@host, @port])
30 28
 		@result = OpenStruct.new pending: true , date: Time.now
31 29
 	end
32 30
 
33 31
 	def check_host
34
-		@host, @port = params[:id].split ':'
35
-		@idn         = SimpleIDN.to_ascii @host
36
-		if /[^a-zA-Z0-9.-]/.match @idn
32
+		@id = params[:id]
33
+		@host, @port = @id.split ':'
34
+		@host = SimpleIDN.to_ascii @host.downcase
35
+		if /[^a-zA-Z0-9.-]/.match @host
37 36
 			flash[:danger] = "Hôte #{@host} invalide"
38 37
 			redirect_to action: :index
39 38
 			return false
40 39
 		end
41
-		@host   = "#{@idn}:#{@port}" if @port
42
-		@result = Datastore.host self.type, @host
40
+		@result = Datastore.host self.type, @id
43 41
 	end
44 42
 end

+ 34
- 1
app/controllers/site_controller.rb View File

@@ -1,4 +1,37 @@
1
+require 'simpleidn'
2
+
1 3
 class SiteController < ApplicationController
2
-	def ciphers
4
+	def check
5
+		host, port, type = params[:host], params[:port], params[:type]
6
+
7
+		host = SimpleIDN.to_ascii host.downcase
8
+		if host.blank? or /[^a-zA-Z0-9.-]/ =~ host
9
+			flash[:danger] = "Hôte #{host} invalide"
10
+			render :index
11
+			return
12
+		end
13
+
14
+		unless port.blank?
15
+			port = port.to_i
16
+			unless (1..65535).include? port
17
+				flash[:danger] = "Port #{port} invalide"
18
+				render :index
19
+				return
20
+			end
21
+			host = "#{host}:#{port}"
22
+		end
23
+
24
+		unless %w(https smtp xmpp tls ssh).include? type
25
+			flash[:danger] = "Type #{type} invalide"
26
+			render :index
27
+			return
28
+		end
29
+
30
+		redirect_to "/#{type}/#{host}"
31
+	end
32
+
33
+	def suite
34
+		@suite = params.require :suite
35
+		@ciphers = CryptCheck::Tls::Cipher.list @suite
3 36
 	end
4 37
 end

+ 0
- 18
app/views/https/index.html.erb View File

@@ -1,18 +0,0 @@
1
-<div id="check" class="container">
2
-	<div class="row">
3
-		<div class="col-sm-12">
4
-			<h1>Vérifier votre domaine</h1>
5
-			<div class="form-group">
6
-				<div class="col-sm-8">
7
-					<%= text_field_tag :check_host, nil, class: %i(form-control input-lg), placeholder: 'your-site.com' %>
8
-				</div>
9
-				<div class="col-sm-2">
10
-					<%= select_tag :check_type, options_for_select({'HTTPS' => :https, 'SMTP' => :smtp, 'XMPP' => :xmpp}), class: %i(form-control input-lg) %>
11
-				</div>
12
-				<div class="col-sm-2">
13
-					<%= submit_tag 'Test-moi !', id: 'check_submit', class: %i(form-control btn btn-primary input-lg pull-right) %>
14
-				</div>
15
-			</div>
16
-		</div>
17
-	</div>
18
-</div>

+ 13
- 10
app/views/ssh/index.html.erb View File

@@ -2,17 +2,20 @@
2 2
 	<div class="row">
3 3
 		<div class="col-sm-12">
4 4
 			<h1>Vérifier votre serveur SSH</h1>
5
-			<div class="form-group">
6
-				<div class="col-sm-8">
7
-					<%= text_field_tag :ssh_check_host, nil, class: %i(form-control input-lg), placeholder: 'your-site.com' %>
5
+			<%= form_tag root_path do %>
6
+				<div class="form-group">
7
+					<div class="col-sm-8">
8
+						<%= text_field_tag :host, nil, class: %i(form-control input-lg), placeholder: 'your-site.com' %>
9
+					</div>
10
+					<div class="col-sm-2">
11
+						<%= text_field_tag :port, nil, class: %i(form-control input-lg), placeholder: 'port' %>
12
+					</div>
13
+					<div class="col-sm-2">
14
+						<%= hidden_field_tag :type, :ssh %>
15
+						<%= submit_tag 'Test-moi !', class: %i(form-control btn btn-primary input-lg pull-right) %>
16
+					</div>
8 17
 				</div>
9
-				<div class="col-sm-2">
10
-					<%= text_field_tag :ssh_check_port, nil, class: %i(form-control input-lg), placeholder: 'port' %>
11
-				</div>
12
-				<div class="col-sm-2">
13
-					<%= submit_tag 'Test-moi !', id: 'ssh_check_submit', class: %i(form-control btn btn-primary input-lg pull-right) %>
14
-				</div>
15
-			</div>
18
+			<% end %>
16 19
 		</div>
17 20
 	</div>
18 21
 </div>

+ 13
- 10
app/views/tls/index.html.erb View File

@@ -2,17 +2,20 @@
2 2
 	<div class="row">
3 3
 		<div class="col-sm-12">
4 4
 			<h1>Vérifier votre serveur TLS</h1>
5
-			<div class="form-group">
6
-				<div class="col-sm-8">
7
-					<%= text_field_tag :tls_check_host, nil, class: %i(form-control input-lg), placeholder: 'your-site.com' %>
5
+			<%= form_tag root_path do %>
6
+				<div class="form-group">
7
+					<div class="col-sm-8">
8
+						<%= text_field_tag :host, nil, class: %i(form-control input-lg), placeholder: 'your-site.com' %>
9
+					</div>
10
+					<div class="col-sm-2">
11
+						<%= text_field_tag :port, nil, class: %i(form-control input-lg), placeholder: 'port' %>
12
+					</div>
13
+					<div class="col-sm-2">
14
+						<%= hidden_field_tag :type, :tls %>
15
+						<%= submit_tag 'Test-moi !', class: %i(form-control btn btn-primary input-lg pull-right) %>
16
+					</div>
8 17
 				</div>
9
-				<div class="col-sm-2">
10
-					<%= text_field_tag :tls_check_port, nil, class: %i(form-control input-lg), placeholder: 'port' %>
11
-				</div>
12
-				<div class="col-sm-2">
13
-					<%= submit_tag 'Test-moi !', id: 'tls_check_submit', class: %i(form-control btn btn-primary input-lg pull-right) %>
14
-				</div>
15
-			</div>
18
+			<% end %>
16 19
 		</div>
17 20
 	</div>
18 21
 </div>

+ 3
- 6
app/workers/check_worker.rb View File

@@ -1,6 +1,3 @@
1
-require 'simpleidn'
2
-require 'cryptcheck'
3
-
4 1
 class CheckWorker
5 2
 	include Sidekiq::Worker
6 3
 	sidekiq_options retry: false
@@ -10,10 +7,9 @@ class CheckWorker
10 7
 	end
11 8
 
12 9
 	def perform(host, port=nil)
13
-		idn    = SimpleIDN.to_ascii host
14
-		host = "#{host}:#{port}" if port
10
+		host    = SimpleIDN.to_ascii host.downcase
15 11
 		result = begin
16
-			server = self.server.new *(port ? [idn, port] : [idn])
12
+			server = self.server.new *(port ? [host, port] : [host])
17 13
 			grade  = self.grade.new server
18 14
 			result = {
19 15
 					key:       key_to_json(server.key),
@@ -39,6 +35,7 @@ class CheckWorker
39 35
 		rescue CryptCheck::Tls::Server::TLSNotAvailableException
40 36
 			{ no_tls: true }
41 37
 		end
38
+		host = "#{host}:#{port}" if port
42 39
 		Datastore.post self.type, host, result
43 40
 	end
44 41
 

+ 2
- 5
app/workers/ssh_worker.rb View File

@@ -1,14 +1,11 @@
1
-require 'simpleidn'
2
-require 'cryptcheck'
3
-
4 1
 class SSHWorker
5 2
 	include Sidekiq::Worker
6 3
 	sidekiq_options retry: false
7 4
 
8 5
 	def perform(host, port=nil)
9
-		idn    = SimpleIDN.to_ascii host
6
+		host    = SimpleIDN.to_ascii host.downcase
10 7
 		result = begin
11
-			server = CryptCheck::Ssh::Server.new idn, port
8
+			server = CryptCheck::Ssh::Server.new *(port ? [host, port] : [host])
12 9
 			{
13 10
 					kex:         server.kex,
14 11
 					encryption:  server.encryption,

Loading…
Cancel
Save