/usr/bin/codesign --force --sign with xcode 9 automatic code signing - ios

Automatic signing configured with Xcode9 working fine with machine but giving below error when I access that machine remotely via ssh & run through commandline bash scripts which is using Xcodebuild with Automatic code sign style or if same code base is configured with jenkins pipeline & triggered a run still give below error message:-
/usr/bin/codesign --force --sign A7F8FCD694D7923A3E57826398C3380E2E5A5446 --entitlements unknown error -1=ffffffffffffffff
Command /usr/bin/codesign failed with exit code 1
not able to understand what is wrong while automatic signing is working with one machine so it should work when somebody try to run remotely as well.

Related

jenkins codesign : Frameworks/OpenSSL.framework: errSecInternalComponent - Command PhaseScriptExecution failed with a nonzero exit code

Im trying to build ci/cd ios App with jenkins using ec2 mac instance of AWS.
I set up all my certificates/private key using the command
security import ./myfile.p12 or security add-certificate
I also added my Provisionning Profile successfully.
The build is running but at the final step Im getting an error during the codesign --force step. I read a lot of question over there but non of the solution provided worked for me..
Error details of the Build
For info: when I run security default-keychain command, I get as the default keychain : /Library/Keychains/System.keychain
And running :
security find-identity -v -p codesigning /Library/Keychains/System.keychain
gaves me result like:
XXXXXXXXXXXXXXXXXXXXX "iPhone Distribution: corp (Land) LTD."
XXXXXXXXXXXXXXXXXXXXX "iPhone Developer: John Doe (XXXXX)"
I already tried to lock/unlock my keychain without success..
Is anyone has an idea how to resolve this issue please ?
After a weeks of research, I just deleted all my certificates form the System.keychain (the corp one and the two of Apple authority - those who expire in 2023 and 2030 ) and reinstall them !
This made the job at the end

Embedding framework in iOS generates an error when signing

I am currently trying to embed the Azure client framework into an iOS project, but the build is failing when it tries to sign the framework, with the following error:
~/Library/Developer/Xcode/DerivedData/MyProject-gtoxtgdnkyheledfgmjhogvasnql/Build/Products/Debug-iphonesimulator/MyProject.app/Frameworks/AZSClient.framework: bundle format unrecognized, invalid, or unsuitable
After poking around on the web, I found this highly useful page:
https://github.com/mattgallagher/CwlSignal/issues/16
The command being run by code sign is this:
/usr/bin/codesign --force --sign - --timestamp=none \
--preserve-metadata=identifier,entitlements,flags \
~/Library/Developer/Xcode/DerivedData/MyProject-gtoxtgdnkyheledfgmjhogvasnql/Build/Products/Debug-iphonesimulator/MyProject.app/Frameworks/AZSClient.framework
which generates the error I mentioned above. Following Mat's lead and modifying the end of the command to point to the actual framework binary as follows:
/usr/bin/codesign --force --sign - --timestamp=none \
--preserve-metadata=identifier,entitlements,flags \
~/Library/Developer/Xcode/DerivedData/MyProject-gtoxtgdnkyheledfgmjhogvasnql/Build/Products/Debug-iphonesimulator/MyProject.app/Frameworks/AZSClient.framework/AZSClient
the command correctly executes and signs the framework.
My Question:
How do I modify the Xcode build system to do this. If I try just building after running the code sign on the command line, it overwrites my code sign. If I try building without signing the framework, it presents an unsigned version of the framework to the target (in this case the simulator).

Xcode build error "Command /usr/bin/codesign failed with exit code 1" in simulator and real environment

I recently created a new project. It was 8 months ago when I created the project last time. So, when I built a new project with simulator, I got an error like the following.
CodeSign {app directory}
cd {app directory}
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Signing Identity: "-"
/usr/bin/codesign --force --sign - --entitlements /Users/{username}/Library/Developer/Xcode/DerivedData/{app directory}
/Users/{username}/Library/Developer/Xcode/DerivedData/{app directory}/{app name}: Is a directory
Command /usr/bin/codesign failed with exit code 1
I tried
Confirm Xcode sign-in status
Check Automatically manage signing
Clean up and delete build DerivedData
Reboot Xcode and PC
Reinstall Podfile and cocoapod
Recreate certificate
xattr -c
I tried several method. But it did not solve it.
Most people seem to be OK in a simulation environment, but in my case it is not. Both the real environment and the simulation will not work.
Thank you.
The error is there in the output from the command:
/Users/{username}/Library/Developer/Xcode/DerivedData/{app directory}/{app name}: Is a directory
You most likely have some custom build phase or script phase which is stomping over your app's executable with a directory.

Building Xcode project with Jenkins gives codesign error

