Read your .mobileprovisioning profile with Objective-C

So, I'm trying to open a .mobileprovisioning profile to read what's inside ... this is what I am doing:

NSString *path = [pathURL path]; NSData *data = [[NSFileManager defaultManager] contentsAtPath:path]; 

Of course, I read the data, but I do not find a way to get this data into something useful ... NSDictionary, NSString or something else ...

I already tried:

 NSString *newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 

Any idea? I am sure that this is an encoding problem, but I can’t solve it after reading and searching for some time ... I think the provisioning profile is saved as hexadecimal, but I don’t know how to read this from objective-c. I found this, but there was no useful answer.

How to convert NData filled with hexadecimal values ​​to NSString

Thanks!

+6
source share
3 answers

The following method should do what you want. As @rbrockerhoff says the mobile provisioning profile is a coded CMS message. This method uses a decoder for the first decoding of data using CMS functions, and then creates a plist string / content from the decoded data. Then this string can be converted to a dictionary, which is returned from the method. The dictionary will contain all the details from the profile of the provision of mobile services.

 - (NSDictionary *)provisioningProfileAtPath:(NSString *)path { CMSDecoderRef decoder = NULL; CFDataRef dataRef = NULL; NSString *plistString = nil; NSDictionary *plist = nil; @try { CMSDecoderCreate(&decoder); NSData *fileData = [NSData dataWithContentsOfFile:path]; CMSDecoderUpdateMessage(decoder, fileData.bytes, fileData.length); CMSDecoderFinalizeMessage(decoder); CMSDecoderCopyContent(decoder, &dataRef); plistString = [[NSString alloc] initWithData:(__bridge NSData *)dataRef encoding:NSUTF8StringEncoding]; NSData *plistData = [plistString dataUsingEncoding:NSUTF8StringEncoding]; plist = [NSPropertyListSerialization propertyListWithData:plistData options:NSPropertyListImmutable format:nil error:nil] } @catch (NSException *exception) { NSLog(@"Could not decode file.\n"); } @finally { if (decoder) CFRelease(decoder); if (dataRef) CFRelease(dataRef); } return plist; } 
+8
source

A .mobileprovisioning file is a coded CMS message.

See https://developer.apple.com/library/mac/documentation/security/Reference/CryptoMessageRef/Reference/reference.html and the API for decoding it for more details.

If you just need a list of encoded properties as text, a quick and dirty hack is to get the byte pointer for your NSData, scan the beginning of "<? Xml" and before closing "</PLIST>". Then make it an NSString.

+2
source

You can simply force open the mobile device provisioning profile in TextEdit, where you can see the internal content and in which you can trim / edit the encoded CMS message or whatever. Then you can simply decode the NSData encodewithUTF string method.

Hope this helps.

0
source

Source: https://habr.com/ru/post/955312/


All Articles