【问题标题】:aps_developer_identity.cer to p12 without having to export from Key Chain?aps_developer_identity.cer 到 p12 无需从 Key Chain 导出?
【发布时间】:2010-11-30 00:16:06
【问题描述】:

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

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

【问题讨论】:

  • “它们都是使用相同的证书签名请求创建的” - 为什么?在那种情况下,它们都将被命名为相同的通用名称,这样做的目的是什么?

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


【解决方案1】:

我设法解决了这个问题,它只需要封装在一个 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 个月到期。这是一项非常无聊且容易出错的工作......

【讨论】:

  • “_CertificateSigningRequest.certSigningRequest”从何而来?我记得在创建开发证书 O_o 的一开始就有这个文件一次
  • 这里有关于如何创建 CSR 的详细说明:jainmarket.blogspot.com/2009/11/… 我添加了下划线,因为我和所有其他证书都保存在同一个文件夹中,这样它是第一个列表...
  • _CertificateSigningRequest.certSigningRequest 问题绝对不清楚,需要解释。该链接没有详细说明这一点。我知道如何用钥匙串制作一个,但是当我在上面的脚本中使用它时,我经常收到错误“没有证书匹配私钥”......为什么?上面到底指的是什么 certSigningRequest?
  • 感谢您发布此信息。很有帮助。
【解决方案2】:

这里的工作很棒。感谢您的真正帮助。我在下面的 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

【讨论】:

  • 谢谢。这非常有帮助。
【解决方案3】:

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

1.双击从苹果开发网站下载的开发者/生产证书文件。(将添加到钥匙串中)

2.我假设你有导出私钥得到的 .p12 文件

3.转到钥匙串下的“我的证书”选项卡。

只需单击您的 APN 开发/产品证书。它应该显示与之关联的私钥

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

这是最终的 .p12 文件!!

【讨论】:

  • 我认为您在发布此答案之前没有阅读该问题。 OP 明确表示他们不想使用 Keychain。
猜你喜欢
  • 1970-01-01
  • 2020-04-07
  • 2019-11-11
  • 2013-05-10
  • 2015-04-17
  • 2015-02-23
  • 1970-01-01
  • 2017-01-16
  • 2013-04-04
相关资源
最近更新 更多