forked from ymzkryo/chainpoint-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcertgen.sh
More file actions
executable file
·78 lines (61 loc) · 1.92 KB
/
Copy pathcertgen.sh
File metadata and controls
executable file
·78 lines (61 loc) · 1.92 KB
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
77
78
#!/usr/bin/env bash
# This script will generate a self-signed certificate for simple
# use with a Chainpoint Node. It will be valid for the IP Address
# provided as the first argument to the script as well as for
# common development addresses.
#
# It will output the certificate and key files in PEM form
# as well as a human readable '.info' that you can examine.
: ${1?"Usage: $0 IP_ADDRESS"}
# Script exits here if command-line parameter absent,
#+ with following error message.
# certgen.sh: 1: Usage: certgen.sh IP_ADDRESS
IP_ADDRESS=$1
# Certificate lifetime (10 years)
DAYS=3650
# A blank passphrase
PASSPHRASE=""
# Filename of generated openssl config file
CONFIG_FILE="certgen.cnf"
cat > $CONFIG_FILE <<-EOF
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
default_md = sha256
[req_distinguished_name]
C = US
ST = California
L = San Francisco
O = Self-Signed
CN = $IP_ADDRESS
[v3_req]
keyUsage = critical, digitalSignature, keyAgreement
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = $IP_ADDRESS
DNS.2 = localhost
DNS.3 = localhost.localdomain
DNS.4 = 127.0.0.1
DNS.5 = ::1
IP.1 = $IP_ADDRESS
IP.2 = 127.0.0.1
IP.3 = ::1
EOF
# The file name can be anything
#FILE_NAME="$IP_ADDRESS"
FILE_NAME="cert"
# Remove previous cert files
[ -f ./cert.key ] && \
chmod 770 $FILE_NAME.* && \
rm $FILE_NAME.* && \
echo 'Old TLS cert files removed' || true
echo "Generating certificate for IP Address : $IP_ADDRESS"
# Generate our Private Key, CSR and Certificate
# Use SHA-2 as SHA-1 is unsupported from Jan 1, 2017
openssl req -new -x509 -newkey rsa:4096 -sha256 -nodes -keyout "$FILE_NAME.key" -days $DAYS -out "$FILE_NAME.crt" -passin pass:$PASSPHRASE -config "$CONFIG_FILE"
# Store the human readable details of the generated crt in *.info file
openssl x509 -noout -fingerprint -text < "$FILE_NAME.crt" > "$FILE_NAME.info"
# Protect the key
chmod 444 "$FILE_NAME.key"