aps_developer_identity.cer到p12而不必从Key Chain导出?

时间:2009-09-21 07:43:43

标签: openssl apple-push-notifications pkcs#12

我有从iPhone开发人员门户网站导出的'aps_developer_identity.cer'证书的棚装。它们都是使用相同的证书签名请求和(因此)相同的私钥创建的。如果我只导出Apple Key Chain中的私钥,那么可以使用私钥和'aps_developer_identity.cer'并使用openssl创建我可以在我的(Windows)服务器上使用的合并的p12 / pkcs#12证书

为了清楚起见,我知道如何通过同时导出私钥和证书从密钥链中获取合并的p12,但是如果可以的话,我想删除所有额外的鼠标点击和输入。

3 个答案:

答案 0 :(得分:38)

我设法解决了这个问题,只需要在shell脚本中进行包装就可以了。 我假设您已下载并重命名了'apple_developer_identity.cer'证书,此处我使用'test.cer',并且您还从钥匙串中导出了您的开发人员密钥,在下面的示例中名为'private_dev_key.p12'。< / p>

#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个应用程序的情况通知。每个应用程序都有开发和生产证书,分别在4个月和12个月后到期。这是一项非常无聊且容易出错的工作......

答案 1 :(得分: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

答案 2 :(得分:-4)

您可以直接在钥匙串中制作p12 / pkcs#12证书。 无需执行任何命令。

1.双击从apple dev网站下载的开发人员/生产证书文件。(它将被添加到钥匙串中)

2.我假设您有从导出私钥

获得的.p12文件

3.转到钥匙串下的“我的证书”标签。

只需点击您的dev / prod证书即可获得APN.it应该显示与之关联的私钥

4.右键单击并导出.p12格式的证书

那是最终的.p12文件!!