summaryrefslogtreecommitdiff
path: root/tools/genconfig.sh
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2017-02-02 16:08:24 +0100
committerMagnus Ahltorp <map@kth.se>2017-02-02 16:08:24 +0100
commit06a6db0d0dc921527c4667037d7cc9fa000645d5 (patch)
tree3f4ff97960386e7bf69d36ae6b4d34331495a752 /tools/genconfig.sh
parentc9f058c7c7984a4443ca302ace4de85d2e5b18fa (diff)
Added tools for getting and generating global configkey-management2
Diffstat (limited to 'tools/genconfig.sh')
-rwxr-xr-xtools/genconfig.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/genconfig.sh b/tools/genconfig.sh
new file mode 100755
index 0000000..89bcd85
--- /dev/null
+++ b/tools/genconfig.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+# usage: genconfig.sh <template> <apikeydir> <logpublickeyfile> <cacertfile> <logadminkey> <destination>
+
+BINDIR=$(dirname $0)
+
+template=$1
+apikeydir=$2
+logpublickeyfile=$3
+cacertfile=$4
+logadminkey=$5
+destination=$6
+
+nodenames=$($BINDIR/compileconfig.py --config=${template} --getnodenames)
+
+cat ${template} > ${destination}
+
+echo "apikeys:" >> ${destination}
+
+for node in ${nodenames}; do \
+ apipk=$(grep -v '^-----' ${apikeydir}/${node}.pem | tr '\n' ' ')
+ echo " - nodename: ${node}" >> ${destination}
+ echo " publickey: ${apipk}" >> ${destination}
+done
+
+if [ -f ${destination}.version ]; then
+ oldversion=$(cat ${destination}.version)
+ version=$(expr $oldversion + 1)
+else
+ version=1
+fi
+
+echo ${version} > ${destination}.version
+
+cafingerprint=$(openssl x509 -in ${cacertfile} -noout -sha256 -fingerprint | sed -e 's/.*=//' -e 's/://g')
+
+logpk=$(grep -v '^-----' ${logpublickeyfile} | tr '\n' ' ')
+echo "logpublickey: ${logpk}" >> ${destination}
+echo "cafingerprint: ${cafingerprint}" >> ${destination}
+echo "version: ${version}" >> ${destination}
+
+openssl dgst -sha256 -sign ${logadminkey} -out ${destination}.sig ${destination}
+