-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgen-certs.sh
More file actions
executable file
·70 lines (58 loc) · 2.12 KB
/
Copy pathgen-certs.sh
File metadata and controls
executable file
·70 lines (58 loc) · 2.12 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
#!/usr/bin/env bash
# scripts/gen-certs.sh — v1.2 dev/test mTLS cert generator (D-V1.2-mtls).
#
# Produces a self-signed CA + a server cert + a client cert under ./certs/.
# Production deployments should NOT use these — provision your own CA and
# set the NEXUS_*_CERT env vars to point at it.
#
# Usage:
# ./scripts/gen-certs.sh # writes ./certs/{ca,server,client}.{crt,key}.pem
# ./scripts/gen-certs.sh /custom/dir
#
# Required: openssl >= 1.1.1.
set -euo pipefail
OUT_DIR="${1:-./certs}"
SUBJ_BASE="/C=US/ST=DEV/L=DEV/O=rust-nexus/OU=v1.2-dev-certs"
DAYS=365
mkdir -p "$OUT_DIR"
cd "$OUT_DIR"
echo "[gen-certs] writing into $(pwd)"
# CA
echo "[gen-certs] generating CA"
openssl genpkey -algorithm ED25519 -out ca.key.pem
openssl req -x509 -new -key ca.key.pem -days "$DAYS" -out ca.crt.pem \
-subj "${SUBJ_BASE}/CN=rust-nexus-dev-ca"
# Server
echo "[gen-certs] generating server cert"
openssl genpkey -algorithm ED25519 -out server.key.pem
openssl req -new -key server.key.pem -out server.csr.pem \
-subj "${SUBJ_BASE}/CN=localhost"
cat > server.ext.cnf <<'EOF'
subjectAltName = DNS:localhost,IP:127.0.0.1
extendedKeyUsage = serverAuth
EOF
openssl x509 -req -in server.csr.pem -CA ca.crt.pem -CAkey ca.key.pem \
-CAcreateserial -days "$DAYS" -out server.crt.pem \
-extfile server.ext.cnf
rm server.csr.pem server.ext.cnf
# Client
echo "[gen-certs] generating client cert"
openssl genpkey -algorithm ED25519 -out client.key.pem
openssl req -new -key client.key.pem -out client.csr.pem \
-subj "${SUBJ_BASE}/CN=operator-dev"
cat > client.ext.cnf <<'EOF'
extendedKeyUsage = clientAuth
EOF
openssl x509 -req -in client.csr.pem -CA ca.crt.pem -CAkey ca.key.pem \
-CAcreateserial -days "$DAYS" -out client.crt.pem \
-extfile client.ext.cnf
rm -f client.csr.pem client.ext.cnf ca.srl
chmod 600 ca.key.pem server.key.pem client.key.pem
cat <<EOF
[gen-certs] done. To use, export:
export NEXUS_CA_CERT=$(pwd)/ca.crt.pem
export NEXUS_SERVER_CERT=$(pwd)/server.crt.pem
export NEXUS_SERVER_KEY=$(pwd)/server.key.pem
export NEXUS_CLIENT_CERT=$(pwd)/client.crt.pem
export NEXUS_CLIENT_KEY=$(pwd)/client.key.pem
EOF