Skip to content

Commit

Permalink
Merge branch 'release/0.27.8/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed May 29, 2024
2 parents 26764b1 + 754e2fc commit 11aa1f4
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 43 deletions.
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.27.7"
s.version = "0.27.8"
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 @@ -1150,9 +1150,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
12 changes: 6 additions & 6 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
GZIP: 3c0abf794bfce8c7cb34ea05a1837752416c8868
libbase58: 7c040313537b8c44b6e2d15586af8e21f7354efd
MatrixSDKCrypto: bf08b72f2cd015d8749420a2b8b92fc0536bedf4
MatrixSDKCrypto: 736069ee0a5ec12852ab3498bf2242acecc443fc
OHHTTPStubs: 90eac6d8f2c18317baeca36698523dc67c513831
OLMKit: da115f16582e47626616874e20f7bb92222c7a51
Realm: 9ca328bd7e700cc19703799785e37f77d1a130f2
SwiftyBeaver: 84069991dd5dca07d7069100985badaca7f0ce82

PODFILE CHECKSUM: 1bf28f5a19566c567d265232f60ee19a3ae86ed3
PODFILE CHECKSUM: 37ab0de0200808bcd3335a637e31736df60fc62e

COCOAPODS: 1.14.3
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pod install
if [ $1 == 'xcframework' ] # optionally supports additional arguments for CFBundleShortVersionString and CFBundleVersion
then
# archive the framework for iOS, macOS, Catalyst and the Simulator
xcodebuild archive -workspace MatrixSDK.xcworkspace -scheme MatrixSDK-iOS -destination "generic/platform=iOS" -archivePath build/MatrixSDK-iOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES IPHONEOS_DEPLOYMENT_TARGET=11.0 GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS=NO MARKETING_VERSION=$2 CURRENT_PROJECT_VERSION=$3
xcodebuild archive -workspace MatrixSDK.xcworkspace -scheme MatrixSDK-iOS -destination "generic/platform=iOS Simulator" -archivePath build/MatrixSDK-iOSSimulator SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES IPHONEOS_DEPLOYMENT_TARGET=11.0 GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS=NO MARKETING_VERSION=$2 CURRENT_PROJECT_VERSION=$3
xcodebuild archive -workspace MatrixSDK.xcworkspace -scheme MatrixSDK-iOS -destination "generic/platform=iOS" -archivePath build/MatrixSDK-iOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES IPHONEOS_DEPLOYMENT_TARGET=13.0 GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS=NO MARKETING_VERSION=$2 CURRENT_PROJECT_VERSION=$3
xcodebuild archive -workspace MatrixSDK.xcworkspace -scheme MatrixSDK-iOS -destination "generic/platform=iOS Simulator" -archivePath build/MatrixSDK-iOSSimulator SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES IPHONEOS_DEPLOYMENT_TARGET=13.0 GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS=NO MARKETING_VERSION=$2 CURRENT_PROJECT_VERSION=$3
xcodebuild archive -workspace MatrixSDK.xcworkspace -scheme MatrixSDK-macOS -destination "generic/platform=macOS" -archivePath build/MatrixSDK-macOS SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES MACOSX_DEPLOYMENT_TARGET=10.10 GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS=NO MARKETING_VERSION=$2 CURRENT_PROJECT_VERSION=$3
xcodebuild archive -workspace MatrixSDK.xcworkspace -scheme MatrixSDK-iOS -destination "generic/platform=macOS,variant=Mac Catalyst" -archivePath ./build/MatrixSDK-MacCatalyst SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES IPHONEOS_DEPLOYMENT_TARGET=13.0 GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS=NO MARKETING_VERSION=$2 CURRENT_PROJECT_VERSION=$3

Expand Down

0 comments on commit 11aa1f4

Please sign in to comment.