Merge remote-tracking branch 'origin/master' into mkirk/webrtc

pull/1/head
Michael Kirk 8 years ago
commit f4a46fce08

@ -1,5 +1,6 @@
// Created by Michael Kirk on 12/20/16. //
// Copyright © 2016 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSCensorshipConfiguration.h" #import "OWSCensorshipConfiguration.h"
#import "TSStorageManager.h" #import "TSStorageManager.h"
@ -52,8 +53,6 @@ NSString *const OWSCensorshipConfigurationReflectorHost = @"signal-reflector-mee
return @{ return @{
// Egypt // Egypt
@"+20": @"google.com.eg", @"+20": @"google.com.eg",
// Cuba
@"+53": @"google.com.cu",
// Oman // Oman
@"+968": @"google.com.om", @"+968": @"google.com.om",
// UAE // UAE

@ -1,9 +1,5 @@
// //
// TSStorageManager.h // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// TextSecureKit
//
// Created by Frederic Jacobs on 27/10/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
// //
#import "TSStorageKeys.h" #import "TSStorageKeys.h"
@ -21,9 +17,17 @@ extern NSString *const TSUIDatabaseConnectionDidUpdateNotification;
@interface TSStorageManager : NSObject @interface TSStorageManager : NSObject
+ (instancetype)sharedManager; + (instancetype)sharedManager;
/**
* Returns NO if:
*
* - Keychain is locked because device has just been restarted.
* - Password could not be retrieved because of a keychain error.
*/
+ (BOOL)isDatabasePasswordAccessible;
- (void)setupDatabase; - (void)setupDatabase;
- (void)deleteThreadsAndMessages; - (void)deleteThreadsAndMessages;
- (BOOL)databasePasswordAccessible;
- (void)resetSignalStorage; - (void)resetSignalStorage;
- (YapDatabase *)database; - (YapDatabase *)database;

@ -1,6 +1,4 @@
// //
// TSStorageManager.m
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// //
@ -23,6 +21,8 @@
NSString *const TSUIDatabaseConnectionDidUpdateNotification = @"TSUIDatabaseConnectionDidUpdateNotification"; NSString *const TSUIDatabaseConnectionDidUpdateNotification = @"TSUIDatabaseConnectionDidUpdateNotification";
NSString *const TSStorageManagerExceptionNameDatabasePasswordInaccessible = @"TSStorageManagerExceptionNameDatabasePasswordInaccessible"; NSString *const TSStorageManagerExceptionNameDatabasePasswordInaccessible = @"TSStorageManagerExceptionNameDatabasePasswordInaccessible";
NSString *const TSStorageManagerExceptionNameDatabasePasswordInaccessibleWhileBackgrounded =
@"TSStorageManagerExceptionNameDatabasePasswordInaccessibleWhileBackgrounded";
NSString *const TSStorageManagerExceptionNameDatabasePasswordUnwritable = @"TSStorageManagerExceptionNameDatabasePasswordUnwritable"; NSString *const TSStorageManagerExceptionNameDatabasePasswordUnwritable = @"TSStorageManagerExceptionNameDatabasePasswordUnwritable";
NSString *const TSStorageManagerExceptionNameNoDatabase = @"TSStorageManagerExceptionNameNoDatabase"; NSString *const TSStorageManagerExceptionNameNoDatabase = @"TSStorageManagerExceptionNameNoDatabase";
@ -270,7 +270,7 @@ static NSString *keychainDBPassAccount = @"TSDatabasePass";
return databasePath; return databasePath;
} }
- (BOOL)databasePasswordAccessible + (BOOL)isDatabasePasswordAccessible
{ {
[SAMKeychain setAccessibilityType:kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly]; [SAMKeychain setAccessibilityType:kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly];
NSError *error; NSError *error;
@ -287,6 +287,17 @@ static NSString *keychainDBPassAccount = @"TSDatabasePass";
return NO; return NO;
} }
- (void)backgroundedAppDatabasePasswordInaccessibleWithErrorDescription:(NSString *)errorDescription
{
OWSAssert([UIApplication sharedApplication].applicationState == UIApplicationStateBackground);
// Presumably this happened in response to a push notification. It's possible that the keychain is corrupted
// but it could also just be that the user hasn't yet unlocked their device since our password is
// kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
[NSException raise:TSStorageManagerExceptionNameDatabasePasswordInaccessibleWhileBackgrounded
format:@"%@", errorDescription];
}
- (NSData *)databasePassword - (NSData *)databasePassword
{ {
[SAMKeychain setAccessibilityType:kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly]; [SAMKeychain setAccessibilityType:kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly];
@ -296,7 +307,19 @@ static NSString *keychainDBPassAccount = @"TSDatabasePass";
[SAMKeychain passwordForService:keychainService account:keychainDBPassAccount error:&keyFetchError]; [SAMKeychain passwordForService:keychainService account:keychainDBPassAccount error:&keyFetchError];
if (keyFetchError) { if (keyFetchError) {
// Either this is a new install so there's no existing password to retrieve UIApplicationState applicationState = [UIApplication sharedApplication].applicationState;
NSString *errorDescription = [NSString stringWithFormat:@"Database password inaccessible. No unlock since device restart? Error: %@ ApplicationState: %d", keyFetchError, (int)applicationState];
DDLogError(@"%@ %@", self.tag, errorDescription);
[DDLog flushLog];
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
// TODO: Rather than crash here, we should detect the situation earlier
// and exit gracefully - (in the app delegate?). See the `
// This is a last ditch effort to avoid blowing away the user's database.
[self backgroundedAppDatabasePasswordInaccessibleWithErrorDescription:errorDescription];
}
// At this point, either this is a new install so there's no existing password to retrieve
// or the keychain has become corrupt. Either way, we want to get back to a // or the keychain has become corrupt. Either way, we want to get back to a
// "known good state" and behave like a new install. // "known good state" and behave like a new install.

Loading…
Cancel
Save