-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_certs.sh
More file actions
executable file
·90 lines (72 loc) · 2.18 KB
/
Copy pathgenerate_certs.sh
File metadata and controls
executable file
·90 lines (72 loc) · 2.18 KB
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
86
87
88
89
90
#!/bin/sh
set -e
# Check if a cert and key file exist. If so, ignore. Otherwise, generate a new
# CA cert and key.
if [ -f "ca.crt" ] || [ -f "ca.key" ]; then
echo "CA certificate or key already exists. skipping CA cert..."
else
openssl req -x509 -newkey rsa:4096 \
-nodes \
-keyout ca.key \
-out ca.crt \
-days 3650 \
-subj "/C=US/ST=Arizona/L=Phoenix/O=Technology/CN=papago-test-ca" \
2>/dev/null
openssl x509 -in ca.crt -noout -subject -dates
fi
# server certificate, signed by the CA above (instead of self-signed)
if [ -f "server.crt" ] || [ -f "server.key" ]; then
echo "server certificate or key already exists. skipping server cert..."
else
SAN_FILE="$(mktemp)"
cat > "${SAN_FILE}" <<EOF
[ v3_req ]
subjectAltName = @alt_names
[ alt_names ]
DNS.1 = localhost
$(printf '%s' "${SAN_CONFIG}")
EOF
SERVER_CSR="$(mktemp)"
openssl req -newkey rsa:4096 \
-nodes \
-keyout server.key \
-out "${SERVER_CSR}" \
-subj "/C=US/ST=Arizona/L=Phoenix/O=Technology/CN=localhost" \
2>/dev/null
openssl x509 -req \
-in "${SERVER_CSR}" \
-CA ca.crt \
-CAkey ca.key \
-CAcreateserial \
-out server.crt \
-days 365 \
-sha512 \
-extfile "${SAN_FILE}" \
-extensions v3_req 2>/dev/null
openssl x509 -in server.crt -noout -subject -issuer -dates
rm -f "${SAN_FILE}" "${SERVER_CSR}"
fi
# client certificate, signed by the same CA, for mutual TLS testing
if [ -f "client.crt" ] || [ -f "client.key" ]; then
echo "client certificate or key already exists. skipping client cert..."
else
CLIENT_CSR="$(mktemp)"
openssl req -newkey rsa:4096 \
-nodes \
-keyout client.key \
-out "${CLIENT_CSR}" \
-subj "/C=US/ST=Arizona/L=Phoenix/O=Technology/CN=papago-client" \
2>/dev/null
openssl x509 -req \
-in "${CLIENT_CSR}" \
-CA ca.crt \
-CAkey ca.key \
-CAcreateserial \
-out client.crt \
-days 365 \
-sha512 2>/dev/null
openssl x509 -in client.crt -noout -subject -issuer -dates
rm -f "${CLIENT_CSR}"
fi
rm -f ca.srl
exit 0