diff --git a/Gemfile b/Gemfile index f0284ca..0a1cba7 100644 --- a/Gemfile +++ b/Gemfile @@ -2,11 +2,9 @@ source 'https://rubygems.org' gem 'rails', '4.2.1' -gem 'sqlite3' gem 'cryptcheck', '~> 1.0.0', path: File.expand_path(File.join File.dirname(__FILE__), '../cryptcheck') gem 'sidekiq', '~> 3.4.2' gem 'stretcher', '~> 1.21.1' -#gem 'mongo', '~> 2.0.6' gem 'faraday', '~> 0.8.9' # For stretcher compatibility gem 'simpleidn', '~> 0.0.5' diff --git a/app/assets/javascripts/check.coffee b/app/assets/javascripts/check.coffee new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/https.coffee b/app/assets/javascripts/https.coffee new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/javascripts/site.coffee.erb b/app/assets/javascripts/site.coffee.erb index b799323..645db99 100644 --- a/app/assets/javascripts/site.coffee.erb +++ b/app/assets/javascripts/site.coffee.erb @@ -1,5 +1,12 @@ $ -> - $('#check_form').submit -> + submit = -> host = $('#check_host').val() - window.location.href = "<%= path :result, %i(host) %>" - false + type = $('#check_type').val() + window.location.href = "<%= Rails.configuration.relative_url_root %>/#{type}/#{host}" + + $('#check_host').keypress (e) -> + submit() if e.which == 13 + return + $('#check_submit').click -> + submit() + return diff --git a/app/assets/javascripts/smtp.coffee b/app/assets/javascripts/smtp.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/smtp.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/xmpp.coffee b/app/assets/javascripts/xmpp.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/xmpp.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/check.scss b/app/assets/stylesheets/check.scss new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/https.scss b/app/assets/stylesheets/https.scss new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/smtp.scss b/app/assets/stylesheets/smtp.scss new file mode 100644 index 0000000..b32f95d --- /dev/null +++ b/app/assets/stylesheets/smtp.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Smtp controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/xmpp.scss b/app/assets/stylesheets/xmpp.scss new file mode 100644 index 0000000..1b007cd --- /dev/null +++ b/app/assets/stylesheets/xmpp.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Xmpp controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/check_controller.rb b/app/controllers/check_controller.rb new file mode 100644 index 0000000..5f87953 --- /dev/null +++ b/app/controllers/check_controller.rb @@ -0,0 +1,39 @@ +class CheckController < ApplicationController + before_action :check_host + + def check_host + @host = params[:id] + @idn = SimpleIDN.to_ascii @host + if /[^a-zA-Z0-9.-]/.match @idn + flash[:danger] = "Hôte #{@host} invalide" + redirect_to :root + return false + end + @result = Datastore.host self.type, @idn + end + + def show + enqueue_host unless @result + return render :processing if @result.pending + return render :no_tls if @result.no_tls + end + + def refresh + unless @result.pending + refresh_allowed = @result.date + Rails.configuration.refresh_delay + if Time.now < refresh_allowed + flash[:warning] = "Merci d’attendre au moins #{l refresh_allowed} pour rafraîchir" + return redirect_to result_path @host + end + enqueue_host + end + redirect_to action: :show + end + + protected + def enqueue_host + Datastore.pending self.type, @host + self.worker.perform_async @idn + @result = OpenStruct.new pending: true , date: Time.now + end +end diff --git a/app/controllers/https_controller.rb b/app/controllers/https_controller.rb new file mode 100644 index 0000000..032ef2c --- /dev/null +++ b/app/controllers/https_controller.rb @@ -0,0 +1,10 @@ +class HttpsController < CheckController + protected + def type + :https + end + + def worker + HTTPSWorker + end +end diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index 75cb725..4b0a771 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -1,42 +1,7 @@ class SiteController < ApplicationController - before_action :check_host, only: %i(result refresh) - - def check_host - @host = params[:id] - @idn = SimpleIDN.to_ascii @host - if /[^a-zA-Z0-9.-]/.match @idn - flash[:danger] = "Hôte #{@host} invalide" - redirect_to :root - return false - end - @result = Datastore.host :https, @idn - end - def index end - def result - enqueue_host unless @result - return render :processing if @result.pending - return render :no_tls if @result.no_tls - end - - def refresh - unless @result.pending - refresh_allowed = @result.date + Rails.configuration.refresh_delay - if Time.now < refresh_allowed - flash[:warning] = "Merci d’attendre au moins #{l refresh_allowed} pour rafraîchir" - return redirect_to result_path @host - end - enqueue_host - end - redirect_to :result - end - - private - def enqueue_host - Datastore.pending :https, @host - HTTPSWorker.perform_async @idn - @result = OpenStruct.new pending: true , date: Time.now + def ciphers end end diff --git a/app/controllers/smtp_controller.rb b/app/controllers/smtp_controller.rb new file mode 100644 index 0000000..63ccfaf --- /dev/null +++ b/app/controllers/smtp_controller.rb @@ -0,0 +1,10 @@ +class SmtpController < CheckController + protected + def type + :smtp + end + + def worker + SMTPWorker + end +end diff --git a/app/controllers/xmpp_controller.rb b/app/controllers/xmpp_controller.rb new file mode 100644 index 0000000..4d4de8c --- /dev/null +++ b/app/controllers/xmpp_controller.rb @@ -0,0 +1,10 @@ +class XmppController < CheckController + protected + def type + :xmpp + end + + def worker + XMPPWorker + end +end diff --git a/app/helpers/check_helper.rb b/app/helpers/check_helper.rb new file mode 100644 index 0000000..09d5a13 --- /dev/null +++ b/app/helpers/check_helper.rb @@ -0,0 +1,2 @@ +module CheckHelper +end diff --git a/app/helpers/https_helper.rb b/app/helpers/https_helper.rb new file mode 100644 index 0000000..37d34c5 --- /dev/null +++ b/app/helpers/https_helper.rb @@ -0,0 +1,2 @@ +module HttpsHelper +end diff --git a/app/helpers/site_helper.rb b/app/helpers/site_helper.rb index 3f305a2..1ac54db 100644 --- a/app/helpers/site_helper.rb +++ b/app/helpers/site_helper.rb @@ -35,7 +35,7 @@ module SiteHelper end def protocol_label(protocol) - color = case protocol + color = case protocol.to_s when 'TLSv1_2' then :success when 'SSLv3', 'SSLv2' then :danger else :default @@ -57,8 +57,9 @@ module SiteHelper keys.sort { |a, b| -1 * (a.rsa_size <=> b.rsa_size)} .collect { |k| key_label k }.join("\n").html_safe end - def cipher_label(cipher) - "\">#{cipher['size']} bits".html_safe + def cipher_size_label(cipher) + size = cipher.kind_of?(CryptCheck::Tls::Cipher) ? cipher.size : cipher['size'] + "\">#{size} bits".html_safe end def color_key(key) @@ -72,20 +73,38 @@ module SiteHelper def cipher_color(key) case key - when 0...112 then :error + when 0...112 then :danger when 112...128 then :warning when 128...256 then :success else :primary end end + def cipher_name_label(cipher, state) + color = case + when !state[:danger].empty? then :danger + when !state[:warning].empty? then :warning + when !state[:success].empty? then :success + else :default + end + color = :primary if color == :success and cipher.size >= 256 + "\">#{cipher.name}".html_safe + end + def cipher_labels(cipher) - { success: %i(pfs), - warning: %i(des3 sha1), - danger: %i(md5 psk srp anonymous null export des rc2 rc4) - }.collect do |color, types| - types.select { |t| CryptCheck::Tls::Cipher.send "#{t}?", cipher.name } - .collect { |t| "#{t.upcase}" } - end.flatten(1).join("\n").html_safe + case cipher + when Hashie::Mash + { success: %i(pfs), + warning: %i(des3 sha1), + danger: %i(md5 psk srp anonymous null export des rc2 rc4) + }.collect do |c, ts| + ts.select { |t| CryptCheck::Tls::Cipher.send "#{t}?", cipher.name }.collect { |t| [c, t] } + end + when Hash + cipher.collect { |c, ts| ts.collect { |t| [c, t] } } + end + .flatten(1) + .collect { |c, t| "#{t.upcase}" } + .join("\n").html_safe end end diff --git a/app/helpers/smtp_helper.rb b/app/helpers/smtp_helper.rb new file mode 100644 index 0000000..7fb720b --- /dev/null +++ b/app/helpers/smtp_helper.rb @@ -0,0 +1,2 @@ +module SmtpHelper +end diff --git a/app/helpers/xmpp_helper.rb b/app/helpers/xmpp_helper.rb new file mode 100644 index 0000000..6022b1f --- /dev/null +++ b/app/helpers/xmpp_helper.rb @@ -0,0 +1,2 @@ +module XmppHelper +end diff --git a/app/views/application/_headers.erb b/app/views/application/_headers.erb index 4d6858f..45442ba 100644 --- a/app/views/application/_headers.erb +++ b/app/views/application/_headers.erb @@ -4,6 +4,9 @@
+ + <% + context.ciphers = 'ALL:COMPLEMENTOFALL' + context.ciphers.collect { |c| CryptCheck::Tls::Cipher.new protocol, c } + .sort { |a, b| -1 * (a.size <=> b.size)}.each do |cipher| %> +