OSX Keychain Access - 从现有的APNS私钥(Apple推送通知服务)生成CSR

jsh*_*erk 12 iphone macos push-notification apple-push-notifications ios

当您需要为APNS创建新证书时,Provisioning Portal"向导"始终提供创建新CSR的步骤,这意味着您还需要创建新的公钥/私钥.这些可能会开始失控,那么有没有办法在现有私钥的Keychain Access中创建CSR(代码签名请求),而不是每次都要创建一个新的?

谢谢

Phi*_*vin 30

通常,您可以通过右键单击Keychain Access中的现有私钥并​​选择使用"密钥名称"从证书颁发机构申请证书来执行此操作.

不幸的是,除非你的钥匙串中还有相应的公钥,否则这将失败,并且"在Keychain中找不到指定的项目" .这没有技术上的原因 - 证书签名请求(CSR)只能从私钥生成 - 但Keychain Access不理解这一点.

你有两个选择.

导出私钥并手动生成CSR

这是一个快速选项,只会生成一个可以上传到Apple的CSR.

  1. 选择在钥匙串访问私钥,然后点击文件 - 出口项目....
  2. 以某种.p12格式保存文件,但请记住路径.这些说明假设它在您的主目录中并被调用exported.p12.将密码留空.
  3. 打开终端并输入:

    openssl req -new -key <(openssl pkcs12 -in ~/exported.p12 -nocerts -nodes -passin pass:"") > new.certSigningRequest
    
    Run Code Online (Sandbox Code Playgroud)

    有关正在发生的事情的详细信息,请参阅本文末尾的[1].

  4. 按Enter键进行每个提示(Apple不关心这些值).完成后,您将.certSigningRequest适合上传到Apple Developer Portal.下载相关证书时,它将与原始私钥配对.

  5. 删除该exported.p12文件,因为它包含私钥材料.

重新创建公钥,以便Keychain Access感到满意

此选项是一个长期修复程序,可让您直接从Keychain Access生成原始密钥的CSR.这些说明假设您目前无法使用Keychain Access这样做,因为您错过了私钥的相应公共版本.您可以通过转到Keychain Access中的"Keys"类别并查找具有相同名称的"私钥"和"公钥"来检查这一点.

  1. 选择在钥匙串访问私钥,然后点击文件 - 出口项目....
  2. 以某种.p12格式保存文件,但请记住路径.这些说明假设它在您的主目录中并被调用exported.p12.将密码留空.
  3. 打开终端并输入:

    openssl pkcs12 -in ~/exported.p12 -nocerts -nodes | openssl rsa -pubout > public.pem
    
    Run Code Online (Sandbox Code Playgroud)

    有关正在发生的事情的详细信息,请参阅本文末尾的[2].

  4. 使用该security工具将此公钥导入Keychain Access :

    security -v import public.pem -k ~/Library/Keychains/login.keychain
    
    Run Code Online (Sandbox Code Playgroud)

    你应该看到"1键导入".

~/Library/Keychains/login.keychain如果要将其导入另一个钥匙串,请更改.(您可以通过转到密钥链访问中的编辑 - 钥匙串列表来查看每个钥匙串的存在位置).

  1. 打开Keychain Access并找到名为"Imported Public Key"的公钥.双击它并将其名称更改为与原始私钥相同的名称.
  2. 删除exported.p12public.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
Run Code Online (Sandbox Code Playgroud)

[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
Run Code Online (Sandbox Code Playgroud)


jsh*_*erk 3

当您进入配置文件以启用/配置推送通知时,它要求的第一件事是 CSR(代码签名证书)。

您可以使用钥匙串访问中的现有私钥生成该私钥,而不是创建新私钥。

只需打开钥匙串访问,然后滚动并找到以前的私钥(可能称为您的名字),然后右键单击(两根手指单击)它并选择从证书颁发机构请求证书“bla bla bla”

我只是在“用户电子邮件地址”和“CA 电子邮件地址”中输入相同的电子邮件地址,然后选择“保存到磁盘”。

然后上传该文件以创建您的 .cer 文件

  • 我按照上面的建议做了同样的事情,但出现错误:(“在钥匙串中找不到指定的项目。”可能是什么问题? (3认同)