Ios – Codesigning ios app from the command line

codesigncommand lineios

I'm working on creating a command line workflow for my ios development and I'm stuck at the last stage: codesigning.

I built an app for armv7 and armv7s, link it and create the app bundle:

$ codesign -d -v path/to/myapp.app
Executable=/path/to/myapp.app/myapp
Identifier=com.mycompany.myapp
Format=bundle with Mach-O universal (armv7 armv7s)
CodeDirectory v=20200 size=2292 flags=0x0(none) hashes=105+5 location=embedded
Signature size=4332
Signed Time=Sep 7, 2014, 2:47:55 AM
Info.plist entries=26
TeamIdentifier=XXXXXX
Sealed Resources version=2 rules=5 files=3
Internal requirements count=1 size=192

I get a codesigning hash XXXXX from:

$ security find-identity -pcodesigning -v
  1) XXXXX "iPhone Developer: My Name (YYYY)"
     1 valid identities found

However, after I codesign using the following:

codesign --force -vvvv --sign XXXXX --resource-rules=path/to/myapp.app/ResourceRules.plist --entitlements path/to/myapp.xcent path/to/myapp.app
path/to/myapp.app: replacing existing signature
path/to/myapp.app: signed bundle with Mach-O universal (armv7 armv7s) [com.mycompany.myapp]

It still seems to be unhappy:

$ codesign --verify -vvvv path/to/myapp.app
path/to/myapp.app: invalid Info.plist (plist or signature have been modified)
In architecture: armv7s

As a reference I built a (similar) app using xcode (I actually used the codesign line from the logs to sign this app), and it works just fine:

$ codesign --verify -vvvv path/to/otherapp.app
path/to/otherapp.app: valid on disk
path/to/otherapp.app: satisfies its Designated Requirement

I'm definitely sure that I have correct codesigning hash, since I have signed and deployed apps via xcode. I'm just trying to reproduce the same steps on the command line and failing miserably. Obviously if I changed info.plist or something, I would expect to see this error, but I don't expect to see it right after I do the codesign step. Some black magic is at work here. Could anyone shed some light or help with some pointers please?

EDIT:

I removed armv7s and just built armv7 and now it seems happy at the codesign verification stage, however I still can't deploy the app with the following error from the logs:

installd[26777] : 0x10050c000 verify_signer_identity: MISValidateSignatureAndCopyInfo failed for /var/tmp/install_staging.Mvi7tR/myapp.app/myapp: 0xe8008019

I have no idea what's going on :\

ANOTHER EDIT:

I got the codesign verification to fail again, heh. So, if I verify myapp.app, then it says everything is OK. However, if I try to verify myapp.app/myapp binary directly, then it says that verification failed (with the above error except for architecture armv7)

Best Answer

Long story short, if I codesign myapp.app/myapp instead of myapp.app, then I can deploy the app to my phone without any issues. I can't seem to codesign both yet, as one of myapp.app/myapp or myapp.app fails codesign --verify, but it's good enough for now since I can deploy the app.

Hopefully this helps someone who is bashing their head against the wall.

I'll try and figure out if I can codesign both on one line somehow, but it's a minor posterity issue.