From ec25ca348aea8790344b29061ceed8f6ab7f64b7 Mon Sep 17 00:00:00 2001 From: Lukas Metzger Date: Sun, 7 Feb 2016 13:07:35 +0100 Subject: [PATCH] Added keyfile resolving --- .gitignore | 2 ++ pdns-client | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..75dc27c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +pdns.private.pem +pdns.public.pem diff --git a/pdns-client b/pdns-client index a7fe5c9..9e77fd0 100755 --- a/pdns-client +++ b/pdns-client @@ -1,10 +1,12 @@ #!/bin/bash +SD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + SERVER="" DOMAIN="" ID="" CONTENT="" -KEY="pdns.private.pem" +KEY="" exit_error() { echo "ERROR: ${1}" >&2 @@ -50,12 +52,23 @@ validate_arguments() { then exit_error "The content cannot be empty" fi - if [[ ! -f "$KEY" ]] +} + +resolve_keyfile() { + if [ -n "$KEY" ] then - exit_error "$KEY is not a file" + openssl rsa -in "$KEY" -check -noout > /dev/null 2>&1 || exit_error "$KEY ist not a valid rsa private key" + else + if openssl rsa -in "pdns.private.pem" -check -noout >/dev/null 2>&1 + then + KEY="pdns.private.pem" + elif openssl rsa -in "$SD/pdns.private.pem" -check -noout >/dev/null 2>&1 + then + KEY="$SD/pdns.private.pem" + else + exit_error "No valid key found. Make shure it is in pdns.private.pem or supply it with -k." + fi fi - - openssl rsa -in "$KEY" -check -noout > /dev/null 2>&1 || exit_error "$KEY ist not a valid rsa private key" } #main @@ -85,6 +98,7 @@ done check_dependencies validate_arguments +resolve_keyfile #Get nonce for signing read NONCE < <(echo "{}" |\