Skip to content

Commit

Permalink
Merge pull request #1853 from matrix-org/valere/bump_crypto_sdk_versi…
Browse files Browse the repository at this point in the history
…on_0.4.1

Bump rust crypto sdk version 0.4.1
  • Loading branch information
BillCarsonFr authored May 24, 2024
2 parents 30d49a6 + 5b4382d commit 0c3ab70
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 34 deletions.
2 changes: 1 addition & 1 deletion MatrixSDK.podspec
Original file line number Diff line number Diff line change
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.1', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true
end

s.subspec 'JingleCallStack' do |ss|
Expand Down
9 changes: 7 additions & 2 deletions MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,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 +838,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
18 changes: 9 additions & 9 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,14 @@ 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)
var pickleKeyData = Data(count: 32)
_ = SecRandomCopyBytes(kSecRandomDefault, 32, &pickleKeyData)

// 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 +131,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 +150,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 +163,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
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
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.1', :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.1)
- 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.1)
- 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: da2b8a81f7e1989fc61ff85ed6aad92332beeb40
OHHTTPStubs: 90eac6d8f2c18317baeca36698523dc67c513831
OLMKit: da115f16582e47626616874e20f7bb92222c7a51
Realm: 9ca328bd7e700cc19703799785e37f77d1a130f2
SwiftyBeaver: 84069991dd5dca07d7069100985badaca7f0ce82

PODFILE CHECKSUM: 1bf28f5a19566c567d265232f60ee19a3ae86ed3
PODFILE CHECKSUM: bce6f6e7af7aa0ac9a50d4f6594d923fc00ed168

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
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
1 change: 1 addition & 0 deletions changelog.d/pr-1853.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Crypto: Update crypto SDK to 0.4.1

0 comments on commit 0c3ab70

Please sign in to comment.