当您需要为 APNS 创建新证书时,配置门户“向导”始终会提供创建新 CSR 的步骤,这意味着您还需要创建新的公钥/私钥。这些可能会开始失控,那么有没有一种方法可以从现有的私钥在钥匙串(keychain)访问中创建 CSR(代码签名请求),而不必每次都创建一个新的?
谢谢
最佳答案
通常,您可以通过右键单击钥匙串(keychain)访问中的现有私钥并选择使用“您的 key 的名称”从证书颁发机构申请证书来执行此操作。
不幸的是,这将失败并显示“在钥匙串(keychain)中找不到指定的项目”,除非您也在您的钥匙串(keychain)中有相应的公钥。这没有技术原因——证书签名请求 (CSR) 可以仅从私钥生成——但钥匙串(keychain)访问不理解这一点。
你有两个选择。
导出私钥并手动生成CSR
这是一个快速选项,它只会生成您可以上传到 Apple 的 CSR。
- 在 Keychain Access 中选择私钥,然后点击文件 - 导出项目...。
- 将文件以
.p12
格式保存在某处,但要记住路径。这些说明假定它位于您的主目录中并称为exported.p12
。将密码留空。 打开终端并输入:
openssl req -new -key <(openssl pkcs12 -in ~/exported.p12 -nocerts -nodes -passin pass:"") > new.certSigningRequest
请参阅本文末尾的 [1],了解有关正在发生的事情的详细信息。
针对每个提示按 Enter(Apple 不关心这些值)。完成后,您将拥有一个适合上传到 Apple Developer Portal 的
.certSigningRequest
。当您下载相关证书时,它将与原始私钥配对。- 删除
exported.p12
文件,因为它包含私钥 Material 。
重新创建公钥,以便钥匙串(keychain)访问快乐
此选项是一项长期修复,可让您直接从钥匙串(keychain)访问中的原始 key 生成 CSR。这些说明假定您目前无法使用钥匙串(keychain)访问来执行此操作,因为您缺少相应的私钥公共(public)版本。您可以通过转到钥匙串(keychain)访问中的“ key ”类别并查找具有相同名称的“私钥”和“公钥”来检查这一点。
- 在 Keychain Access 中选择私钥,然后点击文件 - 导出项目...。
- 将文件以
.p12
格式保存在某处,但要记住路径。这些说明假定它位于您的主目录中并称为exported.p12
。将密码留空。 打开终端并输入:
openssl pkcs12 -in ~/exported.p12 -nocerts -nodes | openssl rsa -pubout > public.pem
请参阅本文末尾的 [2],了解有关正在发生的事情的详细信息。
使用
security
工具将此公钥导入 Keychain Access:security -v import public.pem -k ~/Library/Keychains/login.keychain
您应该看到“已导入 1 个 key ”。
更改 ~/Library/Keychains/login.keychain
如果您想将其导入另一个钥匙串(keychain)。 (您可以通过转到钥匙串(keychain)访问中的编辑 - 钥匙串(keychain)列表来查看每个钥匙串(keychain)所在的位置)。
- 打开钥匙串(keychain)访问并找到名为“导入的公钥”的公钥。双击它并将其名称更改为与您的原始私钥相同的名称。
- 删除
exported.p12
和public.pem
。
您现在可以右键单击原始私钥并选择使用“您的 key 名称”从证书颁发机构申请证书以生成 CSR。
解释
[1] 这个命令,分解:
openssl req -new # Generate a new certificate signing request
-key # Instead of generating a key, use an existing one
<( # Put the output of the following command in a temporary file
# (a Bash feature, not specific to OpenSSL)
openssl pkcs12 -in ~/exported.p12 # Read keys from the specified PKCS12 file
-nocerts # Don't output the certificate contained in the file
-nodes # Output the private key from the file
-passin pass:"" # The password for the container is blank
)
> new.certSigningRequest # Write the generated CSR to a file
[2] 第二个命令,分割:
openssl pkcs12 -in ~/exported.p12 # Read keys from the specified PKCS12 file
-nocerts -nodes # Output only the private key, no certificates
| openssl rsa -pubout # Compute the public key from a private key
> public.pem # Write the public key to a file
关于iphone - OSX Keychain Access - 从现有的 APNS 私钥生成 CSR(Apple 推送通知服务),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12415801/