#!/bin/sh # update-itar.sh - update from the interim trust anchor repository # Copyright 2009, W.C.A. Wijngaards # This file is BSD licensed, see doc/LICENSE. # --- Some settings # directory where unbound works thedir="." # where is the file that unbound is going to read ub_ta_file="$thedir/anchors.mf" # where is the itar master file format itar_url="ftp://ftp.iana.org/itar/anchors.mf" # where is the itar PGP signature itar_sig="ftp://ftp.iana.org/itar/anchors.mf.sig" # which command to fetch urls, cmd $dest $url. "wget -O" "curl -o" fetch_cmd="wget -O" # file with pgp public key pgp_pub_key_file="$thedir/update-itar.key" # our pgp keyring (goes into .gnupg directory) pgp_keyring_file="update-itar.ring" # pgp command to use pgp_cmd="gpg" # --- The script is below usage ( ) { echo "usage: update-itar" echo " Updates the trust anchors from the interim trust" echo " anchor repository, https://itar.iana.org, and checks PGP sig." echo echo " Updates $ub_ta_file with the latest keys." echo " Read that file from the unbound config with" echo " trust-anchor-file: "'"'"$ub_ta_file"'"' echo echo " Exit code 0 means anchors updated, 1 no changes, " echo " others are errors. So, in a cronjob you can do:" echo " cd /usr/local/etc/unbound # your unbound work dir" echo " ./update-itar.sh && unbound-control reload" exit 2 } if test $# -ne 0; then usage fi tmpf="/tmp/update-itar.$$" # one argument: explanation string error_exit ( ) { if test -f $tmpf.log; then cat $tmpf.log; fi rm -f $tmpf $tmpf.sig $tmpf.log echo "Error updating trust anchors: $1" exit 2 } if test ! -f $pgp_pub_key_file || test ! -f $HOME/.gnupg/$pgp_keyring_file || \ test "$pgp_pub_key_file" -nt $HOME/.gnupg/$pgp_keyring_file; then # default key contents right here if test ! -f $pgp_pub_key_file; then echo "creating default IANA ITAR pgp key file" cat >$pgp_pub_key_file <$tmpf.log 2>&1 \ || error_exit "could not import pgp public key into keyring" fi $fetch_cmd $tmpf $itar_url >$tmpf.log 2>&1 \ || error_exit "fetching $itar_url failed" tail -2 $tmpf | grep "; End of file" >/dev/null 2>&1 || \ error_exit "The file fetched from $itar_url was partial" $fetch_cmd $tmpf.sig $itar_sig >$tmpf.log 2>&1 \ || error_exit "fetching $itar_sig failed" # check the file with pgp $pgp_cmd --no-default-keyring --keyring $pgp_keyring_file \ --verify $tmpf.sig $tmpf >$tmpf.log 2>&1 \ || error_exit "the PGP signature failed!" # check for differences val=1 if diff "$ub_ta_file" $tmpf 2>/dev/null ; then # echo "The interim trust anchor repository did not change." : else echo "Updating $ub_ta_file" cp $tmpf $ub_ta_file val=0 fi rm -f $tmpf $tmpf.sig $tmpf.log exit $val