From 21b4aeeb3b0c42793c6e6a5beba7b5e07ee7f397 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Fri, 30 May 2008 21:46:08 -0700 Subject: [PATCH] Fixes bug 228454. Added support for a SUPublicDSAKeyFile, so people don't have to copy/paste their entire DSA public key into their Info.plist. Basically: specify a filename in your Info.plist under the key SUPublicDSAKeyFile, and Sparkle will look for a file of that name in the app's resources directory and load its contents to use as the DSA public key. --- NSBundle+SUAdditions.h | 2 ++ NSBundle+SUAdditions.m | 12 ++++++++++++ SUBasicUpdateDriver.m | 3 +-- SUConstants.h | 1 + SUConstants.m | 1 + 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/NSBundle+SUAdditions.h b/NSBundle+SUAdditions.h index b5a66ee4..38fc9238 100644 --- a/NSBundle+SUAdditions.h +++ b/NSBundle+SUAdditions.h @@ -50,6 +50,8 @@ @discussion Returns an array of dictionaries; each dictionary represents a piece of data and has keys "key", "visibleKey", "value", and "visibleValue". */ - (NSArray *)systemProfile; + +- (NSString *)publicDSAKey; @end #endif diff --git a/NSBundle+SUAdditions.m b/NSBundle+SUAdditions.m index 8a7e7e91..0d225b54 100644 --- a/NSBundle+SUAdditions.m +++ b/NSBundle+SUAdditions.m @@ -65,6 +65,18 @@ return isDiskImage && !isFileVault; } +- (NSString *)publicDSAKey +{ + // Maybe the key is just a string in the Info.plist. + NSString *key = [self objectForInfoDictionaryKey:SUPublicDSAKeyKey]; + if (key) { return key; } + + // More likely, we've got a reference to a Resources file by filename: + NSString *keyFilename = [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey]; + if (!keyFilename) { return nil; } + return [NSString stringWithContentsOfFile:[self pathForResource:keyFilename ofType:nil]]; +} + - (NSArray *)systemProfile { return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHostBundle:self]; diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 1748e791..644f2747 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -135,8 +135,7 @@ // DSA verification, if activated by the developer if ([[hostBundle objectForInfoDictionaryKey:SUExpectsDSASignatureKey] boolValue]) { - NSString *pkeyString = [hostBundle objectForInfoDictionaryKey:SUPublicDSAKeyKey]; - if (![[NSFileManager defaultManager] validatePath:downloadPath withEncodedDSASignature:[updateItem DSASignature] withPublicDSAKey:pkeyString]) + if (![[NSFileManager defaultManager] validatePath:downloadPath withEncodedDSASignature:[updateItem DSASignature] withPublicDSAKey:[hostBundle publicDSAKey]]) { [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSignatureError userInfo:[NSDictionary dictionaryWithObject:@"The update is improperly signed." forKey:NSLocalizedDescriptionKey]]]; return; diff --git a/SUConstants.h b/SUConstants.h index 601fe3cb..c0c427af 100644 --- a/SUConstants.h +++ b/SUConstants.h @@ -22,6 +22,7 @@ extern NSString *SUScheduledCheckIntervalKey; extern NSString *SULastCheckTimeKey; extern NSString *SUExpectsDSASignatureKey; extern NSString *SUPublicDSAKeyKey; +extern NSString *SUPublicDSAKeyFileKey; extern NSString *SUAutomaticallyUpdateKey; extern NSString *SUAllowsAutomaticUpdatesKey; extern NSString *SUEnableAutomaticChecksKey; diff --git a/SUConstants.m b/SUConstants.m index 16219110..10984812 100644 --- a/SUConstants.m +++ b/SUConstants.m @@ -20,6 +20,7 @@ NSString *SUScheduledCheckIntervalKey = @"SUScheduledCheckInterval"; NSString *SULastCheckTimeKey = @"SULastCheckTime"; NSString *SUExpectsDSASignatureKey = @"SUExpectsDSASignature"; NSString *SUPublicDSAKeyKey = @"SUPublicDSAKey"; +NSString *SUPublicDSAKeyFileKey = @"SUPublicDSAKeyFile"; NSString *SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate"; NSString *SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates"; NSString *SUEnableSystemProfilingKey = @"SUEnableSystemProfiling";