-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify-dnssec-keys.sh
executable file
·50 lines (39 loc) · 1.54 KB
/
verify-dnssec-keys.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# temp dir for everything.
OLDDIR=${PWD}
TMPDIR=$(mktemp -d)
cd ${TMPDIR}
# The root anchors can be obtained from:
# https://data.iana.org/root-anchors/
# We use https:// for an additional layer of authentication - as https:// uses
# x.509 certificates.
# PGP has been discontinued...
#wget https://data.iana.org/root-anchors/root-anchors.asc https://data.iana.org/root-anchors/root-anchors.xml https://data.iana.org/root-anchors/icann.pgp
## Import the GPG key obtained
#echo "Importing IANA/ICANN GPG key (DNSSEC Manager <[email protected]>)"
#gpg --import icann.pgp
#
## Verify the signature
#echo "Verifying GPG signature"
#gpg --verify root-anchors.asc root-anchors.xml
wget https://data.iana.org/root-anchors/root-anchors.xml http://data.iana.org/root-anchors/root-anchors.p7s http://data.iana.org/root-anchors/icannbundle.pem
openssl smime -verify -binary -inform DER -in root-anchors.p7s -content root-anchors.xml -CAfile icannbundle.pem
echo "Obtaining key via DNS"
# Via DNS:
#dig . dnskey | grep "IN DNSKEY 257 3 8" > root_dnskey
delv . dnskey | grep "IN DNSKEY 257 3 8" > root_dnskey
/usr/sbin/dnssec-dsfromkey -2 -f root_dnskey . > DSrecord
#Now to compare the two:
XMLKEY=$(cat root-anchors.xml | grep \<Digest\> | tail -n1 | sed -e "s@<Digest>@@" | sed -e "s@</Digest>@@")
DNSKEY=$(cat DSrecord | awk '{print $7$8}')
echo "Key obtained via IANA https: ${XMLKEY}"
echo "Key obtained via DNS (dig): ${DNSKEY}"
if [[ ${XMLKEY} == ${DNSKEY} ]]
then
echo "Keys validated."
else
echo "Keys do not match!!"
fi
# Clean up
cd ${OLDDIR}
rm -rf ${TMPDIR}