-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-self-signed.sh
executable file
·76 lines (53 loc) · 1.59 KB
/
generate-self-signed.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
75
76
#! /bin/bash
#########
# Generates a self-signed certifcate to use with the game servers
#
# This script is based on one by Andi Wilson:
# https://gist.github.com/ptvandi/5a33c28d74ccc5100d7fe2bf5de96deb
#
# Use with react apps like this:
#
# HTTPS=true SSL_CRT_FILE=path/to/server.crt SSL_KEY_FILE=path/to/server.key yarn start
#########
CWD=$(pwd)
LOCAL_CERT_PATH=$CWD/generated
CERT_NAME='localhost (SynergyQuest local cert)'
ORG_NAME='TeamP09'
# expire after 900 years
DAYS=328500
# -- ./.cert --
rm -rf $LOCAL_CERT_PATH
mkdir -p $LOCAL_CERT_PATH
cd $LOCAL_CERT_PATH
# -- rootCA.key --
openssl genrsa -out rootCA.key 2048
# -- rootCA.pem --
openssl req -x509 -new -nodes -key rootCA.key -subj "/C=DE/ST=Hesse/O=$ORG_NAME/CN=$CERT_NAME" -sha256 -days $DAYS -out rootCA.pem
# -- server.csr.cnf --
cat > server.csr.cnf <<- EOM
[req]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn
[dn]
C=DE
ST=Hesse
O=$ORG_NAME
CN=$CERT_NAME
EOM
# -- v3.ext --
cat > v3.ext <<- EOM
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
EOM
# -- server.csr & server.key --
openssl req -new -sha256 -nodes -out server.csr -newkey rsa:2048 -keyout server.key -config <( cat server.csr.cnf )
# -- server.crt & rootCA.srl --
openssl x509 -req -in server.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out server.crt -days $DAYS -sha256 -extfile v3.ext
# pfx file
openssl pkcs12 -export -in server.crt -inkey server.key -out server.pfx -passout pass: