From 7d4715c9f519dfc97ca5e43b4455ab77563bd423 Mon Sep 17 00:00:00 2001 From: Florian Obser Date: Sun, 23 Apr 2017 09:22:00 +0200 Subject: [PATCH] Initial commit --- gen_tlsa.pl | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 gen_tlsa.pl diff --git a/gen_tlsa.pl b/gen_tlsa.pl new file mode 100755 index 0000000..1d05000 --- /dev/null +++ b/gen_tlsa.pl @@ -0,0 +1,41 @@ +#! /usr/bin/perl +use strict; +use warnings; +use 5.010; +use autodie; + +use Digest::SHA; +use MIME::Base64; + + +use constant WAIT_BEGIN => 1; +use constant WAIT_END =>2; + +sub usage { + say STDERR "$0 DNS-LABEL CERT-FILE"; + exit(1); +} + +usage() if (scalar(@ARGV) != 2); + +my $state = WAIT_BEGIN; +my $pem = ''; + +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; + } + } +} +close($fh); +say $ARGV[0], ' IN TLSA 1 0 1 ', Digest::SHA::sha256_hex(decode_base64($pem)); + +#say $pem;