From db2bac7f2780528bda23088d9ec17a6a4a71e2d1 Mon Sep 17 00:00:00 2001 From: manuroe Date: Wed, 16 Nov 2016 13:40:04 +0100 Subject: [PATCH] Crypto: Enable e2e by default Once enabled, it is still not possible to disable it but do some cleaning in case of disabling in case we change our mind on this button. --- Vector/AppDelegate.m | 3 +++ Vector/ViewController/SettingsViewController.m | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Vector/AppDelegate.m b/Vector/AppDelegate.m index 3d93ffdde..4306e7fee 100644 --- a/Vector/AppDelegate.m +++ b/Vector/AppDelegate.m @@ -1262,6 +1262,9 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN - (void)initMatrixSessions { + // Enable e2e encryption for newly created MXSession + [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = YES; + // Disable identicon use [MXSDKOptions sharedInstance].disableIdenticonUseForUserAvatar = YES; diff --git a/Vector/ViewController/SettingsViewController.m b/Vector/ViewController/SettingsViewController.m index 22acd841c..20075d255 100644 --- a/Vector/ViewController/SettingsViewController.m +++ b/Vector/ViewController/SettingsViewController.m @@ -1404,9 +1404,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); UISwitch *switchButton = (UISwitch*)sender; MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject; - // Turn off by default the flag which is used to enable automatically the encryption on new sessions. - [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = NO; - if (switchButton.isOn && !account.mxCredentials.deviceId.length) { // Prompt the user to log in again when no device id is available. @@ -1438,9 +1435,6 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); __strong __typeof(weakSelf)strongSelf = weakSelf; strongSelf->currentAlert = nil; - // Turn on encryption on new sessions after signing off - [MXSDKOptions sharedInstance].enableCryptoWhenStartingMXSession = YES; - switchButton.enabled = NO; [strongSelf startActivityIndicator]; @@ -1462,6 +1456,13 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); MXSession* session = [[AppDelegate theDelegate].mxSessions objectAtIndex:0]; [session enableCrypto:switchButton.isOn success:^{ + + // When disabling crypto, reset the current device id as it cannot be reused. + // This means that the user will need to log in again if he wants to re-enable e2e. + if (!switchButton.isOn) + { + //[account resetDeviceId]; + } // Reload all data source of encrypted rooms MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:session];