One morning last week, I fired up Xcode4, and all projects were refusing to build. The Apple Developer certificate had expired (why does Apple make this expire *earlier* than your annual iOS $99 subscription? Odd).
Anyway, a quick trip the Apple Developer Portal, and the Provisioning page, one-click “renew” certificate (free), 30 seconds refreshing for Apple to process it, re-download, delete the old one (using the Apple app: Keychain Access), install the new one, re-build.
FAIL
…only to be hit by this error message:
“CodeSign error: Certificate identity ‘iPhone Developer: XXX (YYY)’ appears more than once in the keychain. The codesign tool requires there only be one.”
What?
I just deleted that, in Keychain Access. I selected the one that was expired (it’s highlighted with a red error icon), and hit delete. It then disappeared. And allowed me to install a new one.
Xcode4: Clean, re-build. Nope, still refusing
Xcode4: restart, delete all build directories. Nope, still refusing.
Symptom: Apple’s “delete” does not “delete”
It’s a bug – a HUGE bug – in Keychain Access (Apple’s app that is part of OS X).
When you hit “Delete” (either the delete key, or right-click and select the Delete menu item) … Apple 50% of the time doesn’t process the deletion.
However, 100% of the time, Apple makes the item disappear from the screen.
To check if it’s deleted, close Keychain Access and re-open. If the delete was ignored, then you’ll see that the certificate you deleted has RE-APPEARED:

(third-from-the-bottom, you see the cert I had already deleted … has come back from the dead)
Solution: Delete and delete and delete until Apple stops ignoring you?
I’ve found that if you switch to the “All Items” view, on the left hand side, the deletion seems to work every time. But maybe that was just blind luck. Even if it fails, the act of switching back and forth between “All Items” and “My Certificates” seems to force KA to refresh the view, and tells you if the delete has “worked” yet:

thanks for the post, deleting the old expired developer certificate from the keychain worked for me.
you’re the man, thanks
You saved me.
Many thanks.
I was having a similar issue where it wouldn’t let me compile until I removed it. However, I have an additional problem where the certificate keeps getting back in the keychain somehow and I have not been able to determine how. Very frustrating.
This worked for me! Thanks Adam.
All the other posts on this subject seemed to focus on Xcode, and NOTHING was resolving the problem. Hard to believe it’s actually a bug in keychain, but your solution solved the problem immediately.
I struggled to find the duplicate certificate. Finally did this and the duplicate, expired certificate showed up:
Open up Keychain Access app within /Applications/Utilities and click “All Items” under the Category sidebar. Type “iPhone” into the top-right search bar.
Exit, reopen Xcode and I could again build for distribution.
Jim
This worked for me, After delete all of unnecessary certificate. then re-open Xcode. Suddenly all the problem is solved ! Thanks, Adam
Works!
Thanks,
It helped to solve the issue.
Mark
Thanks! This helped big time.
Thanks, you and Jim Schrempp! It worked for me.
Oh my God! Spent hours on this lazy issue and you got the solution. THANKS A LOT!
Thanks for the tip! This worked well on snow leopard. However it is not working on Lion. Any tips on how to solve this?
Many thanks, Adam. Worked for me – I was having this problem of reappearing distribution certificates in Keychain Access. Persistently deleting it and rebuilding the app worked.
Hi There,
Here’s a fix we’ve found that sorts it, without hacking. See full details here:
http://tapadoo.com/2012/certificates-magically-re-appearing-in-your-keychain-try-this/
Excellent, many thanks
Thanks at all
This didn’t work for me, but the link that was posted worked. Here it is again:
http://tapadoo.com/2012/certificates-magically-re-appearing-in-your-keychain-try-this/