Skip to content

Instantly share code, notes, and snippets.

@techdad
Last active March 30, 2017 16:26
Show Gist options
  • Save techdad/0f27c9a260bf56098912 to your computer and use it in GitHub Desktop.
Save techdad/0f27c9a260bf56098912 to your computer and use it in GitHub Desktop.
gen-tsig.sh
#!/usr/bin/env bash
# quick and dirty TSIG generation script
# define key params
algo="hmac-sha512"
size="512"
# get key name
if [[ -z $1 ]]; then
echo "Error: Usage: $0 <key-name>"
exit 1
else
keyn="$1"
fi
# use generate has for our secret
dnssec-keygen -a ${algo} -n host -b ${size} ${keyn}
# extract to bind9 format
grep "Key" K${keyn}.+*.private | \
awk -v keyn="$keyn" -v algo="$algo" \
'{print "key " keyn " {\n\talgorithm " algo ";\n\tsecret \"" $2 "\";\n};"}' \
> ${keyn}.key
# optionally uncomment to delete tmp files
# rm -fv K${keyn}.+*.*
# eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment