21. Januar, 2011

Resign an iPhone App, insert new Bundle ID and send to Xcode Organizer for Upload

Von webfraggle

The challenge: Create a Flash App, pack it with the Packager for iPhone with my certificate and provisioning profiles, send it to the client that he can resign it with his informations and import it into Xcode Organizer for validating and uploading to the App Store.

I did some research and found out that all signing processes in Xcode (while building or resigning in Organizer) is done with a tool called codesign. This tool can also be used via Terminal. I tried it with my Flash .ipa and the included .app. It worked.

But because it is difficult always to use the terminal with more lines long commands I decided to develop a little AIR tool using the new NativeProcess API.

And here is how it works:

1. Select the .ipa.

What is executed:
Old files in this directory are deleted.
The .ipa will be unzipped.

unzip -o /path/to/YourApp.ipa -d /path/to

Find the first .app file inside /Payload.
Load the Info.plist file.
Use the CFBundleExecutable as the binary filename.

The current Signing Authority is read and the entitlements were extracted. The entitlements are needed, because without them the Xcode Organizer can’t sign the app with a new Provisioning Certificate.

codesign -d -vv --entitlements "/path/to/entitlements" /path/to/Payload/YourApp.app/YourApp

2. Sign it with a new Signing Authority.
Enter your new Signing Authority. The correct String can be copy&pasted via your keychain.

3. Enter new Bundle Identifier (App ID Suffix)
This must match with your App ID created in the Apple Developer Provisioning Portal.

4. Resign App and change App ID.
The binary will be resigned with your new informations.
What is executed:
First, codesign with your extracted entitlements:

codesign -f -s "New Signing Authority" -i "new.bundle.id" --entitlements "/path/to/entitlements" -vv /path/to/Payload/YourApp.app/YourApp

Second, change the the Bundle Identifier also inside the Info.plist file.

5. Send it to Xcode Organizer for validating and uploading
After clicking the button open Xcode and go to Window > Organizer

How does this work:
This was a little bit tricky and needed much research how the Organizer wants the Apps.
Every Archived Build is moved to /UserDir/Library/MobileDevice/Archived Applications/UUID.
So first a UUID is generated an a directory with it is created.
e.g. /UserDir/Library/MobileDevice/Archived Applications/8D3E5DF2-F079-4A3B-460D-5525A6C5472B

Then the .app file is copied to that location. But the Orgnanizer needs an ArchiveInfo.plist file with correct informations in it.

My tool uses a standard template and changes all needed information, so that they are matching the informations in your .apps Info.plist file. These are CFBundleIdentifier, CFBundleDisplayName, CFBundleVersion, MinimumOSVersion, DTPlatformVersion, DTSDKName, CFBundleExecutable, CFBundleDisplayName.
Some other data needs to be generated out of other information. e.g. the UUID of the directory or the Archivedate.
Apple counts dates from 01.01.2001 – 00:00:00. Surprising.

That’s it.

At the moment this works only with Flash iPhone Apps. I tried it quickly with another .ipa but it fails. I did no investigation in it because at the moment I didn’t need it.

Xcode Organizer fails silent. But you can look at the Terminal messages of codesign in your Console Log (Konsole in german). Maybe there you can find why validating or uploading fails.

iOSSendToOrganizer.dmg Installer

If you make changes or enhancements please share them with me
iOSSendToOrganizer Source