File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 3
3
4
4
set -e
5
5
6
+ # Read server address from command line args
7
+ SERVER_ADDR=${1:- localhost}
8
+
6
9
mkdir -p certs
7
10
8
11
# Generate a Certificate Authority (CA)
9
12
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} "
11
14
12
15
13
16
# Generate a Server Key and Certificate Signing Request (CSR)
14
17
# Passphrase is set to 123
15
18
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} "
17
20
18
21
# 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
20
23
21
24
# Combine Server Key and Certificate
22
25
cat certs/mongodb.key certs/mongodb.crt > certs/mongodb.pem
You can’t perform that action at this time.
0 commit comments