Clean up ahead of PR.

pull/1/head
Matthew Chen 7 years ago
parent 2375cc2f76
commit 0cc7f3e00e

@ -104,8 +104,6 @@
34612A071FD7238600532771 /* OWSContactsSyncing.m in Sources */ = {isa = PBXBuildFile; fileRef = 34612A051FD7238500532771 /* OWSContactsSyncing.m */; }; 34612A071FD7238600532771 /* OWSContactsSyncing.m in Sources */ = {isa = PBXBuildFile; fileRef = 34612A051FD7238500532771 /* OWSContactsSyncing.m */; };
346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */; }; 346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */; };
3472229F1EB22FFE00E53955 /* AddToGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */; }; 3472229F1EB22FFE00E53955 /* AddToGroupViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */; };
34782E452011428D00A6F16B /* OWSDatabaseConverter.h in Headers */ = {isa = PBXBuildFile; fileRef = 34782E432011428D00A6F16B /* OWSDatabaseConverter.h */; settings = {ATTRIBUTES = (Public, ); }; };
34782E462011428D00A6F16B /* OWSDatabaseConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 34782E442011428D00A6F16B /* OWSDatabaseConverter.m */; };
347850311FD7494A007B8332 /* dripicons-v2.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5B1E787A9800DF2FB9 /* dripicons-v2.ttf */; }; 347850311FD7494A007B8332 /* dripicons-v2.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5B1E787A9800DF2FB9 /* dripicons-v2.ttf */; };
347850321FD7494A007B8332 /* ElegantIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5D1E787BD800DF2FB9 /* ElegantIcons.ttf */; }; 347850321FD7494A007B8332 /* ElegantIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5D1E787BD800DF2FB9 /* ElegantIcons.ttf */; };
347850331FD7494A007B8332 /* fontawesome-webfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A591E7875FB00DF2FB9 /* fontawesome-webfont.ttf */; }; 347850331FD7494A007B8332 /* fontawesome-webfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A591E7875FB00DF2FB9 /* fontawesome-webfont.ttf */; };
@ -594,8 +592,6 @@
346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CropScaleImageViewController.swift; sourceTree = "<group>"; }; 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CropScaleImageViewController.swift; sourceTree = "<group>"; };
3472229D1EB22FFE00E53955 /* AddToGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddToGroupViewController.h; sourceTree = "<group>"; }; 3472229D1EB22FFE00E53955 /* AddToGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddToGroupViewController.h; sourceTree = "<group>"; };
3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddToGroupViewController.m; sourceTree = "<group>"; }; 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddToGroupViewController.m; sourceTree = "<group>"; };
34782E432011428D00A6F16B /* OWSDatabaseConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSDatabaseConverter.h; sourceTree = "<group>"; };
34782E442011428D00A6F16B /* OWSDatabaseConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSDatabaseConverter.m; sourceTree = "<group>"; };
347850561FD86544007B8332 /* SAEFailedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SAEFailedViewController.swift; sourceTree = "<group>"; }; 347850561FD86544007B8332 /* SAEFailedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SAEFailedViewController.swift; sourceTree = "<group>"; };
347850581FD9972E007B8332 /* SwiftSingletons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftSingletons.swift; sourceTree = "<group>"; }; 347850581FD9972E007B8332 /* SwiftSingletons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftSingletons.swift; sourceTree = "<group>"; };
3478505A1FD999D5007B8332 /* et */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = et; path = translations/et.lproj/Localizable.strings; sourceTree = "<group>"; }; 3478505A1FD999D5007B8332 /* et */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = et; path = translations/et.lproj/Localizable.strings; sourceTree = "<group>"; };
@ -1115,8 +1111,6 @@
45666EC51D99483D008FE134 /* OWSAvatarBuilder.m */, 45666EC51D99483D008FE134 /* OWSAvatarBuilder.m */,
45855F351D9498A40084F340 /* OWSContactAvatarBuilder.h */, 45855F351D9498A40084F340 /* OWSContactAvatarBuilder.h */,
45855F361D9498A40084F340 /* OWSContactAvatarBuilder.m */, 45855F361D9498A40084F340 /* OWSContactAvatarBuilder.m */,
34782E432011428D00A6F16B /* OWSDatabaseConverter.h */,
34782E442011428D00A6F16B /* OWSDatabaseConverter.m */,
346129A81FD1F0DF00532771 /* OWSFormat.h */, 346129A81FD1F0DF00532771 /* OWSFormat.h */,
346129AA1FD1F0EE00532771 /* OWSFormat.m */, 346129AA1FD1F0EE00532771 /* OWSFormat.m */,
45666EC71D994C0D008FE134 /* OWSGroupAvatarBuilder.h */, 45666EC71D994C0D008FE134 /* OWSGroupAvatarBuilder.h */,
@ -2045,7 +2039,6 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
451F8A3A1FD711D9005CB9DA /* ContactsViewHelper.h in Headers */, 451F8A3A1FD711D9005CB9DA /* ContactsViewHelper.h in Headers */,
34782E452011428D00A6F16B /* OWSDatabaseConverter.h in Headers */,
34480B491FD0A60200BC14EF /* OWSMath.h in Headers */, 34480B491FD0A60200BC14EF /* OWSMath.h in Headers */,
346129E71FD5C0C600532771 /* OWSDatabaseMigrationRunner.h in Headers */, 346129E71FD5C0C600532771 /* OWSDatabaseMigrationRunner.h in Headers */,
344D6CEA20069E070042AF96 /* SelectRecipientViewController.h in Headers */, 344D6CEA20069E070042AF96 /* SelectRecipientViewController.h in Headers */,
@ -2804,7 +2797,6 @@
346129D01FD207F300532771 /* OWSAlerts.swift in Sources */, 346129D01FD207F300532771 /* OWSAlerts.swift in Sources */,
454A965F1FD60EA3008D2A0E /* OWSFlatButton.swift in Sources */, 454A965F1FD60EA3008D2A0E /* OWSFlatButton.swift in Sources */,
346129B61FD1F7E800532771 /* ProfileFetcherJob.swift in Sources */, 346129B61FD1F7E800532771 /* ProfileFetcherJob.swift in Sources */,
34782E462011428D00A6F16B /* OWSDatabaseConverter.m in Sources */,
346129F51FD5F31400532771 /* OWS102MoveLoggingPreferenceToUserDefaults.m in Sources */, 346129F51FD5F31400532771 /* OWS102MoveLoggingPreferenceToUserDefaults.m in Sources */,
45194F8F1FD71FF500333B2C /* ThreadUtil.m in Sources */, 45194F8F1FD71FF500333B2C /* ThreadUtil.m in Sources */,
451F8A3B1FD71297005CB9DA /* UIUtil.m in Sources */, 451F8A3B1FD71297005CB9DA /* UIUtil.m in Sources */,
@ -3146,7 +3138,11 @@
"DEBUG=1", "DEBUG=1",
"$(inherited)", "$(inherited)",
); );
"GCC_PREPROCESSOR_DEFINITIONS[arch=*]" = "DEBUG=1 $(inherited) SSK_BUILDING_FOR_TESTS=1"; "GCC_PREPROCESSOR_DEFINITIONS[arch=*]" = (
"DEBUG=1",
"$(inherited)",
"SSK_BUILDING_FOR_TESTS=1",
);
GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES; GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES;
GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES; GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES;

