Last active
July 21, 2017 12:16
-
-
Save arkku/0774ba7376262e81eed49a263d391398 to your computer and use it in GitHub Desktop.
Converting Apple Push Notification Services certificates
This file contains 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 | |
# | |
# Obtaining Apple Push Notification Services certificates: | |
# | |
# 1) In developer.apple.com go to the App Id, and configure the push | |
# certificates. Follow Apple's instructions for creating the signing | |
# requests and generating the certificates. | |
# | |
# 2) Download the certificates and import them into the local keychain. | |
# | |
# 3) In Keychain Access, find the certificates, open them and export the | |
# _private key_ (not the certificate itself) for each certificate. | |
# | |
# 4) Now you should have the downloaded aps.cer and exported aps.p12 | |
# files. Run this script on those files to produce the aps.pem file. | |
# | |
# - Kimmo Kulovesi, 2017-07-21 | |
set -e -o pipefail | |
p12="$1.p12" | |
cer="$1.cer" | |
if [ ! -r "$p12" -o ! -r "$cer" ]; then | |
p12="$1" | |
cer="$2" | |
basename="$(echo "$p12" | sed 's/\.p12$//')" | |
else | |
basename="$1" | |
fi | |
if [ ! -r "$p12" -o ! -r "$cer" ]; then | |
echo "Usage: $0 file.p12 file.cer" >&2 | |
exit 1 | |
fi | |
outfile="$basename.pem" | |
echo "Converting $cer..." | |
openssl x509 -in "$cer" -inform der -out "$cer.pem" | |
echo "Converting $p12..." | |
openssl pkcs12 -nocerts -in "$p12" -out "$p12.pem" | |
echo "Decrypting..." | |
openssl rsa -in "$p12.pem" -out "$p12.raw.pem" | |
echo "Combining..." | |
cat "$cer.pem" "$p12.raw.pem" >"$outfile" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment