-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_tls_cert.bash
60 lines (52 loc) · 1.17 KB
/
gen_tls_cert.bash
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
# NOTE: Once the cert is generated, it must be packaged in the android app.
# See README in F2FAuthApp for details.
commonname=${1:="127.0.0.1"} # TODO: replace with the IP/common name to use for the script
basedir="/tmp"
keyname="local_key"
certname="local_cert"
country='US'
state='New York'
locality='New York'
keypath="${basedir}/${keyname}.pem"
certpath="${basedir}/${certname}.pem"
openssl genrsa -out "${keypath}" 2048
csrpath="${basedir}/${certname}.csr"
openssl req \
-new \
-key "${keypath}" \
-out "${csrpath}" \
-config <(cat <<-EOF
[req]
prompt = no
md = sha256
req_extensions = req_ext
distinguished_name = dn
[ dn ]
C=${country}
ST=${state}
L=${locality}
CN=${commonname}
[ req_ext ]
subjectAltName=@alt_names
[ alt_names ]
IP.1=${commonname}
EOF
)
openssl req -text -noout -in "${csrpath}"
openssl x509 -req \
-sha256 \
-days 365 \
-in "${csrpath}" \
-signkey "${keypath}" \
-out "${certpath}" \
-extensions req_ext \
-extfile <(cat <<-EOF
[ req_ext ]
subjectAltName=@alt_names
[ alt_names ]
IP.1=${commonname}
EOF
)
openssl x509 -text -noout -in "${certpath}"
# Copy new cert into app.
cp "${certpath}" "./F2FAuth/app/src/main/res/raw/tls_cert.pem"