Add exception handling to secure coding archivers/unarchivers

This commit is contained in:
Zorg committed 2016-05-14 23:27:59 -04:00
1 parent 8b19b0e1b4
commit fa36cb300b
3 files changed
+24 -10

No files matched your search

+4
View File
@@ -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) {
+1 -1
View File
@@ -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);
+19 -9
View File
@@ -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;
}
}