@ -193,7 +193,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
DDLogInfo(@"%@ %s.", self.logTag, __PRETTY_FUNCTION__); DDLogInfo(@"%@ %s.", self.logTag, __PRETTY_FUNCTION__);
[NSException raise:@"OWSBackup_RestartAppToCompleteBackupRestore" format:@"Killing app to complete backup restore"]; OWSRaiseException(@"OWSBackup_RestartAppToCompleteBackupRestore", @"Killing app to complete backup restore");
} }
#pragma mark - OWSBackupDelegate #pragma mark - OWSBackupDelegate

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "UIImage+OWS.h" #import "UIImage+OWS.h"
@ -98,7 +98,7 @@
break; break;
default: default:
[NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"]; OWSRaiseException(NSInternalInconsistencyException, @"Invalid image orientation");
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "OWSDatabaseMigration.h" #import "OWSDatabaseMigration.h"
@ -32,10 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)migrationId + (NSString *)migrationId
{ {
@throw [NSException OWSRaiseException(NSInternalInconsistencyException, @"Must override %@ in subclass", NSStringFromSelector(_cmd));
exceptionWithName:NSInternalInconsistencyException
reason:[NSString stringWithFormat:@"Must override %@ in subclass", NSStringFromSelector(_cmd)]
userInfo:nil];
} }
+ (NSString *)collection + (NSString *)collection
@ -46,10 +43,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)runUpWithTransaction:(YapDatabaseReadWriteTransaction *)transaction - (void)runUpWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{ {
@throw [NSException OWSRaiseException(NSInternalInconsistencyException, @"Must override %@ in subclass", NSStringFromSelector(_cmd));
exceptionWithName:NSInternalInconsistencyException
reason:[NSString stringWithFormat:@"Must override %@ in subclass", NSStringFromSelector(_cmd)]
userInfo:nil];
} }
- (void)runUp - (void)runUp

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "OWSAvatarBuilder.h" #import "OWSAvatarBuilder.h"
@ -8,6 +8,7 @@
#import "TSContactThread.h" #import "TSContactThread.h"
#import "TSGroupThread.h" #import "TSGroupThread.h"
#import "UIColor+OWS.h" #import "UIColor+OWS.h"
// SHARINGEXTENSION FIXME // SHARINGEXTENSION FIXME
// intern or reimplement this so that SignalMessaging doesn't depend on JSQ // intern or reimplement this so that SignalMessaging doesn't depend on JSQ
#import <JSQMessagesViewController/JSQMessagesAvatarImageFactory.h> #import <JSQMessagesViewController/JSQMessagesAvatarImageFactory.h>
@ -85,18 +86,14 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable UIImage *)buildSavedImage - (nullable UIImage *)buildSavedImage
{ {
@throw [NSException OWSRaiseException(
exceptionWithName:NSInternalInconsistencyException NSInternalInconsistencyException, @"You must override %@ in a subclass", NSStringFromSelector(_cmd));
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
userInfo:nil];
} }
- (UIImage *)buildDefaultImage - (UIImage *)buildDefaultImage
{ {
@throw [NSException OWSRaiseException(
exceptionWithName:NSInternalInconsistencyException NSInternalInconsistencyException, @"You must override %@ in a subclass", NSStringFromSelector(_cmd));
reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
userInfo:nil];
} }
@end @end

