mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Add exception handling to secure coding archivers/unarchivers
This commit is contained in:
1 parent
8b19b0e1b4
commit
fa36cb300b
3 files changed
+24
-10
No files matched your search
Vendored
+4
@@ -250,6 +250,10 @@
|
||||
SUInstallationInputData *installationData = [[SUInstallationInputData alloc] initWithRelaunchPath:pathToRelaunch progressToolPath:progressToolPath hostBundlePath:self.host.bundlePath updateDirectoryPath:self.temporaryDirectory downloadName:self.downloadName dsaSignature:dsaSignature decryptionPassword:decryptionPassword];
|
||||
|
||||
NSData *archivedData = SUArchiveRootObjectSecurely(installationData);
|
||||
if (archivedData == nil) {
|
||||
[self.delegate installerIsRequestingAbortInstallWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while encoding the installer parameters. Please try again later.", nil) }]];
|
||||
return;
|
||||
}
|
||||
|
||||
__weak SUInstallerDriver *weakSelf = self;
|
||||
[self setUpRemotePortWithCompletion:^(BOOL setupSuccess) {
|
||||
|
||||
Vendored
+1
-1
@@ -10,7 +10,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
NSData *SUArchiveRootObjectSecurely(id<NSSecureCoding> rootObject);
|
||||
NSData * _Nullable SUArchiveRootObjectSecurely(id<NSSecureCoding> rootObject);
|
||||
|
||||
id<NSSecureCoding> _Nullable SUUnarchiveRootObjectSecurely(NSData *data, Class klass);
|
||||
|
||||
|
||||
Vendored
+19
-9
@@ -10,16 +10,21 @@
|
||||
|
||||
static NSString *SURootObjectArchiveKey = @"SURootObjectArchive";
|
||||
|
||||
NSData *SUArchiveRootObjectSecurely(id<NSSecureCoding> rootObject)
|
||||
NSData * _Nullable SUArchiveRootObjectSecurely(id<NSSecureCoding> rootObject)
|
||||
{
|
||||
NSMutableData *data = [NSMutableData data];
|
||||
NSKeyedArchiver *keyedArchiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
|
||||
keyedArchiver.requiresSecureCoding = YES;
|
||||
|
||||
[keyedArchiver encodeObject:rootObject forKey:SURootObjectArchiveKey];
|
||||
[keyedArchiver finishEncoding];
|
||||
|
||||
return [data copy];
|
||||
@try {
|
||||
[keyedArchiver encodeObject:rootObject forKey:SURootObjectArchiveKey];
|
||||
[keyedArchiver finishEncoding];
|
||||
return [data copy];
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"Exception while securely archiving object: %@", exception);
|
||||
[keyedArchiver finishEncoding];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
id<NSSecureCoding> _Nullable SUUnarchiveRootObjectSecurely(NSData *data, Class klass)
|
||||
@@ -27,8 +32,13 @@ id<NSSecureCoding> _Nullable SUUnarchiveRootObjectSecurely(NSData *data, Class k
|
||||
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
|
||||
unarchiver.requiresSecureCoding = YES;
|
||||
|
||||
id<NSSecureCoding> rootObject = [unarchiver decodeObjectOfClass:klass forKey:SURootObjectArchiveKey];
|
||||
[unarchiver finishDecoding];
|
||||
|
||||
return rootObject;
|
||||
@try {
|
||||
id<NSSecureCoding> rootObject = [unarchiver decodeObjectOfClass:klass forKey:SURootObjectArchiveKey];
|
||||
[unarchiver finishDecoding];
|
||||
return rootObject;
|
||||
} @catch (NSException *exception) {
|
||||
NSLog(@"Exception while securely unarchiving object: %@", exception);
|
||||
[unarchiver finishDecoding];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user