11#! /bin/bash
2- CERT_PATH=/Users/anandkumarpatel/run/devops-scripts/ansible/certs
32if [[ $1 = ' ' ]]; then
43 echo ' script requires a client name'
54 exit 1
65fi
7- CLIENT=./files/certs/$1
86
97echo ' WARN: hard coded alpha-api-old gamma-services and beta-services for SWARM'
10- # if [[ $2 = '' ]]; then
11- # echo 'script requires a client ip address'
12- # exit 1
13- # fi
8+ if [[ $2 = ' ' ]]; then
9+ echo ' script requires a client ip address'
10+ exit 1
11+ fi
12+
13+ if [[ $3 = ' ' ]]; then
14+ echo ' script requires a path for secrets'
15+ exit 1
16+ fi
17+
18+ CERT_PATH=$3
19+ if [ ! -d " $CERT_PATH " ]; then
20+ echo ' The specified directory for certs does not exist'
21+ fi
1422
23+ CLIENT=./$CERT_PATH /$1
1524mkdir $CLIENT
1625
1726# generate key for client
@@ -28,16 +37,17 @@ openssl req \
2837chmod 400 " $CLIENT /client.csr"
2938
3039echo extendedKeyUsage=clientAuth,serverAuth > " $CLIENT /extfile.cnf"
31- echo subjectAltName=IP:127.0.0.1,DNS:localhost,DNS:swarm >> " $CLIENT /extfile.cnf"
40+ echo subjectAltName=IP:$2 >> " $CLIENT /extfile.cnf"
3241
3342# generate cert for client
3443openssl x509 \
3544 -req \
36- -days 3650 \
45+ -days 365 \
3746 -sha256 \
3847 -in " $CLIENT /client.csr" \
3948 -CA $CERT_PATH /ca.pem \
4049 -CAkey $CERT_PATH /ca-key.pem \
50+ -passin file:$CERT_PATH /pass \
4151 -CAcreateserial \
4252 -out " $CLIENT /cert.pem" \
4353 -extfile " $CLIENT /extfile.cnf"
@@ -48,4 +58,4 @@ chmod 644 "$CLIENT/key.pem"
4858
4959# cleanup files we do not need
5060rm $CLIENT /extfile.cnf
51- rm $CLIENT /client.csr
61+ rm -f $CLIENT /client.csr
0 commit comments