-
Notifications
You must be signed in to change notification settings - Fork 2
/
03-issue-client-cert.sh
executable file
·48 lines (40 loc) · 1.24 KB
/
03-issue-client-cert.sh
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
#!/bin/bash
set -euo pipefail
if [ -z "${1:-}" ]; then
echo "Usage: $0 <CA_NAME>"
echo "<CA_NAME> is the name of the CA cert files"
echo "There should be a <CA_NAME>.pem for the CA certificate"
echo "and a <CA_NAME>.key for the private key"
exit 1
fi
echo "Issuing client certificate"
ISSUER_CA="${1}"
cd "$(dirname "$0")"
CL_C="${TLS_DN_C:-SE}"
CL_ST="${TLS_DN_ST:-Stockholm}"
CL_L="${TLS_DN_L:-Stockholm}"
CL_O="${TLS_DN_O:-MyOrgName}"
CL_OU="${TLS_DN_OU:-MyServiceClient}"
CL_CN="${TLS_CLIENT_COMMON_NAME:-localhost}"
if [ ! -f client.key ]; then
case $ALG in
rsa)
openssl genrsa -out client.key 2048
;;
ec|ecc)
openssl ecparam -name prime256v1 -genkey -noout -out client.key
;;
dsa)
openssl gendsa -out "client.key" <(openssl dsaparam 2048)
;;
*)
echo "Unknown algorithm: $ALG"
exit 1
;;
esac
fi
if [ ! -f client.pem ]; then
openssl req -sha256 -new -key client.key -out client.csr -nodes -subj "/C=${CL_C}/ST=${CL_ST}/L=${CL_L}/O=${CL_O}/OU=${CL_OU}/CN=${CL_CN}" -addext "basicConstraints=critical,CA:false"
openssl x509 -req -CA "${ISSUER_CA}.pem" -CAkey "${ISSUER_CA}.key" -in client.csr -out client.pem -days 3650 -CAcreateserial
rm -f client.csr
fi