-
Notifications
You must be signed in to change notification settings - Fork 41.1k
/
Copy pathcreate-certs.sh
executable file
·72 lines (57 loc) · 1.92 KB
/
create-certs.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
create_ssl_config() {
cat > openssl.cnf <<_END_
subjectAltName = @alt_names
[alt_names]
DNS.1 = example.com
DNS.2 = localhost
[ server_cert ]
keyUsage = digitalSignature, keyEncipherment
nsCertType = server
[ client_cert ]
keyUsage = digitalSignature, keyEncipherment
nsCertType = client
_END_
}
generate_ca_cert() {
local location=$1
mkdir -p ${location}
openssl genrsa -out ${location}/test-ca.key 4096
openssl req -key ${location}/test-ca.key -out ${location}/test-ca.crt \
-x509 -new -nodes -sha256 -days 3650 \
-subj "/O=Spring Boot Test/CN=Certificate Authority" \
-addext "subjectAltName=DNS:hello.example.com,DNS:hello-alt.example.com"
}
generate_cert() {
local location=$1
local caLocation=$2
local hostname=$3
local keyfile=${location}/test-${hostname}-server.key
local certfile=${location}/test-${hostname}-server.crt
mkdir -p ${location}
openssl genrsa -out ${keyfile} 2048
openssl req -key ${keyfile} \
-new -sha256 \
-subj "/O=Spring Boot Test/CN=${hostname}.example.com" \
-addext "subjectAltName=DNS:${hostname}.example.com" | \
openssl x509 -req -out ${certfile} \
-CA ${caLocation}/test-ca.crt -CAkey ${caLocation}/test-ca.key -CAserial ${caLocation}/test-ca.txt -CAcreateserial \
-sha256 -days 3650 \
-extfile openssl.cnf \
-extensions server_cert
}
if ! command -v openssl &> /dev/null; then
echo "openssl is required"
exit
fi
mkdir -p certs
create_ssl_config
generate_ca_cert certs/ca
generate_cert certs/default certs/ca hello
generate_cert certs/alt certs/ca hello-alt
rm -f openssl.cnf
rm -f certs/ca/test-ca.key certs/ca/test-ca.txt
cp -r certs/* spring-boot-sni-reactive-app/src/main/resources
cp -r certs/* spring-boot-sni-servlet-app/src/main/resources
cp -r certs/ca/* spring-boot-sni-client-app/src/main/resources/ca
rm -rf certs