mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-30 05:28:50 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7275cb9e96 |
No files matched your search
@@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface AppInstaller : NSObject
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName;
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName restrictHostBundleToContainingBundle:(BOOL)restrictHostBundleToContainingBundle;
|
||||
|
||||
- (void)start;
|
||||
|
||||
|
||||
@@ -108,9 +108,10 @@ static const NSTimeInterval SUTerminationRequestTargetWaitDelay = 2.0;
|
||||
|
||||
BOOL _targetTerminated;
|
||||
BOOL _receivedTerminationRequest;
|
||||
BOOL _restrictHostBundleToContainingBundle;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName restrictHostBundleToContainingBundle:(BOOL)restrictHostBundleToContainingBundle
|
||||
{
|
||||
if (!(self = [super init])) {
|
||||
return nil;
|
||||
@@ -119,6 +120,7 @@ static const NSTimeInterval SUTerminationRequestTargetWaitDelay = 2.0;
|
||||
_newConnectionLock = OS_UNFAIR_LOCK_INIT;
|
||||
|
||||
_hostBundleIdentifier = [hostBundleIdentifier copy];
|
||||
_restrictHostBundleToContainingBundle = restrictHostBundleToContainingBundle;
|
||||
|
||||
_homeDirectory = [homeDirectory copy];
|
||||
_userName = [userName copy];
|
||||
@@ -296,13 +298,9 @@ static const NSTimeInterval SUTerminationRequestTargetWaitDelay = 2.0;
|
||||
if (![_updateValidator validateHostHasPublicKeys:&prevalidationError]) {
|
||||
success = NO;
|
||||
} else {
|
||||
// Falling back on code signing for prevalidation requires SUVerifyUpdateBeforeExtraction,
|
||||
// SURequireSignedFeed is off or SUSignedFeedFailureExpirationInterval is not zero,
|
||||
// the update is a regular app update, and not a delta update
|
||||
NSNumber *signedFeedFailureExpirationInterval = [_host doubleNumberForInfoDictionaryKey:SUSignedFeedFailureExpirationIntervalKey];
|
||||
BOOL signedFeedFailuresNeverExpire = _host.requiresSignedAppcast && signedFeedFailureExpirationInterval != nil && fpclassify(signedFeedFailureExpirationInterval.doubleValue) == FP_ZERO;
|
||||
|
||||
BOOL fallbackOnCodeSigning = (verifyBeforeExtraction && !archiveTypeMustValidateBeforeExtraction && [_installationType isEqualToString:SPUInstallationTypeApplication] && !signedFeedFailuresNeverExpire);
|
||||
// Falling back on code signing for prevalidation requires SUVerifyUpdateBeforeExtraction
|
||||
// and that update is a regular app update, and not a delta update
|
||||
BOOL fallbackOnCodeSigning = (verifyBeforeExtraction && !archiveTypeMustValidateBeforeExtraction && [_installationType isEqualToString:SPUInstallationTypeApplication]);
|
||||
|
||||
success = [_updateValidator validateDownloadPathWithFallbackOnCodeSigning:fallbackOnCodeSigning error:&prevalidationError];
|
||||
}
|
||||
@@ -481,7 +479,25 @@ static const NSTimeInterval SUTerminationRequestTargetWaitDelay = 2.0;
|
||||
return;
|
||||
}
|
||||
|
||||
NSBundle *hostBundle = [NSBundle bundleWithPath:installationData.hostBundlePath];
|
||||
NSURL *resolvedHostBundleURL = [[NSURL fileURLWithPath:installationData.hostBundlePath isDirectory:YES] URLByResolvingSymlinksInPath];
|
||||
if (resolvedHostBundleURL == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Failed to resolve host bundle URL from %@", installationData.hostBundlePath] }]];
|
||||
return;
|
||||
}
|
||||
|
||||
if (self->_restrictHostBundleToContainingBundle) {
|
||||
// Restrict what bundles are allowed to be updated if requested
|
||||
NSString *installerExecutablePath = NSBundle.mainBundle.executableURL.URLByResolvingSymlinksInPath.path;
|
||||
NSArray<NSString *> *hostBundlePathComponents = resolvedHostBundleURL.pathComponents;
|
||||
NSArray<NSString *> *installerExecutablePathComponents = installerExecutablePath.pathComponents;
|
||||
|
||||
if (hostBundlePathComponents.count == 0 || hostBundlePathComponents.count >= installerExecutablePathComponents.count || [hostBundlePathComponents containsObject:@".."] || ![[installerExecutablePathComponents subarrayWithRange:NSMakeRange(0, hostBundlePathComponents.count)] isEqualToArray:hostBundlePathComponents]) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Refusing to update host bundle %@ because it does not contain %@", resolvedHostBundleURL.path, installerExecutablePath] }]];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NSBundle *hostBundle = [NSBundle bundleWithURL:resolvedHostBundleURL];
|
||||
|
||||
NSString *bundleIdentifier = hostBundle.bundleIdentifier;
|
||||
if (bundleIdentifier == nil || ![bundleIdentifier isEqualToString:self->_hostBundleIdentifier]) {
|
||||
|
||||
+3
-2
@@ -9,15 +9,16 @@ int main(int __unused argc, const char __unused *argv[])
|
||||
@autoreleasepool
|
||||
{
|
||||
NSArray<NSString *> *args = [[NSProcessInfo processInfo] arguments];
|
||||
if (args.count != 4) {
|
||||
if (args.count != 5) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
NSString *hostBundleIdentifier = args[1];
|
||||
NSString *homeDirectory = args[2];
|
||||
NSString *userName = args[3];
|
||||
BOOL restrictHostBundleToContainingBundle = args[4].boolValue;
|
||||
|
||||
AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostBundleIdentifier:hostBundleIdentifier homeDirectory:homeDirectory userName:userName];
|
||||
AppInstaller *appInstaller = [[AppInstaller alloc] initWithHostBundleIdentifier:hostBundleIdentifier homeDirectory:homeDirectory userName:userName restrictHostBundleToContainingBundle:restrictHostBundleToContainingBundle];
|
||||
[appInstaller start];
|
||||
|
||||
// Ignore SIGTERM because we are going to catch it ourselves
|
||||
|
||||
@@ -12,4 +12,7 @@
|
||||
// Non-sandboxed XPC service used for launching our installer
|
||||
// This is necessary for sandboxed applications
|
||||
@interface SUInstallerLauncher : NSObject <SUInstallerLauncherProtocol>
|
||||
|
||||
- (instancetype)initWithRestrictingHostBundleToContainingBundle:(BOOL)restrictHostBundleToContainingBundle;
|
||||
|
||||
@end
|
||||
@@ -31,6 +31,18 @@
|
||||
#endif
|
||||
|
||||
@implementation SUInstallerLauncher
|
||||
{
|
||||
BOOL _restrictHostBundleToContainingBundle;
|
||||
}
|
||||
|
||||
- (instancetype)initWithRestrictingHostBundleToContainingBundle:(BOOL)restrictHostBundleToContainingBundle
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_restrictHostBundleToContainingBundle = restrictHostBundleToContainingBundle;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)submitProgressToolAtPath:(NSString *)progressToolPath withHostBundle:(NSBundle *)hostBundle inSystemDomainForInstaller:(BOOL)inSystemDomainForInstaller SPU_OBJC_DIRECT
|
||||
{
|
||||
@@ -112,7 +124,7 @@
|
||||
return (submittedJob == true);
|
||||
}
|
||||
|
||||
- (SUInstallerLauncherStatus)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle iconBundlePath:(NSString *)iconBundlePath updaterIdentifier:(NSString *)updaterIdentifier userName:(NSString *)userName homeDirectory:(NSString *)homeDirectory mainBundleName:(NSString *)mainBundleName inSystemDomain:(BOOL)systemDomain rootUser:(BOOL)rootUser SPU_OBJC_DIRECT
|
||||
- (SUInstallerLauncherStatus)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle iconBundlePath:(NSString *)iconBundlePath updaterIdentifier:(NSString *)updaterIdentifier userName:(NSString *)userName homeDirectory:(NSString *)homeDirectory mainBundleName:(NSString *)mainBundleName inSystemDomain:(BOOL)systemDomain rootUser:(BOOL)rootUser restrictHostBundleToContainingBundle:(BOOL)restrictHostBundleToContainingBundle SPU_OBJC_DIRECT
|
||||
{
|
||||
// No need to release the quarantine for this utility
|
||||
// In fact, we shouldn't because the tool may be located at a path we should not be writing too.
|
||||
@@ -122,11 +134,11 @@
|
||||
|
||||
// The first argument has to be the path to the program, and the second is a host identifier so that the installer knows what mach services to host
|
||||
// The third and forth arguments are for home directory and user name which only pkg installer scripts may need
|
||||
// We intentionally do not pass any more arguments. Anything else should be done via IPC.
|
||||
// This is compatible to SMJobBless() which does not allow arguments
|
||||
// Even though we aren't using that function for now, it'd be wise to not decrease compatibility to it
|
||||
// The fifth argument specifies whether or not we restrict updating to one of our containing bundles which
|
||||
// impacts what sandboxed apps are allowed to update.
|
||||
// We try not to pass a lot more arguments. Anything else should be preferred to be done via XPC.
|
||||
|
||||
NSArray<NSString *> *arguments = @[installerPath, hostBundleIdentifier, homeDirectory, userName];
|
||||
NSArray<NSString *> *arguments = @[installerPath, hostBundleIdentifier, homeDirectory, userName, @(restrictHostBundleToContainingBundle).stringValue];
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus createStatus = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &auth);
|
||||
@@ -525,7 +537,7 @@ static BOOL SPUUsesSystemDomainForBundlePath(NSString *path, BOOL rootUser
|
||||
}
|
||||
}
|
||||
|
||||
SUInstallerLauncherStatus installerStatus = [self submitInstallerAtPath:installerPath withHostBundle:hostBundle iconBundlePath:mainBundle.bundlePath updaterIdentifier:updaterIdentifier userName:userName homeDirectory:homeDirectory mainBundleName:mainBundleName inSystemDomain:inSystemDomain rootUser:rootUser];
|
||||
SUInstallerLauncherStatus installerStatus = [self submitInstallerAtPath:installerPath withHostBundle:hostBundle iconBundlePath:mainBundle.bundlePath updaterIdentifier:updaterIdentifier userName:userName homeDirectory:homeDirectory mainBundleName:mainBundleName inSystemDomain:inSystemDomain rootUser:rootUser restrictHostBundleToContainingBundle:self->_restrictHostBundleToContainingBundle];
|
||||
|
||||
BOOL submittedProgressTool = NO;
|
||||
if (installerStatus == SUInstallerLauncherSuccess) {
|
||||
|
||||
@@ -45,7 +45,14 @@
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerLauncherProtocol)];
|
||||
|
||||
// Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
|
||||
SUInstallerLauncher *exportedObject = [SUInstallerLauncher new];
|
||||
|
||||
// If isCodeSignedWithTeamID is NO, this may mean a development build is used and our service is adhoc signed.
|
||||
// Only apps that are sandboxed should be using the InstallerLauncher service.
|
||||
// For apps that use this service, we want to enforce that sandboxed apps can only update themselves and not update
|
||||
// arbitrary bundles. This will still allow sandboxed apps to contain helpers to update their bundle
|
||||
// as long as the helper is self contained.
|
||||
BOOL isCodeSignedWithTeamID = ([SUCodeSigningVerifier teamIdentifierFromMainExecutable] != nil);
|
||||
SUInstallerLauncher *exportedObject = [[SUInstallerLauncher alloc] initWithRestrictingHostBundleToContainingBundle:isCodeSignedWithTeamID];
|
||||
newConnection.exportedObject = exportedObject;
|
||||
|
||||
// Resuming the connection allows the system to deliver more incoming messages.
|
||||
|
||||
Reference in new issue
Block a user