-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeJKS.sh
executable file
·51 lines (42 loc) · 1.2 KB
/
makeJKS.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
#!/bin/bash
sleep 5
echo "CERTBOT_DOMAIN = $CERTBOT_DOMAIN"
# echo "RENEWED_LINEAGE = $RENEWED_LINEAGE"
CERTPATH="$RENEWED_LINEAGE"
if [ -z $CERTPATH ]; then
echo "CERTPATH was blank"
exit 1
fi
if [ -d $CERTPATH ]; then
# echo "Creating JKS file..."
echo "CERTPATH = $CERTPATH"
FULLCHAIN=$CERTPATH"/fullchain.pem"
KEY=$CERTPATH"/privKey.pem"
if [ -z "$CERTBOT_TOKEN" ]; then
CERTBOT_TOKEN=$(openssl rand -base64 32)
fi
# echo "Creating pkcs12 store..."
openssl pkcs12 -export \
-in $FULLCHAIN \
-inkey $KEY \
-name "certbot_autogen" \
-out $CERTBOT_DOMAIN.p12 \
-password "pass:$CERTBOT_TOKEN"
if [ -f $CERTBOT_DOMAIN.jks ]; then
rm -f $CERTBOT_DOMAIN.jks
fi
# echo "Creating JKS store..."
keytool -noprompt \
-importkeystore \
-deststorepass $CERTBOT_TOKEN \
-destkeystore $CERTBOT_DOMAIN.jks \
-srckeystore $CERTBOT_DOMAIN.p12 \
-srcstorepass $CERTBOT_TOKEN \
-srcstoretype PKCS12 > /dev/null 2>&1
if [ -f $CERTBOT_DOMAIN.p12 ]; then
rm -f $CERTBOT_DOMAIN.p12
fi
echo "JKS PASSWORD=$CERTBOT_TOKEN"
else
echo "ERROR - Certpath is invalid"
fi