move it to function

This commit is contained in:
Florian Obser 2017-04-23 09:25:17 +02:00
parent 7d4715c9f5
commit 6ea7b77093

View File

@ -18,24 +18,29 @@ sub usage {
usage() if (scalar(@ARGV) != 2); usage() if (scalar(@ARGV) != 2);
my $state = WAIT_BEGIN; gen_tlsa(@ARGV);
my $pem = '';
open(my $fh, '<', $ARGV[1]); sub gen_tlsa {
while(my $line = <$fh>) { my ($label, $cert_file) = @_;
if ($state == WAIT_BEGIN) { my $state = WAIT_BEGIN;
if ($line=~/^-----BEGIN CERTIFICATE-----/) { my $pem = '';
$state = WAIT_END; my ($fh, $line);
}
} elsif ($state == WAIT_END) { open($fh, '<', $cert_file);
if ($line=~/^-----END CERTIFICATE-----/) { while($line = <$fh>) {
last; if ($state == WAIT_BEGIN) {
} else { if ($line=~/^-----BEGIN CERTIFICATE-----/) {
$pem.=$line; $state = WAIT_END;
}
} elsif ($state == WAIT_END) {
if ($line=~/^-----END CERTIFICATE-----/) {
last;
} else {
$pem.=$line;
}
} }
} }
close($fh);
say($label, ' IN TLSA 1 0 1 ',
Digest::SHA::sha256_hex(decode_base64($pem)));
} }
close($fh);
say $ARGV[0], ' IN TLSA 1 0 1 ', Digest::SHA::sha256_hex(decode_base64($pem));
#say $pem;