This repository has been archived by the owner on Oct 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p12info.sh
executable file
·62 lines (47 loc) · 1.56 KB
/
p12info.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
62
#!/bin/bash
# --- configuration -----------------------------------------------------------
RED=`tput setaf 1`
BOLD=`tput bold`
DIM=`tput dim`
RESET=`tput sgr0`
AWK="/^-----BEGIN.*/,/^-----END.*/"
# --- command line arguments --------------------------------------------------
P12_FILE=$1
# --- sanity checks -----------------------------------------------------------
# check the argument was passed
if [[ ! $1 = *[!\ ]* ]]; then
echo "${BOLD}Usage:${RESET}"
echo " p12info.sh path-to-file.p12"
echo
exit 1
fi
# check the p12 file is available
if [ ! -f $P12_FILE ]; then
echo "${RED}'${P12_FILE}' not found.${RESET}"
exit 1
fi
# --- let's do this -----------------------------------------------------------
# temporary files
CERT_FILE=`mktemp`
KEY_FILE=`mktemp`
# extract the cert & private key
echo
echo "${DIM}---${RESET} ${BOLD}OpenSSL Things${RESET} ${DIM}---------------------------------------------${RESET}"
echo
openssl pkcs12 -in $P12_FILE -nokeys -out $CERT_FILE -nodes -passin pass:
openssl pkcs12 -in $P12_FILE -nocerts -out $KEY_FILE -nodes -passin pass:
openssl rsa -in $KEY_FILE -out $KEY_FILE
# delete the "-passin pass:" above to prompt for a password if you want
# display the certificate
echo
echo "${DIM}---${RESET} ${BOLD}Certificate${RESET} ${DIM}------------------------------------------------${RESET}"
echo
awk $AWK $CERT_FILE
# display the private key
echo
echo "${DIM}---${RESET} ${BOLD}Private Key${RESET} ${DIM}------------------------------------------------${RESET}"
echo
awk $AWK $KEY_FILE
echo
# clean up
rm -f $CERT_FILE $KEY_FILE