Debian Codegraph @

dockers/stunnel/create_certs.sh

raw
1 #!/bin/bash
2
3 set -e
4
5 CONFIG_FILE=$(realpath "$(dirname "$0")")/openssl.cnf
6
7 DESTDIR=$(dirname "$0")/keys
8 test -d ${DESTDIR} || mkdir ${DESTDIR}
9 cd ${DESTDIR}
10
11 which openssl &>/dev/null
12 if [ $? -ne 0 ]; then
13 echo "No openssl binary present, exiting."
14 exit 1
15 fi
16
17 openssl genrsa -out ca-key.pem 2048 &>/dev/null
18
19 openssl req -new -x509 -nodes -days 365000 \
20 -key ca-key.pem \
21 -out ca-cert.pem \
22 -config "$CONFIG_FILE" \
23 -extensions v3_ca \
24 -subj "/CN=valkey-py-ca"
25
26 openssl req -newkey rsa:2048 -nodes \
27 -keyout server-key.pem \
28 -out server-req.pem \
29 -config "$CONFIG_FILE" \
30 -extensions v3_req \
31 -subj "/CN=valkey-py-server"
32
33 openssl x509 -req -days 365000 -set_serial 01 \
34 -in server-req.pem \
35 -out server-cert.pem \
36 -CA ca-cert.pem \
37 -CAkey ca-key.pem \
38 -extfile "$CONFIG_FILE" \
39 -extensions v3_req
40
41 openssl req -newkey rsa:2048 -nodes \
42 -keyout client-key.pem \
43 -out client-req.pem \
44 -config "$CONFIG_FILE" \
45 -extensions v3_req \
46 -subj "/CN=valkey-py-client"
47
48 openssl x509 -req -days 365000 -set_serial 01 \
49 -in client-req.pem \
50 -out client-cert.pem \
51 -CA ca-cert.pem \
52 -CAkey ca-key.pem \
53 -extfile "$CONFIG_FILE" \
54 -extensions v3_req
55
56 echo "Keys generated in ${DESTDIR}:"
57 ls