forked from 1c3t3a/rust-socketio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keygen.sh
executable file
·74 lines (62 loc) · 1.31 KB
/
keygen.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
73
74
#!/bin/sh
cd $(dirname $0)
if [ "$1" = "" ] || [ "$2" = "" ]
then
echo "Usage: keygen.sh [DOMAIN] [IP]"
exit 1
fi
DOMAIN="$1"
IP="$2"
CA_NAME=${CA_NAME:-"rust-socketio-dev"}
mkdir cert || true
cd cert
# Credit https://scriptcrunch.com/create-ca-tls-ssl-certificates-keys/
if [ ! -f ca.key ]
then
echo "Generating CA key"
openssl genrsa -out ca.key 4096
fi
if [ ! -f "ca.crt" ]
then
echo "Generating CA cert"
openssl req -x509 -new -nodes -key ca.key -subj "/CN=${CA_NAME}/C=??/L=Varius" -out ca.crt
fi
if [ ! -f "server.key" ]
then
echo "Generating server key"
openssl genrsa -out server.key 4096
fi
if [ ! -f "csr.conf" ]
then
echo """
[ req ]
default_bits = 4096
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn
[ dn ]
C = ??
ST = Varius
L = Varius
O = ${DOMAIN}
OU = ${DOMAIN}
CN = ${DOMAIN}
[ req_ext ]
subjectAltName = @alt_names
[ alt_names ]
DNS.1 = ${DOMAIN}
DNS.2 = localhost
IP.1 = ${IP}
""" > csr.conf
fi
if [ ! -f "server.csr" ]
then
echo "Generating server signing request"
openssl req -new -key server.key -out server.csr -config csr.conf
fi
if [ ! -f "server.crt" ]
then
echo "Generating signed server certifcicate"
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -extfile csr.conf
fi