Separate check of using XPC installer and XPC downloader.

This commit is contained in:
Dmytro Tretiakov committed 2014-05-07 12:43:28 +03:00
1 parent ceedfba634
commit acf758e485
8 files changed
+106 -29

No files matched your search

+1 -1
View File
@@ -64,7 +64,7 @@
if ([delegate respondsToSelector:@selector(appcast:willFetchURLRequest:)])
[delegate appcast:self willFetchURLRequest:request];
if ([SUUpdater shouldUseXPC])
if ([SUUpdater shouldUseXPCDownloader])
{
download = (NSURLDownload *)[[SUXPCURLDownload alloc] initWithRequest:request delegate:self];
}
+1 -1
View File
@@ -35,7 +35,7 @@ static NSString * const kSUAutomaticUpdateParamName = @"autoupdate";
[request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
[self updateURLRequestIfNeeds:request];
if ([SUUpdater shouldUseXPC])
if ([SUUpdater shouldUseXPCDownloader])
{
[SUXPCURLDownload sendSynchronousRequest:request delegate:nil];
}
+4 -4
View File
@@ -202,7 +202,7 @@ NSArray *SUGetAllDevMateURLHosts(void)
[request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"];
[self updateURLRequestIfNeeds:request];
if ([SUUpdater shouldUseXPC])
if ([SUUpdater shouldUseXPCDownloader])
download = (NSURLDownload *)[[SUXPCURLDownload alloc] initWithRequest:request delegate:self];
else
download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
@@ -210,7 +210,7 @@ NSArray *SUGetAllDevMateURLHosts(void)
- (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSString *)name
{
if ([SUUpdater shouldUseXPC]) {
if ([SUUpdater shouldUseXPCDownloader]) {
// The downloader will determine a file name, somewhere within our sandbox.
downloadPath = nil;
[d setDestination:name allowOverwrite:YES];
@@ -387,7 +387,7 @@ NSArray *SUGetAllDevMateURLHosts(void)
#endif
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
if( [SUUpdater shouldUseXPC] )
if( [SUUpdater shouldUseXPCInstaller] )
{
[SUXPCInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:nil completionHandler:^(NSError *xpcError) {
if (xpcError != nil)
@@ -428,7 +428,7 @@ NSArray *SUGetAllDevMateURLHosts(void)
pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater];
NSString *relaunchToolPath = [relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS/finish_installation"];
NSArray *arguments = [NSArray arrayWithObjects:[host bundlePath], pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], tempDir, relaunch ? @"1" : @"0", nil];
if( [SUUpdater shouldUseXPC] )
if( [SUUpdater shouldUseXPCInstaller] )
[SUXPCInstaller launchTaskWithLaunchPath: relaunchToolPath arguments:arguments completionHandler:^{
[NSApp terminate:self];
}];
+4
View File
@@ -12,9 +12,13 @@
#import <Foundation/Foundation.h>
@interface SUCodeSigningVerifier : NSObject
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)destinationPath error:(NSError **)error;
+ (BOOL)hostApplicationIsCodeSigned;
+ (BOOL)hostApplicationIsSandboxed;
+ (BOOL)hostAppAllowsNetworkOutgoingConnections;
@end
#endif
+82 -20
View File
@@ -66,29 +66,47 @@ finally:
+ (BOOL)hostApplicationIsCodeSigned
{
// This API didn't exist prior to 10.6.
if (SecCodeCopySelf == NULL) return NO;
static BOOL sIsCodesigned = NO;
OSStatus result;
SecCodeRef hostCode = NULL;
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
if (result != 0) return NO;
static BOOL onceToken = NO;
while (!onceToken)
{
onceToken = YES;
// This API didn't exist prior to 10.6.
if (SecCodeCopySelf == NULL)
break;
SecRequirementRef requirement = NULL;
result = SecCodeCopyDesignatedRequirement(hostCode, kSecCSDefaultFlags, &requirement);
if (hostCode) CFRelease(hostCode);
if (requirement) CFRelease(requirement);
return (result == 0);
SecCodeRef hostCode = NULL;
OSStatus result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
if (result != noErr)
break;
SecRequirementRef requirement = NULL;
result = SecCodeCopyDesignatedRequirement(hostCode, kSecCSDefaultFlags, &requirement);
if (hostCode) CFRelease(hostCode);
if (requirement) CFRelease(requirement);
sIsCodesigned = (noErr == result);
}
return sIsCodesigned;
}
+ (BOOL)hostApplicationIsSandboxed
{
// This API didn't exist prior to 10.6
if (SecCodeCopySelf == NULL) return NO;
static BOOL sIsAppSandboxed = NO;
BOOL isSandboxed = NO;
do
static BOOL onceToken = NO;
while (!onceToken)
{
onceToken = YES;
// This API didn't exist prior to 10.6
if (SecCodeCopySelf == NULL)
break;
SecCodeRef hostCode = NULL;
SecRequirementRef hostRequirement = NULL;
@@ -116,14 +134,58 @@ finally:
}
status = SecCodeCheckValidity(hostCode, kSecCSDefaultFlags, hostRequirement);
if (noErr == status)
isSandboxed = YES;
sIsAppSandboxed = (noErr == status);
Cleanup();
}
while (NO);
return isSandboxed;
return sIsAppSandboxed;
}
+ (BOOL)hostAppAllowsNetworkOutgoingConnections
{
static BOOL sIsAppAllowsOutgoingConnections = NO;
static BOOL onceToken = NO;
while (!onceToken)
{
onceToken = YES;
if (![self hostApplicationIsSandboxed])
{
sIsAppAllowsOutgoingConnections = YES;
break;
}
SecCodeRef hostCode = NULL;
SecRequirementRef hostRequirement = NULL;
#define Cleanup() \
{ \
if (hostCode) CFRelease(hostCode); \
if (hostRequirement) CFRelease(hostRequirement); \
}
OSStatus status = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
if (status != noErr || hostCode == NULL)
{
Cleanup();
break;
}
CFStringRef requirementString = CFSTR("entitlement[\"com.apple.security.network.client\"] exists");
status = SecRequirementCreateWithString(requirementString, kSecCSDefaultFlags, &hostRequirement);
if (status != noErr || hostRequirement == NULL)
{
Cleanup();
break;
}
status = SecCodeCheckValidity(hostCode, kSecCSDefaultFlags, hostRequirement);
sIsAppAllowsOutgoingConnections = (noErr == status);
Cleanup();
}
return sIsAppAllowsOutgoingConnections;
}
@end
+1 -1
View File
@@ -127,7 +127,7 @@
[delegate updateAlert:self willLoadReleaseNotesWithRequest:request];
}
if ([SUUpdater shouldUseXPC])
if ([SUUpdater shouldUseXPCDownloader])
{
[releaseNotesDownloader release];
releaseNotesDownloader = (NSURLDownload *)[[SUXPCURLDownload alloc] initWithRequest:request delegate:self];
+11 -1
View File
@@ -554,7 +554,17 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
- (id)delegate { return delegate; }
- (NSBundle *)hostBundle { return [host bundle]; }
+ (BOOL)shouldUseXPC
+ (BOOL)shouldUseXPCDownloader
{
if ([SUCodeSigningVerifier hostAppAllowsNetworkOutgoingConnections])
return NO;
NSString *xpcServicePrefixPath = [[[SUUpdater sharedUpdater] hostBundle] bundlePath];
NSString *xpcServiceSuffixPath = @"Contents/XPCServices/com.andymatuschak.Sparkle.download-service.xpc";
return [[NSFileManager defaultManager] fileExistsAtPath:[xpcServicePrefixPath stringByAppendingPathComponent:xpcServiceSuffixPath]];
}
+ (BOOL)shouldUseXPCInstaller
{
if (![SUCodeSigningVerifier hostApplicationIsSandboxed])
return NO;
+2 -1
View File
@@ -12,6 +12,7 @@
- (BOOL)mayUpdateAndRestart;
+ (BOOL)shouldUseXPC;
+ (BOOL)shouldUseXPCDownloader;
+ (BOOL)shouldUseXPCInstaller;
@end