Skip to content

Commit

Permalink
Disable key backup in the rebase version of the code (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
giomfo authored May 19, 2020
1 parent 3ed89de commit 39c5847
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1 deletion.
1 change: 1 addition & 0 deletions Tchap/Assets/Localizations/fr.lproj/Tchap.strings
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"settings_hide_from_users_directory_title" = "Inscrire mon compte sur liste rouge";
"settings_hide_from_users_directory_summary" = "Les autres utilisateurs ne pourront pas découvrir mon compte lors de leurs recherches";
"settings_contacts_discover_matrix_users" = "Utiliser les adresses emails pour retrouver des utilisateurs";
"settings_change_pwd_caution" = "Changer le mot de passe réinitialise les clés de chiffrement sur tous les appareils, rendant l’historique des discussions illisible: pensez d'abord à exporter vos clés pour pouvoir les ré-importer après le changement de mot de passe.";
"settings_change_pwd_non_existing_key_backup_alert_title" = "Changer le mot de passe réinitialise les clés de chiffrement sur tous les appareils, rendant l’historique des discussions illisible: pensez à mettre en place la sauvegarde de vos clés avant ce changement.";
"settings_change_pwd_non_existing_key_backup_alert_setup_key_backup_action" = "Mettre en place la sauvegarde de clés";
"settings_change_pwd_non_existing_key_backup_alert_discard_key_backup_action" = "Changer le mot de passe sans sauvegarde de clés";
Expand Down
2 changes: 2 additions & 0 deletions Tchap/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ internal enum TchapL10n {
internal static let roomTitleUnrestrictedRoom = TchapL10n.tr("Tchap", "room_title_unrestricted_room")
/// Aucun résultat
internal static let searchNoResult = TchapL10n.tr("Tchap", "search_no_result")
/// Changer le mot de passe réinitialise les clés de chiffrement sur tous les appareils, rendant l’historique des discussions illisible: pensez d'abord à exporter vos clés pour pouvoir les ré-importer après le changement de mot de passe.
internal static let settingsChangePwdCaution = TchapL10n.tr("Tchap", "settings_change_pwd_caution")
/// Je vais patienter
internal static let settingsChangePwdKeyBackupInProgressAlertCancelAction = TchapL10n.tr("Tchap", "settings_change_pwd_key_backup_in_progress_alert_cancel_action")
/// Je ne veux plus de mes messages chiffrés
Expand Down
2 changes: 2 additions & 0 deletions Tchap/Modules/Rooms/DataSources/RoomsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ - (BOOL)updateKeyBackupBanner
{
KeyBackupBanner keyBackupBanner = KeyBackupBannerNone;

#ifdef SUPPORT_KEYS_BACKUP
// Tchap: display the banner even if there is no new key to backup, in order to let the user recover an existing
// backup (if any)
//if (self.mxSession.crypto.backup.hasKeysToBackup)
Expand Down Expand Up @@ -155,6 +156,7 @@ - (BOOL)updateKeyBackupBanner
break;
}
}
#endif

BOOL updated = (self.keyBackupBanner != keyBackupBanner);

Expand Down
17 changes: 16 additions & 1 deletion Tchap/Modules/Rooms/RoomsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@

#import "RoomsDataSource.h"

@interface RoomsViewController () <KeyBackupSetupCoordinatorBridgePresenterDelegate, KeyBackupRecoverCoordinatorBridgePresenterDelegate>
@interface RoomsViewController ()
#ifdef SUPPORT_KEYS_BACKUP
<KeyBackupSetupCoordinatorBridgePresenterDelegate, KeyBackupRecoverCoordinatorBridgePresenterDelegate>
#endif
{
RoomsDataSource *roomsDataSource;

// The animated view displayed at the table view bottom when paginating the room directory
UIView* footerSpinnerView;
}

#ifdef SUPPORT_KEYS_BACKUP
@property (nonatomic, strong) KeyBackupSetupCoordinatorBridgePresenter *keyBackupSetupCoordinatorBridgePresenter;
@property (nonatomic, strong) KeyBackupRecoverCoordinatorBridgePresenter *keyBackupRecoverCoordinatorBridgePresenter;
#endif

@end

Expand Down Expand Up @@ -90,6 +95,8 @@ - (void)destroy
[super destroy];
}

