From 99f34299f14a781de5399717eeef138907d69ce9 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 00:07:11 -0400 Subject: [PATCH 1/3] 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)]; + } } } } From e2fc8b42585dbe994a4155439d19177678f0c40f Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 00:32:01 -0400 Subject: [PATCH 2/3] Prevent public DSA key -> no public DSA key downgrade This may prevent developers from making accidental downgrades. --- Sparkle/SUBasicUpdateDriver.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 276e7339..2a942bb1 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -317,6 +317,12 @@ SUHost *newHost = [[SUHost alloc] initWithBundle:newBundle]; NSString *newPublicDSAKey = newHost.publicDSAKey; + // Downgrade in DSA security should not be possible + if (publicDSAKey != nil && newPublicDSAKey == nil) { + SULog(@"A public DSA key is found in the old bundle but no public DSA key is found in the new update. For security reasons, the update will be rejected."); + return NO; + } + BOOL dsaKeysMatch = (publicDSAKey == nil || newPublicDSAKey == nil) ? NO : [publicDSAKey isEqualToString:newPublicDSAKey]; // If the new DSA key differs from the old, then this check is not a security measure, because the new key is not trusted. From 626d2c96f5d2c6caf121a72ac09775ba3683b516 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 27 Aug 2016 09:11:08 -0400 Subject: [PATCH 3/3] Show the public DSA file key that doesn't exist in the insecure alert --- Sparkle/SUUpdater.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 87e6f9d3..d0007318 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -131,7 +131,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults NSString *publicDSAKeyFileKey = [self.host publicDSAKeyFileKey]; if (publicDSAKeyFileKey != nil) { [self showAlertText:SULocalizedString(@"Insecure update error!", nil) - informativeText:[NSString stringWithFormat:SULocalizedString(@"For security reasons, the file indicated by the '%@' key needs to exist in the bundle's Resources.", nil), SUPublicDSAKeyFileKey]]; + informativeText:[NSString stringWithFormat:SULocalizedString(@"For security reasons, the file (%@) indicated by the '%@' key needs to exist in the bundle's Resources.", nil), publicDSAKeyFileKey, SUPublicDSAKeyFileKey]]; } else { if (!isMainBundle) { [self showAlertText:SULocalizedString(@"Insecure update error!", nil)