Merge pull request #1065 from vector-im/blacklist-unverified

e2e: Add global and per-room settings to blacklist unverified devices
This commit is contained in:
manuroe 2017-03-03 14:11:05 +01:00 committed by GitHub
commit 757193624e
3 changed files with 204 additions and 74 deletions

View file

@ -309,6 +309,7 @@
"settings_crypto_device_id" = "\nDevice ID: "; "settings_crypto_device_id" = "\nDevice ID: ";
"settings_crypto_device_key" = "\nDevice key: "; "settings_crypto_device_key" = "\nDevice key: ";
"settings_crypto_export" = "Export keys"; "settings_crypto_export" = "Export keys";
"settings_crypto_blacklist_unverified_devices" = "Encrypt to verified devices only";
// Room Details // Room Details
"room_details_title" = "Room Details"; "room_details_title" = "Room Details";
@ -348,6 +349,7 @@
"room_details_advanced_enable_e2e_encryption"="Enable encryption (warning: cannot be disabled again!)"; "room_details_advanced_enable_e2e_encryption"="Enable encryption (warning: cannot be disabled again!)";
"room_details_advanced_e2e_encryption_enabled"="Encryption is enabled in this room"; "room_details_advanced_e2e_encryption_enabled"="Encryption is enabled in this room";
"room_details_advanced_e2e_encryption_disabled"="Encryption is not enabled in this room."; "room_details_advanced_e2e_encryption_disabled"="Encryption is not enabled in this room.";
"room_details_advanced_e2e_encryption_blacklist_unverified_devices"="Encrypt to verified devices only";
"room_details_advanced_e2e_encryption_prompt_title"="Warning!"; "room_details_advanced_e2e_encryption_prompt_title"="Warning!";
"room_details_advanced_e2e_encryption_prompt_message"="End-to-end encryption is experimental and may not be reliable.\n\nYou should not yet trust it to secure data.\n\nDevices will not yet be able to decrypt history from before they joined the room.\n\nOnce encryption is enabled for a room it cannot be turned off again (for now).\n\nEncrypted messages will not be visible on clients that do not yet implement encryption."; "room_details_advanced_e2e_encryption_prompt_message"="End-to-end encryption is experimental and may not be reliable.\n\nYou should not yet trust it to secure data.\n\nDevices will not yet be able to decrypt history from before they joined the room.\n\nOnce encryption is enabled for a room it cannot be turned off again (for now).\n\nEncrypted messages will not be visible on clients that do not yet implement encryption.";
"room_details_fail_to_update_avatar" = "Fail to update the room photo"; "room_details_fail_to_update_avatar" = "Fail to update the room photo";

View file

@ -1,5 +1,6 @@
/* /*
Copyright 2016 OpenMarket Ltd Copyright 2016 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -81,6 +82,7 @@ NSString *const kRoomSettingsNewAliasesKey = @"kRoomSettingsNewAliasesKey";
NSString *const kRoomSettingsRemovedAliasesKey = @"kRoomSettingsRemovedAliasesKey"; NSString *const kRoomSettingsRemovedAliasesKey = @"kRoomSettingsRemovedAliasesKey";
NSString *const kRoomSettingsCanonicalAliasKey = @"kRoomSettingsCanonicalAliasKey"; NSString *const kRoomSettingsCanonicalAliasKey = @"kRoomSettingsCanonicalAliasKey";
NSString *const kRoomSettingsEncryptionKey = @"kRoomSettingsEncryptionKey"; NSString *const kRoomSettingsEncryptionKey = @"kRoomSettingsEncryptionKey";
NSString *const kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey = @"kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey";
NSString *const kRoomSettingsNameCellViewIdentifier = @"kRoomSettingsNameCellViewIdentifier"; NSString *const kRoomSettingsNameCellViewIdentifier = @"kRoomSettingsNameCellViewIdentifier";
NSString *const kRoomSettingsTopicCellViewIdentifier = @"kRoomSettingsTopicCellViewIdentifier"; NSString *const kRoomSettingsTopicCellViewIdentifier = @"kRoomSettingsTopicCellViewIdentifier";
@ -142,6 +144,7 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
// switches // switches
UISwitch *roomNotifSwitch; UISwitch *roomNotifSwitch;
UISwitch *roomEncryptionSwitch; UISwitch *roomEncryptionSwitch;
UISwitch *roomEncryptionBlacklistUnverifiedDevicesSwitch;
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar. // Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
id appDelegateDidTapStatusBarNotificationObserver; id appDelegateDidTapStatusBarNotificationObserver;
@ -1632,6 +1635,13 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
return; return;
} }
// Room settings on blacklist unverified devices
if ([updatedItemsDict objectForKey:kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey])
{
BOOL blacklistUnverifiedDevices = [((NSNumber*)updatedItemsDict[kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey]) boolValue];
[mxRoom.mxSession.crypto setBlacklistUnverifiedDevicesInRoom:mxRoom.roomId blacklist:blacklistUnverifiedDevices];
}
} }
[self getNavigationItem].rightBarButtonItem.enabled = NO; [self getNavigationItem].rightBarButtonItem.enabled = NO;
@ -1749,6 +1759,11 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
if (mxRoom.mxSession.crypto) if (mxRoom.mxSession.crypto)
{ {
count++; count++;
if (mxRoom.state.isEncrypted)
{
count++;
}
} }
} }
@ -2068,6 +2083,10 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
{ {
roomNotifSwitch = nil; roomNotifSwitch = nil;
} }
else if (roomEncryptionBlacklistUnverifiedDevicesSwitch == directoryVisibilitySwitch)
{
roomEncryptionBlacklistUnverifiedDevicesSwitch = nil;
}
[directoryVisibilitySwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged]; [directoryVisibilitySwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
directoryVisibilitySwitch.onTintColor = kVectorColorGreen; directoryVisibilitySwitch.onTintColor = kVectorColorGreen;
@ -2330,9 +2349,68 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
} }
else if (indexPath.row == 1) else if (mxRoom.state.isEncrypted)
{ {
if (mxRoom.state.isEncrypted) if (indexPath.row == 1)
{
MXKTableViewCellWithLabelAndSwitch *roomBlacklistUnverifiedDevicesCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithLabelAndSwitch defaultReuseIdentifier] forIndexPath:indexPath];
roomBlacklistUnverifiedDevicesCell.mxkLabelLeadingConstraint.constant = roomBlacklistUnverifiedDevicesCell.separatorInset.left;
roomBlacklistUnverifiedDevicesCell.mxkSwitchTrailingConstraint.constant = 15;
[roomBlacklistUnverifiedDevicesCell.mxkSwitch addTarget:self action:@selector(onSwitchUpdate:) forControlEvents:UIControlEventValueChanged];
roomBlacklistUnverifiedDevicesCell.mxkSwitch.onTintColor = kVectorColorGreen;
roomBlacklistUnverifiedDevicesCell.mxkLabel.text = NSLocalizedStringFromTable(@"room_details_advanced_e2e_encryption_blacklist_unverified_devices", @"Vector", nil);
roomBlacklistUnverifiedDevicesCell.mxkLabel.textColor = kVectorTextColorBlack;
roomEncryptionBlacklistUnverifiedDevicesSwitch = roomBlacklistUnverifiedDevicesCell.mxkSwitch;
// Workaround to avoid mixing between switches
// TODO: this is a design issue with switch within UITableViewCell that must fix everywhere
if (directoryVisibilitySwitch == roomEncryptionBlacklistUnverifiedDevicesSwitch)
{
directoryVisibilitySwitch = nil;
}
else if (roomNotifSwitch == roomEncryptionBlacklistUnverifiedDevicesSwitch)
{
roomNotifSwitch = nil;
}
else if (roomEncryptionSwitch == roomEncryptionBlacklistUnverifiedDevicesSwitch)
{
roomEncryptionSwitch = nil;
}
// For the switch value, use by order:
// - the MXCrypto.globalBlacklistUnverifiedDevices if its value is YES
// In this case, the switch is disabled.
// - the changed value made by the user
// - the value used by the crypto
BOOL blacklistUnverifiedDevices;
if (mxRoom.mxSession.crypto.globalBlacklistUnverifiedDevices)
{
blacklistUnverifiedDevices = YES;
roomEncryptionBlacklistUnverifiedDevicesSwitch.enabled = NO;
}
else
{
roomEncryptionBlacklistUnverifiedDevicesSwitch.enabled = YES;
if ([updatedItemsDict objectForKey:kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey])
{
blacklistUnverifiedDevices = [((NSNumber*)updatedItemsDict[kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey]) boolValue];
}
else
{
blacklistUnverifiedDevices = [mxRoom.mxSession.crypto isBlacklistUnverifiedDevicesInRoom:mxRoom.roomId];
}
}
roomEncryptionBlacklistUnverifiedDevicesSwitch.on = blacklistUnverifiedDevices;
cell = roomBlacklistUnverifiedDevicesCell;
}
else if (indexPath.row == 2)
{ {
cell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAdvancedE2eEnabledCellViewIdentifier]; cell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsAdvancedE2eEnabledCellViewIdentifier];
if (!cell) if (!cell)
@ -2347,6 +2425,7 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
} }
}
else else
{ {
// Check user's power level to know whether the user is allowed to turn on the encryption mode // Check user's power level to know whether the user is allowed to turn on the encryption mode
@ -2378,6 +2457,10 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
{ {
roomNotifSwitch = nil; roomNotifSwitch = nil;
} }
else if (roomEncryptionBlacklistUnverifiedDevicesSwitch == roomEncryptionSwitch)
{
roomEncryptionBlacklistUnverifiedDevicesSwitch = nil;
}
roomEncryptionSwitch.on = ([updatedItemsDict objectForKey:kRoomSettingsEncryptionKey] != nil); roomEncryptionSwitch.on = ([updatedItemsDict objectForKey:kRoomSettingsEncryptionKey] != nil);
@ -2400,7 +2483,6 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
} }
} }
} }
}
// Sanity check // Sanity check
if (!cell) if (!cell)
@ -3010,6 +3092,17 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
[updatedItemsDict removeObjectForKey:kRoomSettingsEncryptionKey]; [updatedItemsDict removeObjectForKey:kRoomSettingsEncryptionKey];
} }
} }
else if (theSwitch == roomEncryptionBlacklistUnverifiedDevicesSwitch)
{
if ([mxRoom.mxSession.crypto isBlacklistUnverifiedDevicesInRoom:mxRoom.roomId] != roomEncryptionBlacklistUnverifiedDevicesSwitch.on)
{
updatedItemsDict[kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey] = @(roomEncryptionBlacklistUnverifiedDevicesSwitch.on);
}
else
{
[updatedItemsDict removeObjectForKey:kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey];
}
}
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0); [self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
} }

View file

@ -40,7 +40,8 @@
NSString* const kSettingsViewControllerPhoneBookCountryCellId = @"kSettingsViewControllerPhoneBookCountryCellId"; NSString* const kSettingsViewControllerPhoneBookCountryCellId = @"kSettingsViewControllerPhoneBookCountryCellId";
enum { enum
{
SETTINGS_SECTION_SIGN_OUT_INDEX = 0, SETTINGS_SECTION_SIGN_OUT_INDEX = 0,
SETTINGS_SECTION_USER_SETTINGS_INDEX, SETTINGS_SECTION_USER_SETTINGS_INDEX,
SETTINGS_SECTION_NOTIFICATIONS_SETTINGS_INDEX, SETTINGS_SECTION_NOTIFICATIONS_SETTINGS_INDEX,
@ -54,33 +55,45 @@ enum {
SETTINGS_SECTION_COUNT SETTINGS_SECTION_COUNT
}; };
#define NOTIFICATION_SETTINGS_ENABLE_PUSH_INDEX 0 enum
#define NOTIFICATION_SETTINGS_GLOBAL_SETTINGS_INDEX 1 {
//#define NOTIFICATION_SETTINGS_CONTAINING_MY_USER_NAME_INDEX 1 NOTIFICATION_SETTINGS_ENABLE_PUSH_INDEX = 0,
//#define NOTIFICATION_SETTINGS_CONTAINING_MY_DISPLAY_NAME_INDEX 2 NOTIFICATION_SETTINGS_GLOBAL_SETTINGS_INDEX,
//#define NOTIFICATION_SETTINGS_SENT_TO_ME_INDEX 3 //NOTIFICATION_SETTINGS_CONTAINING_MY_USER_NAME_INDEX,
//#define NOTIFICATION_SETTINGS_INVITED_TO_ROOM_INDEX 4 //NOTIFICATION_SETTINGS_CONTAINING_MY_DISPLAY_NAME_INDEX,
//#define NOTIFICATION_SETTINGS_PEOPLE_LEAVE_JOIN_INDEX 5 //NOTIFICATION_SETTINGS_SENT_TO_ME_INDEX,
//#define NOTIFICATION_SETTINGS_CALL_INVITATION_INDEX 6 //NOTIFICATION_SETTINGS_INVITED_TO_ROOM_INDEX,
#define NOTIFICATION_SETTINGS_COUNT 2 //NOTIFICATION_SETTINGS_PEOPLE_LEAVE_JOIN_INDEX,
//NOTIFICATION_SETTINGS_CALL_INVITATION_INDEX,
NOTIFICATION_SETTINGS_COUNT
};
#define OTHER_VERSION_INDEX 0 enum
#define OTHER_OLM_VERSION_INDEX 1 {
#define OTHER_COPYRIGHT_INDEX 2 OTHER_VERSION_INDEX = 0,
#define OTHER_TERM_CONDITIONS_INDEX 3 OTHER_OLM_VERSION_INDEX,
#define OTHER_PRIVACY_INDEX 4 OTHER_COPYRIGHT_INDEX,
#define OTHER_THIRD_PARTY_INDEX 5 OTHER_TERM_CONDITIONS_INDEX,
#define OTHER_CRASH_REPORT_INDEX 6 OTHER_PRIVACY_INDEX,
#define OTHER_MARK_ALL_AS_READ_INDEX 7 OTHER_THIRD_PARTY_INDEX,
#define OTHER_CLEAR_CACHE_INDEX 8 OTHER_CRASH_REPORT_INDEX,
#define OTHER_COUNT 9 OTHER_MARK_ALL_AS_READ_INDEX,
OTHER_CLEAR_CACHE_INDEX,
OTHER_COUNT
};
#define LABS_CRYPTO_INDEX 0 enum
#define LABS_COUNT 1 {
LABS_CRYPTO_INDEX = 0,
LABS_COUNT
};
#define CRYPTOGRAPHY_INFO_INDEX 0 enum {
#define CRYPTOGRAPHY_EXPORT_INDEX 1 CRYPTOGRAPHY_INFO_INDEX = 0,
#define CRYPTOGRAPHY_COUNT 2 CRYPTOGRAPHY_BLACKLIST_UNVERIFIED_DEVICES_INDEX,
CRYPTOGRAPHY_EXPORT_INDEX,
CRYPTOGRAPHY_COUNT
};
#define SECTION_TITLE_PADDING_WHEN_HIDDEN 0.01f #define SECTION_TITLE_PADDING_WHEN_HIDDEN 0.01f
@ -1704,6 +1717,18 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
cell = cryptoCell; cell = cryptoCell;
} }
else if (row == CRYPTOGRAPHY_BLACKLIST_UNVERIFIED_DEVICES_INDEX)
{
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_crypto_blacklist_unverified_devices", @"Vector", nil);
labelAndSwitchCell.mxkSwitch.on = account.mxSession.crypto.globalBlacklistUnverifiedDevices;
labelAndSwitchCell.mxkSwitch.enabled = YES;
[labelAndSwitchCell.mxkSwitch removeTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleBlacklistUnverifiedDevices:) forControlEvents:UIControlEventTouchUpInside];
cell = labelAndSwitchCell;
}
else if (row == CRYPTOGRAPHY_EXPORT_INDEX) else if (row == CRYPTOGRAPHY_EXPORT_INDEX)
{ {
MXKTableViewCellWithButton *exportKeysBtnCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithButton defaultReuseIdentifier]]; MXKTableViewCellWithButton *exportKeysBtnCell = [tableView dequeueReusableCellWithIdentifier:[MXKTableViewCellWithButton defaultReuseIdentifier]];
@ -2396,6 +2421,16 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
} }
} }
- (void)toggleBlacklistUnverifiedDevices:(id)sender
{
UISwitch *switchButton = (UISwitch*)sender;
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;
account.mxSession.crypto.globalBlacklistUnverifiedDevices = switchButton.on;
[self.tableView reloadData];
}
- (void)markAllAsRead:(id)sender - (void)markAllAsRead:(id)sender
{ {
// Feedback: disable button and run activity indicator // Feedback: disable button and run activity indicator