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