Code Signing on Mac "error: The specified item could not be found in the keychain" - certificate

I'm attempting to sign an application on macOS Sierra, but my Developer ID certificate(s) cannot be found. Can anyone clarify what I'm doing wrong? Thank you!
Here's my flow:
I downloaded an "Application" and "Installer" Developer ID certificate from Apple
I installed both to my System keychain, they show "This certificate is valid"
I open Terminal and change directories to my application folder
I try codesign --deep --force --verbose --sign "<identity>" "<appName>" but I get the following "error: The specified item could not be found in the keychain"
Some things I've tried:
a. Using custom settings for the certificates by setting Code Signing to "Always Trust"
b. Using the certificate's entire Common Name for the identity instead of the value inside the parentheses
c. Running security find-identity -p codesigning, I get the following "Policy: Code Signing Matching identities 0 identities found Valid identities only 0 valid identities found"
d. Deleting the certificates and reinstalling them to the login keychain

You didn't mention the private key you used to generate the cert in the first place.
I purchased a new Mac Mini build machine to replace an old one. The old one had the signing certs. Just importing the signing certs downloaded from Apple didn't work, I also needed the original private key from which the certificate request was formed. So I followed https://stackoverflow.com/a/34063997/28190 to export a new keychain from the old machine, imported to a new one, and then I was able to use that.
You need to customise your `unlock-keychain' calls to point to the imported keychain.

Related

SWIFT: Failed with exit code 1 (WHY?) [duplicate]

I am trying to add new provisioning profile to my Xcode, to test an app on the device. Here are the steps I followed:
Deleted all certificates and provisioning profiles
Create/Add IOS Dev Certificate
Add My IOS Device Online
Create IOS Provisioning Profile
Add IOS Provisioning Profile
Clean App
Build Then Run App
Set Codesigning nd Provisioning Profile In Build Settings
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
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!
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.
It seems like a bug in the code signing mechanism, restarting your mac should solve the problem
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
If trying to sign from ssh/CI you also need to run
security unlock-keychain login.keychain
before trying to sign app bundle
I have met the same problem, I restart my macOS,and it works.
In China,we have a saying between developers:
Little problems,just restart.Big problems,should reinstall.
Sometimes,the above saying will greatly help you!
In case it helps someone else, I encountered an errSecInternalComponent error with codesign because I was running it over an ssh session to my macOS machine. Running the same command from a terminal window on the macOS machine itself worked.
Presumably this is because codesign needs access to the private key from the login keychain.
Running security unlock-keychain login.keychain (as explained by cbracken's answer) from the same session also should work.
As pointed out by #Equilibrium in one of the comments, if you are in command line env. like Jenkins(my case), you might need to pass the password to the security-unlock command mentioned in the solutions.
So instead of using,
security unlock-keychain login.keychain
use:
security unlock-keychain -p <login-keychain-password> <path-to-login-keychain>
where path-to-login keychain can be $HOME/Library/Keychains/login.keychain(my case) or simply login.keychain
for anyone that encountered this issue from jenkins and ssh:
high possibility that you have not granted access to the private key in keychain, i tried but not sure why all of these are not working:
security import .p12 file with -A or -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k #{password} #{keychainPath}
change all provisioning profile to [UUID].mobileprovision and copy them to '~/Library/MobileDevice/Provisioning\ Profiles' on jenkins server
clean derived data and reboot jenkins server
make sure default keychain is login keychain and unlocked it.
finally resolved by:
1.ssh [user]#[jenkinsServerIP] -L 5900:localhost:5900, log into jenkins server
2.open 'vnc://localhost'
this will launch a remote screen, if your jenkins server allow this...
then open keychain.app to grant access of /usr/bin/codesign to the private key
good luck
Nothing work for me from the above Solution.
Fallowing Solution Work for me...
First Open Keychain Access
Then Select Login And click Certificates
Double click Apple Worldwide Developer Relations Certificate Authority
Open trust section, and set to "Use System Defaults" from "Always Trust"
Clean the build folder and run
I ran security unlock-keychain login.keychain and my login password didn't work. So I rebooted, and then just ran Xcode again and it worked. Running the command works as well. Strange issue.
If trying to sign from ssh run command:
security unlock-keychain login.keychain
before trying to sign app bundle
or from UI
Update key access control to "Allow all applications to access this item"
Thx to #Equilibrium and #Jon McClung
I had the same issue Found out the problem is with code signing the app.
Opened the developer account and accepted the updated agreement and it worked.
Right clicking on the private key associated with the codesigning cert in the keychain, and then clicking on 'allow all applications' instead of relying on a prompt fixed it for me, since the build was happening via ssh.
I had to:
1) delete the certificate associated to the project
2) Back to the Xcode and revoke the app certificate
3) The Xcode require a new certificate
4) Lock all KeyChain
5) Clean the project
6) Rebuild
That's it. Hope it helps to anyone.
If you get errSecInternalComponent after
Warning: unable to build chain to self-signed root for signer …
, you might have the wrong Apple World Wide Developer Relations root certificate in your keychain. In this case, make sure that you import the WWDR certificate with which your developer certificate was signed. I imported the WWDR certificate expiring in 2023 and two hours later finally realized that it didn't work because my developer certificate had been signed with the WWDR certificate expiring in 2030 (AppleWWDRCAG3.cer). Download page: https://www.apple.com/certificateauthority/
Posting a work-around that we finally had to resort to, in case someone else is running out of things to try...
After installing a new Apple Distribution certificate in our "login" keychain, our Jenkins job suddenly started to fail singning iOS apps with the same errSecInternalComponent error:
Command /usr/bin/codesign failed with exit code 1
Our build pipeline calls security unlock-keychain, and we have no problems with our Enterprise Distribution cert (which was coincidentally updated and installed in the same Keychain just a few weeks prior), where the unlocking works as expected.
After trying all the usual things mentioned in this thread and elsewhere, we ended up running codesign manually as the Jenkins user in a new Terminal window, taking the exact same command as found in the Jenkins log: /usr/bin/codesign --force --sign...
This prompted entering the password to unlock the Keychain, which we did, and then selected "Always Allow".
After that Jenkins manages to sign (as expected).
This is obviously a bit of a work-around since we might have to do this again when the cert has expired, and it's really strange that unlocking works for Enterprise certs, but not the cert used for distributing through App Store... They literally share the same pipeline.
Just try it once using mac terminal but not from ssh session
security unlock-keychain login.keychain
And choose always allow in the prompted dialog.
And then you could xcodebuild in the remote session.
The above methods are useless to me.
I resoled it by:
Open keychain access.
Click Login Menu.
Remove all personal certificates.
Clean the project.
Rebuild.
That's it. Hope it helps to anyone.
In my case, this solved.
xcode -> preferences -> accounts -> select the account -> manage certificate -> (+) in bottom left -> Apple development
Ref: https://stackoverflow.com/a/62646138/234110
In my case BUCK was trying to sign the IPA for development, but there were not any development certificates installed. Changing the build config to release (this is what I needed - to build for iTunes) fixed it for me.
Just wanted to callout if someone face similar issue what I did. In my case my apple dev and distribution certificates, keys and provisioning profiles where upto date. My iOS code build was working in user mode without any issue however it does not work due to code sign issue when the code build runs with root privileges i.e. % sudo or invoking the Xcode using sudo through command line.
So, I copied the corresponding working certificates and keys the login to the system location in the keychain tool. Then it started working without any code sign issue.
Similarly, we can export the required certificates, keys for build from the working machine and import those into non working machine's keychain tool may solve the issue.
For me, I was able to sign files when using the Mac directly or via VNC, but not via ssh. I figured it must be something to do with access to the certificate within the keychain. I was already doing a security unlock-keychain [keychain name] but this didn't appear good enough.
What finally fixed it for me was (within a direct/VNC connection, not ssh):
Make sure the keychain in which your certificate resides is locked. Close Keychain Access.
Open Terminal
Do not run security unlock-keychain [keychain name].
Run a signing process using codesign tool. You will be challenged for a password to the keychain.
Enter the password and click "Always allow"
From now on I was able to use codesign via ssh, so long as I included security unlock-keychain [keychain name] before the command.
If you have a code signing certificate with the same name in the keychain, make sure you remove it. I had one which XCode reported as "Missing private key". I had to remove it via Keychain Access before the correct certificate was used by codesign.

Valid Signing identity Not Found in Xcode

Actually i developed an app using my own developer certificates and provisioning profile.
Now i need to publish it on my client developer account and my client sent his distribution certificate along with provisioning .And I have installed the certificate and then i drag the provisioning profile to xcode, and i have got error message like "Valid signing identity not found"
Please assits me.
Change code sign in project settings.
You need the private keys that were used to sign the certificate. If you don't have them
anymore you can generate a new signing request.
You need p12 file from your client to use its developer certificate and provisioning profile.When your client provide you that p12 file than double click that file and its run perfectly.
And for geting p12 file ,select the cert, and open the arrow to also select the private key and export them together as a .p12 file from Keychain Access.
There are several ways to solve this issue.
The first one is, to export your developer certificate including the associated key from your keychain and importing it on your client machine.
The other way would be (If your client machine would use another apple dev account) to go through those steps listed here Apple Certification & Provisioning
I would recommend to delete the old certificates from xcode, sometimes xcode might lag otherwise

'valid signing identity not found' Error in all profile in organizer

Code Sign error: The identity 'iPhone Developer: Person's Name (XXXXXXXX)' doesn't match any valid certificate/private key pair in the default keychain
In organizer, I click on Provision Profiles and the provision profile I downloaded. Underneath I get the warning:
A valid signing identity matching this profile could not be found in your keychain
I've looked up many, many other people that had this problem, but all seem to resolve it by deleting the cert and provision
i also tried this but same problem once
i have one profile without postfix bundle id without error
Any help most well come..........
Just check that your certificate is valid or invalid from Keychain Access
Here this type of Error occur if certificate expired.
And also set valid certificate which you want to use in Build Setting - > Code Signing Identifire of Project's Target and also Project
And at last set Identifire in Targets -> Summary -> Builde Identifile for Example com.IdentifireCertiFicateName.yourProject
i hope this help you....
your certificate process at the first time you create CSR file. from that you work on the developer provisioning profile and distribution profile. if you change the system you have to export the certficate and privatekey from keychain access -> my Certificate expand and export your certificate and privatekey file in .p12 format. install those file in your current system. after that set codesing in project and target file.

Signing identity not found on XCODE (Organizer)

I already made iPhone application thanks to all certificates and so on.
Now, I'm installing a second mac to develop applicaions (the same applications) so :
I generated a Certification Signin Request (with keychain)
I didn't upload it but I downloaded the Distribution Certificate (that I generated before with the old computer), and install it (in keychain again)
I Downloaded the Distribution Provisioning profile
The last File , I installed it and in Organizer, the status of the file is "Valid Signing identity not found".
How can I fix that problem ?
This is common operations but I always have trouble with all those certificates :-)
Thanks
Export your existing certificate from your old machine to your new one. This will make you skip all other stuff to do and it's easy as 1,2,3.

Distribution Cert has no private key. Valid signing ident matching profile cannot be found

I've been able to generate and use my development cert & provision for some time. I did have some problems after upgrading xcode, in that the login certs where getting trashed/removed, but I fixed that.
I'm trying to create my distribution cert & provision. I've noticed that the distribution cert doesn't have a private key - you can't expand the cert when clicking on it. Not sure if that's an issue or not. When I drag the distribution profile into Organizer, it comes up with the error message, "A valid signing identity matching this profile could not be found in your keychain".
I've tried putting the distribution cert in both login and system. I also DO have the WWDRCA cert installed.
Any ideas - A real pain ...
It sounds like you do not have the keys corresponding to the certificates in your keychain. If you posted screenshots of your keychain entries and your code signing configuration, it would be easier to see exactly what is going on.
Also make sure you have the Apple certificate in your keychain.
Check if you have still got your private key on login keychain. That's what happens to me. I encountered this same problem when I copied my project from iMac to Macbook Pro. I found out I didn't have my private key installed on the Macbook. So I exported my private key, copied and installed it to the Macbook, and it fixed it!
I've documented the information here: http://www.creatistblog.com/2009/09/iphone-developer-provisioning.html