From 99f34299f14a781de5399717eeef138907d69ce9 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 00:07:11 -0400 Subject: [PATCH] Show alert if no pub key exists, but SUPublicDSAKeyFileKey exists --- Sparkle/SUHost.h | 1 + Sparkle/SUHost.m | 7 ++++++- Sparkle/SUUpdater.m | 21 ++++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 6d058b90..56fa7d18 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -34,6 +34,7 @@ typedef struct { @property (getter=isRunningOnReadOnlyVolume, readonly) BOOL runningOnReadOnlyVolume; @property (getter=isBackgroundApplication, readonly) BOOL backgroundApplication; @property (readonly, copy) NSString *publicDSAKey; +@property (readonly, nonatomic, copy) NSString *publicDSAKeyFileKey; @property (readonly, copy) NSArray *systemProfile; - (id)objectForInfoDictionaryKey:(NSString *)key; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 5f9cff46..427be8d8 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -168,7 +168,7 @@ } // More likely, we've got a reference to a Resources file by filename: - NSString *keyFilename = [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey]; + NSString *keyFilename = [self publicDSAKeyFileKey]; if (!keyFilename) { return nil; } @@ -180,6 +180,11 @@ return [NSString stringWithContentsOfFile:keyPath encoding:NSASCIIStringEncoding error:nil]; } +- (NSString * __nullable)publicDSAKeyFileKey +{ + return [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey]; +} + - (NSArray *)systemProfile { return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHost:self]; diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index cd73c668..87e6f9d3 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -127,16 +127,23 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults BOOL servingOverHttps = [[[feedURL scheme] lowercaseString] isEqualToString:@"https"]; if (!hasPublicDSAKey) { - if (!isMainBundle) { + // If we failed to retrieve a DSA key but the bundle specifies a path to one, we should consider this a configuration failure + NSString *publicDSAKeyFileKey = [self.host publicDSAKeyFileKey]; + if (publicDSAKeyFileKey != nil) { [self showAlertText:SULocalizedString(@"Insecure update error!", nil) - informativeText:SULocalizedString(@"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information.", nil)]; + informativeText:[NSString stringWithFormat:SULocalizedString(@"For security reasons, the file indicated by the '%@' key needs to exist in the bundle's Resources.", nil), SUPublicDSAKeyFileKey]]; } else { - if (!hostIsCodeSigned) { + if (!isMainBundle) { [self showAlertText:SULocalizedString(@"Insecure update error!", nil) - informativeText:SULocalizedString(@"For security reasons, you need to code sign your application or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; - } else if (!servingOverHttps) { - [self showAlertText:SULocalizedString(@"Insecure update error!", nil) - informativeText:SULocalizedString(@"For security reasons, you need to serve your updates over HTTPS and/or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; + informativeText:SULocalizedString(@"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information.", nil)]; + } else { + if (!hostIsCodeSigned) { + [self showAlertText:SULocalizedString(@"Insecure update error!", nil) + informativeText:SULocalizedString(@"For security reasons, you need to code sign your application or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; + } else if (!servingOverHttps) { + [self showAlertText:SULocalizedString(@"Insecure update error!", nil) + informativeText:SULocalizedString(@"For security reasons, you need to serve your updates over HTTPS and/or sign your updates with a DSA key. See https://sparkle-project.org/documentation/ for more information.", nil)]; + } } } }