move it to function
This commit is contained in:
parent
7d4715c9f5
commit
6ea7b77093
39
gen_tlsa.pl
39
gen_tlsa.pl
@ -18,24 +18,29 @@ sub usage {
|
||||
|
||||
usage() if (scalar(@ARGV) != 2);
|
||||
|
||||
my $state = WAIT_BEGIN;
|
||||
my $pem = '';
|
||||
gen_tlsa(@ARGV);
|
||||
|
||||
open(my $fh, '<', $ARGV[1]);
|
||||
while(my $line = <$fh>) {
|
||||
if ($state == WAIT_BEGIN) {
|
||||
if ($line=~/^-----BEGIN CERTIFICATE-----/) {
|
||||
$state = WAIT_END;
|
||||
}
|
||||
} elsif ($state == WAIT_END) {
|
||||
if ($line=~/^-----END CERTIFICATE-----/) {
|
||||
last;
|
||||
} else {
|
||||
$pem.=$line;
|
||||
sub gen_tlsa {
|
||||
my ($label, $cert_file) = @_;
|
||||
my $state = WAIT_BEGIN;
|
||||
my $pem = '';
|
||||
my ($fh, $line);
|
||||
|
||||
open($fh, '<', $cert_file);
|
||||
while($line = <$fh>) {
|
||||
if ($state == WAIT_BEGIN) {
|
||||
if ($line=~/^-----BEGIN CERTIFICATE-----/) {
|
||||
$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;
|
||||
|
Loading…
Reference in New Issue
Block a user