Last active
October 2, 2019 11:49
-
-
Save yoxisem544/3de26b0822b17d5e204a437b0511e4bb to your computer and use it in GitHub Desktop.
To help you generate p12 file to import to another mac.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
read -p "Please enter passphrase to decrypt certifications: " passphrase | |
outputPath="./output" | |
mkdir -p ${outputPath} | |
read -p "Pleas enter password to decrypt output p12 file: " outputPassword | |
for entry in ./certs/*/*.cer | |
do | |
cerID=${entry: -14:10} | |
OIFS="$IFS" | |
IFS='/' | |
read -a new_string <<< "${entry}" | |
IFS="$OIFS" | |
type=${new_string[2]} | |
echo "certificatoin type ${type}: ${cerID} found!" | |
mkdir -p "${outputPath}/${type}" | |
outCertDer="${outputPath}/${type}/${cerID}.der" | |
certPem="${outputPath}/${type}/${cerID}-cert.pem" | |
keyPem="${outputPath}/${type}/${cerID}-key.pem" | |
openssl aes-256-cbc -k "${passphrase}" -in "certs/${type}/${cerID}.cer" -out ${outCertDer} -a -d | |
openssl x509 -inform der -in "${outCertDer}" -out "${certPem}" | |
openssl aes-256-cbc -k "${passphrase}" -in "certs/${type}/${cerID}.p12" -out "${keyPem}" -a -d | |
openssl pkcs12 -export -out "${outputPath}/${type}/${cerID}-cert.p12" -inkey "${keyPem}" -in "${certPem}" -password pass:"${outputPassword}" | |
done | |
echo "Generate done! You can find p12 files under ${outputPath} folder!" | |
read -n 1 -s -r -p "Would you like to keep der, key.pem, cert.pem files? [y/n]" keep | |
if [ "$keep" = "n" ] | |
then | |
rm -rf ${outputPath}/*/*.pem | |
rm -rf ${outputPath}/*/*.der | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment