Xcode Command /usr/bin/codesign failed with exit code 1 : errSecInternalComponent

I am trying to add new provisioning profile to my Xcode, to test an app on the device. Here are the steps I followed:

  1. Deleted all certificates and provisioning profiles

  2. Create/Add IOS Dev Certificate

  3. Add My IOS Device Online

  4. Create IOS Provisioning Profile

  5. Add IOS Provisioning Profile

  6. Clean App

  7. Build Then Run App

  8. Set Codesigning nd Provisioning Profile In Build Settings

  9. Lots of Googling > to no successes

Here is the error I get:

CSSM_SignData returned: 800108E6
/Users/alexpelletier/Library/Developer/Xcode/DerivedData/MyExpense-efnqzvoqwngzcmazaotyalepiice/Build/Products/Debug-iphoneos/MyExpense.app:     errSecInternalComponent
Command /usr/bin/codesign failed with exit code 1

Solution 1:

Open Keychain Access, then in the File menu select Lock All Keychains.

Then go back to Xcode and clean and rebuild. It will prompt you for your password again to unlock the keychain.

After this, assuming you have no other compile issues, it will succeed!

Solution 2:

This occurs when the login keychain is locked. To unlock the login keychain, run:

security unlock-keychain login.keychain

If your keychain is password-protected, specify the password using the -p option:

security unlock-keychain -p PASSWORD login.keychain

If you're using a continuous integration system, you'll likely want to inject the password via an environment variable/token, which most CI systems offer in their settings.

The error code in question is described in Apple's docs as an internal error, so it's entirely possible this occurs in other cases too.

Solution 3:

It seems like a bug in the code signing mechanism, restarting your mac should solve the problem

Solution 4:

Had the same issue on High Sierra/Xcode 9.4.1, all attempts to sign ended in errSecInternalComponent

    • Go to Keychain Access
    • Go to the login keychain
    • Select the category "My Certificates"
    • Find the certificate you're signing with and expand it to see the key.
    • Double click the key
    • Go to the "Access control" tab.
    • Update key access control to "Allow all applications to access this item"

Alternatively:

run codesign command on mac terminal and "Always allow" /usr/bin/codesign access to key

  1. If trying to sign from ssh/CI you also need to run

    security unlock-keychain login.keychain
    

    before trying to sign app bundle