【发布时间】:2012-09-13 22:40:30
【问题描述】:
当您需要为 APNS 创建新证书时,配置门户“向导”始终会提供创建新 CSR 的步骤,这意味着您还需要创建新的公钥/私钥。这些可能会开始失控,那么有没有办法从现有的私钥在钥匙串访问中创建一个 CSR(代码签名请求),而不必每次都创建一个新的?
谢谢
【问题讨论】:
标签: iphone ios macos push-notification apple-push-notifications
当您需要为 APNS 创建新证书时,配置门户“向导”始终会提供创建新 CSR 的步骤,这意味着您还需要创建新的公钥/私钥。这些可能会开始失控,那么有没有办法从现有的私钥在钥匙串访问中创建一个 CSR(代码签名请求),而不必每次都创建一个新的?
谢谢
【问题讨论】:
标签: iphone ios macos push-notification apple-push-notifications
当您进入配置文件以启用/配置推送通知时,它首先要求的是 CSR(代码签名证书)。
您可以使用来自 Keychain Access 的现有私钥生成此文件,而不是创建新的。
只需打开钥匙串访问,然后滚动并找到以前的 PRIVATE KEY(可能称为您的名字),然后右键单击(两指单击)并选择 Request A Certificate From A Certificate Authority With "bla bla bla”。
我只是在用户电子邮件地址和 CA 电子邮件地址中输入相同的电子邮件地址,然后选择保存到磁盘。
然后上传以创建您的 .cer 文件
【讨论】:
通常,您可以通过右键单击 Keychain Access 中的现有私钥并选择使用“您的密钥名称”从证书颁发机构请求证书来执行此操作。
不幸的是,除非您也在您的钥匙串中拥有相应的公钥,否则这将失败并显示“无法在钥匙串中找到指定的项目”。这没有技术原因——证书签名请求 (CSR) 可以仅从私钥生成——但 Keychain Access 不理解这一点。
你有两个选择。
这是一个快速选项,它只会生成一个您可以上传到 Apple 的 CSR。
.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 文件,因为它包含私钥材料。此选项是一项长期修复,可让您直接从 Keychain Access 的原始密钥生成 CSR。这些说明假定您当前无法使用 Keychain Access 来执行此操作,因为您缺少相应的私钥的公共版本。您可以通过转到 Keychain Access 中的“Keys”类别并查找具有相同名称的“private key”和“public key”来检查这一点。
.p12 格式保存在某处,但请记住路径。这些说明假定它位于您的主目录中并称为exported.p12。将密码留空。打开终端并输入:
openssl pkcs12 -in ~/exported.p12 -nocerts -nodes | openssl rsa -pubout > public.pem
请参阅本文末尾的 [2],了解正在发生的事情的详细信息。
使用security 工具将此公钥导入钥匙串访问:
security -v import public.pem -k ~/Library/Keychains/login.keychain
您应该会看到“已导入 1 个密钥”。
如果您想将其导入另一个钥匙串,请更改 ~/Library/Keychains/login.keychain。 (您可以通过转到钥匙串访问中的编辑 - 钥匙串列表来查看每个钥匙串的位置。
exported.p12和public.pem。您现在可以右键单击原始私钥并选择使用“您的密钥名称”从证书颁发机构请求证书以生成 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
【讨论】: