From 452ff64740f7d606304b339140ce44cb0c132d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Mon, 14 Dec 2015 19:49:45 +0000 Subject: [PATCH 1/4] Move sanity checks to a separate function --- Sparkle/SUUpdater.m | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index c3638d97..6a014d4a 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -109,8 +109,18 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults host = [[SUHost alloc] initWithBundle:bundle]; // Saving-the-developer-from-a-stupid-mistake-check: - BOOL hasPublicDSAKey = [host publicDSAKey] != nil; - BOOL isMainBundle = [bundle isEqualTo:[NSBundle mainBundle]]; + [self checkIfConfiguredProperly]; + + + // This runs the permission prompt if needed, but never before the app has finished launching because the runloop won't run before that + [self performSelector:@selector(startUpdateCycle) withObject:nil afterDelay:0]; + } + return self; +} + +-(void)checkIfConfiguredProperly { + BOOL hasPublicDSAKey = [self.host publicDSAKey] != nil; + BOOL isMainBundle = [self.host.bundle isEqualTo:[NSBundle mainBundle]]; BOOL hostIsCodeSigned = [SUCodeSigningVerifier hostApplicationIsCodeSigned]; BOOL servingOverHttps = [[[[self feedURL] scheme] lowercaseString] isEqualToString:@"https"]; if (!isMainBundle && !hasPublicDSAKey) { @@ -130,11 +140,6 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults } else if (isMainBundle && !hasPublicDSAKey && !servingOverHttps) { SULog(@"WARNING: Serving updates over http without signing them with a DSA key is deprecated and may not be possible in a future release. Please serve your updates over https, or sign them with a DSA key, or do both. See Sparkle's documentation for more information."); } - - // This runs the permission prompt if needed, but never before the app has finished launching because the runloop won't run before that - [self performSelector:@selector(startUpdateCycle) withObject:nil afterDelay:0]; - } - return self; } From 0abe9ad994effc7ac238e5ef6b448afbd2bbe8fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Mon, 14 Dec 2015 20:13:18 +0000 Subject: [PATCH 2/4] Deduped alert code --- Sparkle/SUUpdater.m | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 6a014d4a..000fffb4 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -118,28 +118,30 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults return self; } +-(void)showModalAlertText:(NSString *)text informativeText:(NSString *)informativeText { + [self notifyWillShowModalAlert]; + NSAlert *alert = [[NSAlert alloc] init]; + alert.messageText = text; + alert.informativeText = informativeText; + [alert runModal]; + [self notifyDidShowModalAlert]; +} + -(void)checkIfConfiguredProperly { - BOOL hasPublicDSAKey = [self.host publicDSAKey] != nil; - BOOL isMainBundle = [self.host.bundle isEqualTo:[NSBundle mainBundle]]; - BOOL hostIsCodeSigned = [SUCodeSigningVerifier hostApplicationIsCodeSigned]; - BOOL servingOverHttps = [[[[self feedURL] scheme] lowercaseString] isEqualToString:@"https"]; - if (!isMainBundle && !hasPublicDSAKey) { - [self notifyWillShowModalAlert]; - NSAlert *alert = [[NSAlert alloc] init]; - alert.messageText = @"Insecure update error!"; - alert.informativeText = @"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information."; - [alert runModal]; - [self notifyDidShowModalAlert]; - } else if (isMainBundle && !(hasPublicDSAKey || hostIsCodeSigned)) { - [self notifyWillShowModalAlert]; - NSAlert *alert = [[NSAlert alloc] init]; - alert.messageText = @"Insecure update error!"; - alert.informativeText = @"For security reasons, you need to code sign your application or sign your updates with a DSA key. See Sparkle's documentation for more information."; - [alert runModal]; - [self notifyDidShowModalAlert]; - } else if (isMainBundle && !hasPublicDSAKey && !servingOverHttps) { - SULog(@"WARNING: Serving updates over http without signing them with a DSA key is deprecated and may not be possible in a future release. Please serve your updates over https, or sign them with a DSA key, or do both. See Sparkle's documentation for more information."); - } + BOOL hasPublicDSAKey = [self.host publicDSAKey] != nil; + BOOL isMainBundle = [self.host.bundle isEqualTo:[NSBundle mainBundle]]; + BOOL hostIsCodeSigned = [SUCodeSigningVerifier hostApplicationIsCodeSigned]; + NSURL *feedURL = [self feedURL]; + BOOL servingOverHttps = [[[feedURL scheme] lowercaseString] isEqualToString:@"https"]; + if (!isMainBundle && !hasPublicDSAKey) { + [self showModalAlertText:@"Insecure update error!" + informativeText:@"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information."]; + } else if (isMainBundle && !(hasPublicDSAKey || hostIsCodeSigned)) { + [self showModalAlertText:@"Insecure update error!" + informativeText:@"For security reasons, you need to code sign your application or sign your updates with a DSA key. See Sparkle's documentation for more information."]; + } else if (isMainBundle && !hasPublicDSAKey && !servingOverHttps) { + SULog(@"WARNING: Serving updates over HTTP without signing them with a DSA key is deprecated and may not be possible in a future release. Please serve your updates over https, or sign them with a DSA key, or do both. See Sparkle's documentation for more information."); + } } From aa11a9e93496aec9287eee663bd44827b2256b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Mon, 14 Dec 2015 20:13:32 +0000 Subject: [PATCH 3/4] Warn about ATS blocking --- Sparkle/SUUpdater.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 000fffb4..61836f94 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -142,6 +142,14 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults } else if (isMainBundle && !hasPublicDSAKey && !servingOverHttps) { SULog(@"WARNING: Serving updates over HTTP without signing them with a DSA key is deprecated and may not be possible in a future release. Please serve your updates over https, or sign them with a DSA key, or do both. See Sparkle's documentation for more information."); } + +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 + BOOL atsExceptionsExist = nil != [self.host objectForInfoDictionaryKey:@"NSAppTransportSecurity"]; + if (!servingOverHttps && !atsExceptionsExist) { + [self showModalAlertText:@"Insecure feed URL is blocked in OS X 10.11" + informativeText:[NSString stringWithFormat:@"You must change the feed URL (%@) to use HTTPS or disable App Transport Security.\n\nFor more information:\nhttp://sparkle-project.org/documentation/app-transport-security/", [feedURL absoluteString]]]; + } +#endif } From 254ae41759e892e388dde87a374a10ee6e474056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Mon, 14 Dec 2015 20:22:58 +0000 Subject: [PATCH 4/4] Limit alert to main bundle --- Sparkle/SUUpdater.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 61836f94..95be679f 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -145,10 +145,13 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 BOOL atsExceptionsExist = nil != [self.host objectForInfoDictionaryKey:@"NSAppTransportSecurity"]; - if (!servingOverHttps && !atsExceptionsExist) { + if (isMainBundle && !servingOverHttps && !atsExceptionsExist) { [self showModalAlertText:@"Insecure feed URL is blocked in OS X 10.11" informativeText:[NSString stringWithFormat:@"You must change the feed URL (%@) to use HTTPS or disable App Transport Security.\n\nFor more information:\nhttp://sparkle-project.org/documentation/app-transport-security/", [feedURL absoluteString]]]; } + if (!isMainBundle && !servingOverHttps) { + SULog(@"WARNING: Serving updates over HTTP may be blocked in OS X 10.11. Please change the feed URL (%@) to use HTTPS. For more information:\nhttp://sparkle-project.org/documentation/app-transport-security/", feedURL); + } #endif }