Skip to content

Commit

Permalink
Merge pull request #47 from ealeksandrov/fix-entitlements
Browse files Browse the repository at this point in the history
Handle error when parsing entitlements plist
  • Loading branch information
ealeksandrov authored Aug 6, 2023
2 parents 5328732 + 1bfa183 commit 5fbae64
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
41 changes: 33 additions & 8 deletions ProvisionQL/GeneratePreviewForURL.m
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,23 @@ void displayKeyAndValue(NSUInteger level, NSString *key, id value, NSMutableStri
NSString *bundleExecutable = [appPropertyList objectForKey:@"CFBundleExecutable"];

NSString *binaryPath = [basePath stringByAppendingPathComponent:bundleExecutable];
// get entitlements: codesign -d <AppBinary> --entitlements :-
// get entitlements: codesign -d <AppBinary> --entitlements - --xml
NSTask *codesignTask = [NSTask new];
[codesignTask setLaunchPath:@"/usr/bin/codesign"];
[codesignTask setStandardOutput:[NSPipe pipe]];
[codesignTask setArguments:@[@"-d", binaryPath, @"--entitlements", @":-"]];
[codesignTask setStandardError:[NSPipe pipe]];
[codesignTask setArguments:@[@"-d", binaryPath, @"--entitlements", @"-", @"--xml"]];
[codesignTask launch];

NSData *pipeData = [[[codesignTask standardOutput] fileHandleForReading] readDataToEndOfFile];
NSData *outputData = [[[codesignTask standardOutput] fileHandleForReading] readDataToEndOfFile];
NSData *errorData = [[[codesignTask standardError] fileHandleForReading] readDataToEndOfFile];
[codesignTask waitUntilExit];

return pipeData;
if (outputData.length == 0) {
return errorData;
}

return outputData;
}

OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview, CFURLRef url, CFStringRef contentTypeUTI, CFDictionaryRef options) {
Expand Down Expand Up @@ -534,13 +540,27 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
[synthesizedInfo setObject:synthesizedValue forKey:@"TeamIds"];
}

BOOL showEntitlementsWarning = false;
if (codesignEntitlementsData != nil) {
// read the entitlements directly from the codesign output
NSDictionary *entitlementsPropertyList = [NSPropertyListSerialization propertyListWithData:codesignEntitlementsData options:0 format:NULL error:NULL];
NSMutableString *dictionaryFormatted = [NSMutableString string];
displayKeyAndValue(0, nil, entitlementsPropertyList, dictionaryFormatted);
synthesizedValue = [NSString stringWithFormat:@"<pre>%@</pre>", dictionaryFormatted];

if (entitlementsPropertyList != nil) {
NSMutableString *dictionaryFormatted = [NSMutableString string];
displayKeyAndValue(0, nil, entitlementsPropertyList, dictionaryFormatted);
synthesizedValue = [NSString stringWithFormat:@"<pre>%@</pre>", dictionaryFormatted];
} else {
NSString *outputString = [[NSString alloc] initWithData:codesignEntitlementsData encoding:NSUTF8StringEncoding];
NSString *errorOutput;
if ([outputString hasPrefix:@"Executable="]) {
// remove first line with long temporary path to the executable
NSArray *allLines = [outputString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
errorOutput = [[allLines subarrayWithRange:NSMakeRange(1, allLines.count - 1)] componentsJoinedByString:@"<br />"];
} else {
errorOutput = outputString;
}
showEntitlementsWarning = true;
synthesizedValue = errorOutput;
}
[synthesizedInfo setObject:synthesizedValue forKey:@"EntitlementsFormatted"];
} else {
// read the entitlements from the provisioning profile instead
Expand All @@ -556,6 +576,11 @@ OSStatus GeneratePreviewForURL(void *thisInterface, QLPreviewRequestRef preview,
[synthesizedInfo setObject:@"No Entitlements" forKey:@"EntitlementsFormatted"];
}
}
if (showEntitlementsWarning) {
[synthesizedInfo setObject:@"" forKey:@"EntitlementsWarning"];
} else {
[synthesizedInfo setObject:@"hiddenDiv" forKey:@"EntitlementsWarning"];
}

value = [propertyList objectForKey:@"DeveloperCertificates"];
if ([value isKindOfClass:[NSArray class]]) {
Expand Down
13 changes: 8 additions & 5 deletions ProvisionQL/Resources/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
text-transform: uppercase;
}

.expired {
.expired, .warning {
color: darkred;
}
.expiring {
Expand Down Expand Up @@ -116,7 +116,7 @@
a:hover { color: #fff; }
a:visited { color: #aaa; }

.expired {
.expired, .warning {
color: red;
}
.expiring {
Expand Down Expand Up @@ -144,7 +144,7 @@ <h1>__AppInfoTitle__</h1>
Name: <strong>__CFBundleName__</strong><br />
Version: __CFBundleShortVersionString__ (__CFBundleVersion__)<br />
BundleId: __CFBundleIdentifier__<br />
<div class="extension __ExtensionInfo__">
<div class="__ExtensionInfo__">
Extension type: __NSExtensionPointIdentifier__<br />
</div>
DeviceFamily: __UIDeviceFamily__<br />
Expand All @@ -156,7 +156,7 @@ <h2>App Transport Security</h2>
__AppTransportSecurityFormatted__
</div>

<div class="provision __ProvisionInfo__">
<div class="__ProvisionInfo__">
<div class="__AppInfo__">
<h1>Provisioning</h1>
Profile name: <strong>__Name__</strong><br />
Expand All @@ -172,6 +172,9 @@ <h1><span class="__ExpStatus__">__Name__</span></h1>
Expiration Date: <strong><span class="__ExpStatus__">__ExpirationDateFormatted__ (__ExpirationSummary__)</span></strong><br />

<h2>Entitlements</h2>
<div class="__EntitlementsWarning__ warning">
<strong>Entitlements extraction failed.</strong>
</div>
__EntitlementsFormatted__

<h2>Developer Certificates</h2>
Expand All @@ -181,7 +184,7 @@ <h2>Devices (__ProvisionedDevicesCount__)</h2>
__ProvisionedDevicesFormatted__

</div>
<div class="fileInfo">
<div>
<h2>File info</h2>
__FileName__<br />
__FileInfo__<br />
Expand Down

0 comments on commit 5fbae64

Please sign in to comment.