Name of Provisioning Profile used to sign an iPhone app? - iphone

I wrote a script that uses xcodebuild to generate an AdHoc build of an iPhone application.
I would like to edit this script to output the name of the Provisioning Profile used to sign the build.
This would allow me to include the Provisioning Profile in the zip that is automatically generated. This way, I could automatically send the archive to the AdHoc testers and be sure that they have the right Provisioning Profile to install the app.
Is there any way to extract the Provisioning Profile name or file used to sign the application:
from the builded and signed application
from the Xcode project (I don't want to manually parse the project.pbxproj file, as this solution might break in the next Xcode update)
any other way that is scriptable
Unforgiven suggested to use the command security to get the name of the certificate used to sign the app. Once you have this information, is there any way to then find the name of the Provisioning Profile?
Here is what I tried:
Sadly, the output of xcodebuild during the build does not contain this information. During the CodeSign step, there is the line:
/usr/bin/codesign -f -s "iPhone Distribution: My name" ...
but I can't match this with a certificate.
I looked into using codesign, and the command /usr/bin/codesign -d -vvv --entitlements - -r - /Users/lv/Desktop/TicTacBoo.app/TicTacBoo looked promising, but it doesn't give me the information I need.
I haven't found any useful option in xcodebuild either.

The provisioning profile is already in the application. You don't need another copy in your zip file (unless your testers do not understand how to use the copy inside of the application.)
It's named YourApplication.app/embedded.mobileprovision
This doesn't answer your question because the original filename is lost, however it does seem to solve your bigger problem.

You can use the "security" command from the terminal; unfortunately, at least on my MBP with Snow Leopard it appears to cause a segmentation fault in one of the commands you need to issue. For more information, issue from the terminal
man security
Anyway, here is what you can try, assuming your development/production certificates are stored in the login keychain:
security unlock-keychain login.keychain;
security find-certificate -a -c "iPhone Distribution: Your name" -p > cert.pem;
The second command causes the segmentation fault (caused by the -c argument), but it should be exactly what you need. Alternatively, you can use
security find-identity -p codesigning -v;
to get a list of all of the valid certificates you can use to code sign your applications.
For each certificate, the output also contains the SHA1 message digest, so that you can easily search the certificate in the keychain matching the SHA1 digest associated to "iPhone Distribution: Your name". This however, requires that you write your own application using the keychain APIs.
Let me know if this works on your mac or if you experience the same segmentation fault issue.
EDIT/UPDATE: I have verified the bug on other machines and filed a bug to Apple.

How about looking in the _CodeSignature/CodeResources plist file (of the built application) for files of type "mobileprovision"?
Here's a way to do that using defaults(1) to read the plist file. You have to copy the CodeResources file to something with the ".plist" suffix to keep defaults happy...
cp /build/Distribution-iphoneos/MyApp.app/_CodeSignature/CodeResources /tmp/defaults.plist
defaults read /tmp/defaults files |grep .mobileprovision |grep -v embedded.mobileprovision
(in my test case, there were 2 .mobileprovision entries there; ignore the one named "embedded.mobileprovision")

Related

How do I embed a third-party xcframework in my Xcode project?

I'm trying to embed the following third party framework in my Xcode project: https://dicomhero.com/downloads/ but Xcode complains that Command CodeSign failed with a nonzero exit code. I've tried one of several things including:
codesign -d -v dicomhero6.xcframework
Creating a dummy Swift Package with the framework: https://developer.apple.com/documentation/xcode/distributing-binary-frameworks-as-swift-packages
But none of them seem to have worked, and Xcode crashes at start time and suggest moving the framework to the Trash. Is this an issue I can fix on my end, or would I have to contact the developer? Any help would be greatly appreciated!
I tried to download the framework using the link you provided, and then embed it into an empty project. Xcode showed the alert about using code from untrusted source.
When you download a file from internet it receives "quarantine" attributes:
$ xattr xcframework.zip
com.apple.macl
com.apple.quarantine
com.apple.metadata:kMDItemDownloadedDate
com.apple.metadata:kMDItemWhereFroms
com.apple.lastuseddate#PS
com.apple.macl and com.apple.quarantine are the most interesting here.
Not sure what exactly macl means, but I assume it to be some kind of Access Control Layer. The presence of this attribute makes the OS to show this "untrusted developer" alert.
These attributes could be removed with xattr -d. com.apple.quarantine attr gets removed just fine, however com.apple.macl reappears after deleting it.
When you unzip a zip archive by just double clicking on it, Finder re-applies these com.apple.quarantine and com.apple.macl attributes to the unarchived file or directory. But if you decompress the archive with unzip, com.apple.macl will not be applied to the decompressed data.
You could download the archive and then do:
$ cd ~/Downloads
$ unzip xcframework.zip
$ sudo xattr -dr com.apple.quarantine dicomhero6.xcframework
Then drag and drop .xcframework to your Xcode project.
Alternatively you get rid of the "developer cannot be verified" error by just opening the Security and Privacy pane in the System Preferences and "Allow Anyway".

Command /usr/sbin/chown failed with exit code 1?

Each time I try to archive my application to submit it to apple Xcode keeps giving me this error! I'v Triple checked that in the Cocos2d libraries Target i made that my Install Group & Install Owner are correct and i;v restarted my computer & reinstalled Xcode. It runs just fine in the simulator. But like i said as soon as I hit Archive it gives me this error
SetOwnerAndGroup "Home:staff" "/Users/Home/Library/Developer/Xcode/DerivedData/Swimmu-bdswkmmaijgxvyasdnmkpmnfgxji/ArchiveIntermediates/Swimmu/InstallationBuildProductsLocation/usr/local/lib/libcocos2d libraries.a"
cd /Users/Home/Documents/Swimmu
setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/usr/sbin/chown -RH "Home:staff" "/Users/Home/Library/Developer/Xcode/DerivedData/Swimmu-bdswkmmaijgxvyasdnmkpmnfgxji/ArchiveIntermediates/Swimmu/InstallationBuildProductsLocation/usr/local/lib/libcocos2d libraries.a"
chown: /Users/Home/Library/Developer/Xcode/DerivedData/Swimmu-bdswkmmaijgxvyasdnmkpmnfgxji/ArchiveIntermediates/Swimmu/InstallationBuildProductsLocation/usr/local/lib/libcocos2d libraries.a: No such file or directory
Command /usr/sbin/chown failed with exit code 1
Yet a third problem with the same error... Different solution as well. In my case, the default install group $(INSTALL_GROUP) was a windows domain and had \ in it, which translated to space and caused the build to fail.. I fixed it by changing my install group to be admin.
Your name entered in Install Owner should match the name of your Mac OS login under which you are logged in and the Name of Apple's Dev License and certificates.
So go to System Preferences | Users & Groups and set a Full name that matches your Apple's Developer License name
"libcocos2d libraries.a"
The problem may be related to the space in the library. If you created that library target it should be easy to fix by changing the name of the library target to "cocos2d_libraries".
I had a different problem than you, but had the same error:
Command /usr/sbin/chown failed with exit code 1
When I created my XCode project, my app name had a space in it, so trying to deploy my app always failed. I was able to fix this by using a Custom Archive Name.
In XCode 4...
Edit the Deployment Scheme
Click on the Archive tab
Then specify an Archive Name that doesn't have spaces in it.
I was able to fix this by cleaning the project, deleting derived data, and restarting Xcode.

Force symbolicatecrash to use a specific .app and .dSYM file?

I have a .crash log from an ad-hoc version of my app that symbolicatecrash refuses to symbolicate. I have already applied the .patch to remove the 'die' command in symbolicatecrash after apple broke the script in XCode 3.2.6. Symbolicatecrash has worked for other crash logs but refuses to symbolicate this one. My ad hoc app was built and is stored in "Archived Applications", so there is no reason why XCode shouldn't be able to find it. I have even copied the .app and .dSYM files right next to the .crash log, no dice.
Is there a way I can force symobolicatecrash to use a specific .app and .dsym files even if it doesn't think it applies?
Turns out I accidentally deleted the build associated with the crash log. symbolicatecrash uses the following logic to figure out if there are symbols associated with a crash log:
At the bottom of every crash log is a list of Binary Images. Yours is listed first. There is a guid associated with your binary image. For example:
0x1000 - 0x2befff +MyApp armv7 <a95274a309d73458a40cb5a6fd317a1c> /var/mobile/Applications/91884634-DA1A-4BDB-9E1E-6F487D8F25D7/MyApp.app/MyApp
The relevant guid is: a95274a309d73458a40cb5a6fd317a1c
It next uses the tool mdfind, which looks at metadata associated with files in your file system, for the uppercase and hyphenated form of that GUID.
From your archived applications, if you click on MyApp.app.dSYM, then Get Info, then disclose More Info, you will see dSYM UUIDs and two GUIDs listed. The second GUID is the one that is relevant. It will be of the form:
A95274A3-09D7-3458-A40C-B5A6FD317A1C
Provided that the second GUID matches the guid in the .crash file, symbolicate crash will be able to find and symbolicate. If they don't match, it's the wrong binary.
Cheers,
Eric
OK turns out this answer is now what is required for the latest XCode 5.1.1:
Recently I had a crash log from an ad-hoc build. XCode refused to Symbolicate. I had an archived build a few hours old and I wanted to force a symbolication using my archived build. Here is how I did it:
1) First I opened a terminal window and went to the directory containing my archive. I ran this command:
xcrun dwarfdump --uuid Example.app/Example | tr '[:upper:]' '[:lower:]' | tr -d '-'
This pulled out the dsym_uuid of the archived build. The tr command converts the guid from an uppercase guid with dashes to a lowercase guid with no dashes
2) I went into the .crash file and changed the guid associated with my binary in the crash log to the guid associated with the xcdarchive on my machine
For example, went from
0x80000 - 0x49efff +MyApp armv7 <aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa> /var/mobile/Applications/DC23BDC0-75E3-4DCA-8AC3-099889CE22E0/MyApp.app/MyApp
to
0x80000 - 0x49efff +MyApp armv7 <bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb> /var/mobile/Applications/DC23BDC0-75E3-4DCA-8AC3-099889CE22E0/MyApp.app/MyApp
3) From the terminal, I set my DEVELOPER_DIR environment var to:
export DEVELOPER_DIR=/Applications/XCode.app/Contents/Developer
4) Finally, I ran this beast of a command:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/PrivateFrameworks/DTDeviceKitBase.framework/Versions/A/Resources/symbolicatecrash -v MyApp.crash /Users/me/Library/Developer/Xcode/Archives/2013-05-31/MyApp\ 5-31-13\ 7.00\ PM.xcarchive/Products/Applications/MyApp.app
Note that the path to symbolicatecrash changes in newer versions of XCode, to:
/Applications/Xcode6.app/Contents/SharedFrameworks/DTDeviceKitBase.framework/Versions/A/Resources/symbolicatecrash
This command run symbolicatecrash against your archive using the .crash file you have
A little additional information which may help.
I have two UUIDs listed, and my first one matches the one in the crash log, not the second. However my crash comes from a device running ARM6, whereas the OPs came from one running ARM7
I therefore deduce that each UUID matches an architecture, if you build for ARM6 and ARM7 and the crash comes from a device running ARM6, then you'll need to match the first UUID, if it is running ARM7 you'll need the second.
If you only have one UUID, I think you probably only built for one architecture.
This is mainly deduction, but seems likely.
There is a new process for extracting build UUIDs described here:
https://developer.apple.com/library/ios/qa/qa1765/_index.html
This is now the magical command to run to extract build UUID:
xcrun dwarfdump --uuid Example.app/Example | tr '[:upper:]' '[:lower:]' | tr -d '-'
I have been able to force symbolicatecrash to symbolicate my crash log by overriding the dSYM UUID to the expected crashlog's UUID.
Put dsym and unsymbolicated.crash in same folder.
Run ./symbolicatecrash in Verbose mode:
./symbolicatecrash unsymbolicated.crash > symbolicated.crash -d ./MyApp.app.dSYM/ -v
Scroll to bottom and find the crashlog's expected UUID:
Did not find dsym for db3e90fa8b6d462c9d65049ab1f22ea4
-- [db3e90fa8b6d462c9d65049ab1f22ea4] NO MATCH (spotlight)
In Finder right click your .dsym file and click "Get Info" under "More Info" section header you will have the dSYM UUIDs: property. Copy this value to clipboard.
Using a hex editor (I used iHex from App Store) open MyApp.dysm/Contents/Resources/DWARF/MyApp and CMD+F the copied UUID.
Replace this UUID with the expected expected one in this example I replaced it with: "db3e90fa8b6d462c9d65049ab1f22ea4".
NOTE: While this is exceptionally hacky and does not guarantee success and will more then likely result in mis-symbolicated crash with nonsensical method names but maybe it will work for you!

