Skip to content

Commit 8e94b7b

Browse files
authored
Merge pull request matrix-org#1823 from matrix-org/valere/fix_qr_login_rust
Fix QR login support with cryptoV2
2 parents 2b1e26c + 703918b commit 8e94b7b

File tree

7 files changed

+58
-16
lines changed

7 files changed

+58
-16
lines changed

MatrixSDK.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Pod::Spec.new do |s|
4545
ss.dependency 'OLMKit', '~> 3.2.5'
4646
ss.dependency 'Realm', '10.27.0'
4747
ss.dependency 'libbase58', '~> 0.1.4'
48-
ss.dependency 'MatrixSDKCrypto', '0.3.12', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true
48+
ss.dependency 'MatrixSDKCrypto', '0.3.13', :configurations => ["DEBUG", "RELEASE"], :inhibit_warnings => true
4949
end
5050

5151
s.subspec 'JingleCallStack' do |ss|

MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,23 @@ extension MXCryptoMachine: MXCryptoCrossSigning {
613613
log.error("Failed importing cross signing keys", context: error)
614614
}
615615
}
616+
617+
func queryMissingSecretsFromOtherSessions() async throws {
618+
let isMissingSecrets = try machine.queryMissingSecretsFromOtherSessions()
619+
620+
if (isMissingSecrets) {
621+
// Out-of-sync check if there are any secret request to send out as a result of
622+
// the missing secret request
623+
for request in try machine.outgoingRequests() {
624+
if case .toDevice(_, let eventType, _) = request {
625+
if (eventType == kMXEventTypeStringSecretRequest) {
626+
try await handleRequest(request)
627+
}
628+
}
629+
}
630+
}
631+
}
632+
616633
}
617634

618635
extension MXCryptoMachine: MXCryptoVerifying {

MatrixSDK/Crypto/CryptoMachine/MXCryptoProtocols.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ protocol MXCryptoCrossSigning: MXCryptoUserIdentitySource, MXCryptoDevicesSource
9090
func bootstrapCrossSigning(authParams: [AnyHashable: Any]) async throws
9191
func exportCrossSigningKeys() -> CrossSigningKeyExport?
9292
func importCrossSigningKeys(export: CrossSigningKeyExport)
93+
94+
func queryMissingSecretsFromOtherSessions() async throws
9395
}
9496

9597
/// Verification functionality

MatrixSDK/Crypto/MXCryptoV2.swift

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,37 @@ class MXCryptoV2: NSObject, MXCrypto {
387387
case .verified:
388388
// If we want to set verified status, we will manually verify the device,
389389
// including uploading relevant signatures
390+
try? machine.setLocalTrust(userId: machine.userId, deviceId: deviceId, trust: .verified)
390391

391-
Task {
392-
do {
393-
try await machine.verifyDevice(userId: userId, deviceId: deviceId)
394-
log.debug("Successfully marked device as verified")
395-
await MainActor.run {
396-
success?()
392+
if (userId == machine.userId) {
393+
if (machine.crossSigningStatus().hasSelfSigning) {
394+
// If we can cross sign, upload a new signature for that device
395+
Task {
396+
do {
397+
try await machine.verifyDevice(userId: userId, deviceId: deviceId)
398+
log.debug("Successfully marked device as verified")
399+
await MainActor.run {
400+
success?()
401+
}
402+
} catch {
403+
log.error("Failed marking device as verified", context: error)
404+
await MainActor.run {
405+
failure?(error)
406+
}
407+
}
397408
}
398-
} catch {
399-
log.error("Failed marking device as verified", context: error)
400-
await MainActor.run {
401-
failure?(error)
409+
} else {
410+
// It's a good time to request secrets
411+
Task {
412+
do {
413+
try await machine.queryMissingSecretsFromOtherSessions()
414+
await MainActor.run {
415+
success?()
416+
}
417+
} catch {
418+
log.error("Failed to query missing secrets", context: error)
419+
failure?(error)
420+
}
402421
}
403422
}
404423
}

MatrixSDKTests/Crypto/CryptoMachine/MXCryptoProtocolStubs.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ class CryptoCrossSigningStub: CryptoIdentityStub, MXCryptoCrossSigning {
163163
func dehydratedDevices() -> DehydratedDevicesProtocol {
164164
fatalError()
165165
}
166+
167+
func queryMissingSecretsFromOtherSessions() async throws {
168+
169+
}
166170
}
167171

168172
class CryptoVerificationStub: CryptoIdentityStub {

Podfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract_target 'MatrixSDK' do
1616

1717
pod 'Realm', '10.27.0'
1818
pod 'libbase58', '~> 0.1.4'
19-
pod 'MatrixSDKCrypto', "0.3.12", :inhibit_warnings => true
19+
pod 'MatrixSDKCrypto', "0.3.13", :inhibit_warnings => true
2020

2121
target 'MatrixSDK-iOS' do
2222
platform :ios, '11.0'

Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ PODS:
1616
- AFNetworking/NSURLSession
1717
- GZIP (1.3.0)
1818
- libbase58 (0.1.4)
19-
- MatrixSDKCrypto (0.3.12)
19+
- MatrixSDKCrypto (0.3.13)
2020
- OHHTTPStubs (9.1.0):
2121
- OHHTTPStubs/Default (= 9.1.0)
2222
- OHHTTPStubs/Core (9.1.0)
@@ -44,7 +44,7 @@ DEPENDENCIES:
4444
- AFNetworking (~> 4.0.0)
4545
- GZIP (~> 1.3.0)
4646
- libbase58 (~> 0.1.4)
47-
- MatrixSDKCrypto (= 0.3.12)
47+
- MatrixSDKCrypto (= 0.3.13)
4848
- OHHTTPStubs (~> 9.1.0)
4949
- OLMKit (~> 3.2.5)
5050
- Realm (= 10.27.0)
@@ -65,12 +65,12 @@ SPEC CHECKSUMS:
6565
AFNetworking: 3bd23d814e976cd148d7d44c3ab78017b744cd58
6666
GZIP: 416858efbe66b41b206895ac6dfd5493200d95b3
6767
libbase58: 7c040313537b8c44b6e2d15586af8e21f7354efd
68-
MatrixSDKCrypto: 25929a40733b4ab54f659aaf6a730552a0a06504
68+
MatrixSDKCrypto: bf08b72f2cd015d8749420a2b8b92fc0536bedf4
6969
OHHTTPStubs: 90eac6d8f2c18317baeca36698523dc67c513831
7070
OLMKit: da115f16582e47626616874e20f7bb92222c7a51
7171
Realm: 9ca328bd7e700cc19703799785e37f77d1a130f2
7272
SwiftyBeaver: 84069991dd5dca07d7069100985badaca7f0ce82
7373

74-
PODFILE CHECKSUM: e70d3694981265116ff81a851fb0c1c9654995cd
74+
PODFILE CHECKSUM: 1bf28f5a19566c567d265232f60ee19a3ae86ed3
7575

7676
COCOAPODS: 1.13.0

0 commit comments

Comments
 (0)