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

标签 iphone ios macos push-notification apple-push-notifications

当您需要为 APNS 创建新证书时,配置门户“向导”始终会提供创建新 CSR 的步骤,这意味着您还需要创建新的公钥/私钥。这些可能会开始失控,那么有没有一种方法可以从现有的私钥在钥匙串(keychain)访问中创建 CSR(代码签名请求),而不必每次都创建一个新的?

谢谢

最佳答案

通常,您可以通过右键单击钥匙串(keychain)访问中的现有私钥并​​选择使用“您的 key 的名称”从证书颁发机构申请证书来执行此操作。

不幸的是,这将失败并显示“在钥匙串(keychain)中找不到指定的项目”,除非您在您的钥匙串(keychain)中有相应的公钥。这没有技术原因——证书签名请求 (CSR) 可以仅从私钥生成——但钥匙串(keychain)访问不理解这一点。

你有两个选择。

导出私钥并手动生成CSR

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

  1. 在 Keychain Access 中选择私钥,然后点击文件 - 导出项目...
  2. 将文件以.p12 格式保存在某处,但要记住路径。这些说明假定它位于您的主目录中并称为 exported.p12。将密码留空。
  3. 打开终端并输入:

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

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

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

  5. 删除 exported.p12 文件,因为它包含私钥 Material 。

重新创建公钥,以便钥匙串(keychain)访问快乐

此选项是一项长期修复,可让您直接从钥匙串(keychain)访问中的原始 key 生成 CSR。这些说明假定您目前无法使用钥匙串(keychain)访问来执行此操作,因为您缺少相应的私钥公共(public)版本。您可以通过转到钥匙串(keychain)访问中的“ key ”类别并查找具有相同名称的“私钥”和“公钥”来检查这一点。

  1. 在 Keychain Access 中选择私钥,然后点击文件 - 导出项目...
  2. 将文件以.p12 格式保存在某处,但要记住路径。这些说明假定它位于您的主目录中并称为 exported.p12。将密码留空。
  3. 打开终端并输入:

    openssl pkcs12 -in ~/exported.p12 -nocerts -nodes | openssl rsa -pubout > public.pem
    

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

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

    security -v import public.pem -k ~/Library/Keychains/login.keychain
    

    您应该看到“已导入 1 个 key ”。

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

  1. 打开钥匙串(keychain)访问并找到名为“导入的公钥”的公钥。双击它并将其名称更改为与您的原始私钥相同的名称。
  2. 删除exported.p12public.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/

相关文章:

java - 如何在 mac 上查找正在运行的 java 进程的进程 ID?

iPhone 如何设置 View 倒置模式

ios - 添加 UISearchController 后导航栏会变成白色

ios - 从第三层导航 Controller 返回到原始 Root View Controller

ios - 无需代码即可切换 StoryBoards (iphone/iPad)?

python - Mac OS X 无法再使用 pip 安装软件包

iphone - 无限滚动 - setContentOffset : stops deceleration of UIScrollView

iphone - iOS 在 didFinishLaunchingWithOptions : index 0 beyond bounds for empty array 之前崩溃

iphone - pdf在模拟器中显示但在iPhone中不显示

objective-c - 如何将 OSX 应用程序置于最前面?