bringing in testkit tools
[feisty_meow.git] / testkit / library / extract_der_from_pfx.sh
1
2 pfx_file="$1"; shift
3 if [ -z "$pfx_file" -o ! -f "$pfx_file" ]; then
4   echo "This script requires the full path to a PFX file which will have its"
5   echo "certificate extracted into a DER formatted file ending in '.cer'."
6   exit 1
7 fi
8
9 intermed_file="$TMP/$(basename "$pfx_file" .pfx).pem"
10 final_file="$(dirname "$pfx_file")/$(basename "$pfx_file" .pfx).cer"
11
12 echo input PFX file is $pfx_file
13 echo generating intermediate PEM file...
14 openssl pkcs12 -in "$pfx_file" -out "$intermed_file" -nodes -nokeys
15 if [ $? -ne 0 ]; then echo "previous step failed!"; exit 1; fi
16 echo generated intermediate PEM file $intermed_file
17 echo generating final file in DER format...
18 openssl x509 -outform der -in "$intermed_file" -out "$final_file"
19 if [ $? -ne 0 ]; then echo "previous step failed!"; exit 1; fi
20 echo final DER file successfully saved as $final_file
21