From 3de9a4ea55e43747817556543067935c6415ef53 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 10 Jan 2018 10:40:48 -0500 Subject: [PATCH 1/2] Add debug UI actions around clearing and snapshotting session state. --- .../DebugUI/DebugUISessionState.m | 153 ++++++++++++------ .../DebugUI/DebugUITableViewController.m | 8 +- .../translations/ar.lproj/Localizable.strings | 2 +- .../az_AZ.lproj/Localizable.strings | 2 +- .../translations/bg.lproj/Localizable.strings | 2 +- .../translations/bs.lproj/Localizable.strings | 2 +- .../translations/ca.lproj/Localizable.strings | 2 +- .../translations/cs.lproj/Localizable.strings | 2 +- .../translations/da.lproj/Localizable.strings | 2 +- .../translations/fa.lproj/Localizable.strings | 2 +- .../translations/fi.lproj/Localizable.strings | 2 +- .../fil.lproj/Localizable.strings | 2 +- .../translations/fr.lproj/Localizable.strings | 2 +- .../translations/gl.lproj/Localizable.strings | 2 +- .../translations/he.lproj/Localizable.strings | 2 +- .../translations/hr.lproj/Localizable.strings | 2 +- .../translations/hu.lproj/Localizable.strings | 2 +- .../it_IT.lproj/Localizable.strings | 2 +- .../translations/lt.lproj/Localizable.strings | 2 +- .../translations/lv.lproj/Localizable.strings | 2 +- .../translations/mk.lproj/Localizable.strings | 2 +- .../nb_NO.lproj/Localizable.strings | 2 +- .../translations/nl.lproj/Localizable.strings | 2 +- .../pt_BR.lproj/Localizable.strings | 2 +- .../pt_PT.lproj/Localizable.strings | 2 +- .../translations/ro.lproj/Localizable.strings | 2 +- .../translations/ru.lproj/Localizable.strings | 2 +- .../translations/sl.lproj/Localizable.strings | 2 +- .../translations/sn.lproj/Localizable.strings | 2 +- .../translations/sq.lproj/Localizable.strings | 2 +- .../sv_SE.lproj/Localizable.strings | 2 +- .../tr_TR.lproj/Localizable.strings | 2 +- .../src/Account/TSAccountManager.m | 6 +- .../src/Messages/OWSIdentityManager.h | 8 + .../src/Messages/OWSIdentityManager.m | 60 ++++++- .../TSStorageManager+SessionStore.h | 8 +- .../TSStorageManager+SessionStore.m | 28 +++- .../src/Storage/YapDatabaseConnection+OWS.h | 9 +- .../src/Storage/YapDatabaseConnection+OWS.m | 45 +++++- 39 files changed, 289 insertions(+), 96 deletions(-) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m b/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m index 42358ceb3..cbf1eba72 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "DebugUISessionState.h" @@ -20,63 +20,112 @@ NS_ASSUME_NONNULL_BEGIN - (nullable OWSTableSection *)sectionForThread:(nullable TSThread *)threadParameter { - OWSAssert([threadParameter isKindOfClass:[TSContactThread class]]); + NSMutableArray *items = [NSMutableArray new]; + if ([threadParameter isKindOfClass:[TSContactThread class]]) { + TSContactThread *thread = (TSContactThread *)threadParameter; + [items addObjectsFromArray:@[ + [OWSTableItem itemWithTitle:@"Log All Recipient Identities" + actionBlock:^{ + [OWSRecipientIdentity printAllIdentities]; + }], + [OWSTableItem itemWithTitle:@"Log All Sessions" + actionBlock:^{ + dispatch_async([OWSDispatch sessionStoreQueue], ^{ + [[TSStorageManager sharedManager] printAllSessions]; + }); + }], + [OWSTableItem itemWithTitle:@"Toggle Key Change" + actionBlock:^{ + DDLogError(@"Flipping identity Key. Flip again to return."); - TSContactThread *thread = (TSContactThread *)threadParameter; + OWSIdentityManager *identityManager = [OWSIdentityManager sharedManager]; + NSString *recipientId = [thread contactIdentifier]; - return [OWSTableSection - sectionWithTitle:self.name - items:@[ - [OWSTableItem itemWithTitle:@"Log All Recipient Identities" - actionBlock:^{ - [OWSRecipientIdentity printAllIdentities]; - }], - [OWSTableItem itemWithTitle:@"Log All Sessions" - actionBlock:^{ - dispatch_async([OWSDispatch sessionStoreQueue], ^{ - [[TSStorageManager sharedManager] printAllSessions]; - }); - }], - [OWSTableItem itemWithTitle:@"Toggle Key Change" - actionBlock:^{ - DDLogError(@"Flipping identity Key. Flip again to return."); + NSData *currentKey = [identityManager identityKeyForRecipientId:recipientId]; + NSMutableData *flippedKey = [NSMutableData new]; + const char *currentKeyBytes = currentKey.bytes; + for (NSUInteger i = 0; i < currentKey.length; i++) { + const char xorByte = currentKeyBytes[i] ^ 0xff; + [flippedKey appendBytes:&xorByte length:1]; + } + OWSAssert(flippedKey.length == currentKey.length); + [identityManager saveRemoteIdentity:flippedKey recipientId:recipientId]; + }], + [OWSTableItem itemWithTitle:@"Delete all sessions" + actionBlock:^{ + dispatch_async([OWSDispatch sessionStoreQueue], ^{ + [[TSStorageManager sharedManager] + deleteAllSessionsForContact:thread.contactIdentifier]; + }); + }], + [OWSTableItem itemWithTitle:@"Archive all sessions" + actionBlock:^{ + dispatch_async([OWSDispatch sessionStoreQueue], ^{ + [[TSStorageManager sharedManager] + archiveAllSessionsForContact:thread.contactIdentifier]; + }); + }], + [OWSTableItem itemWithTitle:@"Send session reset" + actionBlock:^{ + [OWSSessionResetJob runWithContactThread:thread + messageSender:[Environment current].messageSender + storageManager:[TSStorageManager sharedManager]]; + }], + ]]; + } - OWSIdentityManager *identityManager = [OWSIdentityManager sharedManager]; - NSString *recipientId = [thread contactIdentifier]; +#if DEBUG + [items addObjectsFromArray:@[ + [OWSTableItem itemWithTitle:@"Clear Session and Identity Store" + actionBlock:^{ + [DebugUISessionState clearSessionAndIdentityStore]; + }], + [OWSTableItem itemWithTitle:@"Archive Session and Identity Store" + actionBlock:^{ + [DebugUISessionState archiveSessionAndIdentityStore]; + }], + [OWSTableItem itemWithTitle:@"Restore Session and Identity Store" + actionBlock:^{ + [DebugUISessionState restoreSessionAndIdentityStore]; + }] + ]]; +#endif - NSData *currentKey = [identityManager identityKeyForRecipientId:recipientId]; - NSMutableData *flippedKey = [NSMutableData new]; - const char *currentKeyBytes = currentKey.bytes; - for (NSUInteger i = 0; i < currentKey.length; i++) { - const char xorByte = currentKeyBytes[i] ^ 0xff; - [flippedKey appendBytes:&xorByte length:1]; - } - OWSAssert(flippedKey.length == currentKey.length); - [identityManager saveRemoteIdentity:flippedKey recipientId:recipientId]; - }], - [OWSTableItem itemWithTitle:@"Delete all sessions" - actionBlock:^{ - dispatch_async([OWSDispatch sessionStoreQueue], ^{ - [[TSStorageManager sharedManager] - deleteAllSessionsForContact:thread.contactIdentifier]; - }); - }], - [OWSTableItem itemWithTitle:@"Archive all sessions" - actionBlock:^{ - dispatch_async([OWSDispatch sessionStoreQueue], ^{ - [[TSStorageManager sharedManager] - archiveAllSessionsForContact:thread.contactIdentifier]; - }); - }], - [OWSTableItem itemWithTitle:@"Send session reset" - actionBlock:^{ - [OWSSessionResetJob runWithContactThread:thread - messageSender:[Environment current].messageSender - storageManager:[TSStorageManager sharedManager]]; - }] - ]]; + return [OWSTableSection sectionWithTitle:self.name items:items]; } +#if DEBUG ++ (void)clearSessionAndIdentityStore +{ + dispatch_async([OWSDispatch sessionStoreQueue], ^{ + [[TSStorageManager sharedManager] resetSessionStore]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[OWSIdentityManager sharedManager] clearIdentityState]; + }); + }); +} + ++ (void)archiveSessionAndIdentityStore +{ + dispatch_async([OWSDispatch sessionStoreQueue], ^{ + [[TSStorageManager sharedManager] archiveSessionStore]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[OWSIdentityManager sharedManager] archiveIdentityState]; + }); + }); +} + ++ (void)restoreSessionAndIdentityStore +{ + dispatch_async([OWSDispatch sessionStoreQueue], ^{ + [[TSStorageManager sharedManager] restoreSessionStore]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[OWSIdentityManager sharedManager] restoreIdentityState]; + }); + }); +} +#endif + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m b/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m index 47d07fb32..5213f74f2 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUITableViewController.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "DebugUITableViewController.h" @@ -79,9 +79,9 @@ NS_ASSUME_NONNULL_BEGIN addObject:[self itemForSubsection:[DebugUIContacts new] viewController:viewController thread:thread]]; [subsectionItems addObject:[self itemForSubsection:[DebugUIDiskUsage new] viewController:viewController thread:thread]]; + [subsectionItems + addObject:[self itemForSubsection:[DebugUISessionState new] viewController:viewController thread:thread]]; if ([thread isKindOfClass:[TSContactThread class]]) { - [subsectionItems - addObject:[self itemForSubsection:[DebugUISessionState new] viewController:viewController thread:thread]]; [subsectionItems addObject:[self itemForSubsection:[DebugUICalling new] viewController:viewController thread:thread]]; } @@ -111,6 +111,8 @@ NS_ASSUME_NONNULL_BEGIN [subsectionItems addObject:[self itemForSubsection:[DebugUIContacts new] viewController:viewController thread:nil]]; [subsectionItems addObject:[self itemForSubsection:[DebugUIDiskUsage new] viewController:viewController thread:nil]]; + [subsectionItems + addObject:[self itemForSubsection:[DebugUISessionState new] viewController:viewController thread:nil]]; [subsectionItems addObject:[self itemForSubsection:[DebugUISyncMessages new] viewController:viewController thread:nil]]; [subsectionItems addObject:[self itemForSubsection:[DebugUIMisc new] viewController:viewController thread:nil]]; diff --git a/Signal/translations/ar.lproj/Localizable.strings b/Signal/translations/ar.lproj/Localizable.strings index fd39ef3f9..2acc4398a 100644 --- a/Signal/translations/ar.lproj/Localizable.strings +++ b/Signal/translations/ar.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "وضع علامة \"تم التحقق\""; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "إعادة تعيين هذه الجلسة."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "إعادة تعيين هذه الجلسة"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "إتمام إنشاء المجموعة"; diff --git a/Signal/translations/az_AZ.lproj/Localizable.strings b/Signal/translations/az_AZ.lproj/Localizable.strings index 14246943b..5a0adf984 100644 --- a/Signal/translations/az_AZ.lproj/Localizable.strings +++ b/Signal/translations/az_AZ.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Mark as Verified"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Sessiyanı yenidən başla."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Sessiyanı yenidən başla"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Finish creating group"; diff --git a/Signal/translations/bg.lproj/Localizable.strings b/Signal/translations/bg.lproj/Localizable.strings index 83de72997..0f7500565 100644 --- a/Signal/translations/bg.lproj/Localizable.strings +++ b/Signal/translations/bg.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Маркирай като проверено"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Нулирай сесията."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Нулирай сесията"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Създай групата"; diff --git a/Signal/translations/bs.lproj/Localizable.strings b/Signal/translations/bs.lproj/Localizable.strings index 1af7876e4..684b7d146 100644 --- a/Signal/translations/bs.lproj/Localizable.strings +++ b/Signal/translations/bs.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Označi provjerenim"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Resetuj ovu sesiju."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Resetuj ovu sesiju"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Završi kreiranje grupe"; diff --git a/Signal/translations/ca.lproj/Localizable.strings b/Signal/translations/ca.lproj/Localizable.strings index 27dfdfea6..3b5f28978 100644 --- a/Signal/translations/ca.lproj/Localizable.strings +++ b/Signal/translations/ca.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Marca com a verificat"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reinicia la sessió."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reinicia la sessió"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Acaba de crear el grup"; diff --git a/Signal/translations/cs.lproj/Localizable.strings b/Signal/translations/cs.lproj/Localizable.strings index 3b17e1b27..b48ac6e9d 100644 --- a/Signal/translations/cs.lproj/Localizable.strings +++ b/Signal/translations/cs.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Označit jako ověřený"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Resetovat toto sezení."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Resetovat toto sezení"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Dokončit tvorbu skupiny"; diff --git a/Signal/translations/da.lproj/Localizable.strings b/Signal/translations/da.lproj/Localizable.strings index 390fceb54..3fc4470de 100644 --- a/Signal/translations/da.lproj/Localizable.strings +++ b/Signal/translations/da.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Mark as Verified"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Nulstil denne session."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Nulstil denne session"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Færdigør gruppe opretning"; diff --git a/Signal/translations/fa.lproj/Localizable.strings b/Signal/translations/fa.lproj/Localizable.strings index 7600f51bc..1fe008b1e 100644 --- a/Signal/translations/fa.lproj/Localizable.strings +++ b/Signal/translations/fa.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "علامت‌گذاری به عنوان تائید شده"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "بازگردانی این نشست به حالت اولیه."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "بازگردانی این نشست به حالت اولیه"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "اتمام ساخت گروه"; diff --git a/Signal/translations/fi.lproj/Localizable.strings b/Signal/translations/fi.lproj/Localizable.strings index 20de5b8c3..7eeb7448c 100644 --- a/Signal/translations/fi.lproj/Localizable.strings +++ b/Signal/translations/fi.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Merkitse varmennetuksi"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Alusta tämä istunto."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Alusta tämä istunto"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Päätä ryhmän luonti"; diff --git a/Signal/translations/fil.lproj/Localizable.strings b/Signal/translations/fil.lproj/Localizable.strings index f3e21069f..8c326dcd0 100644 --- a/Signal/translations/fil.lproj/Localizable.strings +++ b/Signal/translations/fil.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Mark as Verified"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reset this session."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reset this session"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Finish creating group"; diff --git a/Signal/translations/fr.lproj/Localizable.strings b/Signal/translations/fr.lproj/Localizable.strings index b0c6295c6..d682bf5f4 100644 --- a/Signal/translations/fr.lproj/Localizable.strings +++ b/Signal/translations/fr.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Marquer comme vérifié"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Réinitialiser cette session."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Réinitialiser cette session"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Terminer la création du groupe"; diff --git a/Signal/translations/gl.lproj/Localizable.strings b/Signal/translations/gl.lproj/Localizable.strings index cd0219b0f..d2c68d502 100644 --- a/Signal/translations/gl.lproj/Localizable.strings +++ b/Signal/translations/gl.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Mark as Verified"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Restablecer esta sesión."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Restablecer esta sesión"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Termina de crear o grupo"; diff --git a/Signal/translations/he.lproj/Localizable.strings b/Signal/translations/he.lproj/Localizable.strings index 0fe7bdb1c..41a098b8e 100644 --- a/Signal/translations/he.lproj/Localizable.strings +++ b/Signal/translations/he.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "סמן כמאומת"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "אתחול ההתחברות הזאת."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "אתחול ההתחברות הזאת"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "סיים יצירת קבוצה"; diff --git a/Signal/translations/hr.lproj/Localizable.strings b/Signal/translations/hr.lproj/Localizable.strings index d64baba3f..1b85c5c0a 100644 --- a/Signal/translations/hr.lproj/Localizable.strings +++ b/Signal/translations/hr.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Označi provjerenim"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Resetuj ovu sesiju."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Resetuj ovu sesiju"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Završi kreiranje grupe"; diff --git a/Signal/translations/hu.lproj/Localizable.strings b/Signal/translations/hu.lproj/Localizable.strings index 3ebdf15e6..9b5646c8f 100644 --- a/Signal/translations/hu.lproj/Localizable.strings +++ b/Signal/translations/hu.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Mark as Verified"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Munkamenet alaphelyzetbe állítása."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Munkamenet alaphelyzetbe állítása"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Finish creating group"; diff --git a/Signal/translations/it_IT.lproj/Localizable.strings b/Signal/translations/it_IT.lproj/Localizable.strings index f2033e0af..4378945b7 100644 --- a/Signal/translations/it_IT.lproj/Localizable.strings +++ b/Signal/translations/it_IT.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Segna come verificato"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Rosetta questa sessione."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Rosetta questa sessione"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Terminazione creazione gruppo"; diff --git a/Signal/translations/lt.lproj/Localizable.strings b/Signal/translations/lt.lproj/Localizable.strings index d61a5f9a2..9f915d196 100644 --- a/Signal/translations/lt.lproj/Localizable.strings +++ b/Signal/translations/lt.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Žymėti kaip patvirtintą"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Atstatyti šį seansą."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Atstatyti šį seansą"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Užbaigti grupės kūrimą"; diff --git a/Signal/translations/lv.lproj/Localizable.strings b/Signal/translations/lv.lproj/Localizable.strings index 519c472b5..0663a831d 100644 --- a/Signal/translations/lv.lproj/Localizable.strings +++ b/Signal/translations/lv.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Mark as Verified"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Pārtraukt šo sesiju."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Pārtraukt šo sesiju"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Finish creating group"; diff --git a/Signal/translations/mk.lproj/Localizable.strings b/Signal/translations/mk.lproj/Localizable.strings index bf6364b39..60486ac8b 100644 --- a/Signal/translations/mk.lproj/Localizable.strings +++ b/Signal/translations/mk.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Mark as Verified"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Ресетирајте ја оваа сесија."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Ресетирајте ја оваа сесија"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Завршете со креирање на група"; diff --git a/Signal/translations/nb_NO.lproj/Localizable.strings b/Signal/translations/nb_NO.lproj/Localizable.strings index 168b3b823..b08b50950 100644 --- a/Signal/translations/nb_NO.lproj/Localizable.strings +++ b/Signal/translations/nb_NO.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Merk som verifisert"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Tilbakestill denne sesjonen."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Tilbakestill denne sesjonen"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Fullfør oppretting av gruppe"; diff --git a/Signal/translations/nl.lproj/Localizable.strings b/Signal/translations/nl.lproj/Localizable.strings index 91d52c0ac..7a9c9e9f0 100644 --- a/Signal/translations/nl.lproj/Localizable.strings +++ b/Signal/translations/nl.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Markeren als geverifieerd"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Deze sessie opnieuw instellen."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Deze sessie opnieuw instellen"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Voltooi aanmaken van groep"; diff --git a/Signal/translations/pt_BR.lproj/Localizable.strings b/Signal/translations/pt_BR.lproj/Localizable.strings index 8d07ccf6d..95683f126 100644 --- a/Signal/translations/pt_BR.lproj/Localizable.strings +++ b/Signal/translations/pt_BR.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Marcar como verificado"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reiniciar esta sessão."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reiniciar esta sessão"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Terminar de criar grupo"; diff --git a/Signal/translations/pt_PT.lproj/Localizable.strings b/Signal/translations/pt_PT.lproj/Localizable.strings index e03f8b04f..2166b1ca1 100644 --- a/Signal/translations/pt_PT.lproj/Localizable.strings +++ b/Signal/translations/pt_PT.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = " Marcar como Verificado "; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reiniciar esta sessão."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reiniciar esta sessão"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Finalizar criação do grupo"; diff --git a/Signal/translations/ro.lproj/Localizable.strings b/Signal/translations/ro.lproj/Localizable.strings index 01f649c1c..3498399ac 100644 --- a/Signal/translations/ro.lproj/Localizable.strings +++ b/Signal/translations/ro.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Marchează ca verificat"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Resetează sesiunea."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Resetează sesiunea"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Grupul a fost creat"; diff --git a/Signal/translations/ru.lproj/Localizable.strings b/Signal/translations/ru.lproj/Localizable.strings index 7599f6906..af5ed3139 100644 --- a/Signal/translations/ru.lproj/Localizable.strings +++ b/Signal/translations/ru.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Отметить как проверенный"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Сбросить сеанс связи."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Сбросить сеанс связи"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Завершение создания группы"; diff --git a/Signal/translations/sl.lproj/Localizable.strings b/Signal/translations/sl.lproj/Localizable.strings index 15793e3dd..1b51c7ec7 100644 --- a/Signal/translations/sl.lproj/Localizable.strings +++ b/Signal/translations/sl.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Označi kot potrjeno"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Ponastavi tekočo sejo."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Ponastavi tekočo sejo"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Končaj z ustvarjanjem skupine"; diff --git a/Signal/translations/sn.lproj/Localizable.strings b/Signal/translations/sn.lproj/Localizable.strings index 19fdd82a8..eb446fea0 100644 --- a/Signal/translations/sn.lproj/Localizable.strings +++ b/Signal/translations/sn.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Mark as Verified"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Tangisa chikamu ichi."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Tangisa chikamu ichi"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Finish creating group"; diff --git a/Signal/translations/sq.lproj/Localizable.strings b/Signal/translations/sq.lproj/Localizable.strings index 9ca355a21..9ed1a90bf 100644 --- a/Signal/translations/sq.lproj/Localizable.strings +++ b/Signal/translations/sq.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Mark as Verified"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reseto sesionin."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Reseto sesionin"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Finish creating group"; diff --git a/Signal/translations/sv_SE.lproj/Localizable.strings b/Signal/translations/sv_SE.lproj/Localizable.strings index 2cb9fd4ae..30c4d4a0b 100644 --- a/Signal/translations/sv_SE.lproj/Localizable.strings +++ b/Signal/translations/sv_SE.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Markera som verifierad"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Nollställ sessionen."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Nollställ sessionen"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Slutför skapa grupp"; diff --git a/Signal/translations/tr_TR.lproj/Localizable.strings b/Signal/translations/tr_TR.lproj/Localizable.strings index ce2e3d76b..9871e94e3 100644 --- a/Signal/translations/tr_TR.lproj/Localizable.strings +++ b/Signal/translations/tr_TR.lproj/Localizable.strings @@ -665,7 +665,7 @@ "FINGERPRINT_SCAN_VERIFY_BUTTON" = "Onaylı olarak işaretle"; /* No comment provided by engineer. */ -"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Oturumu yenile."; +"FINGERPRINT_SHRED_KEYMATERIAL_BUTTON" = "Oturumu yenile"; /* Accessibilty label for finishing new group */ "FINISH_GROUP_CREATION_LABEL" = "Grup oluşturmayı tamamla"; diff --git a/SignalServiceKit/src/Account/TSAccountManager.m b/SignalServiceKit/src/Account/TSAccountManager.m index 80a743f88..1d67ab05b 100644 --- a/SignalServiceKit/src/Account/TSAccountManager.m +++ b/SignalServiceKit/src/Account/TSAccountManager.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "TSAccountManager.h" @@ -93,7 +93,9 @@ NSString *const TSAccountManager_ServerSignalingKey = @"TSStorageServerSignaling [transaction removeAllObjectsInCollection:TSAccountManager_UserAccountCollection]; }]; } - [[TSStorageManager sharedManager] resetSessionStore]; + dispatch_async([OWSDispatch sessionStoreQueue], ^{ + [[TSStorageManager sharedManager] resetSessionStore]; + }); } + (BOOL)isRegistered diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.h b/SignalServiceKit/src/Messages/OWSIdentityManager.h index 51e94150b..2cde37f43 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.h +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.h @@ -50,6 +50,14 @@ extern const NSUInteger kIdentityKeyLength; // This method can be called from any thread. - (void)processIncomingSyncMessage:(OWSSignalServiceProtosVerified *)verified; +#pragma mark - Debug + +#if DEBUG +- (void)clearIdentityState; +- (void)archiveIdentityState; +- (void)restoreIdentityState; +#endif + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.m b/SignalServiceKit/src/Messages/OWSIdentityManager.m index d441b7f47..7a6132665 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.m +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.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" @@ -8,6 +8,7 @@ #import "NSNotificationCenter+OWS.h" #import "NotificationsProtocol.h" #import "OWSError.h" +#import "OWSFileSystem.h" #import "OWSMessageSender.h" #import "OWSOutgoingNullMessage.h" #import "OWSRecipientIdentity.h" @@ -133,8 +134,9 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa - (nullable ECKeyPair *)identityKeyPair { - return [self.dbConnection keyPairForKey:TSStorageManagerIdentityKeyStoreIdentityKey - inCollection:TSStorageManagerIdentityKeyStoreCollection]; + ECKeyPair *_Nullable identityKeyPair = [self.dbConnection keyPairForKey:TSStorageManagerIdentityKeyStoreIdentityKey + inCollection:TSStorageManagerIdentityKeyStoreCollection]; + return identityKeyPair; } - (int)localRegistrationId @@ -745,6 +747,58 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa }]; } +#pragma mark - Debug + +#if DEBUG +- (void)clearIdentityState +{ + [self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + NSMutableArray *identityKeysToRemove = [NSMutableArray new]; + [transaction enumerateKeysInCollection:TSStorageManagerIdentityKeyStoreCollection + usingBlock:^(NSString *_Nonnull key, BOOL *_Nonnull stop) { + if ([key isEqualToString:TSStorageManagerIdentityKeyStoreIdentityKey]) { + // Don't delete our own key. + return; + } + [identityKeysToRemove addObject:key]; + }]; + for (NSString *key in identityKeysToRemove) { + [transaction removeObjectForKey:key inCollection:TSStorageManagerIdentityKeyStoreCollection]; + } + [transaction removeAllObjectsInCollection:TSStorageManagerTrustedKeysCollection]; + }]; +} + +- (NSString *)identityKeySnapshotFilePath +{ + NSString *dirPath = [OWSFileSystem appDocumentDirectoryPath]; + return [dirPath stringByAppendingPathComponent:@".identity-key-snapshot"]; +} + +- (NSString *)trustedKeySnapshotFilePath +{ + NSString *dirPath = [OWSFileSystem appDocumentDirectoryPath]; + return [dirPath stringByAppendingPathComponent:@".trusted-key-snapshot"]; +} + +- (void)archiveIdentityState +{ + [self.dbConnection snapshotCollection:TSStorageManagerIdentityKeyStoreCollection + snapshotFilePath:self.identityKeySnapshotFilePath]; + [self.dbConnection snapshotCollection:TSStorageManagerTrustedKeysCollection + snapshotFilePath:self.trustedKeySnapshotFilePath]; +} + +- (void)restoreIdentityState +{ + [self.dbConnection restoreSnapshotOfCollection:TSStorageManagerIdentityKeyStoreCollection + snapshotFilePath:self.identityKeySnapshotFilePath]; + [self.dbConnection restoreSnapshotOfCollection:TSStorageManagerTrustedKeysCollection + snapshotFilePath:self.trustedKeySnapshotFilePath]; +} + +#endif + #pragma mark - Notifications - (void)applicationDidBecomeActive:(NSNotification *)notification diff --git a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.h b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.h index 5dff6712b..4bec5de02 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.h +++ b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.h @@ -1,9 +1,9 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // -#import #import "TSStorageManager.h" +#import @interface TSStorageManager (SessionStore) @@ -12,6 +12,10 @@ #pragma mark - debug - (void)resetSessionStore; +#if DEBUG +- (void)archiveSessionStore; +- (void)restoreSessionStore; +#endif - (void)printAllSessions; @end diff --git a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m index b87309b59..0d6d96263 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m +++ b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m @@ -1,8 +1,10 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // +#import "OWSFileSystem.h" #import "TSStorageManager+SessionStore.h" +#import "YapDatabaseConnection+OWS.h" #import #import @@ -242,4 +244,28 @@ void AssertIsOnSessionStoreQueue() }]; } +#if DEBUG +- (NSString *)snapshotFilePath +{ + NSString *dirPath = [OWSFileSystem appDocumentDirectoryPath]; + return [dirPath stringByAppendingPathComponent:@".session-snapshot"]; +} + +- (void)archiveSessionStore +{ + AssertIsOnSessionStoreQueue(); + + [self.sessionDBConnection snapshotCollection:TSStorageManagerSessionStoreCollection + snapshotFilePath:self.snapshotFilePath]; +} + +- (void)restoreSessionStore +{ + AssertIsOnSessionStoreQueue(); + + [self.sessionDBConnection restoreSnapshotOfCollection:TSStorageManagerSessionStoreCollection + snapshotFilePath:self.snapshotFilePath]; +} +#endif + @end diff --git a/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.h b/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.h index 5688a6273..584be964c 100644 --- a/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.h +++ b/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.h @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import @@ -38,6 +38,13 @@ NS_ASSUME_NONNULL_BEGIN - (void)purgeCollection:(NSString *)collection; +#pragma mark - Debug + +#if DEBUG +- (void)snapshotCollection:(NSString *)collection snapshotFilePath:(NSString *)snapshotFilePath; +- (void)restoreSnapshotOfCollection:(NSString *)collection snapshotFilePath:(NSString *)snapshotFilePath; +#endif + @end NS_ASSUME_NONNULL_END diff --git a/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.m b/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.m index 39b6eaa1f..f1d672736 100644 --- a/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.m +++ b/SignalServiceKit/src/Storage/YapDatabaseConnection+OWS.m @@ -1,11 +1,11 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "YapDatabaseConnection+OWS.h" -#import #import #import +#import #import NS_ASSUME_NONNULL_BEGIN @@ -168,6 +168,47 @@ NS_ASSUME_NONNULL_BEGIN [self setObject:@(value.timeIntervalSince1970) forKey:key inCollection:collection]; } +#pragma mark - Debug + +#if DEBUG +- (void)snapshotCollection:(NSString *)collection snapshotFilePath:(NSString *)snapshotFilePath +{ + OWSAssert(collection.length > 0); + OWSAssert(snapshotFilePath.length > 0); + + NSMutableDictionary *snapshot = [NSMutableDictionary new]; + [self readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + [transaction + enumerateKeysAndObjectsInCollection:collection + usingBlock:^(NSString *_Nonnull key, id _Nonnull value, BOOL *_Nonnull stop) { + snapshot[key] = value; + }]; + }]; + NSData *_Nullable data = [NSKeyedArchiver archivedDataWithRootObject:snapshot]; + OWSAssert(data); + BOOL success = [data writeToFile:snapshotFilePath atomically:YES]; + OWSAssert(success); +} + +- (void)restoreSnapshotOfCollection:(NSString *)collection snapshotFilePath:(NSString *)snapshotFilePath +{ + OWSAssert(collection.length > 0); + OWSAssert(snapshotFilePath.length > 0); + + NSData *_Nullable data = [NSData dataWithContentsOfFile:snapshotFilePath]; + OWSAssert(data); + NSMutableDictionary *_Nullable snapshot = [NSKeyedUnarchiver unarchiveObjectWithData:data]; + OWSAssert(snapshot); + + [self readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { + [transaction removeAllObjectsInCollection:collection]; + [snapshot enumerateKeysAndObjectsUsingBlock:^(NSString *_Nonnull key, id _Nonnull value, BOOL *_Nonnull stop) { + [transaction setObject:value forKey:key inCollection:collection]; + }]; + }]; +} +#endif + @end NS_ASSUME_NONNULL_END From 0d5b5bc44c7616b5e66bfa08bc7aec27f998fc27 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 12 Jan 2018 16:49:51 -0500 Subject: [PATCH 2/2] Respond to CR. --- .../src/ViewControllers/DebugUI/DebugUISessionState.m | 10 +++++----- Signal/src/util/OWSBackup.m | 4 ++++ SignalServiceKit/src/Messages/OWSIdentityManager.h | 4 +++- SignalServiceKit/src/Messages/OWSIdentityManager.m | 4 +++- .../AxolotlStore/TSStorageManager+SessionStore.h | 2 +- .../AxolotlStore/TSStorageManager+SessionStore.m | 5 ++++- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m b/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m index cbf1eba72..2c1058192 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUISessionState.m @@ -80,9 +80,9 @@ NS_ASSUME_NONNULL_BEGIN actionBlock:^{ [DebugUISessionState clearSessionAndIdentityStore]; }], - [OWSTableItem itemWithTitle:@"Archive Session and Identity Store" + [OWSTableItem itemWithTitle:@"Snapshot Session and Identity Store" actionBlock:^{ - [DebugUISessionState archiveSessionAndIdentityStore]; + [DebugUISessionState snapshotSessionAndIdentityStore]; }], [OWSTableItem itemWithTitle:@"Restore Session and Identity Store" actionBlock:^{ @@ -105,12 +105,12 @@ NS_ASSUME_NONNULL_BEGIN }); } -+ (void)archiveSessionAndIdentityStore ++ (void)snapshotSessionAndIdentityStore { dispatch_async([OWSDispatch sessionStoreQueue], ^{ - [[TSStorageManager sharedManager] archiveSessionStore]; + [[TSStorageManager sharedManager] snapshotSessionStore]; dispatch_async(dispatch_get_main_queue(), ^{ - [[OWSIdentityManager sharedManager] archiveIdentityState]; + [[OWSIdentityManager sharedManager] snapshotIdentityState]; }); }); } diff --git a/Signal/src/util/OWSBackup.m b/Signal/src/util/OWSBackup.m index b0ce065a9..e61c44647 100644 --- a/Signal/src/util/OWSBackup.m +++ b/Signal/src/util/OWSBackup.m @@ -16,6 +16,10 @@ NS_ASSUME_NONNULL_BEGIN // Hide the "import" directories from exports, etc. by prefixing their name with a period. +// +// OWSBackup backs up files and directories in the "app documents" and "shared data container", +// but ignores any top-level files or directories in those locations whose names start with a +// period ".". NSString *const OWSBackup_DirNamePrefix = @".SignalBackup."; NSString *const OWSBackup_FileExtension = @".signalbackup"; NSString *const OWSBackup_EncryptionKeyFilename = @".encryptionKey"; diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.h b/SignalServiceKit/src/Messages/OWSIdentityManager.h index 2cde37f43..4a5e1fb8f 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.h +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.h @@ -53,8 +53,10 @@ extern const NSUInteger kIdentityKeyLength; #pragma mark - Debug #if DEBUG +// Clears everything except the local identity key. - (void)clearIdentityState; -- (void)archiveIdentityState; + +- (void)snapshotIdentityState; - (void)restoreIdentityState; #endif diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.m b/SignalServiceKit/src/Messages/OWSIdentityManager.m index 7a6132665..4e2e20cef 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.m +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.m @@ -771,17 +771,19 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa - (NSString *)identityKeySnapshotFilePath { + // Prefix name with period "." so that backups will ignore these snapshots. NSString *dirPath = [OWSFileSystem appDocumentDirectoryPath]; return [dirPath stringByAppendingPathComponent:@".identity-key-snapshot"]; } - (NSString *)trustedKeySnapshotFilePath { + // Prefix name with period "." so that backups will ignore these snapshots. NSString *dirPath = [OWSFileSystem appDocumentDirectoryPath]; return [dirPath stringByAppendingPathComponent:@".trusted-key-snapshot"]; } -- (void)archiveIdentityState +- (void)snapshotIdentityState { [self.dbConnection snapshotCollection:TSStorageManagerIdentityKeyStoreCollection snapshotFilePath:self.identityKeySnapshotFilePath]; diff --git a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.h b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.h index 4bec5de02..2e1cf67b3 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.h +++ b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.h @@ -13,7 +13,7 @@ - (void)resetSessionStore; #if DEBUG -- (void)archiveSessionStore; +- (void)snapshotSessionStore; - (void)restoreSessionStore; #endif - (void)printAllSessions; diff --git a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m index 0d6d96263..d90e719e8 100644 --- a/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m +++ b/SignalServiceKit/src/Storage/AxolotlStore/TSStorageManager+SessionStore.m @@ -194,6 +194,8 @@ void AssertIsOnSessionStoreQueue() - (void)resetSessionStore { + AssertIsOnSessionStoreQueue(); + DDLogWarn(@"%@ resetting session store", self.logTag); [self.sessionDBConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) { [transaction removeAllObjectsInCollection:TSStorageManagerSessionStoreCollection]; @@ -247,11 +249,12 @@ void AssertIsOnSessionStoreQueue() #if DEBUG - (NSString *)snapshotFilePath { + // Prefix name with period "." so that backups will ignore these snapshots. NSString *dirPath = [OWSFileSystem appDocumentDirectoryPath]; return [dirPath stringByAppendingPathComponent:@".session-snapshot"]; } -- (void)archiveSessionStore +- (void)snapshotSessionStore { AssertIsOnSessionStoreQueue();