Codesign error: Certificate identity appearing twice

IphoneObjective CXcode4Code Signing

Iphone Problem Overview


CodeSign error: Certificate identity 'iPhone Developer: XXXX (12345678)' appears more than once in the keychain. The codesign tool requires there only be one.

So I go to my keychain and delete it. But I get this error every time I restart Xcode 4 and some app is adding the expired old certificate back into keychain. Any ideas why and which app?

Iphone Solutions


Solution 1 - Iphone

I just had the same problem. It has been fixed. It came after I submitted an app and installed a few certificates to sign the app.

Quick Fix: Open up KEYCHAIN ACCESS > click on MY CERTIFICATES> in there you will probably see iPhone Developer: . You will probably see it TWICE! Select the one with the earliest Expiration date, right click and select DELETE.

Restart Xcode if you haven't. Works now. :)

Happy Coding.

Solution 2 - Iphone

I think I figured out why the simple delete is not working. Because the dev certificate is still stored in the provision profile, when I close/re-open the Xcode after deleting the certificate in Keychain, I saw the old certificate come back. So I delete it again. It worked.

The simple delete the profile solution did not work for me.

Solution that worked in my case:

  1. Quit Xcode
  2. If the Keychain access is open, keep it open.
  3. Launch Xcode now.
  4. See that the certificate Xcode was complaining about will be re-added into the keychain at launch from its cache.
  5. Go ahead and delete it.
  6. Compile and happy coding.

Solution 3 - Iphone

I just spent a fair amount of time struggling with this same issue. After all the attempts to fix it, I finally came to realize that it's a bug in Xcode. This post gave me a clue to fix it: certificates magically re appearing in your keychain

In my case, the matching private key was in the System keychain, and just had my name on it (hard to tell it was for provisioning). I had to:

  • Move the associated private key to 'login' keychain
  • Restarted Xcode and noticed that the private key was now showing as associated (confirms what it was for)
  • Delete the cert and private key
  • Restart Xcode and poof! It stopped adding my old cert

An interesting observation is that when you delete the certificate, it doesn't delete the associated private key. Visually, it shows the private key below the cert. Don't be fooled.

Good luck!

Solution 4 - Iphone

Ok, found the answer on another "Related" question. https://stackoverflow.com/questions/5673113/xcode-expired-certificate-problem Known issue with Xcode 4 http://openradar.appspot.com/9173280

Solution 5 - Iphone

If you are a member of the iOS Developer and Enterprise iOS Developer programs and you entered your company name in the same for both applications, you will end up with two valid distribution certificates with the same name.

I believe this question addresses that situation: https://stackoverflow.com/questions/5158942/codesign-collisions-between-developer-and-enterprise-distribution

Solution 6 - Iphone

I have the same issue with xcode45-DP1. this works for me:

  1. remove all certificates related to your account from keychain. QUIT keychain

  2. remove all provisioning profiles related to your account from xcode:organizer:device:Library:provisioning profiles. QUIT xcode

  3. revoke your certificate and regenerate it and download it to your build machine

  4. before download provisioning profile, click on Edit next to the download button to make sure your name is selected.

  5. Then download the provisioning profile

  6. double click on the certificate to install it onto keychain

  7. drag the provisioning profile to xcode:organizer:device:Library:provisioning profiles

  8. do not click the refresh button from the xcode.

  9. make the build.

Solution 7 - Iphone

Answer is here

remove all of my old provisioning profiles using the old certificate with Organizer then quit XCode, remove the old certificate from Keychain and restart XCode.

looks like the xcode will keep certificates around when you have references to the in the provisioning profiles

Solution 8 - Iphone

I was having trouble with zombie certificates being repopulated into my keychain and the certificate identity appearing twice. Simply deleting the duplicate cert did not work.

In Xcode, when I looket at my Code Signing in the target, I remembered I had a different distribution profile in "Ad Hoc" builds than "Release" builds.

When I generated a new certificate, I only downloaded a new profile for Ad Hoc builds, and not for Release builds.

Xcode was hanging onto the certificate for both of those profiles, and Xcode was therefore causing the duplicate certificates... because I forgot to update my profiles properly.

Make sure to update ALL your provisioning profiles to the new certificate, and change ALL the profiles at the same time in Xcode.

Be sure to update all your provisioning profiles with the new certificate, otherwise Xcode will try to put the certificate for BOTH profiles in the keychain... causing the duplicate error!

Solution 9 - Iphone

I had this problem and read every piece of information about it, finally I've found the solution on my own. What people failed to mention is that BEFORE cleaning the certificates in Xcode organizer and BEFORE cleaning the expired keys in your keychain you need to make sure that you don't have any expired certificates in the Provisioning Portal. If you'll have even one expired certificate for an old app that used the old Developer certificate Xcode will pull that into its organizer with first build and from there it will go to your keychain and will cause a duplicate.

