简体   繁体   English

钥匙串上的分发证书中缺少私钥

[英]missing private key in the distribution certificate on keychain

I have the following problem which I could not find a solution for anywhere.我有以下问题,我无法在任何地方找到解决方案。 Basically, we have a company developer account (not enterprise) and so in order to submit our app, I requested from our team lead to send me the distribution certificate and create and send me a distribution provisioning profile.基本上,我们有一个公司开发人员帐户(不是企业),因此为了提交我们的应用程序,我要求我们的团队负责人向我发送分发证书,并创建并向我发送分发配置文件。

With the developer profile, everything works good, but when I installed the cert and the provisioning profile, I did not see the distribution profile on Xcode, and nor do I have a private key under the dist cert in the keychain.使用开发人员配置文件,一切正常,但是当我安装证书和配置文件时,我没有看到 Xcode 上的分发配置文件,而且我在钥匙串中的 dist 证书下也没有私钥。

Does anyone know how to solve this?有谁知道如何解决这个问题? I read in diff places that I will need to revoke the certificate and create a new one, but I can't really do that since we have a bunch of apps in the company and I can't revoke it for everyone.我在不同的地方读到我需要吊销证书并创建一个新证书,但我真的不能这样做,因为我们公司有很多应用程序,我不能为每个人吊销它。

在此处输入图片说明Ahh this is a common issue, The solution is simple:啊,这是一个常见问题,解决方法很简单:

Who ever created the developer credentials originally needs to go to the keychain on their computer and right click on the key(s) for private and public and export the key to a file.创建开发人员凭据的人最初需要转到其计算机上的钥匙串,然后右键单击私有和公共密钥,然后将密钥导出到文件。 Then you just download that file on your computer and open it, and it will be added to your keychain.然后您只需将该文件下载到您的计算机上并打开它,它就会被添加到您的钥匙串中。

You need to have both the private key (.pem file) and the certificate for your provisioning profiles.您需要拥有配置文件的私钥(.pem 文件)和证书。

As long as you still have access to the mac which was used to generate the original distribution certificate it's very simple.只要您仍然可以访问用于生成原始分发证书的 mac,它就非常简单。

Just use that mac's Keychain Access application to export both the certificate and the private key.只需使用该 Mac 的 Keychain Access 应用程序即可导出证书和私钥。 Select both using shift or command and right click to export to a .p12 file.使用 shift 或 command 选择两者并右键单击以导出到 .p12 文件。

Attached a screenshot to make it very clear.附上截图,让大家看得一清二楚。

On your mac, import that .p12 file and you are good to go (just make sure you have a valid provisioning profile).在您的 Mac 上,导入该 .p12 文件,一切顺利(只需确保您拥有有效的配置文件)。

直接选择出口

To add on to others' answers, if you don't have access to that private key anymore it's fairly simple to get back up and running:要补充其他人的答案,如果您不再有权访问该私钥,则恢复并运行非常简单:

  1. revoke your active certificate in the provisioning portal在配置门户中撤销您的活动证书
  2. create new developer certificate (keychain access/.../request for csr...etc.)创建新的开发人员证书(钥匙串访问/.../CSR 请求...等)
  3. download and install a new certificate下载并安装新证书
  4. create a new provisioning profile for existing app id (on provisioning portal)为现有的应用程序 ID 创建一个新的配置文件(在配置门户上)
  5. download and install new provisioning profile and in the build, settings set the appropriate code signing identities下载并安装新的配置文件,并在构建中设置适当的代码签名身份

Delete the existing one from KeyChain, get and add the .p12 file to your mac from where the certificate was created.从 KeyChain 中删除现有的,从创建证书的位置获取 .p12 文件并将其添加到您的 mac。

To get .p12 from source Mac, go to KeyChain, expand the certificate, select both and export 2 items.要从源 Mac 获取 .p12,请转到 KeyChain,展开证书,选择两者并导出 2 个项目。 This will save .p12 file in your location:这将在您的位置保存 .p12 文件:

在此处输入图片说明

For person who are afraid on re-creating AppStore distribution certificate Apple documentation says:对于害怕重新创建 AppStore 分发证书的人,Apple文档说:

Important: Re-creating your development or distribution certificates doesn't affect apps that you've submitted to the App Store nor does it affect your ability to update them.重要提示:重新创建您的开发或分发证书不会影响您提交到 App Store 的应用程序,也不会影响您更新它们的能力。

But it affects apps for Apple Developer Enterprise ecosystem.但它会影响Apple Developer Enterprise生态系统的应用程序。

In my case, I've lost all private keys in my keychain, new ones were imported correctly, but doesn't show the private key as well.就我而言,我丢失了钥匙串中的所有私钥,正确导入了新的私钥,但也没有显示私钥。 The only thing that helped was generating new CertificateSigningRequest唯一有帮助的是生成新的 CertificateSigningRequest

我花了好几个小时来解决这个问题,但只需重新启动 MAC 就可以解决这个问题...

