aps_developer_identity.cer 到 p12 无需从钥匙串导出?

问题描述 投票:0回答:2

我有一个从 iPhone 开发者门户导出的“aps_developer_identity.cer”证书的 shed load。它们都是使用相同的证书签名请求和(因此)相同的私钥创建的。如果我仅从 Apple 钥匙链导出私钥,则可以获取私钥和“aps_developer_identity.cer”并使用 openssl 创建可以在我的(Windows)服务器上使用的合并 p12/pkcs#12 证书.

需要明确的是,我知道如何通过将私钥和证书一起导出来从钥匙串中获取合并的 p12,但如果可以的话,我想删除所有额外的鼠标单击和输入。

openssl apple-push-notifications pkcs#12
2个回答
42
投票

它只需要封装在 shell 脚本中即可。 我假设您已经下载并重命名了“apple_developer_identity.cer”证书,这里我使用“test.cer”,并且您还从钥匙串中导出了开发人员密钥,在下面的示例中名为“private_dev_key.p12”。

#convert *.cer (der format) to pem
openssl x509 -in test.cer -inform DER -out test.pem -outform PEM

#convert p12 private key to pem (requires the input of a minimum 4 char password)
openssl pkcs12 -nocerts -out private_dev_key.pem -in private_dev_key.p12

# if you want remove password from the private key
openssl rsa -out private_key_noenc.pem -in private_key.pem

#take the certificate and the key (with or without password) and create a PKCS#12 format file
openssl pkcs12 -export -in test.pem -inkey private_key_noenc.pem -certfile _CertificateSigningRequest.certSigningRequest  -name "test" -out test.p12

注意:如果您认为这一切有点冗长,只需点击几下鼠标并输入文件名即可完成,那么请考虑您有 20 个应用程序想要启用通知的情况。每个App都有开发证书和生产证书,有效期分别为4个月和12个月。这是一项非常无聊且容易出错的工作...


4
投票

我已经在下面添加了我的 shell 脚本,这可能会对其他人有所帮助。我有几个关键要处理,也想要一个脚本。该脚本将为输出文件输出静态名称(尽管更改起来很简单)。

示例用法(假设脚本名称):

$ . thisScript request_file.cer priv_key.p12 aps_dev.cer

剧本:

if [ $# -ne 3 ]
then
echo "Error in $0 - Invalid Argument Count"
echo "Syntax: $0 request_cer_file p12_file app_cer_file output_filename"
echo "  - request_cer_file      is the request file you sent to apple"
echo "  - p12_file          is found in your keychain (it's the private key)"
echo "  - app_cer_file          is found on App ID screen from Apple"
else

reqFile=$1
p12File=$2
cerFile=$3

certPEM='apn_cert.pem'
pKeyPEM='apn_pkey.pem'
pKeyNoEncPEM='apn_pkey_noenc.pem'
p12FileOut='apn_cert_key.p12'

# remove old
rm $certPEM
rm $pKeyPEM
rm $pKeyNoEncPEM
rm $p12FileOut

#convert *.cer (der format) to pem
openssl x509 -in $cerFile -inform DER -out $certPEM -outform PEM

#convert p12 private key to pem (requires the input of a minimum 4 char password)
openssl pkcs12 -nocerts -out $pKeyPEM -in $p12File

# if you want remove password from the private key
openssl rsa -out $pKeyNoEncPEM -in $pKeyPEM

#take the certificate and the key (with or without password) and create a PKCS#12 format file
openssl pkcs12 -export -in $certPEM -inkey $pKeyNoEncPEM -certfile $reqFile  -name "apn_identity" -out $p12FileOut

#
#   
#   If all things worked then the following should work as a test
#   openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apn_cert.pem -key apn_pkey_noenc.pem 
#
#
echo "Looks like everything was successful"
echo "Test command:"
echo "openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apn_cert.pem -key apn_pkey_noenc.pem"
echo
fi
© www.soinside.com 2019 - 2024. All rights reserved.