Skip to content

Commit

Permalink
Merge branch 'release/0.26.0/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Mar 7, 2023
2 parents 765768f + d3b9188 commit 5ee5ac5
Show file tree
Hide file tree
Showing 56 changed files with 721 additions and 185 deletions.
21 changes: 21 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## Changes in 0.26.0 (2023-03-07)

🙌 Improvements

- CryptoV2: Control CryptoSDK via feature flag ([#1719](https://github.com/matrix-org/matrix-ios-sdk/pull/1719))
- Update MatrixSDKCrypto ([#1725](https://github.com/matrix-org/matrix-ios-sdk/pull/1725))
- Use correct next users with keys query ([#1726](https://github.com/matrix-org/matrix-ios-sdk/pull/1726))
- Creating a direct room with a third party will now use their email as the m.direct ID and their obfuscated email as the room title. ([#1727](https://github.com/matrix-org/matrix-ios-sdk/pull/1727))

🐛 Bugfixes

- Fixed incorrect filtering of "unread rooms" in the all chats list. ([#1723](https://github.com/matrix-org/matrix-ios-sdk/pull/1723))
- Unread rooms: Move the storage file to a better location. ([#1730](https://github.com/matrix-org/matrix-ios-sdk/pull/1730))
- Fixed a crash when roomSummary is nil. ([#1731](https://github.com/matrix-org/matrix-ios-sdk/pull/1731))
- Fix room list last message when the key comes late. ([#6848](https://github.com/vector-im/element-ios/issues/6848))

⚠️ API Changes

- MXRoomSummary: displayname has been renamed to displayName ([#1731](https://github.com/matrix-org/matrix-ios-sdk/pull/1731))


## Changes in 0.25.2 (2023-02-21)

🙌 Improvements
Expand Down
4 changes: 2 additions & 2 deletions MatrixSDK.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "MatrixSDK"
s.version = "0.25.2"
s.version = "0.26.0"
s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)"

s.description = <<-DESC
Expand Down Expand Up @@ -45,7 +45,7 @@ Pod::Spec.new do |s|
ss.dependency 'OLMKit', '~> 3.2.5'
ss.dependency 'Realm', '10.27.0'
ss.dependency 'libbase58', '~> 0.1.4'
ss.dependency 'MatrixSDKCrypto', '0.2.0', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true
ss.dependency 'MatrixSDKCrypto', '0.2.1', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true
end

s.subspec 'JingleCallStack' do |ss|
Expand Down
6 changes: 6 additions & 0 deletions MatrixSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,8 @@
EDC8C4092968A993003792C5 /* MXKeysQueryScheduler.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC8C4072968A993003792C5 /* MXKeysQueryScheduler.swift */; };
EDC8C40D2968C37E003792C5 /* MXKeysQuerySchedulerUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC8C40A2968A9F7003792C5 /* MXKeysQuerySchedulerUnitTests.swift */; };
EDC8C40E2968C37F003792C5 /* MXKeysQuerySchedulerUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC8C40A2968A9F7003792C5 /* MXKeysQuerySchedulerUnitTests.swift */; };
EDCAD251299BF7F40088B4DA /* MXCryptoV2Feature.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCAD250299BF7F40088B4DA /* MXCryptoV2Feature.swift */; };
EDCAD252299BF7F40088B4DA /* MXCryptoV2Feature.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCAD250299BF7F40088B4DA /* MXCryptoV2Feature.swift */; };
EDCB65E22912AB0C00F55D4D /* MXRoomEventDecryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCB65E12912AB0C00F55D4D /* MXRoomEventDecryption.swift */; };
EDCB65E32912AB0C00F55D4D /* MXRoomEventDecryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCB65E12912AB0C00F55D4D /* MXRoomEventDecryption.swift */; };
EDCF802D2941FF220059E774 /* MXCryptoMigrationV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCF802C2941FF220059E774 /* MXCryptoMigrationV2.swift */; };
Expand Down Expand Up @@ -3171,6 +3173,7 @@
EDC2A0E528369E740039F3D6 /* CryptoTests.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CryptoTests.xctestplan; sourceTree = "<group>"; };
EDC8C4072968A993003792C5 /* MXKeysQueryScheduler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXKeysQueryScheduler.swift; sourceTree = "<group>"; };
EDC8C40A2968A9F7003792C5 /* MXKeysQuerySchedulerUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXKeysQuerySchedulerUnitTests.swift; sourceTree = "<group>"; };
EDCAD250299BF7F40088B4DA /* MXCryptoV2Feature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoV2Feature.swift; sourceTree = "<group>"; };
EDCB65E12912AB0C00F55D4D /* MXRoomEventDecryption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXRoomEventDecryption.swift; sourceTree = "<group>"; };
EDCF802C2941FF220059E774 /* MXCryptoMigrationV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMigrationV2.swift; sourceTree = "<group>"; };
EDD4197D28DCAA5F007F3757 /* MXNativeKeyBackupEngine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXNativeKeyBackupEngine.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3525,6 +3528,7 @@
322A51B41D9AB15900C8536D /* MXCrypto.h */,
322A51B51D9AB15900C8536D /* MXCrypto.m */,
ED47CB6C28523995004FD755 /* MXCryptoV2.swift */,
EDCAD250299BF7F40088B4DA /* MXCryptoV2Feature.swift */,
ED5EF151297AB33E00A5ADDA /* MXCryptoV2Factory.swift */,
325D1C251DFECE0D0070B8BF /* MXCrypto_Private.h */,
322A51C51D9BBD3C00C8536D /* MXOlmDevice.h */,
Expand Down Expand Up @@ -7142,6 +7146,7 @@
EC2EACFF266625170038B61F /* MXRoomLastMessage.m in Sources */,
EDF1B6902876CD2C00BBBCEE /* MXTaskQueue.swift in Sources */,
EC8A539525B1BC77004E0802 /* MXUserModel.m in Sources */,
EDCAD251299BF7F40088B4DA /* MXCryptoV2Feature.swift in Sources */,
ED5EF14F297AB29F00A5ADDA /* MXEventDecryptionResult+DecryptedEvent.swift in Sources */,
3252DCAF224BE5D40032264F /* MXKeyVerificationManager.m in Sources */,
323E0C5C1A306D7A00A31D73 /* MXEvent.m in Sources */,
Expand Down Expand Up @@ -7809,6 +7814,7 @@
EC8A53D925B1BCC6004E0802 /* MXThirdPartyProtocolInstance.m in Sources */,
EDF1B6912876CD2C00BBBCEE /* MXTaskQueue.swift in Sources */,
B14EF2422397E90400758AF0 /* MXDeviceInfo.m in Sources */,
EDCAD252299BF7F40088B4DA /* MXCryptoV2Feature.swift in Sources */,
ED5EF150297AB29F00A5ADDA /* MXEventDecryptionResult+DecryptedEvent.swift in Sources */,
B14EF2432397E90400758AF0 /* MXIncomingSASTransaction.m in Sources */,
B14EF2442397E90400758AF0 /* NSObject+sortedKeys.m in Sources */,
Expand Down
22 changes: 13 additions & 9 deletions MatrixSDK/Background/MXBackgroundSyncService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ public enum MXBackgroundSyncServiceError: Error {

/// Initializer
/// - Parameter credentials: account credentials
public init(withCredentials credentials: MXCredentials, persistTokenDataHandler: MXRestClientPersistTokenDataHandler? = nil, unauthenticatedHandler: MXRestClientUnauthenticatedHandler? = nil) {
public init(
withCredentials credentials: MXCredentials,
isCryptoSDKEnabled: Bool = false,
persistTokenDataHandler: MXRestClientPersistTokenDataHandler? = nil,
unauthenticatedHandler: MXRestClientUnauthenticatedHandler? = nil
) {
processingQueue = DispatchQueue(label: "MXBackgroundSyncServiceQueue-" + MXTools.generateSecret())
self.credentials = credentials

Expand All @@ -88,14 +93,13 @@ public enum MXBackgroundSyncServiceError: Error {
// We can flush any crypto data if our sync response store is empty
let resetBackgroundCryptoStore = syncResponseStoreManager.syncToken() == nil

crypto = {
if MXSDKOptions.sharedInstance().isCryptoSDKAvailable && MXSDKOptions.sharedInstance().enableCryptoSDK {
return MXBackgroundCryptoV2(credentials: credentials, restClient: restClient)
}

MXLog.debug("[MXBackgroundSyncService] init: constructing legacy crypto \(MXSDKOptions.sharedInstance().isCryptoSDKAvailable) \(MXSDKOptions.sharedInstance().enableCryptoSDK)")
return MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore)
}()
if isCryptoSDKEnabled {
MXLog.debug("[MXBackgroundSyncService] init: constructing crypto v2")
crypto = MXBackgroundCryptoV2(credentials: credentials, restClient: restClient)
} else {
MXLog.debug("[MXBackgroundSyncService] init: constructing legacy crypto")
crypto = MXLegacyBackgroundCrypto(credentials: credentials, resetBackgroundCryptoStore: resetBackgroundCryptoStore)
}

pushRulesManager = MXBackgroundPushRulesManager(withCredentials: credentials)
MXLog.debug("[MXBackgroundSyncService] init complete")
Expand Down
14 changes: 7 additions & 7 deletions MatrixSDK/Background/Store/MXSyncResponseStoreManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,18 @@ public class MXSyncResponseStoreManager: NSObject {
for event in eventsToProcess {
switch event.eventType {
case .roomAliases:
if summary.displayname == nil {
summary.displayname = (event.content["aliases"] as? [String])?.first
if summary.displayName == nil {
summary.displayName = (event.content["aliases"] as? [String])?.first
}
case .roomCanonicalAlias:
if summary.displayname == nil {
summary.displayname = event.content["alias"] as? String
if summary.displayname == nil {
summary.displayname = (event.content["alt_aliases"] as? [String])?.first
if summary.displayName == nil {
summary.displayName = event.content["alias"] as? String
if summary.displayName == nil {
summary.displayName = (event.content["alt_aliases"] as? [String])?.first
}
}
case .roomName:
summary.displayname = event.content["name"] as? String
summary.displayName = event.content["name"] as? String
default:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ actor MXRoomEventDecryption: MXRoomEventDecrypting {
}

func decrypt(events: [MXEvent]) -> [MXEventDecryptionResult] {
log.debug("Decrypting \(events.count) event(s)")
let results = events.map(decrypt(event:))

let undecrypted = results.filter {
Expand All @@ -63,8 +64,8 @@ actor MXRoomEventDecryption: MXRoomEventDecrypting {
"total": events.count,
"undecrypted": undecrypted.count
])
} else {
log.debug("Decrypted all \(events.count) event(s)")
} else if events.count > 1 {
log.debug("Decrypted all \(events.count) events")
}

return results
Expand Down Expand Up @@ -120,7 +121,7 @@ actor MXRoomEventDecryption: MXRoomEventDecrypting {
do {
let decryptedEvent = try handler.decryptRoomEvent(event)
let result = try MXEventDecryptionResult(event: decryptedEvent)
log.debug("Successfully decrypted event `\(result.clearEvent["type"] ?? "unknown")` eventId `\(eventId)`")
log.debug("Decrypted event `\(result.clearEvent["type"] ?? "unknown")` eventId `\(eventId)`")
return result

} catch let error as DecryptionError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,29 +127,30 @@ struct MXRoomEventEncryption: MXRoomEventEncrypting {
for: room,
historyVisibility: state.historyVisibility
)
log.debug("Collected \(users.count) eligible users")

let settings = try encryptionSettings(for: state)
try await handler.shareRoomKeysIfNecessary(
roomId: roomId,
users: users,
settings: settings
)

log.debug("Encryption and room keys up to date")
}

/// Make sure that we recognize (and store if necessary) the claimed room encryption algorithm
private func ensureRoomEncryption(roomId: String, algorithm: String?) throws {
let existingAlgorithm = legacyStore.algorithm(forRoom: roomId)
if existingAlgorithm != nil && existingAlgorithm == algorithm {
log.debug("Encryption in room is already set to the correct algorithm")
// Encryption in room is already set to the correct algorithm
return
}

guard let algorithm = algorithm else {
log.error("Resetting encryption is not allowed")
throw Error.invalidEncryptionAlgorithm
if existingAlgorithm != nil {
log.error("Resetting encryption is not allowed")
return
} else {
throw Error.invalidEncryptionAlgorithm
}
}

let supportedAlgorithms = Set([kMXCryptoMegolmAlgorithm])
Expand Down
41 changes: 31 additions & 10 deletions MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ extension MXCryptoMachine: MXCryptoSyncing {
// MARK: - Private

private func handleRequest(_ request: Request) async throws {
log.debug("Handling request \(request)")
log.debug("Handling `\(request.type)` request")

switch request {
case .toDevice(let requestId, let eventType, let body):
Expand All @@ -240,9 +240,14 @@ extension MXCryptoMachine: MXCryptoSyncing {
try markRequestAsSent(requestId: requestId, requestType: .keysQuery, response: response.jsonString())

case .keysClaim(let requestId, let oneTimeKeys):
log.debug("Claiming keys \(oneTimeKeys)")

let response = try await requests.claimKeys(
request: .init(oneTimeKeys: oneTimeKeys)
)

let dictionary = response.jsonDictionary() as? [String: Any] ?? [:]
log.debug("Keys claimed\n\(dictionary)")
try markRequestAsSent(requestId: requestId, requestType: .keysClaim, response: response.jsonString())

case .keysBackup(let requestId, let version, let rooms):
Expand Down Expand Up @@ -276,8 +281,6 @@ extension MXCryptoMachine: MXCryptoSyncing {
}

private func handleOutgoingRequests() async throws {
log.debug("->")

let requests = try machine.outgoingRequests()

try await withThrowingTaskGroup(of: Void.self) { [weak self] group in
Expand Down Expand Up @@ -386,19 +389,14 @@ extension MXCryptoMachine: MXCryptoRoomEventEncrypting {
log.debug("Checking room keys in room \(roomId)")

try await sessionsQueue.sync { [weak self] in
self?.log.debug("Collecting missing sessions")
try await self?.getMissingSessions(users: users)
}

log.debug("Acquiring lock for room \(roomId)")
let roomQueue = await roomQueues.getQueue(for: roomId)

try await roomQueue.sync { [weak self] in
self?.log.debug("Sharing room keys")
try await self?.shareRoomKey(roomId: roomId, users: users, settings: settings)
}

log.debug("All room keys have been shared")
}

func encryptRoomEvent(
Expand All @@ -425,13 +423,13 @@ extension MXCryptoMachine: MXCryptoRoomEventEncrypting {
// MARK: - Private

private func getMissingSessions(users: [String]) async throws {
log.debug("Getting missing sessions for \(users.count) user(s)")
log.debug("Checking missing olm sessions for \(users.count) user(s): \(users)")

guard
let request = try machine.getMissingSessions(users: users),
case .keysClaim = request
else {
log.debug("No sessions are missing")
log.debug("No olm sessions are missing")
return
}

Expand All @@ -440,6 +438,8 @@ extension MXCryptoMachine: MXCryptoRoomEventEncrypting {
}

private func shareRoomKey(roomId: String, users: [String], settings: EncryptionSettings) async throws {
log.debug("Checking unshared room keys")

let requests = try machine.shareRoomKey(roomId: roomId, users: users, settings: settings)
guard !requests.isEmpty else {
log.debug("There are no new keys to share")
Expand Down Expand Up @@ -781,3 +781,24 @@ extension MXCryptoMachine: MXCryptoBackup {
isComputingRoomKeyCounts = false
}
}

extension Request {
var type: RequestType {
switch self {
case .toDevice:
return .toDevice
case .keysUpload:
return .keysUpload
case .keysQuery:
return .keysQuery
case .keysClaim:
return .keysClaim
case .keysBackup:
return .keysBackup
case .roomMessage:
return .roomMessage
case .signatureUpload:
return .signatureUpload
}
}
}
6 changes: 5 additions & 1 deletion MatrixSDK/Crypto/CryptoMachine/MXCryptoSDKLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class MXCryptoSDKLogger: Logger {
// This will be changed in rust-sdk directly
let ignored = [
"::uniffi_api:",
"::backup_recovery_key: decrypt_v1"
"::backup_recovery_key: decrypt_v1",
"matrix_sdk_crypto_ffi::machine: backup_enabled",
"matrix_sdk_crypto_ffi::machine: room_key_counts",
"matrix_sdk_crypto_ffi::machine: user_id",
"matrix_sdk_crypto_ffi::machine: identity_keys"
]

for ignore in ignored {
Expand Down
25 changes: 13 additions & 12 deletions MatrixSDK/Crypto/CryptoMachine/MXKeysQueryScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ public actor MXKeysQueryScheduler<Response> {
private func currentOrNextQuery(users: Set<String>) -> Task<Response, Error> {
if let currentQuery = currentQuery {
if currentQuery.contains(users: users) {
log("... query already running")
log("... query with the same user(s) already running")

return currentQuery.task

} else {
log("... queueing users for the next query")
log("... queueing user(s) for the next query")

nextUsers = nextUsers.union(users)

let task = nextTask ?? Task {
// Next task needs to await to completion of the currently running task
let _ = await currentQuery.task.result

// Extract and reset next users
let users = nextUsers
nextUsers = []
// At this point the previous query has already changed `self.currentQuery`
// to `next`, so we can extract its users to execute
let users = self.currentQuery?.users ?? []

// Only then we can execute the actual work
return try await executeQuery(users: users)
Expand All @@ -81,28 +81,29 @@ public actor MXKeysQueryScheduler<Response> {
}

} else {
log("... query starting")

let task = Task {
// Since we do not have any task running we can execute work right away
try await executeQuery(users: users)
}
currentQuery = .init(users: users, task: task)
currentQuery = Query(users: users, task: task)
return task
}
}

private func executeQuery(users: Set<String>) async throws -> Response {
defer {
if let next = nextTask {
log("... query completed, starting next pending query.")
currentQuery = .init(users: users, task: next)
if let nextTask = nextTask {
log("... query for \(users) completed, starting next pending query.")
currentQuery = Query(users: nextUsers, task: nextTask)
} else {
log("... query completed, no other queries scheduled.")
log("... query for \(users) completed, no other queries scheduled.")
currentQuery = nil
}
nextTask = nil
nextUsers = []
}

log("... query starting for \(users)")
return try await queryAction(Array(users))
}

Expand Down
Loading

0 comments on commit 5ee5ac5

Please sign in to comment.