From b05c05821908cf23a31582e5cbc31a1a85effbd1 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 9 Jan 2022 19:25:28 -0800 Subject: [PATCH] Silence deprecations and use modern NSSecureCoding APIs (#2058) --- Autoupdate/SPUXarDeltaArchive.m | 8 +++ Autoupdate/SUSignatureVerifier.m | 13 ++++ .../InstallerProgressAppController.m | 2 +- Sparkle/SPUSecureCoding.m | 69 +++++++++++++------ Sparkle/SULegacyWebView.m | 5 ++ Sparkle/SULog.m | 19 +++++ TestApplication/SUTestApplicationDelegate.m | 2 +- 7 files changed, 94 insertions(+), 24 deletions(-) diff --git a/Autoupdate/SPUXarDeltaArchive.m b/Autoupdate/SPUXarDeltaArchive.m index f6389192..63eed9a3 100644 --- a/Autoupdate/SPUXarDeltaArchive.m +++ b/Autoupdate/SPUXarDeltaArchive.m @@ -106,7 +106,11 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import)); - (nullable SPUDeltaArchiveHeader *)readHeader { NSString *patchFile = self.patchFile; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // Sparkle's XAR delta archives have been superceded by Sparkle's own format xar_t x = xar_open(patchFile.fileSystemRepresentation, READ); +#pragma clang diagnostic pop if (x == NULL) { self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to xar_open() file for reading: %@", patchFile] }]; return nil; @@ -175,7 +179,11 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import)); { NSString *patchFile = self.patchFile; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // Sparkle's XAR delta archives have been superceded by Sparkle's own format xar_t x = xar_open(patchFile.fileSystemRepresentation, WRITE); +#pragma clang diagnostic pop if (x == NULL) { self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to xar_open() file for writing: %@", patchFile] }]; return; diff --git a/Autoupdate/SUSignatureVerifier.m b/Autoupdate/SUSignatureVerifier.m index 64eae48e..ff3d0624 100644 --- a/Autoupdate/SUSignatureVerifier.m +++ b/Autoupdate/SUSignatureVerifier.m @@ -265,7 +265,11 @@ return NO; } + // Sparkle's DSA support is deprecated +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" __block SecGroupTransformRef group = SecTransformCreateGroupTransform(); +#pragma clang diagnostic pop __block SecTransformRef dataReadTransform = NULL; __block SecTransformRef dataDigestTransform = NULL; __block SecTransformRef dataVerifyTransform = NULL; @@ -318,7 +322,10 @@ return cleanup(); } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" SecTransformConnectTransforms(dataReadTransform, kSecTransformOutputAttributeName, dataDigestTransform, kSecTransformInputAttributeName, group, &error); +#pragma clang diagnostic pop if (error) { if (outError != NULL) { *outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{NSLocalizedDescriptionKey : @"Failed to connect data read transform", NSUnderlyingErrorKey: (__bridge NSError *)error}]; @@ -327,7 +334,10 @@ return cleanup(); } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" SecTransformConnectTransforms(dataDigestTransform, kSecTransformOutputAttributeName, dataVerifyTransform, kSecTransformInputAttributeName, group, &error); +#pragma clang diagnostic pop if (error) { if (outError != NULL) { *outError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{NSLocalizedDescriptionKey : @"Failed to connect data digest transform", NSUnderlyingErrorKey: (__bridge NSError *)error}]; @@ -336,7 +346,10 @@ return cleanup(); } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" NSNumber *result = CFBridgingRelease(SecTransformExecute(group, &error)); +#pragma clang diagnostic pop if (error) { SULog(SULogLevelError, @"DSA signature verification failed: %@", error); if (outError != NULL) { diff --git a/Sparkle/InstallerProgress/InstallerProgressAppController.m b/Sparkle/InstallerProgress/InstallerProgressAppController.m index 71ab1816..7c519870 100644 --- a/Sparkle/InstallerProgress/InstallerProgressAppController.m +++ b/Sparkle/InstallerProgress/InstallerProgressAppController.m @@ -331,7 +331,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3; } // Note: we can launch application bundles or open plug-in bundles - if (![[NSWorkspace sharedWorkspace] openFile:pathToRelaunch]) { + if (![[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:pathToRelaunch isDirectory:YES]]) { SULog(SULogLevelError, @"Error: Failed to relaunch bundle at %@", pathToRelaunch); } diff --git a/Sparkle/SPUSecureCoding.m b/Sparkle/SPUSecureCoding.m index 15d0a9b5..f148630d 100644 --- a/Sparkle/SPUSecureCoding.m +++ b/Sparkle/SPUSecureCoding.m @@ -16,33 +16,58 @@ static NSString *SURootObjectArchiveKey = @"SURootObjectArchive"; NSData * _Nullable SPUArchiveRootObjectSecurely(id rootObject) { - NSMutableData *data = [NSMutableData data]; - NSKeyedArchiver *keyedArchiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; - keyedArchiver.requiresSecureCoding = YES; - - @try { - [keyedArchiver encodeObject:rootObject forKey:SURootObjectArchiveKey]; - [keyedArchiver finishEncoding]; - return [data copy]; - } @catch (NSException *exception) { - SULog(SULogLevelError, @"Exception while securely archiving object: %@", exception); - [keyedArchiver finishEncoding]; - return nil; + if (@available(macOS 10.13, *)) { + NSError *error = nil; + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rootObject requiringSecureCoding:YES error:&error]; + if (data == nil) { + SULog(SULogLevelError, @"Error while securely archiving object: %@", error); + } + return data; + } else { + NSMutableData *data = [NSMutableData data]; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + NSKeyedArchiver *keyedArchiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; +#pragma clang diagnostic pop + keyedArchiver.requiresSecureCoding = YES; + + @try { + [keyedArchiver encodeObject:rootObject forKey:SURootObjectArchiveKey]; + [keyedArchiver finishEncoding]; + return [data copy]; + } @catch (NSException *exception) { + SULog(SULogLevelError, @"Exception while securely archiving object: %@", exception); + [keyedArchiver finishEncoding]; + return nil; + } } } id _Nullable SPUUnarchiveRootObjectSecurely(NSData *data, Class klass) { - NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; - unarchiver.requiresSecureCoding = YES; - - @try { - id rootObject = [unarchiver decodeObjectOfClass:klass forKey:SURootObjectArchiveKey]; - [unarchiver finishDecoding]; + if (@available(macOS 10.13, *)) { + NSError *error = nil; + id rootObject = [NSKeyedUnarchiver unarchivedObjectOfClass:klass fromData:data error:&error]; + if (rootObject == nil) { + SULog(SULogLevelError, @"Error while securely unarchiving object: %@", error); + } return rootObject; - } @catch (NSException *exception) { - SULog(SULogLevelError, @"Exception while securely unarchiving object: %@", exception); - [unarchiver finishDecoding]; - return nil; + } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; +#pragma clang diagnostic pop + unarchiver.requiresSecureCoding = YES; + + @try { + id rootObject = [unarchiver decodeObjectOfClass:klass forKey:SURootObjectArchiveKey]; + [unarchiver finishDecoding]; + return rootObject; + } @catch (NSException *exception) { + SULog(SULogLevelError, @"Exception while securely unarchiving object: %@", exception); + [unarchiver finishDecoding]; + return nil; + } } } diff --git a/Sparkle/SULegacyWebView.m b/Sparkle/SULegacyWebView.m index e51307e9..45c1b55e 100644 --- a/Sparkle/SULegacyWebView.m +++ b/Sparkle/SULegacyWebView.m @@ -13,6 +13,9 @@ #import "SULog.h" #import +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + @interface SULegacyWebView () @property (nonatomic, readonly) WebView *webView; @@ -163,4 +166,6 @@ @end +#pragma clang diagnostic pop + #endif diff --git a/Sparkle/SULog.m b/Sparkle/SULog.m index 20029de3..288bb8fc 100644 --- a/Sparkle/SULog.m +++ b/Sparkle/SULog.m @@ -65,7 +65,10 @@ void SULog(SULogLevel level, NSString *format, ...) } NSString *displayName = [[NSFileManager defaultManager] displayNameAtPath:mainBundle.bundlePath]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" client = asl_open([displayName stringByAppendingString:@" [Sparkle]"].UTF8String, SPARKLE_BUNDLE_IDENTIFIER, options); +#pragma clang diagnostic pop queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); } }); @@ -103,13 +106,20 @@ void SULog(SULogLevel level, NSString *format, ...) // Otherwise use ASL // Make sure we do not async, because if we async, the log may not be delivered deterministically + // TODO: When we remove support for macOS 10.11, remove all this asl code dispatch_sync(queue, ^{ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" aslmsg message = asl_new(ASL_TYPE_MSG); +#pragma clang diagnostic pop if (message == NULL) { return; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" if (asl_set(message, ASL_KEY_MSG, logMessage.UTF8String) != 0) { +#pragma clang diagnostic pop return; } @@ -117,16 +127,25 @@ void SULog(SULogLevel level, NSString *format, ...) switch (level) { case SULogLevelDefault: // Just use one level below the error level +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" levelSetResult = asl_set(message, ASL_KEY_LEVEL, TO_STRING(ASL_LEVEL_WARNING)); +#pragma clang diagnostic pop break; case SULogLevelError: +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" levelSetResult = asl_set(message, ASL_KEY_LEVEL, TO_STRING(ASL_LEVEL_ERR)); +#pragma clang diagnostic pop break; } if (levelSetResult != 0) { return; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" asl_send(client, message); +#pragma clang diagnostic pop }); } diff --git a/TestApplication/SUTestApplicationDelegate.m b/TestApplication/SUTestApplicationDelegate.m index 87acc9a2..beb97810 100644 --- a/TestApplication/SUTestApplicationDelegate.m +++ b/TestApplication/SUTestApplicationDelegate.m @@ -16,7 +16,7 @@ #import "SUPopUpTitlebarUserDriver.h" #import "SUBinaryDeltaCreate.h" -@interface SUTestApplicationDelegate () +@interface SUTestApplicationDelegate () @property (nonatomic) SPUUpdater *updater; @property (nonatomic) SUUpdateSettingsWindowController *updateSettingsWindowController;