-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
create-p12.sh
executable file
·61 lines (53 loc) · 1.62 KB
/
create-p12.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
57
58
59
60
61
#!/bin/sh
NC='\033[0m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[1;36m'
PURPLE='\033[1;35m'
helpFunction(){
echo -e "${YELLOW} Usage: $0 -k path -c path -p keyPass -r rfc"
echo -e "\t-k Path to FIEL Key"
echo -e "\t-c Path to FIEL Cert"
echo -e "\t-r FIEL Key Password"
echo -e "\t-p FIEL Rfc RFC ${NC}"
exit 1;
}
while getopts "k:c:p:r:" opt
do
case "$opt" in
k ) KEY_LOCATION="$OPTARG" ;;
c ) CERT_LOCATION="$OPTARG" ;;
r ) RFC="$OPTARG" ;;
p ) KEY_PASS="$OPTARG" ;;
? ) helpFunction ;;
esac
done
if [ -z "$KEY_LOCATION" ]; then
echo -e "\n ❌ ${RED} FIEL KEY not set ❌ ${NC}\n"
helpFunction
fi
if [ -z "$CERT_LOCATION" ]; then
echo -e "\n ❌ ${RED} FIEL CER not set ❌ ${NC}\n"
helpFunction
fi
if [ -z "$KEY_PASS" ]; then
echo -e "\n ❌ ${RED} FIEL KEY pass not set ❌ ${NC}\n"
helpFunction
fi
if [ -z "$RFC" ]; then
echo -e "\n ❌ ${RED} FIEL RFC not set ❌ ${NC}\n"
helpFunction
fi
echo -e "${CYAN} [PFX BUILDER SH]: Creating KEY PEM ${NC}"
openssl pkcs8 -inform der -in $KEY_LOCATION -passin pass:${KEY_PASS} -out key.pem
[ $? -eq 0 ] || exit 1
echo -e "${CYAN} [PFX BUILDER SH]: Creating CER PEM ${NC}"
openssl x509 -inform der -in $CERT_LOCATION -out cer.pem
[ $? -eq 0 ] || exit 1
openssl pkcs12 -passout pass:${KEY_PASS} -export -in cer.pem -inkey key.pem -out ./keystore/${RFC}.p12 -name "${RFC}"
[ $? -eq 0 ] || exit 1
echo -e "${CYAN} [PFX BUILDER SH]: Removing intermediates ${NC}"
rm key.pem && rm cer.pem
[ $? -eq 0 ] || exit 1
echo -e "${GREEN} [PFX BUILDER SH]: PFX created at: \"./keystore/${RFC}.p12${NC}\" -alias ${RFC}"