diff --git a/Sparkle/SPUDownloadDriver.m b/Sparkle/SPUDownloadDriver.m index c61fe91d..32db235e 100644 --- a/Sparkle/SPUDownloadDriver.m +++ b/Sparkle/SPUDownloadDriver.m @@ -81,13 +81,20 @@ if (strongSelf != nil && !strongSelf->_retrievedDownloadResult && !strongSelf->_cleaningUp) { strongSelf->_downloader = nil; - // We can't enforce com.apple.security.network.client == NO or it being absent for sandboxed clients, - // but we should warn about it anyway - SULog(SULogLevelError, @"Error: Connection to update downloader was invalidated. If your app is not sandboxed or has com.apple.security.network.client set to YES, please remove %@ from your Info.plist. Otherwise please check Console logs for "@DOWNLOADER_NAME" if there are any additional details.", SUEnableDownloaderServiceKey); + NSString *additionalFailureReason; + { + NSString *executableFailureReason; + if (!SPUXPCServiceHasExecutablePermission(@DOWNLOADER_NAME, &executableFailureReason)) { + additionalFailureReason = [NSString stringWithFormat:@" %@", executableFailureReason]; + } else { + additionalFailureReason = @""; + } + } NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: SULocalizedStringFromTableInBundle(@"An error occurred while downloading the update. Please try again later.", SPARKLE_TABLE, SUSparkleBundle(), nil), + NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"If your app is not sandboxed or has com.apple.security.network.client set to YES, please remove %@ from your Info.plist. Please also check Console logs for "@DOWNLOADER_NAME" if there are any additional details.%@", SUEnableDownloaderServiceKey, additionalFailureReason] }; NSError *downloadError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:userInfo]; diff --git a/Sparkle/SPUInstallerDriver.m b/Sparkle/SPUInstallerDriver.m index 67968c78..f18cb4d8 100644 --- a/Sparkle/SPUInstallerDriver.m +++ b/Sparkle/SPUInstallerDriver.m @@ -186,9 +186,19 @@ if (strongSelf != nil && strongSelf->_installerConnection != nil && !strongSelf->_aborted) { NSString *impactedTools = usingInstallerService ? (@SPARKLE_RELAUNCH_TOOL_NAME" and "@INSTALLER_LAUNCHER_NAME) : @SPARKLE_RELAUNCH_TOOL_NAME; + NSString *additionalFailureReason; + { + NSString *executableFailureReason; + if (!SPUHelperHasExecutablePermission(@SPARKLE_RELAUNCH_TOOL_NAME, &executableFailureReason) || !SPUHelperHasExecutablePermission(@SPARKLE_INSTALLER_PROGRESS_TOOL_NAME@".app/Contents/MacOS/"@SPARKLE_INSTALLER_PROGRESS_TOOL_NAME, &executableFailureReason)) { + additionalFailureReason = executableFailureReason; + } else { + additionalFailureReason = [NSString stringWithFormat:@"If your application is sandboxed, please ensure Installer Connection & Status entitlements are correctly set up: https://sparkle-project.org/documentation/sandboxing/ . Otherwise if %@ %@ not adhoc signed, your app must be signed with a matching team ID", impactedTools, (usingInstallerService ? @"are" : @"is")]; + } + } + NSDictionary *genericUserInfo = @{ NSLocalizedDescriptionKey: SULocalizedStringFromTableInBundle(@"An error occurred while running the updater. Please try again later.", SPARKLE_TABLE, SUSparkleBundle(), nil), - NSLocalizedFailureReasonErrorKey:[NSString stringWithFormat:@"The remote port connection was invalidated from the updater. If your application is sandboxed, please ensure Installer Connection & Status entitlements are correctly set up: https://sparkle-project.org/documentation/sandboxing/ . Otherwise if %@ %@ not adhoc signed, your app must be signed with a matching team ID. For additional details, check Console logs for %@", impactedTools, (usingInstallerService ? @"are" : @"is"), impactedTools] + NSLocalizedFailureReasonErrorKey:[NSString stringWithFormat:@"The remote port connection was invalidated from the updater. %@. For additional details, check Console logs for %@", additionalFailureReason, impactedTools] }; [strongSelf _reportInstallerError:strongSelf->_installerError genericErrorCode:SUInstallationError genericUserInfo:genericUserInfo]; @@ -412,9 +422,19 @@ #endif if (!retrievedLaunchStatus) { #pragma clang diagnostic pop + NSString *additionalFailureReason; + { + NSString *executableFailureReason; + if (!SPUXPCServiceHasExecutablePermission(@INSTALLER_LAUNCHER_NAME, &executableFailureReason)) { + additionalFailureReason = [NSString stringWithFormat:@" %@", executableFailureReason]; + } else { + additionalFailureReason = @""; + } + } + NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedStringFromTableInBundle(@"An error occurred while connecting to the installer. Please try again later.", SPARKLE_TABLE, SUSparkleBundle(), nil), - NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"If your app is not sandboxed, please remove or disable %@ in your app's Info.plist. Otherwise please check Console logs for "@INSTALLER_LAUNCHER_NAME" and "@SPARKLE_RELAUNCH_TOOL_NAME" processes if there are additional details.", SUEnableInstallerLauncherServiceKey]}]; + NSLocalizedFailureReasonErrorKey: [NSString stringWithFormat:@"If your app is not sandboxed, please remove or disable %@ in your app's Info.plist. Please also check Console logs for "@INSTALLER_LAUNCHER_NAME" and "@SPARKLE_RELAUNCH_TOOL_NAME" processes if there are additional details.%@", SUEnableInstallerLauncherServiceKey, additionalFailureReason]}]; completionHandler(error); diff --git a/Sparkle/SPUXPCServiceInfo.h b/Sparkle/SPUXPCServiceInfo.h index 49cd5139..ac709aff 100644 --- a/Sparkle/SPUXPCServiceInfo.h +++ b/Sparkle/SPUXPCServiceInfo.h @@ -12,4 +12,8 @@ NS_ASSUME_NONNULL_BEGIN BOOL SPUXPCServiceIsEnabled(NSString *enabledKey); +BOOL SPUHelperHasExecutablePermission(NSString *component, NSString * _Nullable __autoreleasing * _Nullable failureReason); + +BOOL SPUXPCServiceHasExecutablePermission(NSString *serviceName, NSString * _Nullable __autoreleasing * _Nullable failureReason); + NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUXPCServiceInfo.m b/Sparkle/SPUXPCServiceInfo.m index f80faae2..6cd87a71 100644 --- a/Sparkle/SPUXPCServiceInfo.m +++ b/Sparkle/SPUXPCServiceInfo.m @@ -20,3 +20,44 @@ BOOL SPUXPCServiceIsEnabled(NSString *enabledKey) return [mainBundleHost boolForInfoDictionaryKey:enabledKey]; } + +BOOL SPUHelperHasExecutablePermission(NSString *component, NSString * _Nullable __autoreleasing * _Nullable failureReason) +{ + NSBundle *sparkleBundle = [NSBundle bundleWithIdentifier:SUBundleIdentifier]; + NSURL *helperURL = [[sparkleBundle.bundleURL URLByAppendingPathComponent:component isDirectory:NO] URLByResolvingSymlinksInPath]; + + NSString *helperPath = helperURL.path; + + NSError *attributesError = nil; + NSDictionary *attributes = [NSFileManager.defaultManager attributesOfItemAtPath:helperPath error:&attributesError]; + + if (attributes == nil) { + if (failureReason != NULL) { + *failureReason = [NSString stringWithFormat:@"Failed to fetch info from file '%@' -- does this helper exist? %@", helperPath, attributesError.localizedDescription]; + } + + return NO; + } + + NSNumber *posixPermissions = attributes[NSFilePosixPermissions]; + + if (posixPermissions != nil) { + mode_t mode = posixPermissions.unsignedShortValue; + if (((mode & S_IXUSR) == 0 || (mode & S_IXGRP) == 0 || (mode & S_IXOTH) == 0)) { + if (failureReason != NULL) { + *failureReason = [NSString stringWithFormat:@"The file '%@' may not have executable permissions -- were they lost during a bad file copy? Please ensure file permissions and symbolic links for Sparkle framework are preserved.", helperPath]; + } + + return NO; + } + } + + return YES; +} + +BOOL SPUXPCServiceHasExecutablePermission(NSString *serviceName, NSString * _Nullable __autoreleasing * _Nullable failureReason) +{ + NSString *componentName = [NSString stringWithFormat:@"XPCServices/%@.xpc/Contents/MacOS/%@", serviceName, serviceName]; + + return SPUHelperHasExecutablePermission(componentName, failureReason); +}