diff --git a/CHANGES.md b/CHANGES.md index 5f5163ec73..d646ee3ca5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +## Changes in 1.10.7 (2023-03-22) + +🙌 Improvements + +- Upgrade MatrixSDK version ([v0.26.4](https://github.com/matrix-org/matrix-ios-sdk/releases/tag/v0.26.4)). + + ## Changes in 1.10.6 (2023-03-21) 🙌 Improvements diff --git a/Config/AppVersion.xcconfig b/Config/AppVersion.xcconfig index 2e4d151a14..698eeaa2b4 100644 --- a/Config/AppVersion.xcconfig +++ b/Config/AppVersion.xcconfig @@ -15,5 +15,5 @@ // // Version -MARKETING_VERSION = 1.10.6 -CURRENT_PROJECT_VERSION = 1.10.6 +MARKETING_VERSION = 1.10.7 +CURRENT_PROJECT_VERSION = 1.10.7 diff --git a/Podfile b/Podfile index 25068ce1e9..d7a2bb7acd 100644 --- a/Podfile +++ b/Podfile @@ -16,7 +16,7 @@ use_frameworks! # - `{ :specHash => {sdk spec hash}` to depend on specific pod options (:git => …, :podspec => …) for MatrixSDK repo. Used by Fastfile during CI # # Warning: our internal tooling depends on the name of this variable name, so be sure not to change it -$matrixSDKVersion = '= 0.26.2' +$matrixSDKVersion = '= 0.26.4' # $matrixSDKVersion = :local # $matrixSDKVersion = { :branch => 'develop'} # $matrixSDKVersion = { :specHash => { git: 'https://git.io/fork123', branch: 'fix' } } diff --git a/Podfile.lock b/Podfile.lock index 593a763d0a..01ef218c44 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -37,9 +37,9 @@ PODS: - LoggerAPI (1.9.200): - Logging (~> 1.1) - Logging (1.4.0) - - MatrixSDK (0.26.2): - - MatrixSDK/Core (= 0.26.2) - - MatrixSDK/Core (0.26.2): + - MatrixSDK (0.26.4): + - MatrixSDK/Core (= 0.26.4) + - MatrixSDK/Core (0.26.4): - AFNetworking (~> 4.0.0) - GZIP (~> 1.3.0) - libbase58 (~> 0.1.4) @@ -47,7 +47,7 @@ PODS: - OLMKit (~> 3.2.5) - Realm (= 10.27.0) - SwiftyBeaver (= 1.9.5) - - MatrixSDK/JingleCallStack (0.26.2): + - MatrixSDK/JingleCallStack (0.26.4): - JitsiMeetSDK (= 5.0.2) - MatrixSDK/Core - MatrixSDKCrypto (0.3.0) @@ -100,8 +100,8 @@ DEPENDENCIES: - KeychainAccess (~> 4.2.2) - KTCenterFlowLayout (~> 1.3.1) - libPhoneNumber-iOS (~> 0.9.13) - - MatrixSDK (= 0.26.2) - - MatrixSDK/JingleCallStack (= 0.26.2) + - MatrixSDK (= 0.26.4) + - MatrixSDK/JingleCallStack (= 0.26.4) - OLMKit - PostHog (~> 2.0.0) - ReadMoreTextView (~> 3.0.1) @@ -183,7 +183,7 @@ SPEC CHECKSUMS: libPhoneNumber-iOS: 0a32a9525cf8744fe02c5206eb30d571e38f7d75 LoggerAPI: ad9c4a6f1e32f518fdb43a1347ac14d765ab5e3d Logging: beeb016c9c80cf77042d62e83495816847ef108b - MatrixSDK: 010cdccea670b6b2e1a665976bd1a1e6ea5330ca + MatrixSDK: f336fa2ba23d5db48873fa78d3e9565f768a2cda MatrixSDKCrypto: 05ebe373ccebf40f8a0cff37d8f8b24fd01b9883 OLMKit: da115f16582e47626616874e20f7bb92222c7a51 PostHog: 660ec6c9d80cec17b685e148f17f6785a88b597d @@ -204,6 +204,6 @@ SPEC CHECKSUMS: zxcvbn-ios: fef98b7c80f1512ff0eec47ac1fa399fc00f7e3c ZXingObjC: fdbb269f25dd2032da343e06f10224d62f537bdb -PODFILE CHECKSUM: 90e256afba3906cdb4c1a3c1eb764abff6843a76 +PODFILE CHECKSUM: 741947b0cd7b44554c29e7ca268403622ba770b4 COCOAPODS: 1.11.3 diff --git a/Riot/Categories/MXRoom+Riot.m b/Riot/Categories/MXRoom+Riot.m index 1a9afe710f..04538ba804 100644 --- a/Riot/Categories/MXRoom+Riot.m +++ b/Riot/Categories/MXRoom+Riot.m @@ -20,7 +20,7 @@ #import "AvatarGenerator.h" #import "MatrixKit.h" -#import "GeneratedInterface-Swift.h" + #import @implementation MXRoom (Riot) @@ -331,10 +331,30 @@ - (void)encryptionTrustLevelForUserId:(NSString*)userId onComplete:(void (^)(Use { [self.mxSession.crypto trustLevelSummaryForUserIds:@[userId] forceDownload:NO success:^(MXUsersTrustLevelSummary *usersTrustLevelSummary) { - MXCrossSigningInfo *crossSigningInfo = [self.mxSession.crypto.crossSigning crossSigningKeysForUser:userId]; - EncryptionTrustLevel *encryption = [[EncryptionTrustLevel alloc] init]; - UserEncryptionTrustLevel userEncryptionTrustLevel = [encryption userTrustLevelWithCrossSigning:crossSigningInfo - devicesTrust:usersTrustLevelSummary.devicesTrust]; + UserEncryptionTrustLevel userEncryptionTrustLevel; + double trustedDevicesPercentage = usersTrustLevelSummary.trustedDevicesProgress.fractionCompleted; + + if (trustedDevicesPercentage >= 1.0) + { + userEncryptionTrustLevel = UserEncryptionTrustLevelTrusted; + } + else if (trustedDevicesPercentage == 0.0) + { + // Verify if the user has the user has cross-signing enabled + if ([self.mxSession.crypto.crossSigning crossSigningKeysForUser:userId]) + { + userEncryptionTrustLevel = UserEncryptionTrustLevelNotVerified; + } + else + { + userEncryptionTrustLevel = UserEncryptionTrustLevelNoCrossSigning; + } + } + else + { + userEncryptionTrustLevel = UserEncryptionTrustLevelWarning; + } + onComplete(userEncryptionTrustLevel); } failure:^(NSError *error) { diff --git a/Riot/Categories/MXRoomSummary+Riot.h b/Riot/Categories/MXRoomSummary+Riot.h index 324a7f3698..d25cdee5f3 100644 --- a/Riot/Categories/MXRoomSummary+Riot.h +++ b/Riot/Categories/MXRoomSummary+Riot.h @@ -15,7 +15,17 @@ */ #import "MatrixKit.h" -#import "RoomEncryptionTrustLevel.h" + +/** + RoomEncryptionTrustLevel represents the trust level in an encrypted room. + */ +typedef NS_ENUM(NSUInteger, RoomEncryptionTrustLevel) { + RoomEncryptionTrustLevelTrusted, + RoomEncryptionTrustLevelWarning, + RoomEncryptionTrustLevelNormal, + RoomEncryptionTrustLevelUnknown +}; + /** Define a `MXRoomSummary` category at Riot level. diff --git a/Riot/Categories/MXRoomSummary+Riot.m b/Riot/Categories/MXRoomSummary+Riot.m index b2c1eeb407..c6a55a230e 100644 --- a/Riot/Categories/MXRoomSummary+Riot.m +++ b/Riot/Categories/MXRoomSummary+Riot.m @@ -33,15 +33,32 @@ - (void)setRoomAvatarImageIn:(MXKImageView*)mxkImageView - (RoomEncryptionTrustLevel)roomEncryptionTrustLevel { - MXUsersTrustLevelSummary *trust = self.trust; - if (!trust) + RoomEncryptionTrustLevel roomEncryptionTrustLevel = RoomEncryptionTrustLevelUnknown; + if (self.trust) { - MXLogError(@"[MXRoomSummary] roomEncryptionTrustLevel: trust is missing"); - return RoomEncryptionTrustLevelUnknown; + double trustedUsersPercentage = self.trust.trustedUsersProgress.fractionCompleted; + double trustedDevicesPercentage = self.trust.trustedDevicesProgress.fractionCompleted; + + if (trustedUsersPercentage >= 1.0) + { + if (trustedDevicesPercentage >= 1.0) + { + roomEncryptionTrustLevel = RoomEncryptionTrustLevelTrusted; + } + else + { + roomEncryptionTrustLevel = RoomEncryptionTrustLevelWarning; + } + } + else + { + roomEncryptionTrustLevel = RoomEncryptionTrustLevelNormal; + } + + roomEncryptionTrustLevel = roomEncryptionTrustLevel; } - EncryptionTrustLevel *encryption = [[EncryptionTrustLevel alloc] init]; - return [encryption roomTrustLevelWithSummary:trust]; + return roomEncryptionTrustLevel; } - (BOOL)isJoined diff --git a/Riot/Modules/Encryption/EncryptionTrustLevel.swift b/Riot/Modules/Encryption/EncryptionTrustLevel.swift deleted file mode 100644 index 414c242a8f..0000000000 --- a/Riot/Modules/Encryption/EncryptionTrustLevel.swift +++ /dev/null @@ -1,49 +0,0 @@ -// -// Copyright 2023 New Vector Ltd -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import Foundation - -/// Object responsible for calculating user and room trust level -@objc class EncryptionTrustLevel: NSObject { - - /// Calculate trust level for a single user given their cross-signing info - @objc func userTrustLevel( - crossSigning: MXCrossSigningInfo?, - devicesTrust: MXTrustSummary - ) -> UserEncryptionTrustLevel { - - // If we could cross-sign but we haven't, the user is simply not verified - if let crossSigning, !crossSigning.isVerified { - return .notVerified - - // If we cannot cross-sign the user (legacy behaviour) and have not signed - // any devices manually, the user is not verified - } else if crossSigning == nil && devicesTrust.trustedCount == 0 { - return .notVerified - } - - // In all other cases we check devices for trust level - return devicesTrust.areAllTrusted ? .trusted : .warning - } - - /// Calculate trust level for a room given trust level of users and their devices - @objc func roomTrustLevel(summary: MXUsersTrustLevelSummary) -> RoomEncryptionTrustLevel { - guard summary.usersTrust.totalCount > 0 && summary.usersTrust.areAllTrusted else { - return .normal - } - return summary.devicesTrust.areAllTrusted ? .trusted : .warning - } -} diff --git a/Riot/Modules/Encryption/RoomEncryptionTrustLevel.h b/Riot/Modules/Encryption/RoomEncryptionTrustLevel.h deleted file mode 100644 index a942f53606..0000000000 --- a/Riot/Modules/Encryption/RoomEncryptionTrustLevel.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// Copyright 2023 New Vector Ltd -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -/** - RoomEncryptionTrustLevel represents the trust level in an encrypted room. - */ -typedef NS_ENUM(NSUInteger, RoomEncryptionTrustLevel) { - RoomEncryptionTrustLevelTrusted, - RoomEncryptionTrustLevelWarning, - RoomEncryptionTrustLevelNormal, - RoomEncryptionTrustLevelUnknown -}; diff --git a/Riot/Modules/Encryption/EncryptionInfo/EncryptionInfoView.h b/Riot/Modules/EncryptionInfo/EncryptionInfoView.h similarity index 100% rename from Riot/Modules/Encryption/EncryptionInfo/EncryptionInfoView.h rename to Riot/Modules/EncryptionInfo/EncryptionInfoView.h diff --git a/Riot/Modules/Encryption/EncryptionInfo/EncryptionInfoView.m b/Riot/Modules/EncryptionInfo/EncryptionInfoView.m similarity index 100% rename from Riot/Modules/Encryption/EncryptionInfo/EncryptionInfoView.m rename to Riot/Modules/EncryptionInfo/EncryptionInfoView.m diff --git a/Riot/Modules/Encryption/EncryptionInfo/EncryptionInfoView.xib b/Riot/Modules/EncryptionInfo/EncryptionInfoView.xib similarity index 100% rename from Riot/Modules/Encryption/EncryptionInfo/EncryptionInfoView.xib rename to Riot/Modules/EncryptionInfo/EncryptionInfoView.xib diff --git a/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.m b/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.m index 64b3f3c549..5202098609 100644 --- a/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.m +++ b/Riot/Modules/MatrixKit/Models/Room/MXKRoomBubbleComponent.m @@ -206,10 +206,10 @@ - (EventEncryptionDecoration)encryptionDecorationForEvent:(MXEvent*)event roomSt // Only show a warning badge if there are trust issues. if (event.sender) { - BOOL isUserVerified = [session.crypto isUserVerified:event.sender]; + MXUserTrustLevel *userTrustLevel = [session.crypto trustLevelForUser:event.sender]; MXDeviceInfo *deviceInfo = [session.crypto eventDeviceInfo:event]; - if (isUserVerified && !deviceInfo.trustLevel.isVerified) + if (userTrustLevel.isVerified && !deviceInfo.trustLevel.isVerified) { return EventEncryptionDecorationUntrustedDevice; } diff --git a/Riot/Modules/Encryption/UserEncryptionTrustLevel.h b/Riot/Modules/Room/Members/Detail/UserEncryptionTrustLevel.h similarity index 100% rename from Riot/Modules/Encryption/UserEncryptionTrustLevel.h rename to Riot/Modules/Room/Members/Detail/UserEncryptionTrustLevel.h diff --git a/Riot/SupportingFiles/Riot-Bridging-Header.h b/Riot/SupportingFiles/Riot-Bridging-Header.h index 296545a4e9..e86152e1ce 100644 --- a/Riot/SupportingFiles/Riot-Bridging-Header.h +++ b/Riot/SupportingFiles/Riot-Bridging-Header.h @@ -18,7 +18,6 @@ #import "RoomBubbleCellData.h" #import "MXKRoomBubbleTableViewCell+Riot.h" #import "UserEncryptionTrustLevel.h" -#import "RoomEncryptionTrustLevel.h" #import "RoomReactionsViewSizer.h" #import "RoomEncryptedDataBubbleCell.h" #import "LegacyAppDelegate.h" diff --git a/Riot/Modules/Encryption/EncryptionTrustLevelBadgeImageHelper.swift b/Riot/Utils/EncryptionTrustLevelBadgeImageHelper.swift similarity index 100% rename from Riot/Modules/Encryption/EncryptionTrustLevelBadgeImageHelper.swift rename to Riot/Utils/EncryptionTrustLevelBadgeImageHelper.swift diff --git a/RiotShareExtension/SupportingFiles/RiotShareExtension-Bridging-Header.h b/RiotShareExtension/SupportingFiles/RiotShareExtension-Bridging-Header.h index 618849c4d6..9a7cf3af1e 100644 --- a/RiotShareExtension/SupportingFiles/RiotShareExtension-Bridging-Header.h +++ b/RiotShareExtension/SupportingFiles/RiotShareExtension-Bridging-Header.h @@ -6,8 +6,6 @@ #import "AvatarGenerator.h" #import "BuildInfo.h" #import "ShareItemSender.h" -#import "UserEncryptionTrustLevel.h" -#import "RoomEncryptionTrustLevel.h" // MatrixKit imports #import "MatrixKit-Bridging-Header.h" diff --git a/RiotShareExtension/target.yml b/RiotShareExtension/target.yml index b289f234bf..eaf51ce3c8 100644 --- a/RiotShareExtension/target.yml +++ b/RiotShareExtension/target.yml @@ -87,4 +87,3 @@ targets: - "**/*.md" # excludes all files with the .md extension - path: ../Riot/Modules/Room/TimelineCells/Styles/RoomTimelineStyleIdentifier.swift - path: ../Riot/Modules/VoiceBroadcast/VoiceBroadcastSDK/MatrixSDK - - path: ../Riot/Modules/Encryption/EncryptionTrustLevel.swift diff --git a/RiotSwiftUI/Modules/Authentication/QRLogin/Common/Service/MatrixSDK/QRLoginService.swift b/RiotSwiftUI/Modules/Authentication/QRLogin/Common/Service/MatrixSDK/QRLoginService.swift index 4d3b36c98d..05506b4bde 100644 --- a/RiotSwiftUI/Modules/Authentication/QRLogin/Common/Service/MatrixSDK/QRLoginService.swift +++ b/RiotSwiftUI/Modules/Authentication/QRLogin/Common/Service/MatrixSDK/QRLoginService.swift @@ -327,7 +327,7 @@ class QRLoginService: NSObject, QRLoginServiceProtocol { MXLog.debug("[QRLoginService] Marking the received master key as trusted") let mskVerificationResult = await withCheckedContinuation { (continuation: CheckedContinuation) in - session.crypto.setUserVerificationForUserId(session.myUserId) { + session.crypto.setUserVerification(true, forUser: session.myUserId) { MXLog.debug("[QRLoginService] Successfully marked the received master key as trusted") continuation.resume(returning: true) } failure: { error in diff --git a/RiotTests/Modules/Encryption/EncryptionTrustLevelTests.swift b/RiotTests/Modules/Encryption/EncryptionTrustLevelTests.swift deleted file mode 100644 index 9424c1764f..0000000000 --- a/RiotTests/Modules/Encryption/EncryptionTrustLevelTests.swift +++ /dev/null @@ -1,171 +0,0 @@ -// -// Copyright 2023 New Vector Ltd -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -import Foundation -import XCTest -@testable import Element -@testable import MatrixSDK - -class EncryptionTrustLevelTests: XCTestCase { - - var encryption: EncryptionTrustLevel! - override func setUp() { - encryption = EncryptionTrustLevel() - } - - // MARK: - Helpers - - func makeCrossSigning(isVerified: Bool) -> MXCrossSigningInfo { - return .init( - userIdentity: .init( - identity: .other( - userId: "Bob", - masterKey: "MSK", - selfSigningKey: "SSK" - ), - isVerified: isVerified - ) - ) - } - - func makeSummary(trusted: Int, total: Int) -> MXTrustSummary { - MXTrustSummary(trustedCount: trusted, totalCount: total) - } - - // MARK: - Users - - func test_userTrustLevel_whenCrossSigningDisabled() { - let devicesToTrustLevel: [(MXTrustSummary, UserEncryptionTrustLevel)] = [ - (makeSummary(trusted: 0, total: 0), .notVerified), - (makeSummary(trusted: 0, total: 2), .notVerified), - (makeSummary(trusted: 1, total: 2), .warning), - (makeSummary(trusted: 3, total: 4), .warning), - (makeSummary(trusted: 5, total: 5), .trusted) - ] - - for (devices, expected) in devicesToTrustLevel { - let trustLevel = encryption.userTrustLevel( - crossSigning: nil, - devicesTrust: devices - ) - XCTAssertEqual(trustLevel, expected, "\(devices.trustedCount) trusted device(s) out of \(devices.totalCount)") - } - } - - func test_userTrustLevel_whenCrossSigningNotVerified() { - let devicesToTrustLevel: [(MXTrustSummary, UserEncryptionTrustLevel)] = [ - (makeSummary(trusted: 0, total: 0), .notVerified), - (makeSummary(trusted: 0, total: 2), .notVerified), - (makeSummary(trusted: 1, total: 2), .notVerified), - (makeSummary(trusted: 3, total: 4), .notVerified), - (makeSummary(trusted: 5, total: 5), .notVerified) - ] - - for (devices, expected) in devicesToTrustLevel { - let trustLevel = encryption.userTrustLevel( - crossSigning: makeCrossSigning(isVerified: false), - devicesTrust: devices - ) - XCTAssertEqual(trustLevel, expected, "\(devices.trustedCount) trusted device(s) out of \(devices.totalCount)") - } - } - - func test_userTrustLevel_whenCrossSigningVerified() { - let devicesToTrustLevel: [(MXTrustSummary, UserEncryptionTrustLevel)] = [ - (makeSummary(trusted: 0, total: 0), .trusted), - (makeSummary(trusted: 0, total: 2), .warning), - (makeSummary(trusted: 1, total: 2), .warning), - (makeSummary(trusted: 3, total: 4), .warning), - (makeSummary(trusted: 5, total: 5), .trusted) - ] - - for (devices, expected) in devicesToTrustLevel { - let trustLevel = encryption.userTrustLevel( - crossSigning: makeCrossSigning(isVerified: true), - devicesTrust: devices - ) - XCTAssertEqual(trustLevel, expected, "\(devices.trustedCount) trusted device(s) out of \(devices.totalCount)") - } - } - - // MARK: - Rooms - - func test_roomTrustLevel() { - let usersDevicesToTrustLevel: [(MXTrustSummary, MXTrustSummary, RoomEncryptionTrustLevel)] = [ - // No users verified - (makeSummary(trusted: 0, total: 0), makeSummary(trusted: 0, total: 0), .normal), - - // Only some users verified - (makeSummary(trusted: 0, total: 1), makeSummary(trusted: 0, total: 1), .normal), - (makeSummary(trusted: 3, total: 4), makeSummary(trusted: 5, total: 5), .normal), - (makeSummary(trusted: 3, total: 4), makeSummary(trusted: 5, total: 5), .normal), - - // All users verified - (makeSummary(trusted: 2, total: 2), makeSummary(trusted: 0, total: 0), .trusted), - (makeSummary(trusted: 3, total: 3), makeSummary(trusted: 0, total: 1), .warning), - (makeSummary(trusted: 3, total: 3), makeSummary(trusted: 3, total: 4), .warning), - (makeSummary(trusted: 4, total: 4), makeSummary(trusted: 5, total: 5), .trusted), - ] - - for (users, devices, expected) in usersDevicesToTrustLevel { - let trustLevel = encryption.roomTrustLevel( - summary: MXUsersTrustLevelSummary( - usersTrust: users, - devicesTrust: devices - ) - ) - XCTAssertEqual(trustLevel, expected, "\(users.trustedCount)/\(users.totalCount) trusted users(s), \(devices.trustedCount)/\(devices.totalCount) trusted device(s)") - } - } -} - -extension UserEncryptionTrustLevel: CustomStringConvertible { - public var description: String { - switch self { - case .trusted: - return "trusted" - case .warning: - return "warning" - case .notVerified: - return "notVerified" - case .noCrossSigning: - return "noCrossSigning" - case .none: - return "none" - case .unknown: - return "unknown" - @unknown default: - return "unknown" - } - } -} - -extension RoomEncryptionTrustLevel: CustomStringConvertible { - public var description: String { - switch self { - case .trusted: - return "trusted" - case .warning: - return "warning" - case .normal: - return "normal" - case .unknown: - return "unknown" - @unknown default: - return "unknown" - } - } -}