I'm trying to build Xcode project with Jenkins. Project for Xcode generated by Unity Engine.
I am able to build this project directly from Xcode GUI, but when trying to build project through Jenkins i'm getting following error at the end of build:
Signing Identity: "iPhone Developer: MyName MySurname (XXXXXXXXXX)"
Provisioning Profile: "iOS Team Provisioning Profile: *"
(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX)
/usr/bin/codesign --force --sign 37DF6AF254E5A4856B1BA024D199DEE3CE596A58 --entitlements /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/myapplication.app.xcent --timestamp=none /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app
/Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app: errSecInternalComponent
Command CodeSign failed with a nonzero exit code
** BUILD FAILED **
The following build commands failed:
CodeSign /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app
(1 failure)
Build step 'Xcode' marked build as failure
Finished: FAILURE
I tried to reproduce following command in terminal, and it woked fine without any errors:
/usr/bin/codesign --force --sign 37DF6AF254E5A4856B1BA024D199DEE3CE596A58 --entitlements /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Unity-iPhone.build/Release-iphoneos/Unity-iPhone.build/myapplication.app.xcent --timestamp=none /Users/Shared/Jenkins/Home/workspace/Xcode_Input/build/Release-iphoneos/myapplication.app
It asked me for my password two times(and same password specified in Jenkins job settings for Xcode), and finished without any errors.
Keychain i used to sign project is unlocked with: security unlock-keychain login.keychain
The question is - what could be the reason of following behavior? How can i solve this problem?
Thanks in advance!
Jenkins is SSHing into the box and not receiving access to your keychain. Jenkins needs to unlock the keychain before performing the build. It looks like you already understand how to unlock your keychain via password prompt. You need to have Jenkins perform the unlock without a prompt.
Have Jenkins run the following before your build command:
security unlock-keychain -p <YourPassword> ~/Library/Keychains/login.keychain
If you'd rather not store the password in cleartext script area of your build, Jenkins offers various ways to store secrets and retrieve them as variables. Here's a decent write-up on doing that: https://support.cloudbees.com/hc/en-us/articles/203802500-Injecting-Secrets-into-Jenkins-Build-Jobs
Alternatively:
security unlock-keychain -p `cat ~/.file_with_your_password` ~/Library/Keychains/login.keychain

Xcode 5 continuous integration CodeSign fail

Hi there.
I'm trying to configure continuous integration for my iOS app with xcode 5 and OS X Server. I added certificates and p12 to system KeyChain, I also copied provisioning profiles to server folder for profiles.
Integration fails and log shows error message
Short message:
Command /usr/bin/codesign failed with exit code 1
Full message:
CodeSign
/Library/Server/Xcode/Data/BotRuns/Cache/c60acccd-d128-d128-b0e3-070a65bdd9dc/DerivedData/Build/Intermediates/ArchiveIntermediates/MomentSeller/InstallationBuildProductsLocation/Applications/MomentSeller.app
cd /Library/Server/Xcode/Data/BotRuns/Cache/c60acccd-d128-d128-b0e3-070a65bdd9dc/source/Moment
setenv CODESIGN_ALLOCATE /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Using code signing identity "iPhone Distribution: Company Name. (ZX6C5SJYP9)" and provisioning profile "Moment Seller Production"
(E6FC8157-98F3-4A28-BFF3-36EFA6334019)
codesign --force --sign C2F81E886780437B90630A748111D3340DC8EFC8 --resource-rules=/Library/Server/Xcode/Data/BotRuns/Cache/c60acccd-d128-d128-b0e3-070a65bdd9dc/DerivedData/Build/Intermediates/ArchiveIntermediates/MomentSeller/InstallationBuildProductsLocation/Applications/MomentSeller.app/ResourceRules.plist
--entitlements /Library/Server/Xcode/Data/BotRuns/Cache/c60acccd-d128-d128-b0e3-070a65bdd9dc/DerivedData/Build/Intermediates/ArchiveIntermediates/MomentSeller/IntermediateBuildFilesPath/Moment.build/Release-iphoneos/MomentSeller.build/MomentSeller.xcent
/Library/Server/Xcode/Data/BotRuns/Cache/c60acccd-d128-d128-b0e3-070a65bdd9dc/DerivedData/Build/Intermediates/ArchiveIntermediates/MomentSeller/InstallationBuildProductsLocation/Applications/MomentSeller.app
/Library/Server/Xcode/Data/BotRuns/Cache/c60acccd-d128-d128-b0e3-070a65bdd9dc/DerivedData/Build/Intermediates/ArchiveIntermediates/MomentSeller/InstallationBuildProductsLocation/Applications/MomentSeller.app:
User interaction is not allowed. Command /usr/bin/codesign failed with
exit code 1
** ARCHIVE FAILED **
The following build commands failed: CodeSign
/Library/Server/Xcode/Data/BotRuns/Cache/c60acccd-d128-d128-b0e3-070a65bdd9dc/DerivedData/Build/Intermediates/ArchiveIntermediates/MomentSeller/InstallationBuildProductsLocation/Applications/MomentSeller.app
(1 failure)
Any ideas?
Thanks.
I've run into this problem myself. This blog helped me out. http://matt.vlasach.com/xcode-bots-hosted-git-repositories-and-automated-testflight-builds/
As posted by Dominik Kroutvar:
User interaction is not allowed. Command /usr/bin/codesign failed with
exit code 1
This error happens when the following setting is not made manually. As
described in one of the posts above you have to put the mobileprofile
for code signing in the system keychain. The certificate is called
iPhone Distribution:. This distribution certificate must have a
private key! Open the Settings dialog either by double click on the
private key or through the context menu>Get Info. Then go to Access
control and put /usr/bin/codesign in the table. This allows the
codesign application to sign your built application. After that
everything should work without the meaningless codesign error exit
code 1.
As already stated you simply need to run security -v unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN".
Run this before the build and the codesign succeeds.

Resources