#ifdef SUPPORT_KEYS_BACKUP

#pragma mark - Key backup

- (void)presentKeyBackupSetup
Expand All @@ -116,6 +123,8 @@ - (void)presentKeyBackupRecover
}
}

#endif

#pragma mark - Override RecentsViewController

- (void)displayList:(MXKRecentsDataSource *)listDataSource
Expand Down Expand Up @@ -193,6 +202,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
#ifdef SUPPORT_KEYS_BACKUP
if (indexPath.section == roomsDataSource.keyBackupBannerSection)
{
switch (roomsDataSource.keyBackupBanner) {
Expand All @@ -207,6 +217,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
}
else
#endif
{
UITableViewCell* cell = [self.recentsTableView cellForRowAtIndexPath:indexPath];

Expand All @@ -224,6 +235,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
}

#ifdef SUPPORT_KEYS_BACKUP

#pragma mark - KeyBackupSetupCoordinatorBridgePresenterDelegate

- (void)keyBackupSetupCoordinatorBridgePresenterDelegateDidCancel:(KeyBackupSetupCoordinatorBridgePresenter * _Nonnull)keyBackupSetupCoordinatorBridgePresenter
Expand All @@ -248,4 +261,6 @@ - (void)keyBackupRecoverCoordinatorBridgePresenterDidRecover:(KeyBackupRecoverCo
self.keyBackupRecoverCoordinatorBridgePresenter = nil;
}

#endif

@end
91 changes: 91 additions & 0 deletions Tchap/Modules/Settings/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
SETTINGS_SECTION_PREFERENCES_INDEX,
SETTINGS_SECTION_OTHER_INDEX,
SETTINGS_SECTION_CRYPTOGRAPHY_INDEX,
#ifdef SUPPORT_KEYS_BACKUP
SETTINGS_SECTION_KEYBACKUP_INDEX,
#endif
SETTINGS_SECTION_DEVICES_INDEX,
SETTINGS_SECTION_DEACTIVATE_ACCOUNT_INDEX,
SETTINGS_SECTION_COUNT
Expand Down Expand Up @@ -118,11 +120,13 @@

@interface SettingsViewController () <UITextFieldDelegate,
DeactivateAccountViewControllerDelegate,
#ifdef SUPPORT_KEYS_BACKUP
SettingsKeyBackupTableViewSectionDelegate,
KeyBackupSetupCoordinatorBridgePresenterDelegate,
KeyBackupRecoverCoordinatorBridgePresenterDelegate,
SignOutAlertPresenterDelegate,
ChangePasswordAlertPresenterDelegate,
#endif
SingleImagePickerPresenterDelegate,
MXKDeviceViewDelegate,
UIDocumentInteractionControllerDelegate,
Expand Down Expand Up @@ -158,6 +162,9 @@ @interface SettingsViewController () <UITextFieldDelegate,
// Devices
NSMutableArray<MXDevice *> *devicesArray;
DeviceView *deviceView;
#ifndef SUPPORT_KEYS_BACKUP
UIAlertController *resetPwdAlertController;
#endif

// The view used to export e2e keys
MXKEncryptionKeysExportView *exportView;
Expand All @@ -167,19 +174,25 @@ @interface SettingsViewController () <UITextFieldDelegate,
NSURL *keyExportsFile;
NSTimer *keyExportsFileDeletionTimer;

#ifdef SUPPORT_KEYS_BACKUP
SettingsKeyBackupTableViewSection *keyBackupSection;
KeyBackupSetupCoordinatorBridgePresenter *keyBackupSetupCoordinatorBridgePresenter;
KeyBackupRecoverCoordinatorBridgePresenter *keyBackupRecoverCoordinatorBridgePresenter;
#endif
}

