Skip to content

Commit

Permalink
BER-359: sync origin with upstream v0.27.8 (#7)
Browse files Browse the repository at this point in the history
* Prepare for new sprint

* version++

* finish version++

* Prepare for new sprint

* Add own device creation ts in crypto API

* deviceCreationTs should be readonly

* version++

* finish version++

* Prepare for new sprint

* Sorting room list alphabetically case-insensitive. (matrix-org#1851)

* Sort Room list alphabetically but caseInsensitive

Signed-off-by: Nicolas Buquet <nbuquet@buquet-net.com>

* Sort Room list alphabetically but caseInsensitive

Signed-off-by: Nicolas Buquet <nbuquet@buquet-net.com>

* Sort Room list alphabetically but caseInsensitive

Signed-off-by: Nicolas Buquet <nbuquet@buquet-net.com>

---------

Signed-off-by: Nicolas Buquet <nbuquet@buquet-net.com>
Co-authored-by: Nicolas Buquet <nbuquet@buquet-net.com>

* Bump rust crypto sdk version 0.4.1

* update minimum ios platform 13.0

* Update min deployment target to 13.0

* Update osx min platform

* update podfile lock

* Fix test compilation

* Add changelog

* Invalidate crypto store cache when entering foreground

* Bump crypto sdk to 0.4.2

* Fix warnings

* Bump the Crypto version in the podspec as well

* version++

* finish version++

* BER-359: update changelog

---------

Signed-off-by: Nicolas Buquet <nbuquet@buquet-net.com>
Co-authored-by: Mauro Romito <mauro.romito@element.io>
Co-authored-by: Stefan Ceriu <stefan.ceriu@gmail.com>
Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
Co-authored-by: Valere <bill.carson@valrsoft.com>
Co-authored-by: Valere <valeref@matrix.org>
Co-authored-by: Doug <douglase@element.io>
Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
Co-authored-by: Nicolas Buquet <github@buquet-net.com>
Co-authored-by: Nicolas Buquet <nbuquet@buquet-net.com>
  • Loading branch information
10 people authored Jun 7, 2024
1 parent 30d45dc commit 47e9ab8
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 44 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
All notable changes specific for Berichten Matrix SDK will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [v0.1.3] - 04/06/2024
##### Added
- BER-359: Merge upstream MatrixSDK v0.27.8.

##### Fixed

##### Changed

## [v0.1.2] - 12/03/2024
##### Added
- BER-332: Merge upstream MatrixSDK v0.27.6.
Expand Down Expand Up @@ -29,6 +37,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

---

[v0.1.3]: https://github.com/nedap/matrix-ios-sdk/compare/nedap/0.1.2...nedap/0.1.3
[v0.1.2]: https://github.com/nedap/matrix-ios-sdk/compare/nedap/0.1.1...nedap/0.1.2
[v0.1.1]: https://github.com/nedap/matrix-ios-sdk/compare/nedap/0.1.0...nedap/0.1.1
[v0.1.0]: https://github.com/nedap/matrix-ios-sdk/compare/nedap/0.1.0...nedap/0.1.0
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Changes in 0.27.8 (2024-05-29)

🙌 Improvements

- When sorting room list alphabetically, sort it case-insensitive. ([#1851](https://github.com/matrix-org/matrix-ios-sdk/pull/1851))
- Crypto: Update crypto SDK to 0.4.1 ([#1853](https://github.com/matrix-org/matrix-ios-sdk/pull/1853))


## Changes in 0.27.7 (2024-05-01)

No significant changes.
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.1.2"
s.version = "0.1.3"
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.3.13', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true
ss.dependency 'MatrixSDKCrypto', '0.4.2', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true
end

s.subspec 'JingleCallStack' do |ss|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,13 @@ actor MXRoomEventDecryption: MXRoomEventDecrypting {
])
return trackedDecryptionResult(for: event, error: error)

case .MissingRoomKey(let message):
case .MissingRoomKey(let message, let withheldCode):
if undecryptedEvents[sessionId] == nil {
log.error("Failed to decrypt event(s) due to missing room keys", context: [
"session_id": sessionId,
"message": message,
"error": error,
"withheldCode": withheldCode ?? "N/A",
"details": "further errors for the same key will be supressed",
])
}
Expand Down
13 changes: 11 additions & 2 deletions MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ class MXCryptoMachine {
}
}

func invalidateCache() async {
await machine.clearCryptoCache()
}

// MARK: - Private

private static func createMachine(userId: String, deviceId: String, log: MXNamedLog) throws -> OlmMachine {
Expand Down Expand Up @@ -591,9 +595,14 @@ extension MXCryptoMachine: MXCryptoCrossSigning {

func bootstrapCrossSigning(authParams: [AnyHashable: Any]) async throws {
let result = try machine.bootstrapCrossSigning()
// If this is called before the device keys have been uploaded there will be a
// request to upload them, do that first.
if let optionalKeyRequest = result.uploadKeysRequest {
try await handleRequest(optionalKeyRequest)
}
let _ = try await [
requests.uploadSigningKeys(request: result.uploadSigningKeysRequest, authParams: authParams),
requests.uploadSignatures(request: result.signatureRequest)
requests.uploadSignatures(request: result.uploadSignatureRequest)
]
}

Expand Down Expand Up @@ -833,7 +842,7 @@ extension MXCryptoMachine: MXCryptoBackup {
guard let message = MXCryptoTools.canonicalJSONString(forJSON: object) else {
throw Error.cannotSerialize
}
return machine.sign(message: message)
return try machine.sign(message: message)
}

func backupRoomKeys() async throws {
Expand Down
21 changes: 11 additions & 10 deletions MatrixSDK/Crypto/Dehydration/DehydrationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class DehydrationService: NSObject {
// Convert it back to Data
let pickleKeyData = MXBase64Tools.data(fromBase64: base64PickleKey)

let rehydrationResult = await rehydrateDevice(pickleKeyData: [UInt8](pickleKeyData))
let rehydrationResult = await rehydrateDevice(pickleKeyData: pickleKeyData)
switch rehydrationResult {
case .success((let deviceId, let rehydratedDevice)):
// Fetch and process the to device events available on the dehydrated device
Expand All @@ -86,14 +86,15 @@ public class DehydrationService: NSObject {
}

// Finally, create a new dehydrated device with the same pickle key
try await dehydrateDevice(pickleKeyData: [UInt8](pickleKeyData))
try await dehydrateDevice(pickleKeyData: pickleKeyData)
} else { // Otherwise, generate a new dehydration pickle key, store it and dehydrate a device
// Generate a new dehydration pickle key
var pickleKeyData = [UInt8](repeating: 0, count: 32)
_ = SecRandomCopyBytes(kSecRandomDefault, 32, &pickleKeyData)
var pickleKeyRaw = [UInt8](repeating: 0, count: 32)
_ = SecRandomCopyBytes(kSecRandomDefault, 32, &pickleKeyRaw)
let pickleKeyData = Data(bytes: pickleKeyRaw, count: 32)

// Convert it to unpadded base 64
let base64PickleKey = MXBase64Tools.unpaddedBase64(from: Data(bytes: pickleKeyData, count: 32))
let base64PickleKey = MXBase64Tools.unpaddedBase64(from: pickleKeyData)

// Store it on the backend
try await storeSecret(base64PickleKey, secretId: secretId, secretStorageKeys: [secretStorageKeyId: privateKeyData])
Expand Down Expand Up @@ -131,10 +132,10 @@ public class DehydrationService: NSObject {

// MARK: - Device dehydration

private func dehydrateDevice(pickleKeyData: [UInt8]) async throws {
let dehydratedDevice = dehydratedDevices.create()
private func dehydrateDevice(pickleKeyData: Data) async throws {
let dehydratedDevice = try dehydratedDevices.create()

let requestDetails = try dehydratedDevice.keysForUpload(deviceDisplayName: deviceDisplayName, pickleKey: [UInt8](pickleKeyData))
let requestDetails = try dehydratedDevice.keysForUpload(deviceDisplayName: deviceDisplayName, pickleKey: pickleKeyData)

let parameters = MXDehydratedDeviceCreationParameters()
parameters.body = requestDetails.body
Expand All @@ -150,7 +151,7 @@ public class DehydrationService: NSObject {
}
}

private func rehydrateDevice(pickleKeyData: [UInt8]) async -> Result<(deviceId: String, rehydratedDevice: RehydratedDeviceProtocol), DehydrationServiceError> {
private func rehydrateDevice(pickleKeyData: Data) async -> Result<(deviceId: String, rehydratedDevice: RehydratedDeviceProtocol), DehydrationServiceError> {
await withCheckedContinuation { continuation in
self.restClient.retrieveDehydratedDevice { [weak self] dehydratedDevice in
guard let self else { return }
Expand All @@ -163,7 +164,7 @@ public class DehydrationService: NSObject {
}

do {
let rehydratedDevice = try self.dehydratedDevices.rehydrate(pickleKey: [UInt8](pickleKeyData), deviceId: dehydratedDevice.deviceId, deviceData: deviceDataJSON)
let rehydratedDevice = try self.dehydratedDevices.rehydrate(pickleKey: pickleKeyData, deviceId: dehydratedDevice.deviceId, deviceData: deviceDataJSON)
continuation.resume(returning: .success((dehydratedDevice.deviceId, rehydratedDevice)))
} catch {
continuation.resume(returning: .failure(DehydrationServiceError.failedRehydration(error)))
Expand Down
2 changes: 2 additions & 0 deletions MatrixSDK/Crypto/MXCrypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ extern NSString *const MXDeviceListDidUpdateUsersDevicesNotification;
*/
- (void)setBlacklistUnverifiedDevicesInRoom:(NSString *)roomId blacklist:(BOOL)blacklist;

- (void) invalidateCache:(void (^)(void))done;

@end

NS_ASSUME_NONNULL_END
Expand Down
12 changes: 11 additions & 1 deletion MatrixSDK/Crypto/MXCryptoV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import MatrixSDKCrypto
/// An implementation of `MXCrypto` which uses [matrix-rust-sdk](https://github.com/matrix-org/matrix-rust-sdk/tree/main/crates/matrix-sdk-crypto)
/// under the hood.
class MXCryptoV2: NSObject, MXCrypto {

enum Error: Swift.Error {
case cannotUnsetTrust
case backupNotEnabled
Expand Down Expand Up @@ -720,4 +721,13 @@ class MXCryptoV2: NSObject, MXCrypto {
return dict[info.userId] = info
}
}
}

func invalidateCache(_ done: @escaping () -> Void) {
Task {
log.debug("Invalidating Olm Machine crypto store cache.")
await machine.invalidateCache()
await MainActor.run {
done()
}
}
}}
4 changes: 2 additions & 2 deletions MatrixSDK/Crypto/Migration/Data/MXCryptoMigrationStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct MXCryptoMigrationStore {
account: try pickledAccount(pickleKey: pickleKey),
sessions: [], // Sessions are extracted in batches separately
inboundGroupSessions: [], // Group sessions are extracted in batches separately
pickleKey: [UInt8](pickleKey),
pickleKey: pickleKey,
backupVersion: legacyStore.backupVersion,
backupRecoveryKey: backupRecoveryKey(),
crossSigning: crossSigning(),
Expand Down Expand Up @@ -194,7 +194,7 @@ private extension PickledAccount {
private extension PickledSession {
init(session: MXOlmSession, pickleKey: Data) throws {
let pickle = try session.session.serializeData(withKey: pickleKey)
let time = "\(Int(session.lastReceivedMessageTs))"
let time = UInt64(session.lastReceivedMessageTs)

self.init(
pickle: pickle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension MXRoomListDataSortable {
// }

if sortOptions.alphabetical {
result.append(NSSortDescriptor(keyPath: \MXRoomSummaryProtocol.displayName, ascending: true))
result.append(NSSortDescriptor(key: "displayName", ascending: true, selector: #selector(NSString.localizedStandardCompare(_:))))
}

if sortOptions.invitesFirst {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ extension MXCoreDataRoomListDataFetcher: MXRoomListDataSortable {
var result: [NSSortDescriptor] = []

if sortOptions.alphabetical {
result.append(NSSortDescriptor(keyPath: \MXRoomSummaryMO.s_displayName, ascending: true))
result.append(NSSortDescriptor(key: "s_displayName", ascending: true, selector: #selector(NSString.localizedStandardCompare(_:))))
}

if sortOptions.invitesFirst {
Expand Down
15 changes: 12 additions & 3 deletions MatrixSDK/MXSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -1154,9 +1154,18 @@ - (void)pause

- (void)resume:(void (^)(void))resumeDone
{
[self handleBackgroundSyncCacheIfRequiredWithCompletion:^{
[self _resume:resumeDone];
}];
// The app has resumed there might have been a NSE run that have invalidated the cache
if (self.crypto) {
[self.crypto invalidateCache:^{
[self handleBackgroundSyncCacheIfRequiredWithCompletion:^{
[self _resume:resumeDone];
}];
}];
} else {
[self handleBackgroundSyncCacheIfRequiredWithCompletion:^{
[self _resume:resumeDone];
}];
}
}

- (void)_resume:(void (^)(void))resumeDone
Expand Down
2 changes: 1 addition & 1 deletion MatrixSDK/MatrixSDKVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

#import <Foundation/Foundation.h>

NSString *const MatrixSDKVersion = @"0.27.7";
NSString *const MatrixSDKVersion = @"0.27.8";
3 changes: 2 additions & 1 deletion MatrixSDKTests/Crypto/CryptoMachine/Device+Stub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ extension Device {
isBlocked: isBlocked,
locallyTrusted: locallyTrusted,
crossSigningTrusted: crossSigningTrusted,
firstTimeSeenTs: 0
firstTimeSeenTs: 0,
dehydrated: false
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class CryptoCrossSigningStub: CryptoIdentityStub, MXCryptoCrossSigning {
locallyTrusted: device.locallyTrusted,
// Modify cross signing trusted
crossSigningTrusted: true,
firstTimeSeenTs: 0
firstTimeSeenTs: 0,
dehydrated: false
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class MXCryptoMigrationStoreUnitTests: XCTestCase {
XCTAssertEqual(sessions[0].pickle, pickle)
XCTAssertEqual(sessions[0].senderKey, "XYZ")
XCTAssertFalse(sessions[0].createdUsingFallbackKey)
XCTAssertEqual(sessions[0].creationTime, "123")
XCTAssertEqual(sessions[0].lastUseTime, "123")
XCTAssertEqual(sessions[0].creationTime, 123)
XCTAssertEqual(sessions[0].lastUseTime, 123)
}

func test_extractsMultipleSessionsInBatches() throws {
Expand Down Expand Up @@ -235,7 +235,7 @@ class MXCryptoMigrationStoreUnitTests: XCTestCase {
func test_extractsPickeKey() throws {
let pickleKey = "some key".data(using: .ascii)!
let key = try extractData(pickleKey: pickleKey).pickleKey
XCTAssertEqual(key, [UInt8](pickleKey))
XCTAssertEqual(key, pickleKey)
}

func test_extractsCrossSigning() throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation

import MatrixSDKCrypto

struct QrCodeStub: QrCodeProtocol {
class QrCodeStub: QrCodeProtocol {
private let _otherUserId: String
private let _otherDeviceId: String
private let _flowId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation

import MatrixSDKCrypto

struct SasStub: SasProtocol {
class SasStub: SasProtocol {

private let _otherUserId: String
private let _otherDeviceId: String
Expand Down
8 changes: 4 additions & 4 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ abstract_target 'MatrixSDK' do

pod 'Realm', '10.27.0'
pod 'libbase58', '~> 0.1.4'
pod 'MatrixSDKCrypto', "0.3.13", :inhibit_warnings => true
pod 'MatrixSDKCrypto', '0.4.2', :inhibit_warnings => true

target 'MatrixSDK-iOS' do
platform :ios, '11.0'
platform :ios, '13.0'

target 'MatrixSDKTests-iOS' do
inherit! :search_paths
Expand All @@ -28,7 +28,7 @@ abstract_target 'MatrixSDK' do
end

target 'MatrixSDK-macOS' do
platform :osx, '10.10'
platform :osx, '10.15'

target 'MatrixSDKTests-macOS' do
inherit! :search_paths
Expand All @@ -40,7 +40,7 @@ end
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
end
end
end
14 changes: 7 additions & 7 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ PODS:
- AFNetworking/Serialization (4.0.1)
- AFNetworking/UIKit (4.0.1):
- AFNetworking/NSURLSession
- GZIP (1.3.0)
- GZIP (1.3.2)
- libbase58 (0.1.4)
- MatrixSDKCrypto (0.3.13)
- MatrixSDKCrypto (0.4.2)
- OHHTTPStubs (9.1.0):
- OHHTTPStubs/Default (= 9.1.0)
- OHHTTPStubs/Core (9.1.0)
Expand Down Expand Up @@ -44,7 +44,7 @@ DEPENDENCIES:
- AFNetworking (~> 4.0.0)
- GZIP (~> 1.3.0)
- libbase58 (~> 0.1.4)
- MatrixSDKCrypto (= 0.3.13)
- MatrixSDKCrypto (= 0.4.2)
- OHHTTPStubs (~> 9.1.0)
- OLMKit (~> 3.2.5)
- Realm (= 10.27.0)
Expand All @@ -63,14 +63,14 @@ SPEC REPOS:

SPEC CHECKSUMS:
AFNetworking: 3bd23d814e976cd148d7d44c3ab78017b744cd58
GZIP: 416858efbe66b41b206895ac6dfd5493200d95b3
libbase58: 7c040313537b8c44b6e2d15586af8e21f7354efd
MatrixSDKCrypto: bf08b72f2cd015d8749420a2b8b92fc0536bedf4
GZIP: 3c0abf794bfce8c7cb34ea05a1837752416c8868
libbase58: 8abc2a53ac38cd37720c0acbc53ef3660e9016c2
MatrixSDKCrypto: 736069ee0a5ec12852ab3498bf2242acecc443fc
OHHTTPStubs: 90eac6d8f2c18317baeca36698523dc67c513831
OLMKit: da115f16582e47626616874e20f7bb92222c7a51
Realm: 9ca328bd7e700cc19703799785e37f77d1a130f2
SwiftyBeaver: 84069991dd5dca07d7069100985badaca7f0ce82

PODFILE CHECKSUM: 1bf28f5a19566c567d265232f60ee19a3ae86ed3
PODFILE CHECKSUM: 37ab0de0200808bcd3335a637e31736df60fc62e

COCOAPODS: 1.14.3
Loading

0 comments on commit 47e9ab8

Please sign in to comment.