Skip to content

Commit 07d9244

Browse files
committed
Add server address args in cert-gen.sh
1 parent 3da5557 commit 07d9244

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

scripts/cert-gen.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33

44
set -e
55

6+
# Read server address from command line args
7+
SERVER_ADDR=${1:-localhost}
8+
69
mkdir -p certs
710

811
# Generate a Certificate Authority (CA)
912
openssl genrsa -out certs/ca.key 4096
10-
openssl req -x509 -new -nodes -key certs/ca.key -sha256 -days 365 -out certs/ca.pem -subj "/CN=localhost"
13+
openssl req -x509 -new -nodes -key certs/ca.key -sha256 -days 365 -out certs/ca.pem -subj "/CN=${SERVER_ADDR}"
1114

1215

1316
# Generate a Server Key and Certificate Signing Request (CSR)
1417
# Passphrase is set to 123
1518
openssl genrsa -out certs/mongodb.key -passout pass:123 4096
16-
openssl req -new -key certs/mongodb.key -out certs/mongodb.csr -subj "/CN=localhost"
19+
openssl req -new -key certs/mongodb.key -out certs/mongodb.csr -subj "/CN=${SERVER_ADDR}"
1720

1821
# Sign the Server Certificate with the CA
19-
openssl x509 -req -extfile <(printf "subjectAltName=DNS:localhost") -in certs/mongodb.csr -CA certs/ca.pem -CAkey certs/ca.key -CAcreateserial -out certs/mongodb.crt -days 365 -sha256
22+
openssl x509 -req -extfile <(printf "subjectAltName=DNS:${SERVER_ADDR}") -in certs/mongodb.csr -CA certs/ca.pem -CAkey certs/ca.key -CAcreateserial -out certs/mongodb.crt -days 365 -sha256
2023

2124
# Combine Server Key and Certificate
2225
cat certs/mongodb.key certs/mongodb.crt > certs/mongodb.pem

0 commit comments

Comments
 (0)