Friday, September 27, 2013

Re-sign a .IPA file

The problem:
  1. To re-sign a .ipa file with a different distribution provisioning profile.
  2. To change the bundle identifier.
Required files:
  1. The .ipa file.
  2. The distribution provisioning profile. (.mobileprovision)
  3. Entitlements.plist
Put all the files under the same directory.

Create "Entitlements.plist":
Copy the following code in a text file and make sure that the extension is (.plist).
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>application-identifier</key>
    <string>kjhdfsui.com.your.bundle.id</string>
    <key>get-task-allow</key>
    <false/>
</dict>
</plist>
To get the bundle-id value used in "Entitlements.plist" (the previous piece of code), open (.mobileprovision) using an editor and copy the value under "Entitlements".

Re-sign:
  1. Unzip the .ipa file. in the terminal type
    unzip MyApp.ipa
  2. Inside the (Payload) folder, you'll find the .app file. Open it by right click > show package content.
  3. find the (info.plist) file and open it using Xcode. replace the old bundle identifier with the new one.
  4. Open the terminal and move to the directory that contains the (.ipa) file.
  5. Remove the old code signature
    rm -r "Payload/MyApp.app/_CodeSignature" "Payload/MyApp.app/CodeResources" 2> /dev/null | true
    
  6. Replace the embedded mobile provisioning profile
    cp "MyEnterprise.mobileprovision" "Payload/MyApp.app/embedded.mobileprovision"
    
  7. Re-sign
    /usr/bin/codesign -f -s "iPhone Distribution: Certificate Name" --resource-rules "Payload/MyApp.app/ResourceRules.plist" --entitlements Entitlements.plist "Payload/MyApp.app"
    
  8. Re-package
    zip -qr "MyApp.resigned.ipa" Payload
    
  9. To submit the app:
    1. Create an app in itunes connect.
    2. Use "Application loader" to upload the app.
For some reason you may face this error "Codesign object file format invalid or unsuitable" in step #7. to solve it, type the following in the terminal:
export CODESIGN_ALLOCATE="/Applications/Xcode.app/Contents/Developer/usr/bin/codesign_allocate"

If you have many versions of Xcode, then you'll need to specify a version that contains "codesign_allocate".

28 comments: