CodeSign error: Code Signing Identity ‘iPhone Distribution: XXXXX’ does not match any code-signing certificate in your keychain.

I’ve been getting this intermittent issue from our Bamboo build server, which builds our iOS project using xcodebuild. It seems to resolve itself after a restart of the mac, however.. a few builds later and it fails again. We’re using XCode 4.1 on OS X Lion 10.7.1.

I inserted this into the build script

security list-keychains

..and I can see that Bamboo has access to the login and the System keychains

Listing the current keychains
08-Sep-2011 12:43:26     “/Users/mac0004/Library/Keychains/login.keychain”
08-Sep-2011 12:43:26     “/Library/Keychains/System.keychain”

….however, after a few builds (and something else that I don’t know what happens), this command reports

Listing the current keychains
08-Sep-2011 13:23:16     “/Library/Keychains/System.keychain”
08-Sep-2011 13:23:16     “/Library/Keychains/System.keychain”

It’s strange how it reports the System.keychain twice, and that it can no longer find the login keychain.

Anyway, the solution for me was to copy/move my iOS certificates to the System.keychain.

I also had another error: ‘CSSM_ERRCODE_INTERNAL_ERROR’, which I resolved by installing the intermediate certificate from Apple again. You can get this from the provisioning portal, certificates section. Or from this link: Apple WWDRCA Intermediate Certificate

If you have similar problems and this doesn’t resolve it, post a comment.