Solution 10 - Iphone

In my case, the "cache" Xcode was looking at was an attached iOS device. To determine if this is the problem for you:

  1. Disconnect all iOS devices
  2. Delete offending certificate and private key from Keychain Access
  3. Restart Xcode
  4. Check Keychain Access: in my case the duplicate was NOT recreated at this point
  5. Reconnect the iOS device
  6. Restart Xcode again
  7. Check Keychain Access: in my case the duplicate was recreated at this point

If this is the root cause for you, you can get round it by making sure you disconnect iOS devices before starting Xcode.

Solution 11 - Iphone

Simply deleting the redundant certificate didn't work for me. It seems that every time xcodebuild is called, it is "Re-creating" the certificate in the keychain from a cache somewhere... same issue as avi I created a hack / fix for it, tried to find where the file was getting cached and clear it, but had not luck. In the end, what worked for me (a bit of a hack, but hey, what else can you do), was to figure out what the certificate number is, and manually remove it from the keychain shortly after xcodebuild is called. First, go to your /usr/bin/ directory (or whatever directory has your xcodebuild file, try which xcodebuild) and run the following command:

sudo mv xcodebuild xcodebuild_actual

Then create a file using your favorite editor (don't forget to sudo) with the following code:

xcodebuild_actual $* &
echo "xcodebuild started, waiting to wipe certificate, 10 seconds"
sleep 2
echo "Wiping Certificate..."
sudo security -v delete-certificate -t -Z 407629F811D52C0BB7AD31BBB18DCB496354B05E

Note: you'll have to modify your sudoers file to have access to run this specific command without having to enter a password.

Replace the hex identity after -Z above with the hex identity of the offending zombie certificate. Finally, make sure that the xcodebuild file is executable:

sudo chmod 755 xcodebuild 

You can now open your keychain and run the build command, and watch how the offending zombie certificate is resurrected, and then summarily shotgunned prior to it becoming a problem for codesigning. Hopefully Apple will come up with a real fix for this.

Solution 12 - Iphone

In my case deleting the certificates didnt work. XCode 4 seems to cache or restore them. The trick that finally worked for me was to have keychain and xcode running. Then in keychain drag my 2 certificates (dev+dist) from 'login' to 'system'. Then the duplicates magically reappeared and i was able to delete them, and then i dragged the certificates back to 'login'

Solution 13 - Iphone

It's very easy, export the correct Certificate to your desktop. Delete that Certificate in the keychain. Try to build source with error message (have no cert..) Then import again the certificate. => Success!

Solution 14 - Iphone

I just deleted one of the private keys in my keychain for the certificate that I don't need any more.

Even though the certificate re-appers but the private key doesn't reappear. Now check for the valid certificates and only one certificate will appear and the other certificates whose private key is deleted is no longer displayed under valid certificates.

I think this is the simplest way to resolve this issue.

Solution 15 - Iphone

I was dealing with same problem once. And I have solved it by removing unused provisioning profile from Organizer tab in xcode. Actually Keychain will get that certificate from this provisioning profile which is either expired certificate or the build by revoked certificate.

So you just have to delete this provisioning profile from Organizer tab. Organizer is on right-top side button of xcode Open it and than in Organizer remove the provisioning profiles that you don't using.

Here is the screenshot,

enter image description here

And don't forget to remove extra certificate from the keychain but after that those certificate does not appear again.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMugunthView Question on Stackoverflow
Solution 1 - IphoneLouieView Answer on Stackoverflow
Solution 2 - IphoneMobilewitsView Answer on Stackoverflow
Solution 3 - IphoneSean AitkenView Answer on Stackoverflow
Solution 4 - IphoneMugunthView Answer on Stackoverflow
Solution 5 - IphoneJosh MetcalfeView Answer on Stackoverflow
Solution 6 - IphoneccsView Answer on Stackoverflow
Solution 7 - IphoneyeahdixonView Answer on Stackoverflow
Solution 8 - Iphonekarlbecker_comView Answer on Stackoverflow
Solution 9 - IphoneSegevView Answer on Stackoverflow
Solution 10 - IphoneSimon WhitakerView Answer on Stackoverflow
Solution 11 - IphoneBadPirateView Answer on Stackoverflow
Solution 12 - IphonePeterView Answer on Stackoverflow
Solution 13 - IphoneGiangView Answer on Stackoverflow
Solution 14 - Iphoneswathy valluriView Answer on Stackoverflow
Solution 15 - IphoneDilipView Answer on Stackoverflow