From 927a909f21ce016c2b1992f164fe538e2400f147 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Wed, 22 Jan 2020 16:21:47 +0100 Subject: [PATCH 1/8] RoomDataSource: Handle room members trust level for an encrypted room. --- .../Modules/Room/DataSources/RoomDataSource.h | 23 ++++ .../Modules/Room/DataSources/RoomDataSource.m | 104 ++++++++++++++++++ 2 files changed, 127 insertions(+) diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.h b/Riot/Modules/Room/DataSources/RoomDataSource.h index fd01e5ad69..ab09e2d2f5 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.h +++ b/Riot/Modules/Room/DataSources/RoomDataSource.h @@ -19,6 +19,18 @@ #import "WidgetManager.h" +/** + RoomEncryptionTrustLevel represents the room members trust level in an encrypted room. + */ +typedef NS_ENUM(NSUInteger, RoomEncryptionTrustLevel) { + RoomEncryptionTrustLevelTrusted, + RoomEncryptionTrustLevelWarning, + RoomEncryptionTrustLevelNormal, + RoomEncryptionTrustLevelUnknown +}; + +@protocol RoomDataSourceDelegate; + /** The data source for `RoomViewController` in Vector. */ @@ -39,6 +51,11 @@ */ @property(nonatomic) BOOL showBubbleDateTimeOnSelection; +/** + Current room members trust level for an encrypted room. + */ +@property(nonatomic, readonly) RoomEncryptionTrustLevel encryptionTrustLevel; + /** Check if there is an active jitsi widget in the room and return it. @@ -85,3 +102,9 @@ failure:(void(^)(NSError*))failure; @end + +@protocol RoomDataSourceDelegate + +- (void)roomDataSource:(RoomDataSource*)roomDataSource didUpdateEncryptionTrustLevel:(RoomEncryptionTrustLevel)roomEncryptionTrustLevel; + +@end diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index 280eef50d3..0b1ffbed99 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -44,6 +44,10 @@ @interface RoomDataSource() // Timer used to debounce cells refresh @property (nonatomic, strong) NSTimer *refreshCellsTimer; +@property (nonatomic, readonly) id roomDataSourceDelegate; + +@property(nonatomic, readwrite) RoomEncryptionTrustLevel encryptionTrustLevel; + @end @implementation RoomDataSource @@ -83,6 +87,9 @@ - (instancetype)initWithRoomId:(NSString *)roomId andMatrixSession:(MXSession *) [self registerKeyVerificationRequestNotification]; [self registerDeviceVerificationTransactionNotification]; + [self registerTrustLevelDidChangeNotifications]; + + self.encryptionTrustLevel = RoomEncryptionTrustLevelUnknown; } return self; } @@ -105,6 +112,21 @@ - (void)finalizeInitialization NSLog(@"[MXKRoomDataSource] finalizeRoomDataSource: Cannot retrieve all room members"); }]; } + + if (self.room.summary.isEncrypted) + { + [self fetchEncryptionTrustedLevel]; + } +} + +- (id)roomDataSourceDelegate +{ + if (!self.delegate || ![self.delegate conformsToProtocol:@protocol(RoomDataSourceDelegate)]) + { + return nil; + } + + return ((id)(self.delegate)); } - (void)updateEventFormatter @@ -167,6 +189,88 @@ - (void)setNeedsUpdateAdditionalContentHeightForCellData:(id= 1.0) + { + roomEncryptionTrustLevel = RoomEncryptionTrustLevelTrusted; + } + else if (trustedMembersPercentage == 0.0) + { + roomEncryptionTrustLevel = RoomEncryptionTrustLevelNormal; + } + else + { + roomEncryptionTrustLevel = RoomEncryptionTrustLevelWarning; + } + + self.encryptionTrustLevel = roomEncryptionTrustLevel; + [self.roomDataSourceDelegate roomDataSource:self didUpdateEncryptionTrustLevel:roomEncryptionTrustLevel]; + + } failure:^(NSError *error) { + NSLog(@"[RoomDataSource] trustLevelDidChangeRelatedToUserId fails to retrieve room members trusted progress"); + }]; + } + + } failure:^(NSError *error) { + NSLog(@"[RoomDataSource] trustLevelDidChangeRelatedToUserId fails to retrieve room members"); + }]; +} + #pragma mark - - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section From 39e841963eaa8385cc33889f2fb8cf70586b8335 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Wed, 22 Jan 2020 16:23:39 +0100 Subject: [PATCH 2/8] ExpandedRoomTitleView: Add badge image view on room avatar. --- .../Title/Expanded/ExpandedRoomTitleView.h | 1 + .../Title/Expanded/ExpandedRoomTitleView.xib | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Riot/Modules/Room/Views/Title/Expanded/ExpandedRoomTitleView.h b/Riot/Modules/Room/Views/Title/Expanded/ExpandedRoomTitleView.h index ff6a1b40d2..e22e0422cd 100644 --- a/Riot/Modules/Room/Views/Title/Expanded/ExpandedRoomTitleView.h +++ b/Riot/Modules/Room/Views/Title/Expanded/ExpandedRoomTitleView.h @@ -19,6 +19,7 @@ @interface ExpandedRoomTitleView : RoomTitleView @property (weak, nonatomic) IBOutlet MXKImageView *roomAvatar; +@property (weak, nonatomic) IBOutlet UIImageView *roomAvatarBadgeImageView; @property (weak, nonatomic) IBOutlet UIView *roomAvatarHeaderBackground; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *roomAvatarHeaderBackgroundHeightConstraint; diff --git a/Riot/Modules/Room/Views/Title/Expanded/ExpandedRoomTitleView.xib b/Riot/Modules/Room/Views/Title/Expanded/ExpandedRoomTitleView.xib index 353189cdd7..537c5168f9 100644 --- a/Riot/Modules/Room/Views/Title/Expanded/ExpandedRoomTitleView.xib +++ b/Riot/Modules/Room/Views/Title/Expanded/ExpandedRoomTitleView.xib @@ -1,11 +1,11 @@ - + - + @@ -27,11 +27,20 @@ + + + + + + + + + @@ -148,6 +157,7 @@ + @@ -155,10 +165,11 @@ + - - + + From 69a04c1af82bf62d838465d39b5b9ed18d669235 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Wed, 22 Jan 2020 16:25:39 +0100 Subject: [PATCH 3/8] Room messages: Handle encryption shields decoration. --- .../Encryption/RoomEncryptedDataBubbleCell.m | 87 +++++++++---------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.m b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.m index 009654230d..bd022f4309 100644 --- a/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.m +++ b/Riot/Modules/Room/Views/BubbleCells/Encryption/RoomEncryptedDataBubbleCell.m @@ -23,60 +23,55 @@ @implementation RoomEncryptedDataBubbleCell + (UIImage*)encryptionIconForEvent:(MXEvent*)event andSession:(MXSession*)session { - NSString *encryptionIcon; + MXRoom *room = [session roomWithRoomId:event.roomId]; + BOOL isRoomEncrypted = room.summary.isEncrypted && session.crypto; + + if (!isRoomEncrypted) + { + return nil; + } + + NSString *encryptionIconName; + UIImage* encryptionIcon; if (!event.isEncrypted) { - encryptionIcon = @"e2e_unencrypted"; - if (event.isLocalEvent - || event.contentHasBeenEdited) // Local echo for an edit is clear but uses a true event id, the one of the edited event + || event.contentHasBeenEdited) // Local echo for an edit is clear but uses a true event id, the one of the edited event { // Patch: Display the verified icon by default on pending outgoing messages in the encrypted rooms when the encryption is enabled - MXRoom *room = [session roomWithRoomId:event.roomId]; - if (room.summary.isEncrypted && session.crypto) - { - // The outgoing message are encrypted by default - encryptionIcon = @"e2e_verified"; - } + // The outgoing message are encrypted by default + encryptionIconName = nil; + } + else + { + encryptionIconName = @"encryption_warning"; } } else if (event.decryptionError) { - encryptionIcon = @"e2e_blocked"; + encryptionIconName = @"encryption_warning"; } else { MXDeviceInfo *deviceInfo = [session.crypto eventDeviceInfo:event]; - if (deviceInfo) + if (deviceInfo.trustLevel.isVerified) { - switch (deviceInfo.trustLevel.localVerificationStatus) - { - case MXDeviceUnknown: - case MXDeviceUnverified: - { - encryptionIcon = @"e2e_warning"; - break; - } - case MXDeviceVerified: - { - encryptionIcon = @"e2e_verified"; - break; - } - default: - break; - } + encryptionIconName = nil; + } + else + { + encryptionIconName = @"encryption_warning"; } } - if (!encryptionIcon) + if (encryptionIconName) { - // Use the warning icon by default - encryptionIcon = @"e2e_warning"; + encryptionIcon = [UIImage imageNamed:encryptionIconName]; } - return [UIImage imageNamed:encryptionIcon]; + return encryptionIcon; } + (void)addEncryptionStatusFromBubbleData:(MXKRoomBubbleCellData *)bubbleData inContainerView:(UIView *)containerView @@ -104,19 +99,23 @@ + (void)addEncryptionStatusFromBubbleData:(MXKRoomBubbleCellData *)bubbleData in } UIImage *icon = [RoomEncryptedDataBubbleCell encryptionIconForEvent:component.event andSession:bubbleData.mxSession]; - UIImageView *encryptStatusImageView = [[UIImageView alloc] initWithImage:icon]; - - CGRect frame = encryptStatusImageView.frame; - frame.origin.y = component.position.y + 3; - encryptStatusImageView.frame = frame; - CGPoint center = encryptStatusImageView.center; - center.x = containerView.frame.size.width / 2; - encryptStatusImageView.center = center; - - encryptStatusImageView.tag = componentIndex; - - [containerView addSubview:encryptStatusImageView]; + if (icon) + { + UIImageView *encryptStatusImageView = [[UIImageView alloc] initWithImage:icon]; + + CGRect frame = encryptStatusImageView.frame; + frame.origin.y = component.position.y + 3; + encryptStatusImageView.frame = frame; + + CGPoint center = encryptStatusImageView.center; + center.x = containerView.frame.size.width / 2; + encryptStatusImageView.center = center; + + encryptStatusImageView.tag = componentIndex; + + [containerView addSubview:encryptStatusImageView]; + } } } From 2ab9a4ae83516b121bf655d3765e172141706d49 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Wed, 22 Jan 2020 16:27:04 +0100 Subject: [PATCH 4/8] RoomVC: Handle encryption shields decoration for composer and expanded header. --- Riot/Modules/Room/RoomViewController.m | 85 +++++++++++++++++-- .../Views/InputToolbar/RoomInputToolbarView.m | 4 - 2 files changed, 77 insertions(+), 12 deletions(-) diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 4053321bef..9f58642a85 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -125,7 +125,8 @@ @interface RoomViewController () + ReactionHistoryCoordinatorBridgePresenterDelegate, CameraPresenterDelegate, MediaPickerCoordinatorBridgePresenterDelegate, + RoomDataSourceDelegate> { // The expanded header ExpandedRoomTitleView *expandedHeader; @@ -1421,6 +1422,11 @@ - (BOOL)isRoomPreview return NO; } +- (BOOL)isEncryptionEnabled +{ + return self.roomDataSource.room.summary.isEncrypted && self.mainSession.crypto != nil; +} + - (void)refreshRoomTitle { if (rightBarButtonItems && !self.navigationItem.rightBarButtonItems) @@ -1541,12 +1547,8 @@ - (void)refreshRoomInputToolbar roomInputToolbarView.supportCallOption &= ([[AppDelegate theDelegate] callStatusBarWindow] == nil); } - // Check whether the encryption is enabled in the room - if (self.roomDataSource.room.summary.isEncrypted) - { - // Encrypt the user's messages as soon as the user supports the encryption? - roomInputToolbarView.isEncryptionEnabled = (self.mainSession.crypto != nil); - } + // Update encryption decoration if needed + [self updateEncryptionDecorationForRoomInputToolbar:roomInputToolbarView]; } else if (self.inputToolbarView && [self.inputToolbarView isKindOfClass:DisabledRoomInputToolbarView.class]) { @@ -1626,6 +1628,61 @@ - (void)updateInputToolBarViewHeight [UIView setAnimationsEnabled:YES]; } +- (UIImage*)roomEncryptionBadgeImage +{ + NSString *encryptionIconName; + UIImage *encryptionIcon; + + if (self.isEncryptionEnabled) + { + RoomEncryptionTrustLevel roomEncryptionTrustLevel = ((RoomDataSource*)self.roomDataSource).encryptionTrustLevel; + + switch (roomEncryptionTrustLevel) { + case RoomEncryptionTrustLevelWarning: + encryptionIconName = @"encryption_warning"; + break; + case RoomEncryptionTrustLevelNormal: + encryptionIconName = @"encryption_normal"; + break; + case RoomEncryptionTrustLevelTrusted: + encryptionIconName = @"encryption_trusted"; + break; + default: + break; + } + } + + if (encryptionIconName) + { + encryptionIcon = [UIImage imageNamed:encryptionIconName]; + } + + return encryptionIcon; +} + +- (void)updateInputToolbarEncryptionDecoration +{ + if (self.inputToolbarView && [self.inputToolbarView isKindOfClass:RoomInputToolbarView.class]) + { + RoomInputToolbarView *roomInputToolbarView = (RoomInputToolbarView*)self.inputToolbarView; + [self updateEncryptionDecorationForRoomInputToolbar:roomInputToolbarView]; + } +} + +- (void)updateExpandedHeaderEncryptionDecoration +{ + if (self->expandedHeader) + { + self->expandedHeader.roomAvatarBadgeImageView.image = self.roomEncryptionBadgeImage; + } +} + +- (void)updateEncryptionDecorationForRoomInputToolbar:(RoomInputToolbarView*)roomInputToolbarView +{ + roomInputToolbarView.isEncryptionEnabled = self.isEncryptionEnabled; + roomInputToolbarView.encryptedRoomIcon.image = self.roomEncryptionBadgeImage; +} + - (void)handleLongPressFromCell:(id)cell withTappedEvent:(MXEvent*)event { if (event && !customizedRoomDataSource.selectedEventId) @@ -1725,9 +1782,12 @@ - (void)showExpandedHeader:(BOOL)isVisible // Note the avatar title view does not define tap gesture. expandedHeader.roomAvatar.alpha = 0.0; + expandedHeader.roomAvatarBadgeImageView.alpha = 0.0; shadowImage = [[UIImage alloc] init]; + [self updateExpandedHeaderEncryptionDecoration]; + // Dismiss the keyboard when header is expanded. [self.inputToolbarView dismissKeyboard]; } @@ -1758,7 +1818,8 @@ - (void)showExpandedHeader:(BOOL)isVisible self.bubblesTableViewTopConstraint.constant = (isVisible ? self.expandedHeaderContainerHeightConstraint.constant - self.bubblesTableView.mxk_adjustedContentInset.top : 0); self.jumpToLastUnreadBannerContainerTopConstraint.constant = (isVisible ? self.expandedHeaderContainerHeightConstraint.constant : self.bubblesTableView.mxk_adjustedContentInset.top); - expandedHeader.roomAvatar.alpha = 1; + self->expandedHeader.roomAvatar.alpha = 1; + self->expandedHeader.roomAvatarBadgeImageView.alpha = 1; // Force to render the view [self forceLayoutRefresh]; @@ -3193,6 +3254,14 @@ - (RoomInputToolbarView*)inputToolbarViewAsRoomInputToolbarView return roomInputToolbarView; } +#pragma mark - RoomDataSourceDelegate + +- (void)roomDataSource:(RoomDataSource *)roomDataSource didUpdateEncryptionTrustLevel:(RoomEncryptionTrustLevel)roomEncryptionTrustLevel +{ + [self updateInputToolbarEncryptionDecoration]; + [self updateExpandedHeaderEncryptionDecoration]; +} + #pragma mark - Segues - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender diff --git a/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m b/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m index 855c21454a..233ccab1dd 100644 --- a/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m +++ b/Riot/Modules/Room/Views/InputToolbar/RoomInputToolbarView.m @@ -128,8 +128,6 @@ - (void)setIsEncryptionEnabled:(BOOL)isEncryptionEnabled if (_isEncryptionEnabled) { - self.encryptedRoomIcon.image = [UIImage imageNamed:@"e2e_verified"]; - // Check the device screen size before using large placeholder if ([GBDeviceInfo deviceInfo].family == GBDeviceFamilyiPad || [GBDeviceInfo deviceInfo].displayInfo.display >= GBDeviceDisplay4p7Inch) { @@ -138,8 +136,6 @@ - (void)setIsEncryptionEnabled:(BOOL)isEncryptionEnabled } else { - self.encryptedRoomIcon.image = [UIImage imageNamed:@"e2e_unencrypted"]; - // Check the device screen size before using large placeholder if ([GBDeviceInfo deviceInfo].family == GBDeviceFamilyiPad || [GBDeviceInfo deviceInfo].displayInfo.display >= GBDeviceDisplay4p7Inch) { From 90da9b38687ea020d669cffb1a8f0340ba72d26d Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Wed, 22 Jan 2020 16:45:33 +0100 Subject: [PATCH 5/8] Update changes. --- CHANGES.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 3349c7ebfa..d65df8187b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,10 @@ +Changes in 0.10.5 (2020-xx-xx) +=============================================== + +Improvements: + * ON/OFF Cross-signing development in a Lab setting (#2855). + * RoomVC: Update encryption decoration with shields (#2934, #2930, #2906). + Changes in 0.10.4 (2019-12-11) =============================================== From d2e93bb9aa1cbef7bd096dc61e47fd4dc8f450dc Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 23 Jan 2020 16:37:23 +0100 Subject: [PATCH 6/8] RoomDataSource: Now compute encryption trust level from trusted devices percentage in room. --- Riot/Modules/Room/DataSources/RoomDataSource.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index 0b1ffbed99..24da3dcebe 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -238,18 +238,18 @@ - (void)encryptionTrustLevelDidChangeRelatedToUserId:(NSString*)userId // If user belongs to the room refresh the trust level if (roomMember) - { - [self.room trustedMembersProgressWithSuccess:^(NSProgress *trustedMembersProgress) { + { + [self.room trustLevelSummaryWithSuccess:^(MXUsersTrustLevelSummary *usersTrustLevelSummary) { RoomEncryptionTrustLevel roomEncryptionTrustLevel; - double trustedMembersPercentage = trustedMembersProgress.fractionCompleted; + double trustedDevicesPercentage = usersTrustLevelSummary.trustedDevicesProgress.fractionCompleted; - if (trustedMembersPercentage >= 1.0) + if (trustedDevicesPercentage >= 1.0) { roomEncryptionTrustLevel = RoomEncryptionTrustLevelTrusted; } - else if (trustedMembersPercentage == 0.0) + else if (trustedDevicesPercentage == 0.0) { roomEncryptionTrustLevel = RoomEncryptionTrustLevelNormal; } From a7df696f5b0ac6ce7d44154e21d855643de43f73 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Thu, 23 Jan 2020 16:39:33 +0100 Subject: [PATCH 7/8] RoomDataSource: Fix refactoring. --- Riot/Modules/Room/DataSources/RoomDataSource.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Riot/Modules/Room/DataSources/RoomDataSource.m b/Riot/Modules/Room/DataSources/RoomDataSource.m index 24da3dcebe..3bd0d0165f 100644 --- a/Riot/Modules/Room/DataSources/RoomDataSource.m +++ b/Riot/Modules/Room/DataSources/RoomDataSource.m @@ -239,7 +239,7 @@ - (void)encryptionTrustLevelDidChangeRelatedToUserId:(NSString*)userId // If user belongs to the room refresh the trust level if (roomMember) { - [self.room trustLevelSummaryWithSuccess:^(MXUsersTrustLevelSummary *usersTrustLevelSummary) { + [self.room membersTrustLevelSummaryWithSuccess:^(MXUsersTrustLevelSummary *usersTrustLevelSummary) { RoomEncryptionTrustLevel roomEncryptionTrustLevel; From 5480e913adbcd0abc5fdb3dc0370b269651e46a7 Mon Sep 17 00:00:00 2001 From: SBiOSoftWhare Date: Fri, 24 Jan 2020 17:13:08 +0100 Subject: [PATCH 8/8] RoomVC: Use encryption normal shield when retrieving room encryption trust level. --- Riot/Modules/Room/RoomViewController.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 9f58642a85..7da406e14a 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -1647,6 +1647,9 @@ - (UIImage*)roomEncryptionBadgeImage case RoomEncryptionTrustLevelTrusted: encryptionIconName = @"encryption_trusted"; break; + case RoomEncryptionTrustLevelUnknown: + encryptionIconName = @"encryption_normal"; + break; default: break; }