Codesign error: Certificate identity appearing twice
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?
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. :)
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:
- Quit Xcode
- If the Keychain access is open, keep it open.
- Launch Xcode now.
- See that the certificate Xcode was complaining about will be re-added into the keychain at launch from its cache.
- Go ahead and delete it.
- Compile and happy coding.
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.
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: CodeSign collisions between Developer and Enterprise Distribution
I have the same issue with xcode45-DP1. this works for me:
remove all certificates related to your account from keychain. QUIT keychain
remove all provisioning profiles related to your account from xcode:organizer:device:Library:provisioning profiles. QUIT xcode
revoke your certificate and regenerate it and download it to your build machine
before download provisioning profile, click on Edit next to the download button to make sure your name is selected.
Then download the provisioning profile
double click on the certificate to install it onto keychain
drag the provisioning profile to xcode:organizer:device:Library:provisioning profiles
do not click the refresh button from the xcode.
make the build.
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
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.
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.
In my case, the "cache" Xcode was looking at was an attached iOS device. To determine if this is the problem for you:
- Disconnect all iOS devices
- Delete offending certificate and private key from Keychain Access
- Restart Xcode
- Check Keychain Access: in my case the duplicate was NOT recreated at this point
- Reconnect the iOS device
- Restart Xcode again
- 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.
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.
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'
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!
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.
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,
And don't forget to remove extra certificate from the keychain but after that those certificate does not appear again.