Identity not found when trying to code-sign an application with a certificate

certificatecode-signingkeychain

After properly creating a valid certificate for code signing, when running the command:

$ codesign -s CertificateName AppPathName

I always get a:

CertificateName: no identity found

Anyways, When I open the Keychain Access I see that certificate created in the System folder (with a + circle over it).

Also, when I run:

$ security find-identity -p codesigning ~/Library/Keychains/System.keychain

The result is:

Policy: Code Signing
  Matching identities
     0 identities found

  Valid identities only
     0 valid identities found

What does this mean?

My console does not have access to the keychain?
I also tried everything with sudo.

(I use zsh Terminal if that is important)

EDIT:

I've also found out that the System Keychain is locked, but unlocking it won't work and after performing a codesign action it goes back to "locked" again.

Best Answer

This is not the explanation of the problem but the way I worked around to solve it:

  • Deleted the previously created certificates.
  • Unlocked the System keychain with the keychain Access tool (locker on the left).
  • Recreated the certificates filling most of the fields of information even if not totally required.
  • Switched to a simple and clean terminal (just in case a modified terminal lacked some kind of access to the keychain)
  • Executed the codesigning commands with sudo

This worked for me, but I don't really understand what was causing the problem previously.