@ -122,7 +122,7 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling
NSString *phoneNumber = self.phoneNumberAwaitingVerification; NSString *phoneNumber = self.phoneNumberAwaitingVerification;
if (!phoneNumber) { if (!phoneNumber) {
@throw [NSException exceptionWithName:@"RegistrationFail" reason:@"Internal Corrupted State" userInfo:nil]; OWSRaiseException(@"RegistrationFail", @"Internal Corrupted State");
} }
[self storeLocalNumber:phoneNumber]; [self storeLocalNumber:phoneNumber];

@ -1262,9 +1262,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
if (messageDict) { if (messageDict) {
[messagesArray addObject:messageDict]; [messagesArray addObject:messageDict];
} else { } else {
@throw [NSException exceptionWithName:InvalidMessageException OWSRaiseException(InvalidMessageException, @"Failed to encrypt message");
reason:@"Failed to encrypt message"
userInfo:nil];
} }
} @catch (NSException *exception) { } @catch (NSException *exception) {
if ([exception.name isEqualToString:OWSMessageSenderInvalidDeviceException]) { if ([exception.name isEqualToString:OWSMessageSenderInvalidDeviceException]) {
@ -1324,9 +1322,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} }
if (!bundle) { if (!bundle) {
@throw [NSException exceptionWithName:InvalidVersionException OWSRaiseException(
reason:@"Can't get a prekey bundle from the server with required information" InvalidVersionException, @"Can't get a prekey bundle from the server with required information");
userInfo:nil];
} else { } else {
SessionBuilder *builder = [[SessionBuilder alloc] initWithSessionStore:storage SessionBuilder *builder = [[SessionBuilder alloc] initWithSessionStore:storage
preKeyStore:storage preKeyStore:storage
@ -1341,10 +1338,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} }
} @catch (NSException *exception) { } @catch (NSException *exception) {
if ([exception.name isEqualToString:UntrustedIdentityKeyException]) { if ([exception.name isEqualToString:UntrustedIdentityKeyException]) {
@throw [NSException OWSRaiseExceptionWithUserInfo(UntrustedIdentityKeyException,
exceptionWithName:UntrustedIdentityKeyException (@{ TSInvalidPreKeyBundleKey : bundle, TSInvalidRecipientKey : identifier }),
reason:nil @"");
userInfo:@{ TSInvalidPreKeyBundleKey : bundle, TSInvalidRecipientKey : identifier }];
} }
@throw exception; @throw exception;
} }

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "TSRequest.h" #import "TSRequest.h"
@ -19,7 +19,7 @@
} }
- (id)init { - (id)init {
[NSException raise:NSInternalInconsistencyException format:@"You must use the initWithURL: method"]; OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL: method");
return nil; return nil;
} }
@ -29,7 +29,7 @@
- (id)initWithURL:(NSURL *)URL - (id)initWithURL:(NSURL *)URL
cachePolicy:(NSURLRequestCachePolicy)cachePolicy cachePolicy:(NSURLRequestCachePolicy)cachePolicy
timeoutInterval:(NSTimeInterval)timeoutInterval { timeoutInterval:(NSTimeInterval)timeoutInterval {
[NSException raise:NSInternalInconsistencyException format:@"You must use the initWithURL method"]; OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL method");
return nil; return nil;
} }