你换了一台不是创建分发证书的原始Mac后,你会丢失私钥。只需删除原始证书并重新创建一个新的,对我有用~

When I try to upload iOS build to test flight then error was appear.当我尝试将 iOS 版本上传到试飞时出现错误。

"Missing privacy key" . "Missing privacy key"

在此处输入图片说明

Just 2 step for fix this error.只需 2 步即可修复此错误。

  1. Remove old certificate from developer.apple.com从 developer.apple.com 删除旧证书
  2. Create new certificate from Xcode or developer.apple.com从 Xcode 或 developer.apple.com 创建新证书

My problem has been solved (I am using Xcode 9.4.1).我的问题已解决(我使用的是 Xcode 9.4.1)。

Please check, Xcode created new certificate.请检查,Xcode 创建了新证书。

在此处输入图片说明

I got into this situation ("Missing private key.") after Xcode failed to create new distribution certificate - an unknown error occurred.在 Xcode 无法创建新的分发证书后,我陷入了这种情况(“缺少私钥。”) - 发生了未知错误。

Then, I struggled to obtain the private key or to generate new certificate.然后,我努力获取私钥或生成新证书。 From the certificate manager in Xcode I got strange errors like "The passphrase you entered is wrong".从 Xcode 中的证书管理器中,我收到了一些奇怪的错误,例如“您输入的密码错误”。 But it did not even ask me for any passphrase.但它甚至没有问我任何密码。

What helped me was:对我有帮助的是:

  1. Revoke all not-working distribution certificates at developer.apple.com在 developer.apple.com 撤销所有无效的分发证书
  2. Restart my Mac重新启动我的 Mac

After that, Xcode was able to create new distribution certificate and no private key was missing.之后,Xcode 能够创建新的分发证书,并且没有丢失私钥。

Lesson learned: Restart your Mac as much as your Windows ;)经验教训:像重启 Windows 一样重启 Mac ;)

At the Menu > Visual Studio (mac) > Preferences > Publishing > Apple Developer Accounts > [Select your apple id] > View Details > Create Certificate在菜单 > Visual Studio (mac) > Preferences > Publishing > Apple Developer Accounts > [Select your apple id] > View Details > Create Certificate

To delete unused/invalid certificates, go to website:https://developer.apple.com/account/resources/certificates/list要删除未使用/无效的证书,请访问网站:https ://developer.apple.com/account/resources/certificates/list

delete any unwanted certificate there在那里删除任何不需要的证书

Next is to create App ID (identifiers), go to website:接下来是创建App ID(标识符),访问网站:
https://developer.apple.com/account/resources/identifiers/list https://developer.apple.com/account/resources/identifiers/list

Next, go to website to create provisioning profiles:接下来,转到网站以创建配置文件:
https://developer.apple.com/account/resources/profiles/add https://developer.apple.com/account/resources/profiles/add

use the certificate to bind with your app id.使用证书与您的应用程序 ID 绑定。

Next is to download the profiles:接下来是下载配置文件:
At your mac > At the Menu > Visual Studio (mac) > Preferences > Publishing > Apple Developer Accounts > [Select your apple id] > View Details > Download All Profiles在您的 mac > 在菜单 > Visual Studio (mac) > 首选项 > 发布 > Apple 开发者帐户 > [选择您的 Apple ID] > 查看详细信息 > 下载所有配置文件

I'm the creator of the key, but the key was attached to an expired Certificate.我是密钥的创建者,但密钥已附加到过期的证书上。

To solve it I went to -> Xcode/Preferences/Accounts/"Account you use to archive"/Manage Certificates..为了解决它,我去了 -> Xcode/Preferences/Accounts/"Account you used to archive"/Manage Certificates..

Then click on the dropdown menu with the "+" sign on the bottom left corner, and choose the type of certificate you need updated (mine was Apple Distribution).然后单击左下角带有“+”号的下拉菜单,并选择您需要更新的证书类型(我的是 Apple Distribution)。

This updated my new certificate with its key attached.这更新了我的新证书并附上了密钥。

I accessed that certificate on apple's developer website and after downloaded it I opened it.我在苹果的开发者网站上访问了该证书,下载后我打开了它。 Likewise, at open I got a little window asking if I wanted to add the certificate to keychain.同样,在打开时,我会看到一个小窗口,询问我是否要将证书添加到钥匙串中。 Just tapped "add" and the "missing private key" error was gone.只需点击“添加”,“缺少私钥”错误就消失了。

  • I assume you have switched device and trying to create a new certificate for your new device,我假设您已切换设备并尝试为您的新设备创建新证书,<\/li>
  • First revive the development certificate form the developers portal,首先从开发者门户中恢复开发证书,<\/li>
  • Go to xcode > preferences > accounts > select your apple id with the dev portal access > manage certificates > click on the team account > click on the little + button > click on apple distribution转到 xcode > 首选项 > 帐户 > 使用开发门户访问权限选择您的 Apple ID > 管理证书 > 单击团队帐户 > 单击小 + 按钮 > 单击 Apple 分发<\/li>
  • Go to the apple developer portal , you can see a distribution certificate is created ,去苹果开发者门户,你可以看到一个分发证书被创建了,<\/li>
  • Go to profiles create a new profile with the new certificate.转到配置文件,使用新证书创建新配置文件。<\/li>
  • Download > install done下载>安装完成<\/li><\/ul>"

