From 59933ce1d69ebf1d41e2497d19bce9f16e769ca6 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 11 Jan 2018 11:15:50 -0500 Subject: [PATCH] Fix rebase breakage. --- Signal/src/AppDelegate.m | 6 +++--- Signal/src/ViewControllers/DebugUI/DebugUIMisc.m | 9 --------- .../ViewControllers/OWSBackupExportViewController.m | 1 + Signal/src/util/OWSBackup.m | 13 +++++++++++-- SignalServiceKit/src/Util/OWSFileSystem.h | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 313887e48..72418628c 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -130,13 +130,13 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; SetRandFunctionSeed(); + // XXX - careful when moving this. It must happen before we initialize TSStorageManager. + [self verifyDBKeysAvailableBeforeBackgroundLaunch]; + // If a backup restore is in progress, try to complete it. // Otherwise, cleanup backup state. [OWSBackup applicationDidFinishLaunching]; - // XXX - careful when moving this. It must happen before we initialize TSStorageManager. - [self verifyDBKeysAvailableBeforeBackgroundLaunch]; - // Prevent the device from sleeping during database view async registration // (e.g. long database upgrades). // diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m b/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m index 30cc540e0..56ecea710 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m @@ -95,15 +95,6 @@ NS_ASSUME_NONNULL_BEGIN [DebugUIMisc sendUnencryptedDatabase:thread]; }]]; } - [items addObject:[OWSTableItem - subPageItemWithText:@"Export Backup w/ Password" - actionBlock:^(UIViewController *viewController) { - OWSBackupExportViewController *backupViewController = - [OWSBackupExportViewController new]; - [backupViewController exportBackup:thread skipPassword:NO]; - [viewController.navigationController pushViewController:backupViewController - animated:YES]; - }]]; [items addObject:[OWSTableItem subPageItemWithText:@"Export Backup w/o Password" actionBlock:^(UIViewController *viewController) { diff --git a/Signal/src/ViewControllers/OWSBackupExportViewController.m b/Signal/src/ViewControllers/OWSBackupExportViewController.m index 82d169e71..bebd6165f 100644 --- a/Signal/src/ViewControllers/OWSBackupExportViewController.m +++ b/Signal/src/ViewControllers/OWSBackupExportViewController.m @@ -217,6 +217,7 @@ NS_ASSUME_NONNULL_BEGIN { OWSAssert(self.backup.backupPassword.length > 0); + // TODO: We could consider clearing the password from the pasteboard after a certain delay. [UIPasteboard.generalPasteboard setString:self.backup.backupPassword]; } diff --git a/Signal/src/util/OWSBackup.m b/Signal/src/util/OWSBackup.m index e2828eb4b..cf6ae7b2c 100644 --- a/Signal/src/util/OWSBackup.m +++ b/Signal/src/util/OWSBackup.m @@ -667,6 +667,10 @@ NSString *const Keychain_ImportBackupKey = @"ImportBackupKey"; } self.encryptionKey = [OWSAES256Key keyWithData:encryptionKeyData]; + if (![self isValidBackup]) { + return; + } + NSData *_Nullable databasePassword = [self readDataFromFileName:OWSBackup_DatabasePasswordFilename]; if (!databasePassword) { OWSFail(@"%@ Could not retrieve database password.", self.logTag); @@ -771,6 +775,10 @@ NSString *const Keychain_ImportBackupKey = @"ImportBackupKey"; DDLogInfo(@"%@ restoreDirectoryContents: %@ -> %@", self.logTag, srcDirPath, dstDirPath); if (![[NSFileManager defaultManager] fileExistsAtPath:srcDirPath]) { + // Not all backups will have both a "app documents" and "shared data container" folder. + // The latter should always be present for "modern" installs, but we are permissive + // here about what we accept so that we can easily apply this branch to historic + // (pre-shared data container) versions of the app and restore from them. DDLogInfo(@"%@ Skipping restore directory: %@.", self.logTag, srcDirPath); return YES; } @@ -861,9 +869,10 @@ NSString *const Keychain_ImportBackupKey = @"ImportBackupKey"; - (NSString *)relativePathforPath:(NSString *)filePath basePath:(NSString *)basePath { OWSAssert(filePath.stringByStandardizingPath.length > 0); - OWSAssert([filePath.stringByStandardizingPath hasPrefix:basePath]); + OWSAssert([filePath.stringByStandardizingPath hasPrefix:basePath.stringByStandardizingPath]); - NSString *relativePath = [filePath.stringByStandardizingPath substringFromIndex:basePath.length]; + NSString *relativePath = + [filePath.stringByStandardizingPath substringFromIndex:basePath.stringByStandardizingPath.length]; NSString *separator = @"/"; if ([relativePath hasPrefix:separator]) { relativePath = [relativePath substringFromIndex:separator.length]; diff --git a/SignalServiceKit/src/Util/OWSFileSystem.h b/SignalServiceKit/src/Util/OWSFileSystem.h index fceb6f7fe..20903497b 100644 --- a/SignalServiceKit/src/Util/OWSFileSystem.h +++ b/SignalServiceKit/src/Util/OWSFileSystem.h @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)init NS_UNAVAILABLE; // TODO: We shouldn't ignore the return value of this method. -+ (BOOL)protectFileOrFolderAtPath:(NSString *)path; ++ (BOOL)protectFileOrFolderAtPath:(NSString *)path __attribute__((warn_unused_result)); + (NSString *)appDocumentDirectoryPath;