@ -1,13 +1,9 @@
// //
// TSRequestVerificationCodeRequest.m // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// Signal
//
// Created by Frederic Jacobs on 02/12/15.
// Copyright © 2015 Open Whisper Systems. All rights reserved.
// //
#import "TSConstants.h"
#import "TSRequestVerificationCodeRequest.h" #import "TSRequestVerificationCodeRequest.h"
#import "TSConstants.h"
@implementation TSRequestVerificationCodeRequest @implementation TSRequestVerificationCodeRequest
@ -30,10 +26,7 @@
case TSVerificationTransportVoice: case TSVerificationTransportVoice:
return @"voice"; return @"voice";
default: default:
@throw [NSException OWSRaiseException(@"Unsupported transport exception", @"Transport %u in enum is not supported.", transport);
exceptionWithName:@"Unsupported transport exception"
reason:[NSString stringWithFormat:@"Transport %u in enum is not supported.", transport]
userInfo:nil];
} }
} }

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "OWSSignalService.h" #import "OWSSignalService.h"
@ -310,16 +310,12 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange =
NSData *certData = [self certificateDataWithName:certName error:&error]; NSData *certData = [self certificateDataWithName:certName error:&error];
if (error) { if (error) {
DDLogError(@"%@ Failed to get %@ certificate data with error: %@", self.logTag, certName, error); DDLogError(@"%@ Failed to get %@ certificate data with error: %@", self.logTag, certName, error);
@throw [NSException exceptionWithName:@"OWSSignalService_UnableToReadCertificate" OWSRaiseException(@"OWSSignalService_UnableToReadCertificate", error.description);
reason:error.description
userInfo:nil];
} }
if (!certData) { if (!certData) {
DDLogError(@"%@ No data for certificate: %@", self.logTag, certName); DDLogError(@"%@ No data for certificate: %@", self.logTag, certName);
@throw [NSException exceptionWithName:@"OWSSignalService_UnableToReadCertificate" OWSRaiseException(@"OWSSignalService_UnableToReadCertificate", error.description);
reason:error.description
userInfo:nil];
} }
[certificates addObject:certData]; [certificates addObject:certData];
} }

