]> WPIA git - nre.git/blob - commonFunctions
several fixes on certificate profiles
[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" == "" && "$end" == "" ]] && start="$ROOT_VALIDITY"
28     BASE="$PWD"
29     echo "Signing: $1 with $2"
30     echo "$start $end"
31     pushd $2.ca > /dev/null
32     if [[ "$2" == "root" && "$1" == root.* ]]; then
33         signkey="-selfsign"
34     else
35         signkey="-cert key.crt"
36     fi
37     openssl ca $signkey -keyfile key.key -in "$BASE/$1.csr" -out "$BASE/$1.crt" -batch -config "$BASE/selfsign.config" -extfile "$BASE/$3" $start $end
38     popd > /dev/null
39     echo "Signed"
40 }
41