parent
97c46bea93
commit
11c86006b7
@ -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 |
||||
|
@ -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/ |
@ -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/ |
@ -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/ |
@ -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/ |
@ -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 |
@ -0,0 +1,10 @@ |
||||
class HttpsController < CheckController |
||||
protected |
||||
def type |
||||
:https |
||||
end |
||||
|
||||
def worker |
||||
HTTPSWorker |
||||
end |
||||
end |
@ -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 |
||||
|
@ -0,0 +1,10 @@ |
||||
class SmtpController < CheckController |
||||
protected |
||||
def type |
||||
:smtp |
||||
end |
||||
|
||||
def worker |
||||
SMTPWorker |
||||
end |
||||
end |
@ -0,0 +1,10 @@ |
||||
class XmppController < CheckController |
||||
protected |
||||
def type |
||||
:xmpp |
||||
end |
||||
|
||||
def worker |
||||
XMPPWorker |
||||
end |
||||
end |
@ -0,0 +1,2 @@ |
||||
module CheckHelper |
||||
end |
@ -0,0 +1,2 @@ |
||||
module HttpsHelper |
||||
end |
@ -0,0 +1,2 @@ |
||||
module SmtpHelper |
||||
end |
@ -0,0 +1,2 @@ |
||||
module XmppHelper |
||||
end |
@ -0,0 +1,35 @@ |
||||
<div class="container"> |
||||
<div class="row"> |
||||
<table class="table-bordered table-condensed table-striped col-sm-12"> |
||||
<thead> |
||||
<tr> |
||||
<th class="col-sm-4">Algorithme</th> |
||||
<th class="col-sm-1">Taille</th> |
||||
<td class="col-sm-7"></td> |
||||
</tr> |
||||
</thead> |
||||
<tbody> |
||||
<% %i(TLSv1_2).each do |protocol| |
||||
context = OpenSSL::SSL::SSLContext.new protocol rescue next |
||||
%> |
||||
<!-- |
||||
<tr> |
||||
<th colspan="3"><h1><%= protocol %><h1></th> |
||||
</tr> |
||||
--> |
||||
<% |
||||
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| %> |
||||
<tr> |
||||
<% state = cipher.state %> |
||||
<th><%= cipher_name_label cipher, state %></th> |
||||
<th><%= cipher_size_label cipher %></th> |
||||
<th><%= cipher_labels state %></th> |
||||
</tr> |
||||
<% end %> |
||||
<% end %> |
||||
</tbody> |
||||
</table> |
||||
</div> |
||||
</div> |
@ -0,0 +1,48 @@ |
||||
require 'simpleidn' |
||||
require 'cryptcheck' |
||||
|
||||
class CheckWorker |
||||
include Sidekiq::Worker |
||||
sidekiq_options retry: false |
||||
|
||||
def key_to_json(key) |
||||
key.nil? ? nil : { type: key.type, size: key.size, rsa_size: key.rsa_equivalent_size } |
||||
end |
||||
|
||||
def perform(host) |
||||
idn = SimpleIDN.to_ascii host |
||||
result = begin |
||||
server = self.module::Server.new idn |
||||
grade = self.module::Grade.new server |
||||
result = { |
||||
key: key_to_json(server.key), |
||||
dh: server.dh.collect { |k| key_to_json k }, |
||||
protocols: server.supported_protocols, |
||||
ciphers: server.supported_ciphers.collect { |c| { protocol: c.protocol, name: c.name, size: c.size, dh: key_to_json(c.dh) } }, |
||||
score: { |
||||
rank: grade.grade, |
||||
details: { |
||||
score: grade.score, |
||||
protocol: grade.protocol_score, |
||||
key_exchange: grade.key_exchange_score, |
||||
cipher_strengths: grade.cipher_strengths_score |
||||
}, |
||||
error: grade.error, |
||||
warning: grade.warning, |
||||
success: grade.success |
||||
} |
||||
} |
||||
|
||||
|
||||
self.result server, grade, result |
||||
rescue CryptCheck::Tls::Server::TLSNotAvailableException |
||||
{ no_tls: true } |
||||
end |
||||
Datastore.post self.type, host, result |
||||
end |
||||
|
||||
protected |
||||
def result(_, _, result) |
||||
result |
||||
end |
||||
end |
@ -1,42 +1,17 @@ |
||||
require 'simpleidn' |
||||
require 'cryptcheck' |
||||
|
||||
class HTTPSWorker |
||||
include Sidekiq::Worker |
||||
class HTTPSWorker < CheckWorker |
||||
sidekiq_options retry: false |
||||
|
||||
def key_to_json(key) |
||||
key.nil? ? nil : { type: key.type, size: key.size, rsa_size: key.rsa_equivalent_size } |
||||
protected |
||||
def module |
||||
CryptCheck::Tls::Https |
||||
end |
||||
|
||||
def perform(host) |
||||
idn = SimpleIDN.to_ascii host |
||||
result = begin |
||||
server = CryptCheck::Tls::Https::Server.new idn |
||||
grade = CryptCheck::Tls::Https::Grade.new server |
||||
def type |
||||
:https |
||||
end |
||||
|
||||
{ |
||||
key: key_to_json(server.key), |
||||
dh: server.dh.collect { |k| key_to_json k }, |
||||
protocols: server.supported_protocols, |
||||
ciphers: server.supported_ciphers.collect { |c| { protocol: c.protocol, name: c.name, size: c.size, dh: key_to_json(c.dh) } }, |
||||
hsts: server.hsts, |
||||
score: { |
||||
rank: grade.grade, |
||||
details: { |
||||
score: grade.score, |
||||
protocol: grade.protocol_score, |
||||
key_exchange: grade.key_exchange_score, |
||||
cipher_strengths: grade.cipher_strengths_score |
||||
}, |
||||
error: grade.error, |
||||
warning: grade.warning, |
||||
success: grade.success |
||||
} |
||||
} |
||||
rescue CryptCheck::Tls::Server::TLSNotAvailableException |
||||
{ no_tls: true } |
||||
end |
||||
Datastore.post :https, host, result |
||||
def result(server, _, hash) |
||||
hash[:hsts] = server.hsts |
||||
hash |
||||
end |
||||
end |
||||
|
@ -0,0 +1,12 @@ |
||||
class SMTPWorker < CheckWorker |
||||
sidekiq_options retry: false |
||||
|
||||
protected |
||||
def module |
||||
CryptCheck::Tls::Smtp |
||||
end |
||||
|
||||
def type |
||||
:smtp |
||||
end |
||||
end |
@ -0,0 +1,12 @@ |
||||
class XMPPWorker < CheckWorker |
||||
sidekiq_options retry: false |
||||
|
||||
protected |
||||
def module |
||||
CryptCheck::Tls::Xmpp |
||||
end |
||||
|
||||
def type |
||||
:xmpp |
||||
end |
||||
end |
@ -1,5 +1,19 @@ |
||||
Rails.application.routes.draw do |
||||
namespace :https, id: /[^\/]*/ do |
||||
get ':id/', action: :show |
||||
get ':id/refresh', action: :refresh, as: :refresh |
||||
end |
||||
|
||||
namespace :smtp, id: /[^\/]*/ do |
||||
get ':id/', action: :show |
||||
get ':id/refresh', action: :refresh, as: :refresh |
||||
end |
||||
|
||||
namespace :xmpp, id: /[^\/]*/ do |
||||
get ':id/', action: :show |
||||
get ':id/refresh', action: :refresh, as: :refresh |
||||
end |
||||
|
||||
root 'site#index' |
||||
get '/:id/refresh' => 'site#refresh', as: :refresh, id: /.*/ |
||||
get '/:id' => 'site#result', as: :result, id: /.*/ |
||||
get '/ciphers' => 'site#ciphers' |
||||
end |
||||
|
@ -0,0 +1,14 @@ |
||||
require 'test_helper' |
||||
|
||||
class CheckControllerTest < ActionController::TestCase |
||||
test "should get result" do |
||||
get :show |
||||
assert_response :success |
||||
end |
||||
|
||||
test "should get refresh" do |
||||
get :refresh |
||||
assert_response :success |
||||
end |
||||
|
||||
end |
@ -0,0 +1,14 @@ |
||||
require 'test_helper' |
||||
|
||||
class HttpsControllerTest < ActionController::TestCase |
||||
test "should get result" do |
||||
get :show |
||||
assert_response :success |
||||
end |
||||
|
||||
test "should get refresh" do |
||||
get :refresh |
||||
assert_response :success |
||||
end |
||||
|
||||
end |
@ -0,0 +1,14 @@ |
||||
require 'test_helper' |
||||
|
||||
class SmtpControllerTest < ActionController::TestCase |
||||
test "should get show" do |
||||
get :show |
||||
assert_response :success |
||||
end |
||||
|
||||
test "should get refresh" do |
||||
get :refresh |
||||
assert_response :success |
||||
end |
||||
|
||||
end |
@ -0,0 +1,14 @@ |
||||
require 'test_helper' |
||||
|
||||
class XmppControllerTest < ActionController::TestCase |
||||
test "should get show" do |
||||
get :show |
||||
assert_response :success |
||||
end |
||||
|
||||
test "should get refresh" do |
||||
get :refresh |
||||
assert_response :success |
||||
end |
||||
|
||||
end |
Loading…
Reference in new issue