#ifdef SUPPORT_KEYS_BACKUP
@property (nonatomic, strong) SignOutAlertPresenter *signOutAlertPresenter;
@property (nonatomic, weak) UIButton *signOutButton;
#endif
@property (nonatomic, strong) SingleImagePickerPresenter *imagePickerPresenter;

@property (weak, nonatomic) DeactivateAccountViewController *deactivateAccountViewController;
@property (strong, nonatomic) id<Style> currentStyle;

#ifdef SUPPORT_KEYS_BACKUP
@property (nonatomic, strong) ChangePasswordAlertPresenter *changePasswordAlertPresenter;
#endif
@property (strong, nonatomic) ChangePasswordCoordinatorBridgePresenter *changePasswordPresenter;

// Observer
Expand Down Expand Up @@ -237,6 +250,7 @@ - (void)viewDidLoad
[self addMatrixSession:mxSession];
}

#ifdef SUPPORT_KEYS_BACKUP
if (self.mainSession.crypto.backup)
{
MXDeviceInfo *deviceInfo = [self.mainSession.crypto.deviceList storedDevice:self.mainSession.matrixRestClient.credentials.userId
Expand All @@ -248,6 +262,7 @@ - (void)viewDidLoad
keyBackupSection.delegate = self;
}
}
#endif

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(onSave:)];
self.navigationItem.rightBarButtonItem.accessibilityIdentifier=@"SettingsVCNavBarSaveButton";
Expand Down Expand Up @@ -295,11 +310,13 @@ - (void)viewDidLoad

}];

#ifdef SUPPORT_KEYS_BACKUP
self.signOutAlertPresenter = [SignOutAlertPresenter new];
self.signOutAlertPresenter.delegate = self;

self.changePasswordAlertPresenter = [ChangePasswordAlertPresenter new];
self.changePasswordAlertPresenter.delegate = self;
#endif
}

- (void)userInterfaceThemeDidChange
Expand Down Expand Up @@ -382,8 +399,10 @@ - (void)dealloc
deviceView = nil;
}

#ifdef SUPPORT_KEYS_BACKUP
keyBackupSetupCoordinatorBridgePresenter = nil;
keyBackupRecoverCoordinatorBridgePresenter = nil;
#endif
}

- (void)onMatrixSessionStateDidChange:(NSNotification *)notif
Expand Down Expand Up @@ -446,6 +465,14 @@ - (void)viewWillDisappear:(BOOL)animated
currentAlert = nil;
}

#ifndef SUPPORT_KEYS_BACKUP
if (resetPwdAlertController)
{
[resetPwdAlertController dismissViewControllerAnimated:NO completion:nil];
resetPwdAlertController = nil;
}
#endif

if (_sessionAccountDataDidChangeNotificationObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:_sessionAccountDataDidChangeNotificationObserver];
Expand Down Expand Up @@ -765,6 +792,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
count = CRYPTOGRAPHY_COUNT;
}
}
#ifdef SUPPORT_KEYS_BACKUP
else if (section == SETTINGS_SECTION_KEYBACKUP_INDEX)
{
// Check whether this section is visible.
Expand All @@ -773,6 +801,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
count = keyBackupSection.numberOfRows;
}
}
#endif
else if (section == SETTINGS_SECTION_DEACTIVATE_ACCOUNT_INDEX)
{
count = 1;
Expand Down Expand Up @@ -1394,10 +1423,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = exportKeysBtnCell;
}
}
#ifdef SUPPORT_KEYS_BACKUP
else if (section == SETTINGS_SECTION_KEYBACKUP_INDEX)
{
cell = [keyBackupSection cellForRowAtRow:row];
}
#endif
else if (section == SETTINGS_SECTION_DEACTIVATE_ACCOUNT_INDEX)
{
MXKTableViewCellWithButton *deactivateAccountBtnCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithButton defaultReuseIdentifier]];
Expand Down Expand Up @@ -1483,6 +1514,7 @@ - (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSectio
return NSLocalizedStringFromTable(@"settings_cryptography", @"Vector", nil);
}
}
#ifdef SUPPORT_KEYS_BACKUP
else if (section == SETTINGS_SECTION_KEYBACKUP_INDEX)
{
// Check whether this section is visible
Expand All @@ -1491,6 +1523,7 @@ - (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSectio
return NSLocalizedStringFromTable(@"settings_key_backup", @"Vector", nil);
}
}
#endif
else if (section == SETTINGS_SECTION_DEACTIVATE_ACCOUNT_INDEX)
{
return NSLocalizedStringFromTable(@"settings_deactivate_my_account", @"Vector", nil);
Expand Down Expand Up @@ -1726,6 +1759,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath

- (void)onSignout:(id)sender
{
#ifdef SUPPORT_KEYS_BACKUP
self.signOutButton = (UIButton*)sender;

MXKeyBackup *keyBackup = self.mainSession.crypto.backup;
Expand All @@ -1735,6 +1769,26 @@ - (void)onSignout:(id)sender
from:self
sourceView:self.signOutButton
animated:YES];
#else
// Feedback: disable button and run activity indicator
UIButton *button = (UIButton*)sender;
button.enabled = NO;
[self startActivityIndicator];

__weak typeof(self) weakSelf = self;

[[AppDelegate theDelegate] logoutWithConfirmation:YES completion:^(BOOL isLoggedOut) {

if (!isLoggedOut && weakSelf)
{
typeof(self) self = weakSelf;

// Enable the button and stop activity indicator
button.enabled = YES;
[self stopActivityIndicator];
}
}];
#endif
}

- (void)togglePushNotifications:(id)sender
Expand Down Expand Up @@ -2268,13 +2322,47 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField

- (void)promptUserBeforePasswordChange
{
#ifdef SUPPORT_KEYS_BACKUP
MXKeyBackup *keyBackup = self.mainSession.crypto.backup;

[self.changePasswordAlertPresenter presentFor:keyBackup.state
areThereKeysToBackup:keyBackup.hasKeysToBackup
from:self
sourceView:self.tableView
animated:YES];
#else
MXWeakify(self);
[resetPwdAlertController dismissViewControllerAnimated:NO completion:nil];

resetPwdAlertController = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"warning", @"Vector", nil) message:NSLocalizedStringFromTable(@"settings_change_pwd_caution", @"Tchap", nil) preferredStyle:UIAlertControllerStyleAlert];
resetPwdAlertController.accessibilityLabel=@"promptUserBeforePasswordChange";
UIAlertAction *continueAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"continue", @"Vector", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {

MXStrongifyAndReturnIfNil(self);
self->resetPwdAlertController = nil;
[self presentChangePassword];
}];

UIAlertAction *exportAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"settings_crypto_export", @"Vector", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {

MXStrongifyAndReturnIfNil(self);
self->resetPwdAlertController = nil;
[self exportEncryptionKeys:nil];

}];

UIAlertAction* cancel = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {

MXStrongifyAndReturnIfNil(self);
self->resetPwdAlertController = nil;

}];

[resetPwdAlertController addAction:continueAction];
[resetPwdAlertController addAction:exportAction];
[resetPwdAlertController addAction:cancel];
[self presentViewController:resetPwdAlertController animated:YES completion:nil];
#endif
}

- (void)presentChangePassword
Expand Down Expand Up @@ -2457,6 +2545,8 @@ - (void)changePasswordCoordinatorBridgePresenterDelegateDidCancel:(ChangePasswor
}];
}

#ifdef SUPPORT_KEYS_BACKUP

#pragma mark - SettingsKeyBackupTableViewSectionDelegate

- (void)settingsKeyBackupTableViewSectionDidUpdate:(SettingsKeyBackupTableViewSection *)settingsKeyBackupTableViewSection
Expand Down Expand Up @@ -2631,5 +2721,6 @@ - (void)changePasswordAlertPresenterDidTapChangePasswordAction:(ChangePasswordAl
[self presentChangePassword];
}

#endif

@end

0 comments on commit 39c5847

Please sign in to comment.