Xcode - 如果开发证书是使用撤销按钮创建的,如何将私钥添加到开发证书

Xcode -How to add a private key to Development Certificate if it's created using the Revoke button

我误按了 Revoke 按钮。:

我去了 developer.apple > Certificates 我下载了新的 Development Certificate 是通过按下 Revoke 按钮创建的。之后我得到的错误之一是

错误的第二部分说证书需要 private key(橙色)。

Xcode > Preferences > Accounts > App ID > Team > plus sign 中表示 Development Certificate10/30/20, 12:04 AM:

当我查看钥匙串时,带有该到期日期的证书就在那里,但它的左侧没有箭头来切换嵌套的私钥:

如何向使用撤销按钮创建的开发证书添加私钥?

顺便说一下,按下 Revoke 按钮后创建的分发证书确实附有私钥。

当您按下 Revoke 按钮时,您会收到一个新的 iPhone Distribution certificate 和一个新的 iPhone Developer certificate。您可以在 developer.apple > certificates 的开发人员门户中查看这些证书。这些证书也将在您的钥匙串中。您使用证书到期日期查看哪些证书对应什么。

按下 Revoke 按钮的问题是你会得到一个 iPhone Distribution certificateprivate key 但至于 iPhone Developer certificate 不会 有私钥。

如果您查看您的钥匙串,您会看到下面这张照片。请注意 iPhone Distribution certificate 旁边有一个灰色箭头,但 iPhone Developer certificate 没有:

这将导致以下 2 个错误:

它会导致一个循环,您再次按下 Revoke 按钮并最终出现相同的 2 个错误。我不确定苹果为什么这样做,但肯定有人犯了错误。

当您转到 Keychain > login > My Certificates 时,您只会看到具有私钥的证书(灰色箭头表示)。由于按下 Revoke 按钮的 iPhone Developer certificate 没有密钥,因此它不会在那里。 According to this 您需要该密钥,否则您将收到错误消息:

If your iOS developer and distribution certificates do not appear in "My Certificates", then they are not correctly configured for use on your Mac. Please note that "Certificates" is a repository of all certificates your Mac holds, whereas "My Certificates" is the subset of certificates valid for your Mac to actually use - a certificate appearing in "Certificates" only is not enough.

If the certificate is not in My Certificates then this is most likely because you do not have the correct key for that certificate also on that Mac. You will need to locate the private key made for that certificate (i.e., from the original Mac which requested the certificate or a backup server).

As long as they do appear in My Certificates, then they key is there.

由于 iPhone Developer certificate 不会出现在 我的证书 中,修复是在您按下 Revoke 按钮后,删除 iPhone Developer certificate它从 BOTH 开发人员门户网站 developer.apple > certificates AND keychain 生成。 从钥匙串中删除它非常重要!使用到期日期找到它。请 保留 iPhone Distribution Certificate 因为它应该可以正常工作并且有一个密钥(由灰色箭头指示)。

BOTH 两个地方删除后,您可以在 these directions:

之后自己手动生成一个 developer certificate

手动生成代码签名证书

1- 打开你的 Keychain Access.

2- 在左上角苹果标志旁边 select Keychain Access > Certificate Assistant > Request a Certificate From a Certificate Authority...

3- 填写用户电子邮件地址(只需使用您的)和通用名称(只需使用您的姓名)和select 已保存到磁盘。我 selected Let me specify key pair information(也许没有必要)但在下一个屏幕上只需使用 Key Size: 2048 bitsalgorithm: RSA。单击继续并将生成的 certSigningRequest 文件保存到您的桌面。

4- 转到 https://developer.apple.com 并登录您的帐户。

5- Select 左侧边栏中的证书、ID 和配置文件。

6- 转到证书并单击右上角的 + 按钮。

7- Select iOS 应用程序开发并单击继续。

8- 在下一页上,您将看到创建 certSigningRequest 文件的说明。单击继续。

9- 将创建的 certSigningRequest(从第 3 步开始,保存到桌面的那个)上传到表单,然后单击继续。它将为您生成代码签名证书。

10- 下载证书并双击安装。安装后,它将被添加到您的钥匙串访问应用程序中。假设它保存到您的下载文件夹中,您可以直接进入那里并双击它。

完成这些步骤后,这两个错误应该都会消失。

如果错误仍然存​​在,请查看位于 developer.apple > certificateskeychain > My Certificates 的门户中的证书。如果任何东西在门户中但不在 My Certificates 中,那么您需要找到它的钥匙串访问(查看钥匙串 > Certificates),将其删除,然后从门户网站。

我花了一段时间才弄明白,但 到期日期 是找到混乱证书的关键。

不幸的是,没有办法让它工作。我在 Mojave,所以:

  1. 我在外部硬盘驱动器上安装了 Big Sur 并从那里启动它。
  2. 安装 Xcode 12.
  3. 创建了空项目
  4. 我也是付费团队的成员,但这是不必要的。
  5. 签名和创建证书顺利进行,没有错误
  6. 我在 iCloud 的系统偏好设置中选择了钥匙串访问。
  7. 我将我的证书和密钥导出到从 Mojave 可见的外部驱动器分区。
  8. 重新启动并启动 mojave
  9. 导入的证书

这对付费帐户和非付费帐户都不起作用。我的证书被标记为不受信任,Xcode 11.2 仍然存在修复和修复问题。我收到了 8 封电子邮件,说我的证书在此过程中被吊销了。 所以这可能是 Mojave 认为苹果认为系统不安全。这很有趣,因为昨天我为 Mojave 安装了最新的安全更新(之后我失去了我的 Mac 迷你内置扬声器 :( ) 这看起来像是 Apple 方面的严重错误,我通过反馈助手报告了它,但我怀疑他们是否会修复它,所以现在我不得不告别为 Apple 平台编写代码。