5/4/2016 - 8:04 AM

Change password of a p12 file

Change password of a p12 file


# Usage Input.p12 Output.p12
# Use at your own risk

echo 'Downloading Apple Root Certificate'
curl > AppleWWDRCA.cer

echo 'Please enter original .p12 password'
openssl pkcs12 -in $1 -nocerts -out privateKey.pem -passout pass:qwert

echo 'Please enter original .p12 password one more time (sorry about that)'
openssl pkcs12 -in $1 -clcerts -nokeys -out publicCert.pem

FRIENDLY_NAME=`cat privateKey.pem | grep friendlyName | awk '{print substr($0, 19, 150); exit}'`

echo 'Enter new password'
openssl pkcs12 -export -out $2 \
  -inkey privateKey.pem \
  -in publicCert.pem \
  -certfile AppleWWDRCA.cer \
  -passin pass:qwert \
  -name "$FRIENDLY_NAME"

rm privateKey.pem publicCert.pem AppleWWDRCA.cer
echo "Nicely done!\n"