forked from redredgroovy/easy-ca
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcreate-client
executable file
·86 lines (68 loc) · 1.96 KB
/
create-client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# Derek Moore <[email protected]>
# Tiago Possato <[email protected]>
usage() {
echo "Usage: $0 -c CLIENT_NAME -n CERT_NAME"
echo "Options:"
echo " -c CLIENT_NAME Client name (commonName) for the new cert"
echo " -n CERT_NAME Cert name for the new cert"
echo
exit 2
}
CLIENT_NAME=
CERT_NAME=
while getopts "c:n:" FLAG; do
case "${FLAG}" in
c) CLIENT_NAME=${OPTARG} ;;
n) CERT_NAME=${OPTARG} ;;
*) usage ;;
esac
done
if [ "${CLIENT_NAME}" == "" ]; then
usage
fi
if [ "${CERT_NAME}" == "" ]; then
usage
fi
echo "CERT_NAME: "${CERT_NAME}
echo "CLIENT_NAME: "${CLIENT_NAME}
BIN_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source ${BIN_DIR}/functions
source ${BIN_DIR}/defaults.conf
SAFE_NAME=`echo ${CERT_NAME} | sed 's/\*/star/g'`
SAFE_NAME=`echo $SAFE_NAME | sed 's/[^A-Za-z0-9-]/-/g'`
echo
echo "Creating new client certificate for '${CLIENT_NAME}'"
echo
pushd ${BIN_DIR}/.. > /dev/null
if [ -f conf/${SAFE_NAME}.client.conf ]; then
echo "Configuration already exists for '${CERT_NAME}', exiting."
exit 1
fi
#echo -n "Enter passphase for signing CA key: "
#read -s PASS
#echo
#export CA_PASS=${PASS}
export CA_PASS=""
# Generate the client cert openssl config
export SAN=""
export CA_USERNAME=${CLIENT_NAME}
template "${BIN_DIR}/templates/client.tpl" "conf/${SAFE_NAME}.client.conf"
# Create the client key and csr
openssl req -new -nodes \
-config conf/${SAFE_NAME}.client.conf \
-keyout private/${SAFE_NAME}.client.key \
-out csr/${SAFE_NAME}.client.csr
chmod 0400 private/${SAFE_NAME}.client.key
# Create the client certificate
openssl ca -batch -notext \
-config conf/ca.conf \
-in csr/${SAFE_NAME}.client.csr \
-out certs/${SAFE_NAME}.client.crt \
-days 730 \
-extensions client_ext \
-passin env:CA_PASS
popd > /dev/null
echo
echo "Client certificate created."
echo