Skip to content

Commit

Permalink
Merge branch 'release/0.24.8/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jan 24, 2023
2 parents ad1d93e + 48084d9 commit 59982e0
Show file tree
Hide file tree
Showing 68 changed files with 3,541 additions and 620 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.24.8 (2023-01-24)

✨ Features

- Implement MSC3912: Relation-based redactions ([#1688](https://github.com/matrix-org/matrix-ios-sdk/pull/1688))

🙌 Improvements

- CryptoV2: Add keys query scheduler ([#1676](https://github.com/matrix-org/matrix-ios-sdk/pull/1676))
- CryptoV2: Create crypto migration data ([#1681](https://github.com/matrix-org/matrix-ios-sdk/pull/1681))
- CryptoSDK: Perform crypto migration if necessary ([#1684](https://github.com/matrix-org/matrix-ios-sdk/pull/1684))
- Rename MXSessionSyncProgress ([#1686](https://github.com/matrix-org/matrix-ios-sdk/pull/1686))
- CryptoV2: Batch migrate olm and megolm sessions ([#1687](https://github.com/matrix-org/matrix-ios-sdk/pull/1687))
- CryptoV2: Extract room event encryption ([#1689](https://github.com/matrix-org/matrix-ios-sdk/pull/1689))
- CryptoV2: Migration improvements ([#1692](https://github.com/matrix-org/matrix-ios-sdk/pull/1692))

🐛 Bugfixes

- Messages' replies: fix localizations issues. ([#1685](https://github.com/matrix-org/matrix-ios-sdk/pull/1685))


## Changes in 0.24.7 (2023-01-10)

✨ Features
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.24.7"
s.version = "0.24.8"
s.summary = "The iOS SDK to build apps compatible with Matrix (https://www.matrix.org)"

s.description = <<-DESC
Expand Down Expand Up @@ -66,7 +66,7 @@ Pod::Spec.new do |s|

# Experimental / NOT production-ready Rust-based crypto library
s.subspec 'CryptoSDK' do |ss|
ss.dependency 'MatrixSDKCrypto', '0.1.7', :configurations => ["DEBUG"], :inhibit_warnings => true
ss.dependency 'MatrixSDKCrypto', '0.1.8', :configurations => ["DEBUG"], :inhibit_warnings => true
end

end
172 changes: 154 additions & 18 deletions MatrixSDK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion MatrixSDK/Background/Crypto/MXBackgroundCrypto.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
/// Light-weight crypto protocol to be used with background services
/// that can recieve room keys and decrypt notification messages
protocol MXBackgroundCrypto {
func handleSyncResponse(_ syncResponse: MXSyncResponse)
func handleSyncResponse(_ syncResponse: MXSyncResponse) async
func canDecryptEvent(_ event: MXEvent) -> Bool
func decryptEvent(_ event: MXEvent) throws
}
4 changes: 2 additions & 2 deletions MatrixSDK/Background/Crypto/MXBackgroundCryptoV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class MXBackgroundCryptoV2: MXBackgroundCrypto {
)
}

func handleSyncResponse(_ syncResponse: MXSyncResponse) {
func handleSyncResponse(_ syncResponse: MXSyncResponse) async {
let toDeviceCount = syncResponse.toDevice?.events.count ?? 0

log.debug("Handling new sync response with \(toDeviceCount) to-device event(s)")

do {
_ = try machine.handleSyncResponse(
_ = try await machine.handleSyncResponse(
toDevice: syncResponse.toDevice,
deviceLists: syncResponse.deviceLists,
deviceOneTimeKeysCounts: syncResponse.deviceOneTimeKeysCount ?? [:],
Expand Down
28 changes: 25 additions & 3 deletions MatrixSDK/Background/MXBackgroundCryptoStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ - (void)performSessionOperationWithDevice:(NSString*)deviceKey andSessionId:(NSS
if (olmSession)
{
MXLogDebug(@"[MXBackgroundCryptoStore] performSessionOperationWithDevice: Transfer data for %@ from cryptoStore to bgCryptoStore", sessionId);
[bgCryptoStore storeSession:olmSession forDevice:deviceKey];
[bgCryptoStore storeSession:olmSession];
}
}

Expand Down Expand Up @@ -209,9 +209,9 @@ - (MXOlmSession*)sessionWithDevice:(NSString*)deviceKey andSessionId:(NSString*)
return sessions;
}

- (void)storeSession:(MXOlmSession*)session forDevice:(NSString*)deviceKey
- (void)storeSession:(MXOlmSession*)session
{
[bgCryptoStore storeSession:session forDevice:deviceKey];
[bgCryptoStore storeSession:session];
}


Expand Down Expand Up @@ -322,6 +322,12 @@ + (void)deleteReadonlyStoreWithCredentials:(MXCredentials*)credentials
NSAssert(NO, @"This method should be useless in the context of MXBackgroundCryptoStore");
}

- (NSString *)userId
{
NSAssert(NO, @"This method should be useless in the context of MXBackgroundCryptoStore");
return nil;
}

- (void)storeDeviceId:(NSString*)deviceId
{
NSAssert(NO, @"This method should be useless in the context of MXBackgroundCryptoStore");
Expand All @@ -338,6 +344,22 @@ - (void)storeDeviceSyncToken:(NSString*)deviceSyncToken
NSAssert(NO, @"This method should be useless in the context of MXBackgroundCryptoStore");
}

- (void)enumerateSessionsBy:(NSInteger)batchSize block:(void (^)(NSArray<MXOlmSession *> *, double))block
{
NSAssert(NO, @"This method should be useless in the context of MXBackgroundCryptoStore");
}

- (void)enumerateInboundGroupSessionsBy:(NSInteger)batchSize block:(void (^)(NSArray<MXOlmInboundGroupSession *> *, NSSet<NSString *> *, double))block
{
NSAssert(NO, @"This method should be useless in the context of MXBackgroundCryptoStore");
}

- (NSUInteger)sessionsCount
{
NSAssert(NO, @"This method should be useless in the context of MXBackgroundCryptoStore");
return 0;
}

- (NSArray<MXOlmInboundGroupSession*> *)inboundGroupSessions
{
NSAssert(NO, @"This method should be useless in the context of MXBackgroundCryptoStore");
Expand Down
28 changes: 15 additions & 13 deletions MatrixSDK/Background/MXBackgroundSyncService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public enum MXBackgroundSyncServiceError: Error {

crypto = {
#if DEBUG
if MXSDKOptions.sharedInstance().enableCryptoV2 {
if MXSDKOptions.sharedInstance().isCryptoSDKAvailable && MXSDKOptions.sharedInstance().enableCryptoSDK {
// Crypto V2 is currently unable to decrypt notifications due to single-process store,
// so it uses dummy background crypto that does not do anything.
return MXDummyBackgroundCrypto()
Expand Down Expand Up @@ -391,16 +391,18 @@ public enum MXBackgroundSyncServiceError: Error {
return
}

self.handleSyncResponse(syncResponse, syncToken: eventStreamToken)

if let event = self.syncResponseStoreManager.event(withEventId: eventId, inRoom: roomId),
!self.crypto.canDecryptEvent(event),
(syncResponse.toDevice?.events ?? []).count > 0 {
// we got the event but not the keys to decrypt it. continue to sync
self.launchBackgroundSync(forEventId: eventId, roomId: roomId, completion: completion)
} else {
// do not allow to sync anymore
self._event(withEventId: eventId, inRoom: roomId, allowSync: false, completion: completion)
Task {
await self.handleSyncResponse(syncResponse, syncToken: eventStreamToken)

if let event = self.syncResponseStoreManager.event(withEventId: eventId, inRoom: roomId),
!self.crypto.canDecryptEvent(event),
(syncResponse.toDevice?.events ?? []).count > 0 {
// we got the event but not the keys to decrypt it. continue to sync
self.launchBackgroundSync(forEventId: eventId, roomId: roomId, completion: completion)
} else {
// do not allow to sync anymore
self._event(withEventId: eventId, inRoom: roomId, allowSync: false, completion: completion)
}
}
case .failure(let error):
guard let _ = self else {
Expand All @@ -418,7 +420,7 @@ public enum MXBackgroundSyncServiceError: Error {
}
}

private func handleSyncResponse(_ syncResponse: MXSyncResponse, syncToken: String) {
private func handleSyncResponse(_ syncResponse: MXSyncResponse, syncToken: String) async {
MXLog.debug("""
[MXBackgroundSyncService] handleSyncResponse: \
Received \(syncResponse.rooms?.join?.count ?? 0) joined rooms, \
Expand All @@ -432,7 +434,7 @@ public enum MXBackgroundSyncServiceError: Error {
}
syncResponseStoreManager.updateStore(with: syncResponse, syncToken: syncToken)

crypto.handleSyncResponse(syncResponse)
await crypto.handleSyncResponse(syncResponse)

if MXSDKOptions.sharedInstance().autoAcceptRoomInvites,
let invitedRooms = syncResponse.rooms?.invite {
Expand Down
19 changes: 19 additions & 0 deletions MatrixSDK/Contrib/Swift/Data/MXRoom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ import Foundation

public extension MXRoom {

enum Error: Swift.Error {
case missingState
}

/**
The current state of the room.
*/
func state() async throws -> MXRoomState {
return try await withCheckedThrowingContinuation { cont in
state {
if let state = $0 {
cont.resume(returning: state)
} else {
cont.resume(throwing: Error.missingState)
}
}
}
}


/**
The current list of members of the room.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ actor MXRoomEventDecryption: MXRoomEventDecrypting {
])
return trackedDecryptionResult(for: event, error: error)
}
case .Store(let message):
log.error("Failed to decrypt event due to store error", context: [
"session_id": sessionId,
"message": message,
"error": error
])
return trackedDecryptionResult(for: event, error: error)
}
}

Expand Down
Loading

0 comments on commit 59982e0

Please sign in to comment.