Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement