Skip to content

Instantly share code, notes, and snippets.

@blacklee
Created January 5, 2016 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blacklee/4fc8822c3e3b8e5c2632 to your computer and use it in GitHub Desktop.
Save blacklee/4fc8822c3e3b8e5c2632 to your computer and use it in GitHub Desktop.
APNS pem file
set -e
set -x
input=$1
output=$2
input_cert=$(echo $input)-cert.p12
input_key=$(echo $input)-key.p12
input_file_not_exists=0
if [[ ! -f $input_cert ]]; then
echo "$input_cert not exist"
input_file_not_exists=1
fi
if [[ ! -f $input_key ]]; then
echo "$input_key not exist"
input_file_not_exists=1
fi
if [[ $input_file_not_exists -eq 1 ]]; then
echo "you should prepare 2 files: $input_key and $input_cert"
exit 1
fi
if [[ $output == "" ]]; then
echo "you may specify the output file name"
exit 1
fi
openssl pkcs12 -clcerts -nokeys -in apns-cert.p12 -out apns-cert.pem
openssl pkcs12 -nocerts -in apns-key.p12 -out apns-key.pem
openssl rsa -in apns-key.pem -out apns-key-noenc.pem
cat apns-cert.pem apns-key-noenc.pem > $(echo $output).pem
rm apns-cert.pem
rm apns-key-noenc.pem
rm apns-key.pem
@blacklee
Copy link
Author

blacklee commented Jun 2, 2016

  1. 登录到 iPhone Developer Connection Portal(http://developer.apple.com/iphone/manage/overview/index.action )并点击 App IDs
  2. 创建一个不使用通配符的 App ID 。通配符 ID 不能用于推送通知服务。例如, com.itotem.iphone
  3. 点击App ID旁的“Configure”,然后按下按钮生产 推送通知许可证。根据“向导” 的步骤生成一个签名并上传,最后下载生成的许可证。
  4. 通过双击.cer文件将你的 aps_developer_identity.cer 引入Keychain中。
  5. 在Mac上启动 Keychain助手,然后在login keychain中选择 Certificates分类。你将看到一个可扩展选项“Apple Development Push Services”
  6. 扩展此选项然后右击“Apple Development Push Services” > Export “Apple Development Push Services ID123”。保存为 apns-dev-cert.p12文件。
  7. 扩展“Apple Development Push Services” 对“Private Key”做同样操作,保存为 apns-dev-key.p12 文件。
  8. 需要通过终端命令将这些文件转换为PEM格式:
    openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
    openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
  9. 如果你想要移除密码,要么在导出/转换时不要设定或者执行:
    openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem
  10. 最后,你需要将键和许可文件合成为apns-dev.pem文件,此文件在连接到APNS时需要使用:
    cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment