]> WPIA git - nre.git/blob - commonFunctions
cleanup shellscripts + README.md
[nre.git] / commonFunctions
1 #!/bin/bash
2 . structure
3
4 genKey(){ #subj, internalName
5     openssl genrsa -out $2.key ${KEYSIZE}
6     openssl req -new -key $2.key -out $2.csr -subj "$1/O=Test Environment CA Ltd./OU=Test Environment CAs"
7
8 }
9
10 genca(){ #subj, internalName
11     mkdir $2.ca
12
13     genKey "$1" "$2.ca/key"
14     
15     mkdir $2.ca/newcerts
16     echo 01 > $2.ca/serial
17     touch $2.ca/db
18     echo unique_subject = no >$2.ca/db.attr
19
20 }
21
22 caSign(){ # csr,ca,config,start,end
23     start="$4"
24     end="$5"
25     [ "$start" != "" ] && start="-startdate $start"
26     [ "$end" != "" ] && end="-enddate $end"
27     [ "$start" == "" -a "$end" == "" ] && start="-days 366"
28     BASE="$PWD"
29     echo "Signing: $1 with $2"
30     echo "$start $end"
31     pushd $2.ca > /dev/null
32     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
33     popd > /dev/null
34     echo "Signed"
35 }
36