X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=commonFunctions;h=f46505b445d912f2d311f7f03bc6474003c616df;hb=6ae3c38ec9e46bea24edfcef895ee14f85f420ff;hp=5e1ffbf2929b40210e5ed3fb6ed98b2c56e17d97;hpb=2d5c169f43c88c0abedf60990b1fd622e8261b49;p=nre.git diff --git a/commonFunctions b/commonFunctions old mode 100755 new mode 100644 index 5e1ffbf..f46505b --- a/commonFunctions +++ b/commonFunctions @@ -1,8 +1,9 @@ +#!/bin/bash . structure genKey(){ #subj, internalName openssl genrsa -out $2.key ${KEYSIZE} - openssl req -new -key $2.key -out $2.csr -subj "$1/O=Test Environment CA Ltd./OU=Test Environment CAs" + openssl req -new -key $2.key -out $2.csr -subj "$1/O=Test Environment CA Ltd./OU=Test Environment CAs/C=AU" } @@ -21,14 +22,19 @@ genca(){ #subj, internalName caSign(){ # csr,ca,config,start,end start="$4" end="$5" - [ "$start" != "" ] && start="-startdate $start" - [ "$end" != "" ] && end="-enddate $end" - [ "$start" == "" -a "$end" == "" ] && start="-days 366" + [[ "$start" != "" ]] && start="-startdate $start" + [[ "$end" != "" ]] && end="-enddate $end" + [[ "$start" == "" && "$end" == "" ]] && start="$ROOT_VALIDITY" BASE="$PWD" - echo "Signing: $1 with $2" + echo "Signing: $BASE/$1 with $2" echo "$start $end" pushd $2.ca > /dev/null - openssl ca -cert key.crt -keyfile key.key -in "$BASE/$1.csr" -out "$BASE/$1.crt" -batch -config "$BASE/selfsign.config" -extfile "$BASE/$3" $start $end + if [[ "$2" == "root" && "$1" == root.* ]]; then + signkey="-selfsign" + else + signkey="-cert key.crt" + fi + openssl ca $signkey -keyfile key.key -in "$BASE/$1.csr" -out "$BASE/$1.crt" -batch -config "$BASE/../selfsign.config" -extfile "$BASE/$3" $start $end popd > /dev/null echo "Signed" }