diff --git a/Autoupdate/SUSignatureVerifier.m b/Autoupdate/SUSignatureVerifier.m index a40863ee..54c4374d 100644 --- a/Autoupdate/SUSignatureVerifier.m +++ b/Autoupdate/SUSignatureVerifier.m @@ -241,6 +241,20 @@ } } } +#else + switch (_pubKeys.dsaPubKeyStatus) { + case SUSigningInputStatusAbsent: + break; + case SUSigningInputStatusInvalid: + // We don't keep track of DSA signatures, so we will ignore this mistake and treat it as if it were absent + break; + case SUSigningInputStatusPresent: + if (error != NULL) { + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: @"The old app has a DSA public key but DSA support is disabled, and the old app does not have an EdDSA public key." }]; + } + + return NO; + } #endif if (error != NULL) { diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index 8205cc6b..8c4b5cda 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -12,9 +12,17 @@ SPARKLE_EMBED_INSTALLER_CONNECTION_XPC_SERVICE = 0 // Set to 0 to disable building legacy 1.x SUUpdater stub SPARKLE_BUILD_LEGACY_SUUPDATER = 1 -// Set to 0 to not build legacy DSA signing support (useful for migrating to EdDSA) +// Set to 0 to not build legacy DSA signing support +// Don't disable this if you haven't migrated to EdDSA yet or if you support updating +// other developer's applications that haven't migrated to EdDSA yet +// If this is disabled, this requires an update to OTHER_SWIFT_FLAGS_COMMON below SPARKLE_BUILD_LEGACY_DSA_SUPPORT = 1 +// Set to 0 to not build legacy DSA signing support for generate_appcast +// Don't disable this if you still have items in your appcast feed that still need DSA signatures +// If this is disabled, this requires an update to OTHER_SWIFT_FLAGS_COMMON below +GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT = 1 + // Set to 0 to not build legacy / xar based delta update support SPARKLE_BUILD_LEGACY_DELTA_SUPPORT = 1 @@ -22,9 +30,11 @@ SPARKLE_BUILD_LEGACY_DELTA_SUPPORT = 1 SPARKLE_BUILD_BZIP2_DELTA_SUPPORT = 1 // Set to 0 to not build support for package (pkg) based installations +// If this is disabled, this requires an update to OTHER_SWIFT_FLAGS_COMMON below SPARKLE_BUILD_PACKAGE_SUPPORT = 1 // Set to 0 to not build support for extracting updates from disk images (dmgs) +// If this is disabled, this requires an update to OTHER_SWIFT_FLAGS_COMMON below SPARKLE_BUILD_DMG_SUPPORT = 1 // Set to 0 to only build all non-UI bits (which means client uses a custom SPUUserDriver) @@ -35,9 +45,10 @@ SPARKLE_COPY_LOCALIZATIONS = 1 // Compilation flags for Swift tools and unit tests // If SPARKLE_BUILD_LEGACY_DELTA_SUPPORT is set to 0, remove -DSPARKLE_BUILD_LEGACY_DSA_SUPPORT +// If GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT is set to 0, remove -DGENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT // If SPARKLE_BUILD_PACKAGE_SUPPORT is set to 0, remove -DSPARKLE_BUILD_PACKAGE_SUPPORT // If SPARKLE_BUILD_DMG_SUPPORT is set to 0, remove -DSPARKLE_BUILD_DMG_SUPPORT -OTHER_SWIFT_FLAGS_COMMON = -DSPARKLE_BUILD_LEGACY_DSA_SUPPORT -DSPARKLE_BUILD_PACKAGE_SUPPORT -DSPARKLE_BUILD_DMG_SUPPORT +OTHER_SWIFT_FLAGS_COMMON = -DSPARKLE_BUILD_LEGACY_DSA_SUPPORT -DGENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT -DSPARKLE_BUILD_PACKAGE_SUPPORT -DSPARKLE_BUILD_DMG_SUPPORT // Minimum supported macOS version MACOSX_DEPLOYMENT_TARGET = 10.13 @@ -95,7 +106,7 @@ GCC_INLINES_ARE_PRIVATE_EXTERN = YES PRODUCT_NAME = ${TARGET_NAME} PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle.${PRODUCT_NAME:rfc1034identifier} -GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPU_OBJC_DIRECT=__attribute__((objc_direct)) SPU_OBJC_DIRECT_MEMBERS=__attribute__((objc_direct_members)) SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_BUILD_UI_BITS=$(SPARKLE_BUILD_UI_BITS) SPARKLE_COPY_LOCALIZATIONS=$(SPARKLE_COPY_LOCALIZATIONS) SPARKLE_BUILD_LEGACY_SUUPDATER=$(SPARKLE_BUILD_LEGACY_SUUPDATER) SPARKLE_BUILD_PACKAGE_SUPPORT=$(SPARKLE_BUILD_PACKAGE_SUPPORT) SPARKLE_BUILD_DMG_SUPPORT=$(SPARKLE_BUILD_DMG_SUPPORT) SPARKLE_BUILD_LEGACY_DELTA_SUPPORT=$(SPARKLE_BUILD_LEGACY_DELTA_SUPPORT) SPARKLE_BUILD_BZIP2_DELTA_SUPPORT=$(SPARKLE_BUILD_BZIP2_DELTA_SUPPORT) SPARKLE_BUILD_LEGACY_DSA_SUPPORT=$(SPARKLE_BUILD_LEGACY_DSA_SUPPORT) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" CURRENT_PROJECT_VERSION=\"$(CURRENT_PROJECT_VERSION)\" MARKETING_VERSION=\"$(MARKETING_VERSION)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_INSTALLER_PROGRESS_TOOL_NAME=\"$(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)\" SPARKLE_ICON_NAME=\"$(SPARKLE_ICON_NAME)\" INSTALLER_LAUNCHER_NAME=\"${INSTALLER_LAUNCHER_NAME}\" INSTALLER_LAUNCHER_BUNDLE_ID=\"${INSTALLER_LAUNCHER_BUNDLE_ID}\" INSTALLER_LAUNCHER_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_LAUNCHER_XPC_SERVICE) INSTALLER_CONNECTION_NAME=\"${INSTALLER_CONNECTION_NAME}\" INSTALLER_CONNECTION_BUNDLE_ID=\"${INSTALLER_CONNECTION_BUNDLE_ID}\" INSTALLER_CONNECTION_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_CONNECTION_XPC_SERVICE) INSTALLER_STATUS_NAME=\"${INSTALLER_STATUS_NAME}\" INSTALLER_STATUS_BUNDLE_ID=\"${INSTALLER_STATUS_BUNDLE_ID}\" INSTALLER_STATUS_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_STATUS_XPC_SERVICE) DOWNLOADER_NAME=\"${DOWNLOADER_NAME}\" DOWNLOADER_BUNDLE_ID=\"${DOWNLOADER_BUNDLE_ID}\" DOWNLOADER_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_DOWNLOADER_XPC_SERVICE) +GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPU_OBJC_DIRECT=__attribute__((objc_direct)) SPU_OBJC_DIRECT_MEMBERS=__attribute__((objc_direct_members)) SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_BUILD_UI_BITS=$(SPARKLE_BUILD_UI_BITS) SPARKLE_COPY_LOCALIZATIONS=$(SPARKLE_COPY_LOCALIZATIONS) SPARKLE_BUILD_LEGACY_SUUPDATER=$(SPARKLE_BUILD_LEGACY_SUUPDATER) SPARKLE_BUILD_PACKAGE_SUPPORT=$(SPARKLE_BUILD_PACKAGE_SUPPORT) SPARKLE_BUILD_DMG_SUPPORT=$(SPARKLE_BUILD_DMG_SUPPORT) SPARKLE_BUILD_LEGACY_DELTA_SUPPORT=$(SPARKLE_BUILD_LEGACY_DELTA_SUPPORT) SPARKLE_BUILD_BZIP2_DELTA_SUPPORT=$(SPARKLE_BUILD_BZIP2_DELTA_SUPPORT) SPARKLE_BUILD_LEGACY_DSA_SUPPORT=$(SPARKLE_BUILD_LEGACY_DSA_SUPPORT) GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT=$(GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" CURRENT_PROJECT_VERSION=\"$(CURRENT_PROJECT_VERSION)\" MARKETING_VERSION=\"$(MARKETING_VERSION)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_INSTALLER_PROGRESS_TOOL_NAME=\"$(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)\" SPARKLE_ICON_NAME=\"$(SPARKLE_ICON_NAME)\" INSTALLER_LAUNCHER_NAME=\"${INSTALLER_LAUNCHER_NAME}\" INSTALLER_LAUNCHER_BUNDLE_ID=\"${INSTALLER_LAUNCHER_BUNDLE_ID}\" INSTALLER_LAUNCHER_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_LAUNCHER_XPC_SERVICE) INSTALLER_CONNECTION_NAME=\"${INSTALLER_CONNECTION_NAME}\" INSTALLER_CONNECTION_BUNDLE_ID=\"${INSTALLER_CONNECTION_BUNDLE_ID}\" INSTALLER_CONNECTION_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_CONNECTION_XPC_SERVICE) INSTALLER_STATUS_NAME=\"${INSTALLER_STATUS_NAME}\" INSTALLER_STATUS_BUNDLE_ID=\"${INSTALLER_STATUS_BUNDLE_ID}\" INSTALLER_STATUS_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_STATUS_XPC_SERVICE) DOWNLOADER_NAME=\"${DOWNLOADER_NAME}\" DOWNLOADER_BUNDLE_ID=\"${DOWNLOADER_BUNDLE_ID}\" DOWNLOADER_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_DOWNLOADER_XPC_SERVICE) CODE_SIGN_IDENTITY = - SDKROOT = macosx diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index cc6adbc7..d465ed1d 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -45,11 +45,8 @@ extern NSString *const SUSkippedMajorVersionKey; extern NSString *const SUSkippedMajorSubreleaseVersionKey; extern NSString *const SUScheduledCheckIntervalKey; extern NSString *const SULastCheckTimeKey; -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT -extern NSString *const SUExpectsDSASignatureKey; extern NSString *const SUPublicDSAKeyKey; extern NSString *const SUPublicDSAKeyFileKey; -#endif extern NSString *const SUPublicEDKeyKey; extern NSString *const SUAutomaticallyUpdateKey; extern NSString *const SUAllowsAutomaticUpdatesKey; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 010aa188..b4339f0b 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -41,11 +41,8 @@ NSString *const SUSkippedMajorVersionKey = @"SUSkippedMajorVersion"; NSString *const SUSkippedMajorSubreleaseVersionKey = @"SUSkippedMajorSubreleaseVersion"; NSString *const SUScheduledCheckIntervalKey = @"SUScheduledCheckInterval"; NSString *const SULastCheckTimeKey = @"SULastCheckTime"; -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT -NSString *const SUExpectsDSASignatureKey = @"SUExpectsDSASignature"; NSString *const SUPublicDSAKeyKey = @"SUPublicDSAKey"; NSString *const SUPublicDSAKeyFileKey = @"SUPublicDSAKeyFile"; -#endif NSString *const SUPublicEDKeyKey = @"SUPublicEDKey"; NSString *const SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate"; NSString *const SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates"; @@ -75,7 +72,7 @@ NSString *const SURelaunchToolNameKey = @"SURelaunchToolName"; NSString *const SUAppcastAttributeDeltaFrom = @"sparkle:deltaFrom"; NSString *const SUAppcastAttributeDeltaFromSparkleExecutableSize = @"sparkle:deltaFromSparkleExecutableSize"; NSString *const SUAppcastAttributeDeltaFromSparkleLocales = @"sparkle:deltaFromSparkleLocales"; -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT +#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT || GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT NSString *const SUAppcastAttributeDSASignature = @"sparkle:dsaSignature"; #endif NSString *const SUAppcastAttributeEDSignature = @"sparkle:edSignature"; diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 3f5c5944..8f402d89 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -31,9 +31,7 @@ SPU_OBJC_DIRECT_MEMBERS @property (getter=isRunningOnReadOnlyVolume, nonatomic, readonly) BOOL runningOnReadOnlyVolume; @property (getter=isRunningTranslocated, nonatomic, readonly) BOOL runningTranslocated; -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT @property (readonly, nonatomic, copy, nullable) NSString *publicDSAKeyFileKey; -#endif - (nullable id)objectForInfoDictionaryKey:(NSString *)key; - (BOOL)boolForInfoDictionaryKey:(NSString *)key; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index a6bc4266..fff669ed 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -135,7 +135,6 @@ NS_ASSUME_NONNULL_BEGIN return [self objectForInfoDictionaryKey:SUPublicEDKeyKey]; } -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - (NSString *_Nullable)publicDSAKey SPU_OBJC_DIRECT { // Maybe the key is just a string in the Info.plist. @@ -161,23 +160,17 @@ NS_ASSUME_NONNULL_BEGIN } return key; } -#endif - (SUPublicKeys *)publicKeys { return [[SUPublicKeys alloc] initWithEd:[self publicEDKey] -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - dsa:[self publicDSAKey] -#endif - ]; + dsa:[self publicDSAKey]]; } -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - (NSString * _Nullable)publicDSAKeyFileKey { return [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey]; } -#endif - (nullable id)objectForInfoDictionaryKey:(NSString *)key { diff --git a/Sparkle/SUSignatures.h b/Sparkle/SUSignatures.h index fe48afe6..e95e9b98 100644 --- a/Sparkle/SUSignatures.h +++ b/Sparkle/SUSignatures.h @@ -47,10 +47,8 @@ SPU_OBJC_DIRECT_MEMBERS #endif @interface SUPublicKeys : NSObject -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT @property (nonatomic, readonly, nullable) NSString *dsaPubKey; @property (nonatomic, readonly) SUSigningInputStatus dsaPubKeyStatus; -#endif @property (nonatomic, readonly, nullable) const unsigned char *ed25519PubKey; @property (nonatomic, readonly) SUSigningInputStatus ed25519PubKeyStatus; @@ -59,9 +57,7 @@ SPU_OBJC_DIRECT_MEMBERS @property (nonatomic, readonly) BOOL hasAnyKeys; - (instancetype)initWithEd:(NSString * _Nullable)ed -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT dsa:(NSString * _Nullable)dsa -#endif ; @end diff --git a/Sparkle/SUSignatures.m b/Sparkle/SUSignatures.m index b871b79b..9e800073 100644 --- a/Sparkle/SUSignatures.m +++ b/Sparkle/SUSignatures.m @@ -150,21 +150,15 @@ static BOOL decodeStatus(NSCoder *decoder, NSString *key, SUSigningInputStatus * unsigned char _ed25519_public_key[32]; } -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT @synthesize dsaPubKey = _dsaPubKey; -#endif @synthesize ed25519PubKeyStatus = _ed25519PubKeyStatus; - (instancetype)initWithEd:(NSString * _Nullable)maybeEd25519 -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT dsa:(NSString * _Nullable)maybeDsa -#endif { self = [super init]; if (self) { -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT _dsaPubKey = maybeDsa; -#endif if (maybeEd25519 != nil) { NSData *ed = nil; _ed25519PubKeyStatus = decode(maybeEd25519, &ed); @@ -185,13 +179,11 @@ static BOOL decodeStatus(NSCoder *decoder, NSString *key, SUSigningInputStatus * return self; } -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - (SUSigningInputStatus)dsaPubKeyStatus { // We don't currently do any prevalidation of DSA public keys, // so this is always going to be "present" or "absent". return (_dsaPubKey != nil) ? SUSigningInputStatusPresent : SUSigningInputStatusAbsent; } -#endif - (const unsigned char *)ed25519PubKey { if (_ed25519PubKeyStatus == SUSigningInputStatusPresent) { @@ -201,12 +193,8 @@ static BOOL decodeStatus(NSCoder *decoder, NSString *key, SUSigningInputStatus * } - (BOOL)hasAnyKeys { - return - _ed25519PubKeyStatus != SUSigningInputStatusAbsent -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - || [self dsaPubKeyStatus] != SUSigningInputStatusAbsent -#endif - ; + return (_ed25519PubKeyStatus != SUSigningInputStatusAbsent) || + ([self dsaPubKeyStatus] != SUSigningInputStatusAbsent); } @end diff --git a/Sparkle/SUUpdateValidator.m b/Sparkle/SUUpdateValidator.m index a4f4597f..9cb97611 100644 --- a/Sparkle/SUUpdateValidator.m +++ b/Sparkle/SUUpdateValidator.m @@ -154,29 +154,14 @@ SUHost *newHost = [[SUHost alloc] initWithBundle:newBundle]; SUPublicKeys *newPublicKeys = newHost.publicKeys; -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT + BOOL oldHasLegacyDSAKey = publicKeys.dsaPubKeyStatus != SUSigningInputStatusAbsent; -#endif BOOL oldHasEdDSAKey = publicKeys.ed25519PubKeyStatus != SUSigningInputStatusAbsent; -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT BOOL oldHasAnyDSAKey = oldHasLegacyDSAKey || oldHasEdDSAKey; -#else - BOOL oldHasAnyDSAKey = oldHasEdDSAKey; -#endif -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT BOOL newHasLegacyDSAKey = newPublicKeys.dsaPubKeyStatus != SUSigningInputStatusAbsent; -#endif BOOL newHasEdDSAKey = newPublicKeys.ed25519PubKeyStatus != SUSigningInputStatusAbsent; -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT BOOL newHasAnyDSAKey = newHasLegacyDSAKey || newHasEdDSAKey; -#else - BOOL newHasAnyDSAKey = newHasEdDSAKey; -#endif -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT BOOL migratesDSAKeys = oldHasLegacyDSAKey && !oldHasEdDSAKey && newHasEdDSAKey && !newHasLegacyDSAKey; -#else - BOOL migratesDSAKeys = NO; -#endif BOOL updateIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:newHost.bundle.bundleURL]; BOOL hostIsCodeSigned = [SUCodeSigningVerifier bundleAtURLIsCodeSigned:host.bundle.bundleURL]; diff --git a/Tests/SUSignatureVerifierTest.m b/Tests/SUSignatureVerifierTest.m index f0465a83..d62bd538 100644 --- a/Tests/SUSignatureVerifierTest.m +++ b/Tests/SUSignatureVerifierTest.m @@ -30,7 +30,6 @@ _pubEdKey = @"rhHib+w769W2/6/t+oM1ZxgjBB93BfBKMLO0Qo1etQs="; } -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - (void)testVerifyFileAtPathUsingDSA { NSString *pubKey = [NSString stringWithContentsOfFile:_pubDSAKeyFile encoding:NSASCIIStringEncoding error:nil]; @@ -40,11 +39,19 @@ NSError *error = nil; +#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT XCTAssertTrue([self checkFile:_testFile withDSAKey:pubKey signature:validSig error:&error], @"Expected valid signature: %@", error); +#else + XCTAssertFalse([self checkFile:_testFile + withDSAKey:pubKey + signature:validSig + error:&error], + @"Expected DSA verification to fail: %@", error); +#endif XCTAssertFalse([self checkFile:_testFile withDSAKey:@"lol" @@ -64,11 +71,19 @@ error:&error], @"Expected invalid signature: %@", error); +#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT XCTAssertTrue([self checkFile:_testFile withDSAKey:pubKey signature:@"MC0CFAsKO7cq2q7L5/FWe6ybVIQkwAwSAhUA2Q8GKsE309eugi/v3Kh1W3w3N8c=" error:&error], @"Expected valid signature: %@", error); +#else + XCTAssertFalse([self checkFile:_testFile + withDSAKey:pubKey + signature:@"MC0CFAsKO7cq2q7L5/FWe6ybVIQkwAwSAhUA2Q8GKsE309eugi/v3Kh1W3w3N8c=" + error:&error], + @"Expected DSA verification to fail: %@", error); +#endif XCTAssertFalse([self checkFile:_testFile withDSAKey:pubKey @@ -76,7 +91,6 @@ error:&error], @"Expected invalid signature: %@", error); } -#endif - (void)testVerifyFileAtPathUsingED25519 { @@ -115,38 +129,47 @@ @"Invalid signature: %@", error); } -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - (BOOL)checkFile:(NSString *)aFile withDSAKey:(NSString *)pubKey signature:(NSString *)sigString error:(NSError * __autoreleasing *)error { SUPublicKeys *pubKeys = [[SUPublicKeys alloc] initWithEd:nil dsa:pubKey]; SUSignatureVerifier *v = [[SUSignatureVerifier alloc] initWithPublicKeys:pubKeys]; - SUSignatures *sig = [[SUSignatures alloc] initWithEd:nil dsa:sigString]; + SUSignatures *sig = [[SUSignatures alloc] initWithEd:nil +#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT + dsa:sigString +#endif + ]; return [v verifyFileAtPath:aFile signatures:sig error:error]; } + +static SUSignatures *_createSignatures(NSString *edString, NSString *dsaString) +{ +#if !SPARKLE_BUILD_LEGACY_DSA_SUPPORT + (void)dsaString; #endif + + SUSignatures *sig = [[SUSignatures alloc] initWithEd:edString +#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT + dsa:dsaString +#endif + ]; + + return sig; +} - (BOOL)checkFile:(NSString *)aFile withEdKey:(NSString *)pubKey signature:(NSString *)sigString error:(NSError * __autoreleasing *)error { SUPublicKeys *pubKeys = [[SUPublicKeys alloc] initWithEd:pubKey -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - dsa:nil -#endif - ]; + dsa:nil]; SUSignatureVerifier *v = [[SUSignatureVerifier alloc] initWithPublicKeys:pubKeys]; - SUSignatures *sig = [[SUSignatures alloc] initWithEd:sigString -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - dsa:nil -#endif - ]; + SUSignatures *sig = _createSignatures(sigString, nil); return [v verifyFileAtPath:aFile signatures:sig error:error]; } -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - (void)testVerifyFileWithBothKeys { NSString *dsaKey = [NSString stringWithContentsOfFile:_pubDSAKeyFile encoding:NSASCIIStringEncoding error:nil]; @@ -157,10 +180,10 @@ NSError *error = nil; XCTAssertFalse([v verifyFileAtPath:_testFile - signatures:[[SUSignatures alloc] initWithEd:nil dsa:nil] error:&error], + signatures:_createSignatures(nil, nil) error:&error], @"Fail if no signatures are provided: %@", error); XCTAssertFalse([v verifyFileAtPath:_testFile - signatures:[[SUSignatures alloc] initWithEd:@"lol" dsa:@"lol"] error:&error], + signatures:_createSignatures(@"lol", @"lol") error:&error], @"Fail if both signatures are invalid: %@", error); NSString *dsaSig = @"MCwCFCIHCIYYkfZavNzTitTW5tlRp/k5AhQ40poFytqcVhIYdCxQznaXeJPJDQ=="; @@ -169,38 +192,43 @@ NSString *wrongEdSig = @"wTcpXCgWoa4NrJpsfzS61FXJIbv963//12U2ef9xstzVOLPHYK2N4/ojgpDV5N1/NGG1uWMBgK+kEWp0Z5zMDQ=="; XCTAssertFalse([v verifyFileAtPath:_testFile - signatures:[[SUSignatures alloc] initWithEd:nil dsa:dsaSig] error:&error], + signatures:_createSignatures(nil, dsaSig) error:&error], @"EdDSA signature must be present if app has EdDSA key: %@", error); XCTAssertTrue([v verifyFileAtPath:_testFile - signatures:[[SUSignatures alloc] initWithEd:edSig dsa:nil] error:&error], + signatures:_createSignatures(edSig, nil) error:&error], @"Allow just an EdDSA signature if that's all that's available: %@", error); XCTAssertFalse([v verifyFileAtPath:_testFile - signatures:[[SUSignatures alloc] initWithEd:wrongEdSig dsa:dsaSig] error:&error], + signatures:_createSignatures(wrongEdSig, dsaSig) error:&error], @"Fail on a bad Ed25519 signature regardless: %@", error); XCTAssertTrue([v verifyFileAtPath:_testFile - signatures:[[SUSignatures alloc] initWithEd:edSig dsa:wrongDSASig] error:&error], + signatures:_createSignatures(edSig, wrongDSASig) error:&error], @"Allow bad DSA signature if EdDSA signature is good: %@", error); XCTAssertFalse([v verifyFileAtPath:_testFile - signatures:[[SUSignatures alloc] initWithEd:@"lol" dsa:dsaSig] error:&error], + signatures:_createSignatures(@"lol", dsaSig) error:&error], @"Fail if the Ed25519 signature is invalid: %@", error); + +#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT XCTAssertFalse([v verifyFileAtPath:_testFile - signatures:[[SUSignatures alloc] initWithEd:edSig dsa:@"lol"] error:&error], + signatures:_createSignatures(edSig, @"lol") error:&error], @"Fail if invalid DSA signature is used even if EdDSA signature is good: %@", error); +#else + XCTAssertTrue([v verifyFileAtPath:_testFile + signatures:_createSignatures(edSig, @"lol") error:&error], + @"Allow invalid DSA signature if EdDSA signature is good: %@", error); +#endif XCTAssertTrue([v verifyFileAtPath:_testFile - signatures:[[SUSignatures alloc] initWithEd:edSig dsa:dsaSig] error:&error], + signatures:_createSignatures(edSig, dsaSig) error:&error], @"Pass if both are valid: %@", error); } -#endif - (void)testVerifyFileWithWrongKey { NSError *error = nil; -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT NSString *dsaSig = @"MCwCFCIHCIYYkfZavNzTitTW5tlRp/k5AhQ40poFytqcVhIYdCxQznaXeJPJDQ=="; NSString *edSig = @"EIawm2YkDZ2gBfkEMF2+1VuuTeXnCGZOdnMdVgPPvDZioq7bvDayXqKkIIzSjKMmeFdcFJOHdnba5ZV60+gPBw=="; @@ -211,23 +239,15 @@ SUSignatureVerifier *dsaOnlyVerifier = [[SUSignatureVerifier alloc] initWithPublicKeys:dsaOnlyKeys]; XCTAssertFalse([dsaOnlyVerifier verifyFileAtPath:_testFile - signatures:[[SUSignatures alloc] initWithEd:edSig dsa:nil] error:&error], + signatures:_createSignatures(edSig, nil) error:&error], @"DSA cannot verify an Ed signature: %@", error); -#endif SUPublicKeys *edOnlyKeys = [[SUPublicKeys alloc] initWithEd:_pubEdKey -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - dsa:nil -#endif - ]; + dsa:nil]; SUSignatureVerifier *edOnlyVerifier = [[SUSignatureVerifier alloc] initWithPublicKeys:edOnlyKeys]; { - SUSignatures *signatures = [[SUSignatures alloc] initWithEd:nil -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - dsa:dsaSig -#endif - ]; + SUSignatures *signatures = _createSignatures(nil, dsaSig); XCTAssertFalse([edOnlyVerifier verifyFileAtPath:_testFile signatures:signatures error:&error], @@ -236,7 +256,6 @@ } -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT - (void)testValidatePath { NSString *dsaStr = [NSString stringWithContentsOfFile:_pubDSAKeyFile encoding:NSASCIIStringEncoding error:nil]; @@ -245,13 +264,18 @@ XCTAssertNotNil(pubkeys); XCTAssertNotNil(pubkeys.dsaPubKey); - SUSignatures *sig = [[SUSignatures alloc] initWithEd:nil dsa:@"MC0CFFMF3ha5kjvrJ9JTpTR8BenPN9QUAhUAzY06JRdtP17MJewxhK0twhvbKIE="]; + SUSignatures *sig = _createSignatures(nil, @"MC0CFFMF3ha5kjvrJ9JTpTR8BenPN9QUAhUAzY06JRdtP17MJewxhK0twhvbKIE="); XCTAssertNotNil(sig); +#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT XCTAssertNotNil(sig.dsaSignature); - - NSError *error = nil; - XCTAssertTrue([SUSignatureVerifier validatePath:_testFile withSignatures:sig withPublicKeys:pubkeys error:&error], @"Expected valid signature: %@", error); -} #endif + NSError *error = nil; +#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT + XCTAssertTrue([SUSignatureVerifier validatePath:_testFile withSignatures:sig withPublicKeys:pubkeys error:&error], @"Expected valid signature: %@", error); +#else + XCTAssertFalse([SUSignatureVerifier validatePath:_testFile withSignatures:sig withPublicKeys:pubkeys error:&error], @"Expected verification to fail due to disabling DSA: %@", error); +#endif +} + @end diff --git a/Tests/SUUpdateValidatorTest.swift b/Tests/SUUpdateValidatorTest.swift index d8d990a5..5e69c99a 100644 --- a/Tests/SUUpdateValidatorTest.swift +++ b/Tests/SUUpdateValidatorTest.swift @@ -12,9 +12,7 @@ import XCTest class SUUpdateValidatorTest: XCTestCase { enum BundleConfig: String, CaseIterable, Equatable { case none = "None" -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT case dsaOnly = "DSAOnly" -#endif case edOnly = "EDOnly" case both = "Both" case codeSignedOnly = "CodeSignedOnly" @@ -31,10 +29,8 @@ class SUUpdateValidatorTest: XCTestCase { return false case .edOnly, .both, .codeSignedBoth, .codeSignedBothNew, .codeSignedOldED, .codeSignedInvalid: return true -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT case .dsaOnly: return true -#endif } } } @@ -129,6 +125,8 @@ class SUUpdateValidatorTest: XCTestCase { #endif #if SPARKLE_BUILD_LEGACY_DSA_SUPPORT testPrevalidation(bundle: .both, signatures: signatureConfig, expectedResult: signatureConfig.ed == .valid && signatureConfig.dsa != .invalidFormat) +#else + testPrevalidation(bundle: .both, signatures: signatureConfig, expectedResult: signatureConfig.ed == .valid) #endif } } @@ -166,6 +164,8 @@ class SUUpdateValidatorTest: XCTestCase { #endif #if SPARKLE_BUILD_LEGACY_DSA_SUPPORT testPostValidation(bundle: .both, signatures: signatureConfig, expectedResult: signatureConfig.ed == .valid && signatureConfig.dsa != .invalidFormat) +#else + testPostValidation(bundle: .both, signatures: signatureConfig, expectedResult: signatureConfig.ed == .valid) #endif } } @@ -188,6 +188,8 @@ class SUUpdateValidatorTest: XCTestCase { for bundleConfig in BundleConfig.allCases { #if SPARKLE_BUILD_LEGACY_DSA_SUPPORT testPostValidation(oldBundle: .dsaOnly, newBundle: bundleConfig, signatures: SignatureConfig(ed: .valid, dsa: .valid), expectedResult: bundleConfig.hasAnyKeys && bundleConfig != .codeSignedInvalid) +#else + testPostValidation(oldBundle: .dsaOnly, newBundle: bundleConfig, signatures: SignatureConfig(ed: .valid), expectedResult: false) #endif do { #if SPARKLE_BUILD_LEGACY_DSA_SUPPORT @@ -199,6 +201,8 @@ class SUUpdateValidatorTest: XCTestCase { } #if SPARKLE_BUILD_LEGACY_DSA_SUPPORT testPostValidation(oldBundle: .both, newBundle: bundleConfig, signatures: SignatureConfig(ed: .valid, dsa: .valid), expectedResult: bundleConfig.hasAnyKeys && bundleConfig != .codeSignedInvalid) +#else + testPostValidation(oldBundle: .both, newBundle: bundleConfig, signatures: SignatureConfig(ed: .valid), expectedResult: bundleConfig.hasAnyKeys && bundleConfig != .codeSignedInvalid) #endif do { #if SPARKLE_BUILD_LEGACY_DSA_SUPPORT diff --git a/generate_appcast/Appcast.swift b/generate_appcast/Appcast.swift index f8b6a676..87d8584f 100644 --- a/generate_appcast/Appcast.swift +++ b/generate_appcast/Appcast.swift @@ -179,7 +179,7 @@ func makeAppcasts(archivesSourceDir: URL, outputPathURL: URL?, cacheDirectory ca group.enter() DispatchQueue.global().async { -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT if let privateDSAKey = keys.privateDSAKey { do { update.dsaSignature = try dsaSignature(path: update.archivePath, privateDSAKey: privateDSAKey) @@ -343,7 +343,7 @@ func makeAppcasts(archivesSourceDir: URL, outputPathURL: URL?, cacheDirectory ca group.enter() DispatchQueue.global().async { -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT if item.supportsDSA, let privateDSAKey = keys.privateDSAKey { do { delta.dsaSignature = try dsaSignature(path: deltaPath, privateDSAKey: privateDSAKey) @@ -361,7 +361,7 @@ func makeAppcasts(archivesSourceDir: URL, outputPathURL: URL?, cacheDirectory ca } do { var hasAnyDSASignature = (delta.edSignature != nil) -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT hasAnyDSASignature = hasAnyDSASignature || (delta.dsaSignature != nil) #endif if hasAnyDSASignature { diff --git a/generate_appcast/ArchiveItem.swift b/generate_appcast/ArchiveItem.swift index f1d3e9cd..646dca07 100644 --- a/generate_appcast/ArchiveItem.swift +++ b/generate_appcast/ArchiveItem.swift @@ -16,7 +16,7 @@ struct UpdateBranch: Hashable { class DeltaUpdate { let fromVersion: String let archivePath: URL -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT var dsaSignature: String? #endif var edSignature: String? @@ -77,7 +77,7 @@ class ArchiveItem: CustomStringConvertible { let archiveFileAttributes: [FileAttributeKey: Any] var deltas: [DeltaUpdate] -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT var dsaSignature: String? #endif var edSignature: String? @@ -146,7 +146,7 @@ class ArchiveItem: CustomStringConvertible { } let shortVersion = infoPlist["CFBundleShortVersionString"] as? String let publicEdKey = infoPlist[SUPublicEDKeyKey] as? String -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT let supportsDSA = infoPlist[SUPublicDSAKeyKey] != nil || infoPlist[SUPublicDSAKeyFileKey] != nil #else let supportsDSA = false diff --git a/generate_appcast/FeedXML.swift b/generate_appcast/FeedXML.swift index 157fffff..6411cf57 100644 --- a/generate_appcast/FeedXML.swift +++ b/generate_appcast/FeedXML.swift @@ -448,7 +448,7 @@ func writeAppcast(appcastDestPath: URL, appcast: Appcast, fullReleaseNotesLink: if let sig = update.edSignature { attributes.append(XMLNode.attribute(withName: SUAppcastAttributeEDSignature, uri: sparkleNS, stringValue: sig) as! XMLNode) } -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT if let sig = update.dsaSignature { attributes.append(XMLNode.attribute(withName: SUAppcastAttributeDSASignature, uri: sparkleNS, stringValue: sig) as! XMLNode) } @@ -482,7 +482,7 @@ func writeAppcast(appcastDestPath: URL, appcast: Appcast, fullReleaseNotesLink: if let sig = delta.edSignature { attributes.append(XMLNode.attribute(withName: SUAppcastAttributeEDSignature, uri: sparkleNS, stringValue: sig) as! XMLNode) } -#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT if let sig = delta.dsaSignature { attributes.append(XMLNode.attribute(withName: SUAppcastAttributeDSASignature, uri: sparkleNS, stringValue: sig) as! XMLNode) } diff --git a/generate_appcast/Signatures.swift b/generate_appcast/Signatures.swift index ed8b0fd0..8bd3041f 100644 --- a/generate_appcast/Signatures.swift +++ b/generate_appcast/Signatures.swift @@ -17,6 +17,7 @@ struct PrivateKeys { } } +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT func loadPrivateDSAKey(at privateKeyURL: URL) throws -> SecKey { let data = try Data(contentsOf: privateKeyURL) @@ -94,6 +95,7 @@ func dsaSignature(path: URL, privateDSAKey: SecKey) throws -> String { } return resultData.base64EncodedString() } +#endif func edSignature(path: URL, publicEdKey: Data, privateEdKey: Data) throws -> String { assert(publicEdKey.count == 32) diff --git a/generate_appcast/main.swift b/generate_appcast/main.swift index 7e902d81..8ef2bd2a 100644 --- a/generate_appcast/main.swift +++ b/generate_appcast/main.swift @@ -63,17 +63,21 @@ struct GenerateAppcast: ParsableCommand { @Option(name: .customLong("ed-key-file"), help: ArgumentHelp("Path to the private EdDSA key file. If not specified, the private EdDSA key will be read from the Keychain instead. '-' can be used to echo the EdDSA key from a 'secret' environment variable to the standard input stream. For example: echo \"$PRIVATE_KEY_SECRET\" | ./\(programName) --ed-key-file -", valueName: "private-EdDSA-key-file")) var privateEdKeyPath: String? +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT @Option(name: .customShort("f"), help: ArgumentHelp("Path to the private DSA key file. Only use this option for transitioning to EdDSA from older updates.", valueName: "private-dsa-key-file"), transform: { URL(fileURLWithPath: $0) }) var privateDSAKeyURL: URL? @Option(name: .customShort("n"), help: ArgumentHelp("The name of the private DSA key. This option must be used together with `-k`. Only use this option for transitioning to EdDSA from older updates.", valueName: "dsa-key-name")) var privateDSAKeyName: String? +#endif @Option(name: .customShort("s"), help: ArgumentHelp("(DEPRECATED): The private EdDSA string (128 characters). This option is deprecated. Please use the Keychain, or pass the key as standard input when using the --ed-key-file - option instead.", valueName: "private-EdDSA-key")) var privateEdString : String? +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT @Option(name: .customShort("k"), help: ArgumentHelp("The path to the keychain to look up the private DSA key. This option must be used together with `-n`. Only use this option for transitioning to EdDSA from older updates.", valueName: "keychain-for-dsa"), transform: { URL(fileURLWithPath: $0) }) var keychainURL: URL? +#endif @Option(name: .customLong("download-url-prefix"), help: ArgumentHelp("A URL that will be used as prefix for the URL from where updates will be downloaded.", valueName: "url"), transform: { URL(string: $0) }) var downloadURLPrefix : URL? @@ -187,6 +191,7 @@ struct GenerateAppcast: ParsableCommand { """) func validate() throws { +#if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT guard (keychainURL == nil) == (privateDSAKeyName == nil) else { throw ValidationError("Both -n and -k options must be provided together, or neither should be provided.") } @@ -195,6 +200,7 @@ struct GenerateAppcast: ParsableCommand { guard (keychainURL == nil) || (privateDSAKeyURL == nil) else { throw ValidationError("-f cannot be provided if -n and -k is provided") } +#endif guard (privateEdKeyPath == nil) || (privateEdString == nil) else { throw ValidationError("--ed-key-file cannot be provided if -s is provided") @@ -224,6 +230,7 @@ struct GenerateAppcast: ParsableCommand { func run() throws { // Extract the keys let privateDSAKey : SecKey? + #if GENERATE_APPCAST_BUILD_LEGACY_DSA_SUPPORT if let privateDSAKeyURL = privateDSAKeyURL { do { privateDSAKey = try loadPrivateDSAKey(at: privateDSAKeyURL) @@ -241,6 +248,9 @@ struct GenerateAppcast: ParsableCommand { } else { privateDSAKey = nil } + #else + privateDSAKey = nil + #endif let privateEdKeyString: String? if let privateEdString = privateEdString {