-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform_import_keystore
executable file
·70 lines (59 loc) · 1.91 KB
/
platform_import_keystore
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
#! /bin/bash
scriptname=`basename $0`
pk8="testkey.pk8"
pem="testkey.x509.pem"
out="keystore.jks"
# informations should be passed by argument.
alias=""
keystorepass=""
keypass=""
usage() {
cat << EOF
usage: ${scriptname} [-k keystore pass] [-p key pass] [-a key alias]
This script is used to import ${pem} and ${pk8} into a Java Key Store.
EOF
}
while [ $# -gt 0 ]; do
case $1
in
-k)
keystorepass=$2
shift 2
;;
-p)
keypass=$2
shift 2
;;
-a)
alias=$2
shift 2
;;
-h | help | -help | --help)
usage
exit 0
esac
done
if [ -z ${alias} ] | [ -z ${keystorepass} ] | [ -z ${keypass} ]; then
echo "${scriptname}: Missing informations..." 1>&2
usage
exit 1
fi
for f in "${pk8}" "${pem}"; do
if [ ! -f "$f" ]; then
echo "${scriptname}: Can't find file $f..." 1>&2
exit 1
fi
done
if [ -e ${out} ]; then
mv ${out} ${out}.$(date +%s).backup
fi
echo openssl pkcs8 -in ${pk8} -inform DER -outform PEM -out platform.priv.pem -nocrypt
openssl pkcs8 -in ${pk8} -inform DER -outform PEM -out platform.priv.pem -nocrypt
echo openssl pkcs12 -export -in ${pem} -inkey platform.priv.pem -out platform.pk12 -name ${alias} -password pass:${keystorepass}
openssl pkcs12 -export -in ${pem} -inkey platform.priv.pem -out platform.pk12 -name ${alias} -password pass:${keystorepass}
echo keytool -J-Duser.language=en -importkeystore -destkeystore ${out} -srckeystore platform.pk12 -srcstoretype PKCS12 -deststorepass ${keystorepass} -srcstorepass ${keystorepass}
keytool -J-Duser.language=en -importkeystore -destkeystore ${out} -srckeystore platform.pk12 -srcstoretype PKCS12 -deststorepass ${keystorepass} -srcstorepass ${keystorepass}
echo keytool -J-Duser.language=en -keypasswd -keystore ${out} -alias ${alias} -storepass ${keystorepass} -new ${keypass}
keytool -J-Duser.language=en -keypasswd -keystore ${out} -alias ${alias} -storepass ${keystorepass} -new ${keypass}
rm platform.priv.pem
rm platform.pk12