From 9516ab1106b81fc80dfcb3b6bd8a23874e53f3f4 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 23 Jan 2017 17:26:35 -0500 Subject: [PATCH] Bail on startup if DB password is inaccessible Most likely this would be because the user hasn't unlocked their device since last restart. This behavior existed once before, but the startup ordering is pretty delicate. So, we're now redundantly checking in SSK in case this delicate startup logic gets mis-ordered again. Also fixed the AppDelegate method to check for the proper applicationState, since it will never be "active" in didFinishLaunching. fixes https://github.com/WhisperSystems/Signal-iOS/issues/1627 // FREEBIE --- Podfile | 2 +- Podfile.lock | 8 ++++---- Signal/src/AppDelegate.m | 24 +++++++++--------------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Podfile b/Podfile index 69ef648f8..6e17c7678 100644 --- a/Podfile +++ b/Podfile @@ -4,7 +4,7 @@ source 'https://github.com/CocoaPods/Specs.git' target 'Signal' do pod 'SocketRocket', :git => 'https://github.com/facebook/SocketRocket.git' pod 'AxolotlKit', git: 'https://github.com/WhisperSystems/SignalProtocolKit.git' - pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git', branch: 'master' + pod 'SignalServiceKit', git: 'https://github.com/WhisperSystems/SignalServiceKit.git', branch: 'mkirk/dont-reset-storage-before-first-unlock' #pod 'SignalServiceKit', path: '../SignalServiceKit' pod 'OpenSSL' pod 'PastelogKit', '~> 1.3' diff --git a/Podfile.lock b/Podfile.lock index 9e15d67af..d5ecbc0f1 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -121,7 +121,7 @@ DEPENDENCIES: - OpenSSL - PastelogKit (~> 1.3) - SCWaveformView (~> 1.0) - - SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`, branch `master`) + - SignalServiceKit (from `https://github.com/WhisperSystems/SignalServiceKit.git`, branch `mkirk/dont-reset-storage-before-first-unlock`) - SocketRocket (from `https://github.com/facebook/SocketRocket.git`) - ZXingObjC @@ -129,7 +129,7 @@ EXTERNAL SOURCES: AxolotlKit: :git: https://github.com/WhisperSystems/SignalProtocolKit.git SignalServiceKit: - :branch: master + :branch: mkirk/dont-reset-storage-before-first-unlock :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :git: https://github.com/facebook/SocketRocket.git @@ -139,7 +139,7 @@ CHECKOUT OPTIONS: :commit: 714f5ebe199ecc999b33c6f97a4bb57e2db90e75 :git: https://github.com/WhisperSystems/SignalProtocolKit.git SignalServiceKit: - :commit: 8f81015730111d235ce90edc2f920170134a9e62 + :commit: 4846aabd13d30bb39bcc3bea395abe40beaced57 :git: https://github.com/WhisperSystems/SignalServiceKit.git SocketRocket: :commit: 41b57bb2fc292a814f758441a05243eb38457027 @@ -170,6 +170,6 @@ SPEC CHECKSUMS: YapDatabase: b1e43555a34a5298e23a045be96817a5ef0da58f ZXingObjC: bf15b3814f7a105b6d99f47da2333c93a063650a -PODFILE CHECKSUM: cb24c78080551874a45d1a20de4a1bef7427b41f +PODFILE CHECKSUM: 92037a2e2a31e58603ec77779d6e87f5f54b0d2a COCOAPODS: 1.0.1 diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index f37bd5e08..6c6a10e80 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -63,6 +63,9 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; [logger addLoggingCallback:^(NSString *category, id details, NSUInteger index){ }]; + // XXX - careful when moving this. It must happen before we initialize TSStorageManager. + [self verifyDBKeysAvailableBeforeBackgroundLaunch]; + // Setting up environment [Environment setCurrent:[Release releaseEnvironmentWithLogging:logger]]; @@ -88,7 +91,6 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; #elif RELEASE loggingIsEnabled = Environment.preferences.loggingIsEnabled; #endif - [self verifyBackgroundBeforeKeysAvailableLaunch]; if (loggingIsEnabled) { [DebugLogger.sharedLogger enableFileLogging]; @@ -378,31 +380,23 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; } /** - * Signal requires an iPhone to be unlocked after reboot to be able to access keying material. + * The user must unlock the device once after reboot before the database encryption key can be accessed. */ -- (void)verifyBackgroundBeforeKeysAvailableLaunch { - if ([self applicationIsActive]) { +- (void)verifyDBKeysAvailableBeforeBackgroundLaunch +{ + if (UIApplication.sharedApplication.applicationState != UIApplicationStateBackground) { return; } - if (![[TSStorageManager sharedManager] databasePasswordAccessible]) { + if ([TSStorageManager isDatabasePasswordAccessible]) { UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.alertBody = NSLocalizedString(@"PHONE_NEEDS_UNLOCK", nil); [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; + DDLogInfo(@"%@ exiting because we are in the background and the database password is not accessible.", self.tag); exit(0); } } -- (BOOL)applicationIsActive { - UIApplication *app = [UIApplication sharedApplication]; - - if (app.applicationState == UIApplicationStateActive) { - return YES; - } - - return NO; -} - #pragma mark - Logging + (NSString *)tag