Add debug UI actions around clearing and snapshotting session state.

pull/1/head
Matthew Chen 7 years ago
parent a1770ec7fc
commit 3de9a4ea55

@ -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<OWSTableItem *> *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

@ -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]];

@ -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" = "إتمام إنشاء المجموعة";

@ -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";

@ -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" = "Създай групата";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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" = "اتمام ساخت گروه";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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" = "סיים יצירת קבוצה";

@ -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";

@ -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";

@ -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";

@ -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ą";

@ -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";

@ -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" = "Завршете со креирање на група";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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" = "Завершение создания группы";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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

@ -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

@ -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<NSString *> *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

@ -1,9 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <AxolotlKit/SessionStore.h>
#import "TSStorageManager.h"
#import <AxolotlKit/SessionStore.h>
@interface TSStorageManager (SessionStore) <SessionStore>
@ -12,6 +12,10 @@
#pragma mark - debug
- (void)resetSessionStore;
#if DEBUG
- (void)archiveSessionStore;
- (void)restoreSessionStore;
#endif
- (void)printAllSessions;
@end

@ -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 <AxolotlKit/SessionRecord.h>
#import <YapDatabase/YapDatabase.h>
@ -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

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <YapDatabase/YapDatabaseConnection.h>
@ -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

@ -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 <Curve25519Kit/Curve25519.h>
#import <AxolotlKit/PreKeyRecord.h>
#import <AxolotlKit/SignedPrekeyRecord.h>
#import <Curve25519Kit/Curve25519.h>
#import <YapDatabase/YapDatabaseTransaction.h>
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<NSString *, id> *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<NSString *, id> *_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

Loading…
Cancel
Save