update iphone app "CodeResources file must be a symbolic link"

I tried to update an iphone app, which lies in an other "itunes connect" profile. I used "application loader" and everything is fine until I try to upload the zip file
I get this strange message and cant figure out whats going wrong
"The CodeResources file must be a symbolic link to _CodeSignature/CodeResources"
I opened the bundle and the folder _CodeSignature is there.
I compiled the app with my distribution profile (no problems)
How are you zipping it? I'm betting that FooApp.app/CodeResources is a file, not a symlink.
If you're using command-line "zip", you need to use zip -y -r to preserve the symlink.
Had the same issue with XCode 3.2.5 (new submission interface), and all it took was to:
delete the build folder
clean, and then
build and archive again.
I had the same issue. But then I noticed that I was building in release mode to the simulator, and not a device. When I targeted a device, I got the proper application file, which I then zipped with the iTunes Artwork and submitted without issue.
I had the same issue here but I "fixed" it after I changed the "Deployment Target" from 2.0 to 3.0 in the target I was building and removed the "Architectures" to only armv6 (before I had both armv6 and armv7). Finally I had to put 'No' to 'Build Active Architecture Only'.
I haven't figured out why I keep getting this error for every binary I create. I've followed all the standard procedures (double-checking my project settings, deleting build folders, cleaning all targets, removing and reinstalling certificates and provisioning profiles, creating and installing new certificates and provisioning profiles, repairing disk permissions, etc) but none of them seem to solve the problem.
I think the problem is that my XCode installation is unable to create symbolic links. I might reinstall it (or even OS X) to see if that fixes the issue permanently.
But in the mean time, this works for me. I use terminal to navigate into the binary and run the following commands
rm CodeResources
ln -s _CodeSignature/CodeResources CodeResources
This deletes the invalid CodeResources file and replaces it with the required symbolic link to _CodeSignature/CodeResources.
I just ran across this issue. It turned out, I had two info.plist files in my resources folder (one for the iPhone version and another for the iPad version). Once I took care of that, the issue went away.
Try this on the command line:
cd (to where your project is)
ln -s _CodeSignature/CodeResources CodeResources
I've just had the same problem. Turns out the project file project.pbxproj in Project.xcodeproj had been corrupted while uploading to an SVN server.
My solution was simply to revert to an older revision, which worked fine.
You have to:
1. Enter the AppName.app folder
2. Create a file named CodeResources
3. Open the file with a plain text editor
4. Type in _CodeSignature/CodeResources (The path where the actual CodeResources file is.)
{The app will now know where the CodeResources file is, and will have an account for all the files in the .app folder.}

Using a non-default keychain in Xcode

How can I use a non-default keychain in Xcode iPhone project.
I have already tried '--keychain mycerts.keychain' in 'Other Code Signing Flags' in 'Code signing' build settings.
After a long time of research, I concluded that it cannot be done.
The codesign tool requires an absolute path to the keychain.
Use an additional "Run Script Build Phase" to call the codesign tool with the custom keychain. The embedded script should look like:
codesign -s 'your-identity' --keychain "${SRCROOT}/path/to/keychain" "${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
in the Build setting under Code Signing -> Other code signing Flags, create a flag "--keychain keychain-name.keychain"
While inconvenient, you can temporarily change your "default Keychain" to whichever keychain has your certificate/keys. XCode will then search that keychain during code-signing. You can do this via Keychain Access.app or the security(1) command-line utility. You're responsible for unlocking said keychain yourself, however.
This problem can be solved by setting the keychain search list to include your keychain:
security list-keychains -s login.keychain mycerts.keychain etc.keychain
To view the active keychain search list, use the same command without the -s param:
security list-keychains
A great link for reference is here: https://ss64.com/osx/security-keychain.html