Skip to content

Instantly share code, notes, and snippets.

@bonsaiviking
Created July 17, 2012 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonsaiviking/3130353 to your computer and use it in GitHub Desktop.
Save bonsaiviking/3130353 to your computer and use it in GitHub Desktop.
Rate TLS ciphers similar to ssllabs.com's ranking system
#!/usr/bin/perl
use strict;
use warnings;
use 5.012;
my %kex_scores = (
NULL => 0,
anon => 0,
EXPORT => 40,
#Otherwise => 80
);
my %cipher_scores = (
NULL => 0,
40 => 20,
DES40 => 20,
DES => 20, #56
56 => 20,
IDEA => 20, #64
128 => 80,
SEED => 80, #128
"3DES" => 80, #168
256 => 100,
);
while (<>) {
chomp;
my $state = 0;
my ($ks, $cs);
for my $f (split /_/) {
if ($state == 0) {
$ks = $kex_scores{$f};
if (defined $ks) {
$state = 1;
}
else {
$cs = $cipher_scores{$f};
if (defined $cs) {
$state = 2;
}
}
}
elsif ($state == 1) {
$cs = $cipher_scores{$f};
if (defined $cs) {
$state = 2;
}
}
else {
last;
}
}
$ks //= 80;
$cs = 0 if $ks == 0; #NULL means 0, period.
if (defined $cs) {
my $score = .4 * $ks + .6 * $cs;
$score = 0 if $ks == 0 or $cs == 0;
if ($score >= 80) {
$score = 'strong';
}
elsif ($score < 50) {
if ($score >= 20) {
$score = 'weak';
}
else {
$score = 'broken';
}
}
say "$_ $score";
}
else {
#say "$_ unknown";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment