-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbootstrap-jwt-auth-prerequisites.sh
executable file
·59 lines (50 loc) · 1.89 KB
/
bootstrap-jwt-auth-prerequisites.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
#!/bin/sh
####################################################################################################
#
# FILENAME: bootstrap-jwt-auth-prerequisites
#
# PURPOSE: Creates a self-signed SSL certificate in the temp directory of this project.
# And an encrypted private key in the folder in parameter
#
# DESCRIPTION: Self-signed SSL certificates (AKA "Server keys") are needed for JWT auth stuff.
#
#
#### FETCH INPUT ###################################################################################
#
if [ -z "$1" ] ; then
echo "Usage: $0 [PASSWORD] [<ENV_NAME>]" 1>&2
exit 1
fi
PASSWORD="$1"
ENV="$2"
if [ -z "$2" ] ; then
ENV="env"
fi
#### CREATE LOCAL VARIABLES ########################################################################
#
COUNTRY_NAME="FR"
STATE="France"
LOCALITY="Paris"
ORGANIZATION_NAME="sfdx"
ORGANIZATIONAL_UNIT="jwt:auth"
COMMON_NAME="jwt.auth.com"
EMAIL="[email protected]"
CERTIFICATE_EXPIRE_DAYS=365
#### CREATE CERTIFICATE AND PRIVATE KEY ############################################################
#
mkdir ./tmp 2>/dev/null
cd tmp
openssl genrsa -des3 -passout pass:x -out server.pass.key 2048 2>/dev/null
openssl rsa -passin pass:x -in server.pass.key -out server.key 2>/dev/null
openssl req -new -key server.key -out server.csr \
-subj "/C=$COUNTRY_NAME/ST=$STATE/L=$LOCALITY/O=$ORGANIZATION_NAME/OU=$ORGANIZATIONAL_UNIT/CN=$COMMON_NAME/emailAddress=$EMAIL" 2>/dev/null
openssl x509 -req -sha256 -days $CERTIFICATE_EXPIRE_DAYS -in server.csr -signkey server.key -out "$ENV.crt" 2>/dev/null
mkdir ../build 2>/dev/null
mkdir ../certificate 2>/dev/null
openssl aes-256-cbc -salt -e -in server.key -out "${ENV}_server.key.enc" -pass pass:$PASSWORD 2>/dev/null
mv "${ENV}_server.key.enc" ../build
mv "$ENV.crt" ../certificate
cd ..
rm -rf tmp
echo "$ENV.crt in the build folder"
echo "${ENV}_server.key.enc created in the certificate folder"