2016-06-27 16:49:54 +02:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Test::More;
|
|
|
|
use Data::Dumper;
|
|
|
|
use JSON;
|
|
|
|
|
2016-06-28 23:59:36 +02:00
|
|
|
my $tests = 0;
|
2016-06-27 16:49:54 +02:00
|
|
|
|
|
|
|
my (
|
|
|
|
$out,
|
|
|
|
$json,
|
|
|
|
$found,
|
|
|
|
);
|
|
|
|
# OK
|
2016-08-09 10:35:58 +02:00
|
|
|
pass("Running testssl.sh against badssl.com to create a baseline (may take 2~3 minutes)"); $tests++;
|
2020-11-27 13:19:52 +01:00
|
|
|
my $okout = `./testssl.sh -S -e --freak --logjam --drown --rc4 --sweet32 --breach --winshock --crime --jsonfile tmp.json --color 0 badssl.com`;
|
2016-06-27 16:49:54 +02:00
|
|
|
my $okjson = json('tmp.json');
|
2017-03-29 17:41:23 +02:00
|
|
|
unlink 'tmp.json';
|
2016-06-29 00:38:51 +02:00
|
|
|
cmp_ok(@$okjson,'>',10,"We have more then 10 findings"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
|
|
|
|
# Expiration
|
2016-06-29 00:35:52 +02:00
|
|
|
pass("Running testssl against expired.badssl.com"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
$out = `./testssl.sh -S --jsonfile tmp.json --color 0 expired.badssl.com`;
|
2021-10-05 19:53:58 +02:00
|
|
|
like($out, qr/Chain of trust\s+NOT ok \(expired\)/,"The chain of trust should be expired"); $tests++;
|
2018-01-31 21:44:33 +01:00
|
|
|
like($out, qr/Certificate Validity \(UTC\)\s+expired/,"The certificate should be expired"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
$json = json('tmp.json');
|
2017-03-29 17:41:23 +02:00
|
|
|
unlink 'tmp.json';
|
2016-06-27 16:49:54 +02:00
|
|
|
$found = 0;
|
|
|
|
foreach my $f ( @$json ) {
|
2019-04-09 12:47:12 +02:00
|
|
|
if ( $f->{id} eq "cert_expirationStatus" ) {
|
2016-06-27 16:49:54 +02:00
|
|
|
$found = 1;
|
2018-01-23 11:46:24 +01:00
|
|
|
like($f->{finding},qr/^expired/,"Finding reads expired."); $tests++;
|
2016-10-28 15:30:07 +02:00
|
|
|
is($f->{severity}, "CRITICAL", "Severity should be CRITICAL"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
2016-06-29 00:35:52 +02:00
|
|
|
is($found,1,"We had a finding for this in the JSON output"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
|
|
|
|
# Self signed and not-expired
|
2016-06-29 00:35:52 +02:00
|
|
|
pass("Running testssl against self-signed.badssl.com"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
$out = `./testssl.sh -S --jsonfile tmp.json --color 0 self-signed.badssl.com`;
|
2018-06-13 14:30:35 +02:00
|
|
|
unlike($out, qr/Certificate Validity \(UTC\)s+expired/,"The certificate should not be expired"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
$json = json('tmp.json');
|
2017-03-29 17:41:23 +02:00
|
|
|
unlink 'tmp.json';
|
2016-06-27 16:49:54 +02:00
|
|
|
$found = 0;
|
|
|
|
foreach my $f ( @$json ) {
|
2019-04-09 12:47:12 +02:00
|
|
|
if ( $f->{id} eq "cert_expirationStatus" ) {
|
2016-06-27 16:49:54 +02:00
|
|
|
$found = 1;
|
2018-01-23 11:46:24 +01:00
|
|
|
like($f->{finding},qr/days/,"Finding doesn't read expired."); $tests++;
|
2018-07-11 17:14:29 +02:00
|
|
|
isnt($f->{severity}, "CRITICAL", "Severity should be OK, MEDIUM or HIGH"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
2016-06-29 00:35:52 +02:00
|
|
|
is($found,1,"We had a finding for this in the JSON output"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
|
2016-08-09 10:35:58 +02:00
|
|
|
like($out, qr/Chain of trust.*?NOT ok.*\(self signed\)/,"Chain of trust should fail because of self signed"); $tests++;
|
|
|
|
$found = 0;
|
|
|
|
foreach my $f ( @$json ) {
|
2018-01-23 11:46:24 +01:00
|
|
|
if ( $f->{id} eq "cert_chain_of_trust" ) {
|
2016-08-09 10:35:58 +02:00
|
|
|
$found = 1;
|
2018-01-23 11:46:24 +01:00
|
|
|
like($f->{finding},qr/^.*self signed/,"Finding says certificate cannot be trusted."); $tests++;
|
2016-10-28 15:30:07 +02:00
|
|
|
is($f->{severity}, "CRITICAL", "Severity should be CRITICAL"); $tests++;
|
2016-08-09 10:35:58 +02:00
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
2016-06-29 00:35:52 +02:00
|
|
|
is($found,1,"We had a finding for this in the JSON output"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
|
2016-06-29 00:35:52 +02:00
|
|
|
like($okout, qr/Chain of trust[^\n]*?Ok/,"Chain of trust should be ok"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
$found = 0;
|
|
|
|
foreach my $f ( @$okjson ) {
|
2018-01-23 11:46:24 +01:00
|
|
|
if ( $f->{id} eq "cert_chain_of_trust" ) {
|
2016-06-27 16:49:54 +02:00
|
|
|
$found = 1;
|
2018-01-23 11:46:24 +01:00
|
|
|
like($f->{finding},qr/passed/,"Finding says certificate can be trusted."); $tests++;
|
|
|
|
# is($f->{finding},"^.*passed.*","Finding says certificate can be trusted."); $tests++;
|
2016-06-29 00:35:52 +02:00
|
|
|
is($f->{severity}, "OK", "Severity should be OK"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
2016-06-29 00:35:52 +02:00
|
|
|
is($found,1,"We had a finding for this in the JSON output"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
|
|
|
|
# Wrong host
|
2016-06-29 00:35:52 +02:00
|
|
|
#pass("Running testssl against wrong.host.badssl.com"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
#$out = `./testssl.sh -S --jsonfile tmp.json --color 0 wrong.host.badssl.com`;
|
2016-06-29 00:35:52 +02:00
|
|
|
#unlike($out, qr/Certificate Expiration\s+expired\!/,"The certificate should not be expired"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
#$json = json('tmp.json');
|
2017-03-29 17:41:23 +02:00
|
|
|
#unlink 'tmp.json';
|
2016-06-27 16:49:54 +02:00
|
|
|
#$found = 0;
|
|
|
|
#foreach my $f ( @$json ) {
|
|
|
|
# if ( $f->{id} eq "expiration" ) {
|
|
|
|
# $found = 1;
|
2016-06-29 00:35:52 +02:00
|
|
|
# unlike($f->{finding},qr/^Certificate Expiration.*expired\!/,"Finding should not read expired."); $tests++;
|
|
|
|
# is($f->{severity}, "ok", "Severity should be ok"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
# last;
|
|
|
|
# }
|
|
|
|
#}
|
2016-06-29 00:35:52 +02:00
|
|
|
#is($found,1,"We had a finding for this in the JSON output"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
|
|
|
|
# Incomplete chain
|
2016-06-29 00:35:52 +02:00
|
|
|
pass("Running testssl against incomplete-chain.badssl.com"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
$out = `./testssl.sh -S --jsonfile tmp.json --color 0 incomplete-chain.badssl.com`;
|
2016-06-29 00:35:52 +02:00
|
|
|
like($out, qr/Chain of trust.*?NOT ok\s+\(chain incomplete\)/,"Chain of trust should fail because of incomplete"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
$json = json('tmp.json');
|
2017-03-29 17:41:23 +02:00
|
|
|
unlink 'tmp.json';
|
2016-06-27 16:49:54 +02:00
|
|
|
$found = 0;
|
|
|
|
foreach my $f ( @$json ) {
|
2018-01-23 11:46:24 +01:00
|
|
|
if ( $f->{id} eq "cert_chain_of_trust" ) {
|
2016-06-27 16:49:54 +02:00
|
|
|
$found = 1;
|
2018-01-23 11:46:24 +01:00
|
|
|
like($f->{finding},qr/^.*chain incomplete/,"Finding says certificate cannot be trusted."); $tests++;
|
2016-10-28 15:30:07 +02:00
|
|
|
is($f->{severity}, "CRITICAL", "Severity should be CRITICAL"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
2016-06-29 00:35:52 +02:00
|
|
|
is($found,1,"We had a finding for this in the JSON output"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
|
|
|
|
# TODO: RSA 8192
|
|
|
|
|
2016-06-29 00:24:57 +02:00
|
|
|
# TODO: CBC
|
2016-06-29 00:35:52 +02:00
|
|
|
#pass("Running testssl against cbc.badssl.com"); $tests++;
|
2016-06-29 00:24:57 +02:00
|
|
|
#$out = `./testssl.sh -e -U --jsonfile tmp.json --color 0 cbc.badssl.com`;
|
2016-06-29 00:35:52 +02:00
|
|
|
#like($out, qr/Chain of trust.*?NOT ok\s+\(chain incomplete\)/,"Chain of trust should fail because of incomplete"); $tests++;
|
2016-06-29 00:24:57 +02:00
|
|
|
#$json = json('tmp.json');
|
2017-03-29 17:41:23 +02:00
|
|
|
#unlink 'tmp.json';
|
2016-06-29 00:24:57 +02:00
|
|
|
#$found = 0;
|
|
|
|
#foreach my $f ( @$json ) {
|
2018-01-23 11:46:24 +01:00
|
|
|
# if ( $f->{id} eq "cert_chain_of_trust" ) {
|
2016-06-29 00:24:57 +02:00
|
|
|
# $found = 1;
|
2016-06-29 00:35:52 +02:00
|
|
|
# like($f->{finding},qr/^All certificate trust checks failed.*incomplete/,"Finding says certificate cannot be trusted."); $tests++;
|
2016-10-28 15:30:07 +02:00
|
|
|
# is($f->{severity}, "CRITICAL", "Severity should be CRITICAL"); $tests++;
|
2016-06-29 00:24:57 +02:00
|
|
|
# last;
|
|
|
|
# }
|
|
|
|
#}
|
2016-06-29 00:35:52 +02:00
|
|
|
#is($found,1,"We had a finding for this in the JSON output"); $tests++;
|
2016-06-27 16:49:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
done_testing($tests);
|
|
|
|
|
|
|
|
sub json($) {
|
|
|
|
my $file = shift;
|
|
|
|
$file = `cat $file`;
|
|
|
|
unlink $file;
|
|
|
|
return from_json($file);
|
2017-03-29 17:41:23 +02:00
|
|
|
}
|
2021-05-31 22:39:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
# vim:ts=5:sw=5:expandtab
|
|
|
|
|