Skip to content

Instantly share code, notes, and snippets.

@t-kashima
Created March 7, 2013 07:07
Show Gist options
  • Save t-kashima/5106113 to your computer and use it in GitHub Desktop.
Save t-kashima/5106113 to your computer and use it in GitHub Desktop.
##############################################################
#
# P12 to Pem
#
# iOSのPushの証明書と鍵からpemファイルを生成する
#
# %p12topem cert.p12 key.p12 password
#
# output: apns.pem, apns-key-noec.pem
#
###############################################################
if [ $# -lt 2 ]; then
echo "$0 file_type password"
exit;
fi
CERT_FILE=$1
KEY_FILE=$2
PASSWORD=$3
expect -c "
set timeout 3
spawn openssl pkcs12 -clcerts -nokeys -out apns-cert.pem -in $CERT_FILE
expect \"Enter Import Password:\" {
send \"$PASSWORD\n\"
}
interact
"
expect -c "
set timeout 3
spawn openssl pkcs12 -nocerts -out apns-key.pem -in $KEY_FILE
expect \"Enter Import Password:\" {
send \"$PASSWORD\n\"
expect \"Enter PEM pass phrase:\" {
send \"$PASSWORD\n\"
expect \"Verifying - Enter PEM pass phrase:\" {
send \"$PASSWORD\n\"
}
}
}
interact
"
expect -c "
spawn openssl rsa -in apns-key.pem -out apns-key-noenc.pem
expect \"Enter pass phrase for apns-key.pem:\" {
send \"$PASSWORD\n\"
}
interact
"
cat apns-cert.pem apns-key-noenc.pem > apns.pem
echo 'Finished making apns.pem and apns-key-noec.pem !!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment