forked from scmart/token-android-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cert-generator.sh
executable file
·56 lines (47 loc) · 1.45 KB
/
cert-generator.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
#!/bin/bash
# This script will generate trust store certs for different environments
askEnvironment() {
read -p "Which environment? \"dev\" or \"release\": [dev]" ENV
ENV=${ENV:-dev}
}
askHost() {
read -p "Enter address: [$HOST]" CERTHOST
CERTHOST=${CERTHOST:-$HOST}
}
getBouncyCastle() {
if [ ! -f bcprov-jdk15on-156.jar ]
then
wget -O bcprov-jdk15on-156.jar https://www.bouncycastle.org/download/bcprov-jdk15on-156.jar
fi
}
generateCertificate() {
getBouncyCastle
openssl s_client -connect $CERTHOST:443 </dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-OCEND CERTIFICATE-/p' > chatstore.cert
keytool -import -noprompt -trustcacerts -alias $CERTHOST -file chatstore.cert -keystore chatkey.store -storepass whisper -storetype BKS -providerclass org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath bcprov-jdk15on-156.jar
}
moveCertificate() {
MOVE_PATH="./app/src/debug/res/raw/"
if [[ $ENV == "release" ]]
then
MOVE_PATH="./app/src/release/res/raw/"
fi
mv chatkey.store $MOVE_PATH
rm chatstore.cert
}
while true; do
askEnvironment
if [[ $ENV == "dev" ]] || [[ $ENV == "release" ]]
then
HOST="token-chat-service-development.herokuapp.com"
if [[ $ENV == "release" ]]
then
HOST="chat.service.tokenbrowser.com"
fi
askHost
generateCertificate
moveCertificate
echo "Done"
break
fi
done
exit 0