Update authorization prompt when updating an app

We have a slightly different prompt for an app updating itself vs an app/tool updating another app. Also put prompt in the localization strings.
This commit is contained in:
Zorg committed 2021-04-18 11:44:30 -07:00
1 parent 8f3e340e47
commit db6ef214ab
4 files changed
+47 -7

No files matched your search

+15 -4
View File
@@ -91,7 +91,7 @@
return (submittedJob == true);
}
- (SUInstallerLauncherStatus)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle authorizationPrompt:(NSString *)authorizationPrompt inSystemDomain:(BOOL)systemDomain
- (SUInstallerLauncherStatus)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle updaterIdentifier:(NSString *)updaterIdentifier authorizationPrompt:(NSString *)authorizationPrompt inSystemDomain:(BOOL)systemDomain
{
SUFileManager *fileManager = [[SUFileManager alloc] init];
@@ -121,8 +121,19 @@
// https://developer.apple.com/library/mac/technotes/tn2095/_index.html#//apple_ref/doc/uid/DTS10003110-CH1-SECTION7
// We can set a custom right name for authenticating as an administrator
// Using this right rather than using something like kSMRightModifySystemDaemons allows us to present a better worded prompt
// Note the right name is cached, so if we want to change the authorization
// prompt, we may need to change the right name. I have found no good way around this :|
NSString *sparkleAuthTag = @"sparkle2-auth"; // this needs to change if auth wording changes
NSString *rightNameString;
if ([hostBundleIdentifier isEqualToString:updaterIdentifier]) {
// Application bundle is likely updating itself
rightNameString = [NSString stringWithFormat:@"%@.%@", hostBundleIdentifier, sparkleAuthTag];
} else {
// Updater is likely updating a bundle that is not itself
rightNameString = [NSString stringWithFormat:@"%@.%@.%@", updaterIdentifier, hostBundleIdentifier, sparkleAuthTag];
}
const char *rightName = [[NSString stringWithFormat:@"%@.sparkle-auth", hostBundleIdentifier] UTF8String];
const char *rightName = rightNameString.UTF8String;
assert(rightName != NULL);
OSStatus getRightResult = AuthorizationRightGet(rightName, NULL);
@@ -323,7 +334,7 @@ static BOOL SPUNeedsSystemAuthorizationAccess(NSString *path, NSString *installa
// Note: do not pass untrusted information such as paths to the installer and progress agent tools, when we can find them ourselves here
- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler
- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath updaterIdentifier:(NSString *)updaterIdentifier authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler
{
dispatch_async(dispatch_get_main_queue(), ^{
NSBundle *hostBundle = [NSBundle bundleWithPath:hostBundlePath];
@@ -397,7 +408,7 @@ static BOOL SPUNeedsSystemAuthorizationAccess(NSString *path, NSString *installa
return;
}
SUInstallerLauncherStatus installerStatus = [self submitInstallerAtPath:installerPath withHostBundle:hostBundle authorizationPrompt:authorizationPrompt inSystemDomain:needsSystemAuthorization];
SUInstallerLauncherStatus installerStatus = [self submitInstallerAtPath:installerPath withHostBundle:hostBundle updaterIdentifier:updaterIdentifier authorizationPrompt:authorizationPrompt inSystemDomain:needsSystemAuthorization];
BOOL submittedProgressTool = NO;
if (installerStatus == SUInstallerLauncherSuccess) {
@@ -11,7 +11,7 @@
@protocol SUInstallerLauncherProtocol
- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler;
- (void)launchInstallerWithHostBundlePath:(NSString *)hostBundlePath updaterIdentifier:(NSString *)updaterBundleIdentifier authorizationPrompt:(NSString *)authorizationPrompt installationType:(NSString *)installationType allowingDriverInteraction:(BOOL)allowingDriverInteraction allowingUpdaterInteraction:(BOOL)allowingUpdaterInteraction completion:(void (^)(SUInstallerLauncherStatus, BOOL))completionHandler;
- (void)checkIfApplicationInstallationRequiresAuthorizationWithHostBundlePath:(NSString *)hostBundlePath reply:(void(^)(BOOL requiresAuthorization))reply;
+6
View File
@@ -101,3 +101,9 @@
/* Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates. */
"You're up-to-date!" = "You’re up to date!";
/* Authorization message shown when app wants permission to update itself. */
"%1$@ wants permission to update." = "%1$@ wants permission to update.";
/* Authorization message shown when app wants permission to update another app / bundle. */
"%1$@ wants permission to update %2$@." = "%1$@ wants permission to update %2$@.";
+25 -2
View File
@@ -436,8 +436,31 @@
assert(installationType != nil);
// The installer launcher could be in a XPC service, so we don't want to do localization in there
NSString *authorizationPrompt = [NSString stringWithFormat:SULocalizedString(@"%1$@ wants to update.", nil), self.host.name];
[installerLauncher launchInstallerWithHostBundlePath:hostBundlePath authorizationPrompt:authorizationPrompt installationType:installationType allowingDriverInteraction:driverAllowsInteraction allowingUpdaterInteraction:!preventsInstallerInteraction completion:^(SUInstallerLauncherStatus result, BOOL systemDomain) {
// Make sure the authorization prompt reflects whether or not the updater is updating itself, or
// if the updater is updating another application. We use SUHost.name property, so an application
// or Sparkle helper application can override its name with SUBundleName key
SUHost *mainBundleHost = [[SUHost alloc] initWithBundle:[NSBundle mainBundle]];
NSString *mainBundleName = mainBundleHost.name;
NSString *hostName = self.host.name;
// Changing this authorization prompt is a little complicated because the
// Auth database retains and caches the right we use, and there isn't a good way
// of updating the prompt. See code in SUInstallerLauncher.m
NSString *authorizationPrompt;
if ([mainBundleName isEqualToString:hostName]) {
authorizationPrompt = [NSString stringWithFormat:SULocalizedString(@"%1$@ wants permission to update.", nil), hostName];
} else {
authorizationPrompt = [NSString stringWithFormat:SULocalizedString(@"%1$@ wants permission to update %2$@.", nil), mainBundleName, hostName];
}
NSString *mainBundleIdentifier;
{
NSString *bundleIdentifier = mainBundleHost.bundle.bundleIdentifier;
mainBundleIdentifier = (bundleIdentifier == nil) ? mainBundleName : bundleIdentifier;
}
[installerLauncher launchInstallerWithHostBundlePath:hostBundlePath updaterIdentifier:mainBundleIdentifier authorizationPrompt:authorizationPrompt installationType:installationType allowingDriverInteraction:driverAllowsInteraction allowingUpdaterInteraction:!preventsInstallerInteraction completion:^(SUInstallerLauncherStatus result, BOOL systemDomain) {
dispatch_async(dispatch_get_main_queue(), ^{
retrievedLaunchStatus = YES;
[launcherConnection invalidate];