From 0cc7f3e00ea1a87cc209f0a5b6ab9131ab9d4d80 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 25 Jan 2018 10:44:13 -0500 Subject: [PATCH] Clean up ahead of PR. --- Signal.xcodeproj/project.pbxproj | 14 +++---- .../OWSBackupImportViewController.m | 2 +- SignalMessaging/categories/UIImage+OWS.m | 4 +- .../migrations/OWSDatabaseMigration.m | 12 ++---- SignalMessaging/utils/OWSAvatarBuilder.m | 15 +++---- .../src/Account/TSAccountManager.m | 2 +- .../src/Messages/OWSMessageSender.m | 16 +++----- .../src/Network/API/Requests/TSRequest.m | 6 +-- .../TSRequestVerificationCodeRequest.m | 13 ++----- .../src/Network/OWSSignalService.m | 10 ++--- .../src/Security/OWSHTTPSecurityPolicy.m | 8 +--- .../TSStorageManager+PreKeyStore.m | 6 +-- .../TSStorageManager+SignedPreKeyStore.m | 6 +-- SignalServiceKit/src/Storage/OWSStorage.m | 39 ++++--------------- .../src/Storage/TSStorageManager.m | 4 +- SignalServiceKit/src/Util/OWSAsserts.h | 18 ++++++++- SignalServiceKit/src/Util/OWSFileSystem.m | 2 +- 17 files changed, 67 insertions(+), 110 deletions(-) diff --git a/Signal.xcodeproj/project.pbxproj b/Signal.xcodeproj/project.pbxproj index 0204a0fbb..f4a8f0e06 100644 --- a/Signal.xcodeproj/project.pbxproj +++ b/Signal.xcodeproj/project.pbxproj @@ -104,8 +104,6 @@ 34612A071FD7238600532771 /* OWSContactsSyncing.m in Sources */ = {isa = PBXBuildFile; fileRef = 34612A051FD7238500532771 /* OWSContactsSyncing.m */; }; 346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */; }; 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 */; }; 347850321FD7494A007B8332 /* ElegantIcons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5D1E787BD800DF2FB9 /* ElegantIcons.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 = ""; }; 3472229D1EB22FFE00E53955 /* AddToGroupViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AddToGroupViewController.h; sourceTree = ""; }; 3472229E1EB22FFE00E53955 /* AddToGroupViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AddToGroupViewController.m; sourceTree = ""; }; - 34782E432011428D00A6F16B /* OWSDatabaseConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSDatabaseConverter.h; sourceTree = ""; }; - 34782E442011428D00A6F16B /* OWSDatabaseConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSDatabaseConverter.m; sourceTree = ""; }; 347850561FD86544007B8332 /* SAEFailedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SAEFailedViewController.swift; sourceTree = ""; }; 347850581FD9972E007B8332 /* SwiftSingletons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftSingletons.swift; sourceTree = ""; }; 3478505A1FD999D5007B8332 /* et */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = et; path = translations/et.lproj/Localizable.strings; sourceTree = ""; }; @@ -1115,8 +1111,6 @@ 45666EC51D99483D008FE134 /* OWSAvatarBuilder.m */, 45855F351D9498A40084F340 /* OWSContactAvatarBuilder.h */, 45855F361D9498A40084F340 /* OWSContactAvatarBuilder.m */, - 34782E432011428D00A6F16B /* OWSDatabaseConverter.h */, - 34782E442011428D00A6F16B /* OWSDatabaseConverter.m */, 346129A81FD1F0DF00532771 /* OWSFormat.h */, 346129AA1FD1F0EE00532771 /* OWSFormat.m */, 45666EC71D994C0D008FE134 /* OWSGroupAvatarBuilder.h */, @@ -2045,7 +2039,6 @@ buildActionMask = 2147483647; files = ( 451F8A3A1FD711D9005CB9DA /* ContactsViewHelper.h in Headers */, - 34782E452011428D00A6F16B /* OWSDatabaseConverter.h in Headers */, 34480B491FD0A60200BC14EF /* OWSMath.h in Headers */, 346129E71FD5C0C600532771 /* OWSDatabaseMigrationRunner.h in Headers */, 344D6CEA20069E070042AF96 /* SelectRecipientViewController.h in Headers */, @@ -2804,7 +2797,6 @@ 346129D01FD207F300532771 /* OWSAlerts.swift in Sources */, 454A965F1FD60EA3008D2A0E /* OWSFlatButton.swift in Sources */, 346129B61FD1F7E800532771 /* ProfileFetcherJob.swift in Sources */, - 34782E462011428D00A6F16B /* OWSDatabaseConverter.m in Sources */, 346129F51FD5F31400532771 /* OWS102MoveLoggingPreferenceToUserDefaults.m in Sources */, 45194F8F1FD71FF500333B2C /* ThreadUtil.m in Sources */, 451F8A3B1FD71297005CB9DA /* UIUtil.m in Sources */, @@ -3146,7 +3138,11 @@ "DEBUG=1", "$(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_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; diff --git a/Signal/src/ViewControllers/OWSBackupImportViewController.m b/Signal/src/ViewControllers/OWSBackupImportViewController.m index a91c38c85..992692c4d 100644 --- a/Signal/src/ViewControllers/OWSBackupImportViewController.m +++ b/Signal/src/ViewControllers/OWSBackupImportViewController.m @@ -193,7 +193,7 @@ NS_ASSUME_NONNULL_BEGIN { 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 diff --git a/SignalMessaging/categories/UIImage+OWS.m b/SignalMessaging/categories/UIImage+OWS.m index 9a88dffb4..300fd07e3 100644 --- a/SignalMessaging/categories/UIImage+OWS.m +++ b/SignalMessaging/categories/UIImage+OWS.m @@ -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" @@ -98,7 +98,7 @@ break; default: - [NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"]; + OWSRaiseException(NSInternalInconsistencyException, @"Invalid image orientation"); } ///////////////////////////////////////////////////////////////////////////// diff --git a/SignalMessaging/environment/migrations/OWSDatabaseMigration.m b/SignalMessaging/environment/migrations/OWSDatabaseMigration.m index f3660a49d..9b6a6af5e 100644 --- a/SignalMessaging/environment/migrations/OWSDatabaseMigration.m +++ b/SignalMessaging/environment/migrations/OWSDatabaseMigration.m @@ -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" @@ -32,10 +32,7 @@ NS_ASSUME_NONNULL_BEGIN + (NSString *)migrationId { - @throw [NSException - exceptionWithName:NSInternalInconsistencyException - reason:[NSString stringWithFormat:@"Must override %@ in subclass", NSStringFromSelector(_cmd)] - userInfo:nil]; + OWSRaiseException(NSInternalInconsistencyException, @"Must override %@ in subclass", NSStringFromSelector(_cmd)); } + (NSString *)collection @@ -46,10 +43,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)runUpWithTransaction:(YapDatabaseReadWriteTransaction *)transaction { - @throw [NSException - exceptionWithName:NSInternalInconsistencyException - reason:[NSString stringWithFormat:@"Must override %@ in subclass", NSStringFromSelector(_cmd)] - userInfo:nil]; + OWSRaiseException(NSInternalInconsistencyException, @"Must override %@ in subclass", NSStringFromSelector(_cmd)); } - (void)runUp diff --git a/SignalMessaging/utils/OWSAvatarBuilder.m b/SignalMessaging/utils/OWSAvatarBuilder.m index 0022ac743..3fb63777b 100644 --- a/SignalMessaging/utils/OWSAvatarBuilder.m +++ b/SignalMessaging/utils/OWSAvatarBuilder.m @@ -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" @@ -8,6 +8,7 @@ #import "TSContactThread.h" #import "TSGroupThread.h" #import "UIColor+OWS.h" + // SHARINGEXTENSION FIXME // intern or reimplement this so that SignalMessaging doesn't depend on JSQ #import @@ -85,18 +86,14 @@ NS_ASSUME_NONNULL_BEGIN - (nullable UIImage *)buildSavedImage { - @throw [NSException - exceptionWithName:NSInternalInconsistencyException - reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] - userInfo:nil]; + OWSRaiseException( + NSInternalInconsistencyException, @"You must override %@ in a subclass", NSStringFromSelector(_cmd)); } - (UIImage *)buildDefaultImage { - @throw [NSException - exceptionWithName:NSInternalInconsistencyException - reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] - userInfo:nil]; + OWSRaiseException( + NSInternalInconsistencyException, @"You must override %@ in a subclass", NSStringFromSelector(_cmd)); } @end diff --git a/SignalServiceKit/src/Account/TSAccountManager.m b/SignalServiceKit/src/Account/TSAccountManager.m index 1d67ab05b..05b7ea0b5 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.m +++ b/SignalServiceKit/src/Account/TSAccountManager.m @@ -122,7 +122,7 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling NSString *phoneNumber = self.phoneNumberAwaitingVerification; if (!phoneNumber) { - @throw [NSException exceptionWithName:@"RegistrationFail" reason:@"Internal Corrupted State" userInfo:nil]; + OWSRaiseException(@"RegistrationFail", @"Internal Corrupted State"); } [self storeLocalNumber:phoneNumber]; diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index c9d80975b..5a492ce63 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -1262,9 +1262,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; if (messageDict) { [messagesArray addObject:messageDict]; } else { - @throw [NSException exceptionWithName:InvalidMessageException - reason:@"Failed to encrypt message" - userInfo:nil]; + OWSRaiseException(InvalidMessageException, @"Failed to encrypt message"); } } @catch (NSException *exception) { if ([exception.name isEqualToString:OWSMessageSenderInvalidDeviceException]) { @@ -1324,9 +1322,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; } if (!bundle) { - @throw [NSException exceptionWithName:InvalidVersionException - reason:@"Can't get a prekey bundle from the server with required information" - userInfo:nil]; + OWSRaiseException( + InvalidVersionException, @"Can't get a prekey bundle from the server with required information"); } else { SessionBuilder *builder = [[SessionBuilder alloc] initWithSessionStore:storage preKeyStore:storage @@ -1341,10 +1338,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; } } @catch (NSException *exception) { if ([exception.name isEqualToString:UntrustedIdentityKeyException]) { - @throw [NSException - exceptionWithName:UntrustedIdentityKeyException - reason:nil - userInfo:@{ TSInvalidPreKeyBundleKey : bundle, TSInvalidRecipientKey : identifier }]; + OWSRaiseExceptionWithUserInfo(UntrustedIdentityKeyException, + (@{ TSInvalidPreKeyBundleKey : bundle, TSInvalidRecipientKey : identifier }), + @""); } @throw exception; } diff --git a/SignalServiceKit/src/Network/API/Requests/TSRequest.m b/SignalServiceKit/src/Network/API/Requests/TSRequest.m index 06b0f7fa7..5606c1a3b 100644 --- a/SignalServiceKit/src/Network/API/Requests/TSRequest.m +++ b/SignalServiceKit/src/Network/API/Requests/TSRequest.m @@ -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" @@ -19,7 +19,7 @@ } - (id)init { - [NSException raise:NSInternalInconsistencyException format:@"You must use the initWithURL: method"]; + OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL: method"); return nil; } @@ -29,7 +29,7 @@ - (id)initWithURL:(NSURL *)URL cachePolicy:(NSURLRequestCachePolicy)cachePolicy timeoutInterval:(NSTimeInterval)timeoutInterval { - [NSException raise:NSInternalInconsistencyException format:@"You must use the initWithURL method"]; + OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL method"); return nil; } diff --git a/SignalServiceKit/src/Network/API/Requests/TSRequestVerificationCodeRequest.m b/SignalServiceKit/src/Network/API/Requests/TSRequestVerificationCodeRequest.m index a95ee007f..56812af34 100644 --- a/SignalServiceKit/src/Network/API/Requests/TSRequestVerificationCodeRequest.m +++ b/SignalServiceKit/src/Network/API/Requests/TSRequestVerificationCodeRequest.m @@ -1,13 +1,9 @@ // -// TSRequestVerificationCodeRequest.m -// Signal -// -// Created by Frederic Jacobs on 02/12/15. -// Copyright © 2015 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // -#import "TSConstants.h" #import "TSRequestVerificationCodeRequest.h" +#import "TSConstants.h" @implementation TSRequestVerificationCodeRequest @@ -30,10 +26,7 @@ case TSVerificationTransportVoice: return @"voice"; default: - @throw [NSException - exceptionWithName:@"Unsupported transport exception" - reason:[NSString stringWithFormat:@"Transport %u in enum is not supported.", transport] - userInfo:nil]; + OWSRaiseException(@"Unsupported transport exception", @"Transport %u in enum is not supported.", transport); } } diff --git a/SignalServiceKit/src/Network/OWSSignalService.m b/SignalServiceKit/src/Network/OWSSignalService.m index 75e4cb6e5..243d14dfa 100644 --- a/SignalServiceKit/src/Network/OWSSignalService.m +++ b/SignalServiceKit/src/Network/OWSSignalService.m @@ -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" @@ -310,16 +310,12 @@ NSString *const kNSNotificationName_IsCensorshipCircumventionActiveDidChange = NSData *certData = [self certificateDataWithName:certName error:&error]; if (error) { DDLogError(@"%@ Failed to get %@ certificate data with error: %@", self.logTag, certName, error); - @throw [NSException exceptionWithName:@"OWSSignalService_UnableToReadCertificate" - reason:error.description - userInfo:nil]; + OWSRaiseException(@"OWSSignalService_UnableToReadCertificate", error.description); } if (!certData) { DDLogError(@"%@ No data for certificate: %@", self.logTag, certName); - @throw [NSException exceptionWithName:@"OWSSignalService_UnableToReadCertificate" - reason:error.description - userInfo:nil]; + OWSRaiseException(@"OWSSignalService_UnableToReadCertificate", error.description); } [certificates addObject:certData]; } diff --git a/SignalServiceKit/src/Security/OWSHTTPSecurityPolicy.m b/SignalServiceKit/src/Security/OWSHTTPSecurityPolicy.m index 64a07c99b..8aaecbb98 100644 --- a/SignalServiceKit/src/Security/OWSHTTPSecurityPolicy.m +++ b/SignalServiceKit/src/Security/OWSHTTPSecurityPolicy.m @@ -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 @implementation OWSHTTPSecurityPolicy @@ -44,10 +43,7 @@ NSString *path = [bundle pathForResource:service ofType:@"cer"]; if (![[NSFileManager defaultManager] fileExistsAtPath:path]) { - @throw [NSException - exceptionWithName:@"Missing server certificate" - reason:[NSString stringWithFormat:@"Missing signing certificate for service %@", service] - userInfo:nil]; + OWSRaiseException(@"Missing server certificate", @"Missing signing certificate for service %@", service); } NSData *certificateData = [NSData dataWithContentsOfFile:path]; diff --git a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+PreKeyStore.m b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+PreKeyStore.m index 6654c1691..dca61472b 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+PreKeyStore.m +++ b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+PreKeyStore.m @@ -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" @@ -61,9 +61,7 @@ inCollection:TSStorageManagerPreKeyStoreCollection]; if (!preKeyRecord) { - @throw [NSException exceptionWithName:InvalidKeyIdException - reason:@"No pre key found matching key id" - userInfo:@{}]; + OWSRaiseException(InvalidKeyIdException, @"No pre key found matching key id"); } else { return preKeyRecord; } diff --git a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.m b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.m index 445a29af4..bbd80e11f 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.m +++ b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.m @@ -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" @@ -41,9 +41,7 @@ NSString *const TSStorageManagerKeyPrekeyCurrentSignedPrekeyId = @"currentSigned inCollection:TSStorageManagerSignedPreKeyStoreCollection]; if (!preKeyRecord) { - @throw [NSException exceptionWithName:InvalidKeyIdException - reason:@"No signed pre key found matching key id" - userInfo:@{}]; + OWSRaiseException(InvalidKeyIdException, @"No signed pre key found matching key id"); } else { return preKeyRecord; } diff --git a/SignalServiceKit/src/Storage/OWSStorage.m b/SignalServiceKit/src/Storage/OWSStorage.m index 843124cd6..57c21eb2f 100644 --- a/SignalServiceKit/src/Storage/OWSStorage.m +++ b/SignalServiceKit/src/Storage/OWSStorage.m @@ -276,7 +276,7 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void); // Sleep to give analytics events time to be delivered. [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 // this can be deleting any existing database file (if we're recovering // 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]; OWSAssert(databasePassword.length > 0); NSData *databaseSalt = [self databaseSalt]; @@ -555,32 +559,6 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void); + (nullable NSData *)tryToLoadDatabaseKeySpec:(NSError **)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 @@ -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 // but it could also just be that the user hasn't yet unlocked their device since our password is // kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly - [NSException raise:OWSStorageExceptionName_DatabasePasswordInaccessibleWhileBackgrounded - format:@"%@", errorDescription]; + OWSRaiseException(OWSStorageExceptionName_DatabasePasswordInaccessibleWhileBackgrounded, @"%@", errorDescription); } + (void)deletePasswordFromKeychain @@ -784,8 +761,8 @@ typedef NSData *_Nullable (^CreateDatabaseMetadataBlock)(void); // Sleep to give analytics events time to be delivered. [NSThread sleepForTimeInterval:15.0f]; - [NSException raise:OWSStorageExceptionName_DatabasePasswordUnwritable - format:@"Setting keychain value failed with error: %@", error]; + OWSRaiseException( + OWSStorageExceptionName_DatabasePasswordUnwritable, @"Setting keychain value failed with error: %@", error); } else { DDLogWarn(@"Succesfully set new keychain value."); } diff --git a/SignalServiceKit/src/Storage/TSStorageManager.m b/SignalServiceKit/src/Storage/TSStorageManager.m index ac27cd6e2..f77ebec86 100644 --- a/SignalServiceKit/src/Storage/TSStorageManager.m +++ b/SignalServiceKit/src/Storage/TSStorageManager.m @@ -161,8 +161,8 @@ void runAsyncRegistrationsForStorage(OWSStorage *storage) NSString *databaseDirPath = [[OWSFileSystem appSharedDataDirectoryPath] stringByAppendingPathComponent:@"database"]; if (![OWSFileSystem ensureDirectoryExists:databaseDirPath]) { - [NSException raise:TSStorageManagerExceptionName_CouldNotCreateDatabaseDirectory - format:@"Could not create new database directory"]; + OWSRaiseException( + TSStorageManagerExceptionName_CouldNotCreateDatabaseDirectory, @"Could not create new database directory"); } return databaseDirPath; } diff --git a/SignalServiceKit/src/Util/OWSAsserts.h b/SignalServiceKit/src/Util/OWSAsserts.h index c417c12b6..6d19db47a 100755 --- a/SignalServiceKit/src/Util/OWSAsserts.h +++ b/SignalServiceKit/src/Util/OWSAsserts.h @@ -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 @@ -124,4 +124,20 @@ NS_ASSUME_NONNULL_BEGIN // This function is intended for use in Swift. 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 diff --git a/SignalServiceKit/src/Util/OWSFileSystem.m b/SignalServiceKit/src/Util/OWSFileSystem.m index d892f57f9..ce23746bc 100644 --- a/SignalServiceKit/src/Util/OWSFileSystem.m +++ b/SignalServiceKit/src/Util/OWSFileSystem.m @@ -83,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN newFilePath, error]; OWSFail(@"%@", errorDescription); - [NSException raise:exceptionName format:@"%@", errorDescription]; + OWSRaiseException(exceptionName, @"%@", errorDescription); } DDLogInfo(@"%@ Moved file or directory from: %@ to: %@ in: %f",