Skip to content

Commit

Permalink
Merge pull request #793 from vector-im/vector_723
Browse files Browse the repository at this point in the history
End-to-end encryption UI/UX
  • Loading branch information
giomfo authored Nov 16, 2016
2 parents d1c8bd2 + 4253e06 commit ad8b2a4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Vector/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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";
Expand Down
3 changes: 2 additions & 1 deletion Vector/Views/EncryptionInfoView/EncryptionInfoView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
45 changes: 39 additions & 6 deletions Vector/Views/EncryptionInfoView/EncryptionInfoView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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];
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion Vector/Views/EncryptionInfoView/EncryptionInfoView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@
<action selector="onButtonPressed:" destination="8VI-1E-fge" eventType="touchUpInside" id="j21-e2-e3C"/>
</connections>
</button>
<button hidden="YES" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="L4h-aG-8UN">
<rect key="frame" x="506" y="560" width="40" height="30"/>
<state key="normal" title="Verify">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onButtonPressed:" destination="8VI-1E-fge" eventType="touchUpInside" id="nKr-w7-ECp"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
Expand All @@ -67,9 +76,11 @@
<constraint firstItem="4nG-AI-PEC" firstAttribute="top" secondItem="8VI-1E-fge" secondAttribute="top" constant="10" id="AsZ-Vi-ffo"/>
<constraint firstAttribute="bottom" secondItem="qkC-t0-Qd0" secondAttribute="bottom" constant="10" id="DyR-rX-nt0"/>
<constraint firstAttribute="bottom" secondItem="Ump-1C-SzI" secondAttribute="bottom" constant="10" id="Nfo-nh-gvW"/>
<constraint firstAttribute="bottom" secondItem="L4h-aG-8UN" secondAttribute="bottom" constant="10" id="Owt-zM-W2X"/>
<constraint firstAttribute="centerX" secondItem="Ump-1C-SzI" secondAttribute="centerX" multiplier="4" id="YMC-ob-tqT"/>
<constraint firstAttribute="bottom" secondItem="IdO-jn-iTV" secondAttribute="bottom" constant="10" id="YcV-iN-9WU"/>
<constraint firstAttribute="trailing" secondItem="4nG-AI-PEC" secondAttribute="trailing" constant="10" id="aQF-F6-6lU"/>
<constraint firstAttribute="centerX" secondItem="L4h-aG-8UN" secondAttribute="centerX" multiplier="0.57" id="g1v-Mg-fQ6"/>
<constraint firstAttribute="centerX" secondItem="IdO-jn-iTV" secondAttribute="centerX" multiplier="0.57" id="gAm-ph-zPW"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
Expand All @@ -78,7 +89,8 @@
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<connections>
<outlet property="blockButton" destination="IdO-jn-iTV" id="HI0-ZU-esJ"/>
<outlet property="okButton" destination="Ump-1C-SzI" id="nXR-dU-t3K"/>
<outlet property="cancelButton" destination="Ump-1C-SzI" id="U8M-nT-JiK"/>
<outlet property="confirmVerifyButton" destination="L4h-aG-8UN" id="GX6-dB-JG6"/>
<outlet property="textView" destination="3Vk-Jx-L6Y" id="uOw-Bq-neN"/>
<outlet property="verifyButton" destination="qkC-t0-Qd0" id="6LD-04-WgO"/>
</connections>
Expand Down

0 comments on commit ad8b2a4

Please sign in to comment.