@ -1,9 +1,8 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "OWSHTTPSecurityPolicy.h" #import "OWSHTTPSecurityPolicy.h"
#import <AssertMacros.h> #import <AssertMacros.h>
@implementation OWSHTTPSecurityPolicy @implementation OWSHTTPSecurityPolicy
@ -44,10 +43,7 @@
NSString *path = [bundle pathForResource:service ofType:@"cer"]; NSString *path = [bundle pathForResource:service ofType:@"cer"];
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
@throw [NSException OWSRaiseException(@"Missing server certificate", @"Missing signing certificate for service %@", service);
exceptionWithName:@"Missing server certificate"
reason:[NSString stringWithFormat:@"Missing signing certificate for service %@", service]
userInfo:nil];
} }
NSData *certificateData = [NSData dataWithContentsOfFile:path]; NSData *certificateData = [NSData dataWithContentsOfFile:path];

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "TSStorageKeys.h" #import "TSStorageKeys.h"
@ -61,9 +61,7 @@
inCollection:TSStorageManagerPreKeyStoreCollection]; inCollection:TSStorageManagerPreKeyStoreCollection];
if (!preKeyRecord) { if (!preKeyRecord) {
@throw [NSException exceptionWithName:InvalidKeyIdException OWSRaiseException(InvalidKeyIdException, @"No pre key found matching key id");
reason:@"No pre key found matching key id"
userInfo:@{}];
} else { } else {
return preKeyRecord; return preKeyRecord;
} }

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
#import "OWSIdentityManager.h" #import "OWSIdentityManager.h"
@ -41,9 +41,7 @@ NSString *const TSStorageManagerKeyPrekeyCurrentSignedPrekeyId = @"currentSigned
inCollection:TSStorageManagerSignedPreKeyStoreCollection]; inCollection:TSStorageManagerSignedPreKeyStoreCollection];
if (!preKeyRecord) { if (!preKeyRecord) {
@throw [NSException exceptionWithName:InvalidKeyIdException OWSRaiseException(InvalidKeyIdException, @"No signed pre key found matching key id");
reason:@"No signed pre key found matching key id"
userInfo:@{}];
} else { } else {
return preKeyRecord; return preKeyRecord;
} }

@ -276,7 +276,7 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void);
// Sleep to give analytics events time to be delivered. // Sleep to give analytics events time to be delivered.
[NSThread sleepForTimeInterval:15.0f]; [NSThread sleepForTimeInterval:15.0f];
[NSException raise:OWSStorageExceptionName_NoDatabase format:@"Failed to initialize database."]; OWSRaiseException(OWSStorageExceptionName_NoDatabase, @"Failed to initialize database.");
} }
} }
@ -384,6 +384,10 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void);
// We determine the database password, salt and key spec first, since a side effect of // We determine the database password, salt and key spec first, since a side effect of
// this can be deleting any existing database file (if we're recovering // this can be deleting any existing database file (if we're recovering
// from a corrupt keychain). // from a corrupt keychain).
//
// Although we don't use databasePassword or databaseSalt in this method,
// we use their accessors to ensure that all three exist in the keychain
// and can be loaded or that we reset the database & keychain.
NSData *databasePassword = [self databasePassword]; NSData *databasePassword = [self databasePassword];
OWSAssert(databasePassword.length > 0); OWSAssert(databasePassword.length > 0);
NSData *databaseSalt = [self databaseSalt]; NSData *databaseSalt = [self databaseSalt];
@ -555,32 +559,6 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void);
+ (nullable NSData *)tryToLoadDatabaseKeySpec:(NSError **)errorHandle + (nullable NSData *)tryToLoadDatabaseKeySpec:(NSError **)errorHandle
{ {
return [self tryToLoadKeyChainValue:keychainDBKeySpec errorHandle:errorHandle]; return [self tryToLoadKeyChainValue:keychainDBKeySpec errorHandle:errorHandle];
// NSData *_Nullable keySpecData = [self tryToLoadKeyChainValue:keychainDBKeySpec errorHandle:errorHandle];
//
// if (!keySpecData) {
// DDLogInfo(@"%@ Trying to derive database key spec.", self.logTag);
// NSData *_Nullable passwordData = [self tryToLoadDatabasePassword:errorHandle];
// if (passwordData && !*errorHandle) {
// NSData *_Nullable saltData = [self tryToLoadDatabaseSalt:errorHandle];
// if (saltData && !*errorHandle) {
// OWSAssert(passwordData.length > 0);
// OWSAssert(saltData.length == kSQLCipherSaltLength);
//
// keySpecData = [YapDatabaseCryptoUtils databaseKeySpecForPassword:passwordData saltData:saltData];
// OWSAssert(keySpecData.length == kSQLCipherKeySpecLength);
//
// if (keySpecData) {
// DDLogInfo(@"%@ database key spec derived.", self.logTag);
// [self storeDatabaseKeySpec:keySpecData];
// }
// }
// }
// }
//
// OWSAssert(keySpecData);
//
// return keySpecData;
} }
- (NSData *)databasePassword - (NSData *)databasePassword
@ -743,8 +721,7 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void);
// Presumably this happened in response to a push notification. It's possible that the keychain is corrupted // 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 // but it could also just be that the user hasn't yet unlocked their device since our password is
// kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly // kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
[NSException raise:OWSStorageExceptionName_DatabasePasswordInaccessibleWhileBackgrounded OWSRaiseException(OWSStorageExceptionName_DatabasePasswordInaccessibleWhileBackgrounded, @"%@", errorDescription);
format:@"%@", errorDescription];
} }
+ (void)deletePasswordFromKeychain + (void)deletePasswordFromKeychain
@ -784,8 +761,8 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void);
// Sleep to give analytics events time to be delivered. // Sleep to give analytics events time to be delivered.
[NSThread sleepForTimeInterval:15.0f]; [NSThread sleepForTimeInterval:15.0f];
[NSException raise:OWSStorageExceptionName_DatabasePasswordUnwritable OWSRaiseException(
format:@"Setting keychain value failed with error: %@", error]; OWSStorageExceptionName_DatabasePasswordUnwritable, @"Setting keychain value failed with error: %@", error);
} else { } else {
DDLogWarn(@"Succesfully set new keychain value."); DDLogWarn(@"Succesfully set new keychain value.");
} }

@ -161,8 +161,8 @@ void runAsyncRegistrationsForStorage(OWSStorage *storage)
NSString *databaseDirPath = [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"database"]; NSString *databaseDirPath = [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"database"];
if (![OWSFileSystem ensureDirectoryExists:databaseDirPath]) { if (![OWSFileSystem ensureDirectoryExists:databaseDirPath]) {
[NSException raise:TSStorageManagerExceptionName_CouldNotCreateDatabaseDirectory OWSRaiseException(
format:@"Could not create new database directory"]; TSStorageManagerExceptionName_CouldNotCreateDatabaseDirectory, @"Could not create new database directory");
} }
return databaseDirPath; return databaseDirPath;
} }

@ -1,5 +1,5 @@
// //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// //
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -124,4 +124,20 @@ NS_ASSUME_NONNULL_BEGIN
// This function is intended for use in Swift. // This function is intended for use in Swift.
void AssertIsOnMainThread(void); void AssertIsOnMainThread(void);
#define OWSRaiseException(name, formatParam, ...) \
{ \
[DDLog flushLog]; \
@throw [NSException exceptionWithName:name \
reason:[NSString stringWithFormat:formatParam, ##__VA_ARGS__] \
userInfo:nil]; \
}
#define OWSRaiseExceptionWithUserInfo(name, userInfoParam, formatParam, ...) \
{ \
[DDLog flushLog]; \
@throw [NSException exceptionWithName:name \
reason:[NSString stringWithFormat:formatParam, ##__VA_ARGS__] \
userInfo:userInfoParam]; \
}
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -83,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN
newFilePath, newFilePath,
error]; error];
OWSFail(@"%@", errorDescription); OWSFail(@"%@", errorDescription);
[NSException raise:exceptionName format:@"%@", errorDescription]; OWSRaiseException(exceptionName, @"%@", errorDescription);
} }
DDLogInfo(@"%@ Moved file or directory from: %@ to: %@ in: %f", DDLogInfo(@"%@ Moved file or directory from: %@ to: %@ in: %f",

Loading…
Cancel
Save