Check whether you are using Login or not to add the certificates, if you are checking in System at top left hand side then we wont be able to see it.检查您是否使用登录来添加证书,如果您在左上角的系统中检查,那么我们将无法看到它。

So drag and drop the .cer into login then check you are able to get the private key or not.因此,将 .cer 拖放到登录中,然后检查您是否能够获取私钥。

Just to shed some light on this.只是为了说明这一点。

After I deleted my p12 certificate from Keychain.从钥匙串中删除我的 p12 证书后。 I re-downloaded my own certificate from Apple developer portal.我从 Apple 开发者门户重新下载了我自己的证书。

I was only able to download the certificate.我只能下载证书。 But to sign you need the private key as well.但是要签名,您还需要私钥。 So you either:所以你要么:

  • export both private key and certificate from Keychain to get it.从钥匙串导出私钥和证书以获取它。

  • Upload a Certificate Signing Request and generate new certificates上传证书签名请求并生成新证书

That certificate by itself has no value for signing purposes.该证书本身对于签名目的没有价值。 My guess is that the private key is created by keychain the moment you 'request a certificate from a certificate authority' but isn't shown to you until you add its tying certificate.我的猜测是私钥是在您“从证书颁发机构请求证书”的那一刻由钥匙串创建的,但在您添加其绑定证书之前不会显示给您。

Contact with the creator of iOS Distribution key and tell to export certificate and private key, then just download and double click it to access in your keychain.联系 iOS 分发密钥的创建者并告知导出证书和私钥,然后只需下载并双击它即可在您的钥匙串中访问。

在此处输入图片说明

My problem was that for whatever reason, the login keychain was missing in the Keychain Access.我的问题是,无论出于何种原因,钥匙串访问中都缺少登录钥匙串。 Xcode created a new certificate and added it to the login keychain but could not use it. Xcode 创建了一个新证书并将其添加到登录钥匙串中,但无法使用它。 Restarting the computer solved my problem.重新启动计算机解决了我的问题。

在此处输入图片说明

If you are creating your own Distribution cert, not using someone else's then this could help.如果您正在创建自己的分发证书,而不是使用其他人的证书,那么这可能会有所帮助。

Spent quite a bit of time on this today, issues from not being able to create a SigningRequest to generating a distribution cert and not having it attached to my private key in KeyChain Access.今天在这方面花了很多时间,从无法创建 SigningRequest 到生成分发证书以及没有将其附加到我在 KeyChain Access 中的私钥的问题。 These steps helped solve this for me.这些步骤帮助我解决了这个问题。

If you are still having issues, revoke your current cert and start fresh.如果您仍然遇到问题,请撤销您当前的证书并重新开始。

  1. Creating a new signing request创建新的签名请求<\/li><\/ol>

    The Keychain Access > Certificate Assistant > Request a Certificate from a Certificate Authority is actually contextually aware of what you currently have selected when you launch it. Keychain Access > Certificate Assistant > Request a Certificate from a Certificate Authority 实际上会根据上下文了解您在启动它时当前选择的内容。 Just to be sure that you aren't accidentally skewing your Request with some random selection, go to your Login Items and select the Apple Worldwide Developer item.只是为了确保您不会因一些随机选择而意外扭曲您的请求,请转到您的登录项目并选择 Apple Worldwide Developer 项目。 Then launch the above Request and create the CertificateSigningRequest.certSigningRequest file.然后启动上述请求并创建 CertificateSigningRequest.certSigningRequest 文件。

    在此处输入图像描述<\/a>

    1. Go to Apple Dev portal, add new distribution certificate, upload your CertificateSigningRequest.certSigningRequest file and download the newly created distribution certificate.转到 Apple Dev 门户,添加新的分发证书,上传您的 CertificateSigningRequest.certSigningRequest 文件并下载新创建的分发证书。

      <\/li>

    2. To import the distribution cert into your keychain, instead of just double clicking it, I recommend opening your keychain, go to "login\/Certificates" area and drag and drop the cert here.要将分发证书导入您的钥匙串,而不是双击它,我建议打开您的钥匙串,转到“登录\/证书”区域并将证书拖放到此处。

      <\/li><\/ol>

      I had an issue where my cert would auto-install into the System area, instead of the login area where my private key existed and this caused my key not to be linked to the new cert.我有一个问题,我的证书会自动安装到系统区域,而不是我的私钥所在的登录区域,这导致我的密钥没有链接到新证书。

      "

An old XCode version will also cause this.旧的 XCode 版本也会导致此问题。 I was on XCode10 (old for 2022).我在 XCode10(2022 年旧)上。 Updated to latest version, which resolved the issue.更新到最新版本,解决了这个问题。

我可以通过更新 macOS 和 XCode 来解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM