From 4253e06b20107f6670691da13049085a1543f0d8 Mon Sep 17 00:00:00 2001 From: giomfo Date: Wed, 16 Nov 2016 16:45:31 +0100 Subject: [PATCH] End-to-end encryption UI/UX #723 - prompt user before verifying a device --- Vector/Assets/en.lproj/Vector.strings | 3 ++ .../EncryptionInfoView/EncryptionInfoView.h | 3 +- .../EncryptionInfoView/EncryptionInfoView.m | 45 ++++++++++++++++--- .../EncryptionInfoView/EncryptionInfoView.xib | 14 +++++- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/Vector/Assets/en.lproj/Vector.strings b/Vector/Assets/en.lproj/Vector.strings index a7c8870598..23793d9d17 100644 --- a/Vector/Assets/en.lproj/Vector.strings +++ b/Vector/Assets/en.lproj/Vector.strings @@ -214,6 +214,9 @@ "room_event_encryption_info_unverify" = "Unverify"; "room_event_encryption_info_block" = "Block"; "room_event_encryption_info_unblock" = "Unblock"; +"room_event_encryption_verify_title" = "Verify device\n\n"; +"room_event_encryption_verify_message" = "To verify that this device can be trusted, please contact its owner using\nsome other means (e.g. in person or a phone call) and ask them\nwhether the key they see in their User Settings for this device matches\nthe key below:\n\n\tDevice name: %@\n\tDevice ID: %@\n\tDevice key: %@\n\nIf it matches, press the verify button below. If it doesnt, then someone\nelse is intercepting this device and you probably want to press the block\nbutton instead.\n\nIn future this verification process will be more sophisticated."; +"room_event_encryption_verify_ok" = "Verify"; // Room Title "room_title_new_room" = "New room"; diff --git a/Vector/Views/EncryptionInfoView/EncryptionInfoView.h b/Vector/Views/EncryptionInfoView/EncryptionInfoView.h index 01bd3af246..c1f47650e8 100644 --- a/Vector/Views/EncryptionInfoView/EncryptionInfoView.h +++ b/Vector/Views/EncryptionInfoView/EncryptionInfoView.h @@ -19,9 +19,10 @@ @interface EncryptionInfoView : UIView @property (weak, nonatomic) IBOutlet UITextView *textView; -@property (weak, nonatomic) IBOutlet UIButton *okButton; +@property (weak, nonatomic) IBOutlet UIButton *cancelButton; @property (weak, nonatomic) IBOutlet UIButton *verifyButton; @property (weak, nonatomic) IBOutlet UIButton *blockButton; +@property (weak, nonatomic) IBOutlet UIButton *confirmVerifyButton; - (instancetype)initWithEvent:(MXEvent*)event andMatrixSession:(MXSession*)session; diff --git a/Vector/Views/EncryptionInfoView/EncryptionInfoView.m b/Vector/Views/EncryptionInfoView/EncryptionInfoView.m index 1611645f34..7cc7ebf35b 100644 --- a/Vector/Views/EncryptionInfoView/EncryptionInfoView.m +++ b/Vector/Views/EncryptionInfoView/EncryptionInfoView.m @@ -47,8 +47,11 @@ - (void)awakeFromNib [super awakeFromNib]; // Localize string - [_okButton setTitle:[NSBundle mxk_localizedStringForKey:@"ok"] forState:UIControlStateNormal]; - [_okButton setTitle:[NSBundle mxk_localizedStringForKey:@"ok"] forState:UIControlStateHighlighted]; + [_cancelButton setTitle:[NSBundle mxk_localizedStringForKey:@"ok"] forState:UIControlStateNormal]; + [_cancelButton setTitle:[NSBundle mxk_localizedStringForKey:@"ok"] forState:UIControlStateHighlighted]; + + [_confirmVerifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_verify_ok", @"Vector", nil) forState:UIControlStateNormal]; + [_confirmVerifyButton setTitle:NSLocalizedStringFromTable(@"room_event_encryption_verify_ok", @"Vector", nil) forState:UIControlStateHighlighted]; } - (instancetype)initWithEvent:(MXEvent*)event andMatrixSession:(MXSession*)session @@ -324,11 +327,16 @@ + (NSAttributedString *)verticalWhitespace - (IBAction)onButtonPressed:(id)sender { - if (sender == _okButton) + if (sender == _cancelButton) + { + [self removeFromSuperview]; + } + else if (sender == _confirmVerifyButton && deviceInfo) { + [mxSession.crypto setDeviceVerification:MXDeviceVerified forDevice:deviceInfo.deviceId ofUser:deviceInfo.userId]; [self removeFromSuperview]; } - else + else if (deviceInfo) { MXDeviceVerification verificationStatus; @@ -347,8 +355,33 @@ - (IBAction)onButtonPressed:(id)sender return; } - [mxSession.crypto setDeviceVerification:verificationStatus forDevice:deviceInfo.deviceId ofUser:deviceInfo.userId]; - [self removeFromSuperview]; + if (verificationStatus == MXDeviceVerified) + { + // Prompt user + NSMutableAttributedString *textViewAttributedString = [[NSMutableAttributedString alloc] + initWithString:NSLocalizedStringFromTable(@"room_event_encryption_verify_title", @"Vector", nil) + attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack, + NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}]; + + NSString *message = [NSString stringWithFormat:NSLocalizedStringFromTable(@"room_event_encryption_verify_message", @"Vector", nil), deviceInfo.displayName, deviceInfo.deviceId, deviceInfo.fingerprint]; + + [textViewAttributedString appendAttributedString:[[NSMutableAttributedString alloc] + initWithString:message + attributes:@{NSForegroundColorAttributeName : kVectorTextColorBlack, + NSFontAttributeName: [UIFont systemFontOfSize:14]}]]; + + self.textView.attributedText = textViewAttributedString; + + [_cancelButton setTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] forState:UIControlStateNormal]; + [_cancelButton setTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] forState:UIControlStateHighlighted]; + _verifyButton.hidden = _blockButton.hidden = YES; + _confirmVerifyButton.hidden = NO; + } + else + { + [mxSession.crypto setDeviceVerification:verificationStatus forDevice:deviceInfo.deviceId ofUser:deviceInfo.userId]; + [self removeFromSuperview]; + } } } diff --git a/Vector/Views/EncryptionInfoView/EncryptionInfoView.xib b/Vector/Views/EncryptionInfoView/EncryptionInfoView.xib index a6ef272524..3dd31bdbab 100644 --- a/Vector/Views/EncryptionInfoView/EncryptionInfoView.xib +++ b/Vector/Views/EncryptionInfoView/EncryptionInfoView.xib @@ -58,6 +58,15 @@ + @@ -67,9 +76,11 @@ + + @@ -78,7 +89,8 @@ - + +