Skip to content

Commit 7d62ce2

Browse files
authored
Merge pull request #1681 from matrix-org/andy/libolm_migration
Create Crypto V2 Migration Data
2 parents 41a9445 + 02d3318 commit 7d62ce2

21 files changed

+887
-86
lines changed

MatrixSDK.xcodeproj/project.pbxproj

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,14 @@
18741874
ED51943A28462D130006EEC6 /* MXRoomStateUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED51943828462D130006EEC6 /* MXRoomStateUnitTests.swift */; };
18751875
ED51943C284630090006EEC6 /* MXRestClientStub.m in Sources */ = {isa = PBXBuildFile; fileRef = ED51943B284630090006EEC6 /* MXRestClientStub.m */; };
18761876
ED51943D284630090006EEC6 /* MXRestClientStub.m in Sources */ = {isa = PBXBuildFile; fileRef = ED51943B284630090006EEC6 /* MXRestClientStub.m */; };
1877+
ED558068296F0361003443E3 /* MXCryptoMigrationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED558067296F0361003443E3 /* MXCryptoMigrationStore.swift */; };
1878+
ED558069296F0361003443E3 /* MXCryptoMigrationStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED558067296F0361003443E3 /* MXCryptoMigrationStore.swift */; };
1879+
ED55806D296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55806C296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift */; };
1880+
ED55806E296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55806C296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift */; };
1881+
ED558070296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift */; };
1882+
ED558071296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift */; };
1883+
ED5580732970265A003443E3 /* MXCryptoMachineLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED5580722970265A003443E3 /* MXCryptoMachineLogger.swift */; };
1884+
ED5580742970265A003443E3 /* MXCryptoMachineLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED5580722970265A003443E3 /* MXCryptoMachineLogger.swift */; };
18771885
ED5AE8C52816C8CF00105072 /* MXCoreDataRoomSummaryStore.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = ED5AE8C22816C8CF00105072 /* MXCoreDataRoomSummaryStore.xcdatamodeld */; };
18781886
ED5AE8C62816C8CF00105072 /* MXCoreDataRoomSummaryStore.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = ED5AE8C22816C8CF00105072 /* MXCoreDataRoomSummaryStore.xcdatamodeld */; };
18791887
ED5C753C28B3E80300D24E85 /* MXLogger.h in Headers */ = {isa = PBXBuildFile; fileRef = ED5C753528B3E80300D24E85 /* MXLogger.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -2001,6 +2009,8 @@
20012009
EDC8C40E2968C37F003792C5 /* MXKeysQuerySchedulerUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDC8C40A2968A9F7003792C5 /* MXKeysQuerySchedulerUnitTests.swift */; };
20022010
EDCB65E22912AB0C00F55D4D /* MXRoomEventDecryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCB65E12912AB0C00F55D4D /* MXRoomEventDecryption.swift */; };
20032011
EDCB65E32912AB0C00F55D4D /* MXRoomEventDecryption.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCB65E12912AB0C00F55D4D /* MXRoomEventDecryption.swift */; };
2012+
EDCF802D2941FF220059E774 /* MXCryptoMigrationV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCF802C2941FF220059E774 /* MXCryptoMigrationV2.swift */; };
2013+
EDCF802E2941FF220059E774 /* MXCryptoMigrationV2.swift in Sources */ = {isa = PBXBuildFile; fileRef = EDCF802C2941FF220059E774 /* MXCryptoMigrationV2.swift */; };
20042014
EDD4197E28DCAA5F007F3757 /* MXNativeKeyBackupEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = EDD4197D28DCAA5F007F3757 /* MXNativeKeyBackupEngine.h */; };
20052015
EDD4197F28DCAA5F007F3757 /* MXNativeKeyBackupEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = EDD4197D28DCAA5F007F3757 /* MXNativeKeyBackupEngine.h */; };
20062016
EDD4198128DCAA7B007F3757 /* MXNativeKeyBackupEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = EDD4198028DCAA7B007F3757 /* MXNativeKeyBackupEngine.m */; };
@@ -3065,6 +3075,10 @@
30653075
ED51943828462D130006EEC6 /* MXRoomStateUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXRoomStateUnitTests.swift; sourceTree = "<group>"; };
30663076
ED51943B284630090006EEC6 /* MXRestClientStub.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXRestClientStub.m; sourceTree = "<group>"; };
30673077
ED51943E284630100006EEC6 /* MXRestClientStub.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXRestClientStub.h; sourceTree = "<group>"; };
3078+
ED558067296F0361003443E3 /* MXCryptoMigrationStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMigrationStore.swift; sourceTree = "<group>"; };
3079+
ED55806C296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMigrationStoreUnitTests.swift; sourceTree = "<group>"; };
3080+
ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMigrationV2Tests.swift; sourceTree = "<group>"; };
3081+
ED5580722970265A003443E3 /* MXCryptoMachineLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMachineLogger.swift; sourceTree = "<group>"; };
30683082
ED5AE8C32816C8CF00105072 /* MXRoomSummaryCoreDataStore2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MXRoomSummaryCoreDataStore2.xcdatamodel; sourceTree = "<group>"; };
30693083
ED5AE8C42816C8CF00105072 /* MXRoomSummaryCoreDataStore.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MXRoomSummaryCoreDataStore.xcdatamodel; sourceTree = "<group>"; };
30703084
ED5C753528B3E80300D24E85 /* MXLogger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MXLogger.h; sourceTree = "<group>"; };
@@ -3127,6 +3141,7 @@
31273141
EDC8C4072968A993003792C5 /* MXKeysQueryScheduler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXKeysQueryScheduler.swift; sourceTree = "<group>"; };
31283142
EDC8C40A2968A9F7003792C5 /* MXKeysQuerySchedulerUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXKeysQuerySchedulerUnitTests.swift; sourceTree = "<group>"; };
31293143
EDCB65E12912AB0C00F55D4D /* MXRoomEventDecryption.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXRoomEventDecryption.swift; sourceTree = "<group>"; };
3144+
EDCF802C2941FF220059E774 /* MXCryptoMigrationV2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXCryptoMigrationV2.swift; sourceTree = "<group>"; };
31303145
EDD4197D28DCAA5F007F3757 /* MXNativeKeyBackupEngine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXNativeKeyBackupEngine.h; sourceTree = "<group>"; };
31313146
EDD4198028DCAA7B007F3757 /* MXNativeKeyBackupEngine.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MXNativeKeyBackupEngine.m; sourceTree = "<group>"; };
31323147
EDD578DC2881C37C006739DD /* MXDeviceInfoSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MXDeviceInfoSource.swift; sourceTree = "<group>"; };
@@ -4401,9 +4416,11 @@
44014416
32C78B64256CFC4D008130B1 /* Migration */ = {
44024417
isa = PBXGroup;
44034418
children = (
4419+
ED558066296F034F003443E3 /* Data */,
44044420
32C78B65256CFC4D008130B1 /* MXCryptoVersion.h */,
44054421
32C78B66256CFC4D008130B1 /* MXCryptoMigration.m */,
44064422
32C78B67256CFC4D008130B1 /* MXCryptoMigration.h */,
4423+
EDCF802C2941FF220059E774 /* MXCryptoMigrationV2.swift */,
44074424
);
44084425
path = Migration;
44094426
sourceTree = "<group>";
@@ -5350,6 +5367,7 @@
53505367
ED21F67A28104B9A002FF83D /* Crypto */ = {
53515368
isa = PBXGroup;
53525369
children = (
5370+
ED55806A296F0E18003443E3 /* Migration */,
53535371
ED8F1D1428857FD300F897E7 /* CrossSigning */,
53545372
ED8F1D2E2885AAEB00F897E7 /* Trust */,
53555373
ED8F1D292885A7DF00F897E7 /* Devices */,
@@ -5398,6 +5416,7 @@
53985416
isa = PBXGroup;
53995417
children = (
54005418
ED2DD111286C450600F06731 /* MXCryptoMachine.swift */,
5419+
ED5580722970265A003443E3 /* MXCryptoMachineLogger.swift */,
54015420
ED8F1D3A2885BB2D00F897E7 /* MXCryptoProtocols.swift */,
54025421
ED2DD112286C450600F06731 /* MXEventDecryptionResult+DecryptedEvent.swift */,
54035422
ED2DD113286C450600F06731 /* MXCryptoRequests.swift */,
@@ -5475,6 +5494,31 @@
54755494
path = Data;
54765495
sourceTree = "<group>";
54775496
};
5497+
ED558066296F034F003443E3 /* Data */ = {
5498+
isa = PBXGroup;
5499+
children = (
5500+
ED558067296F0361003443E3 /* MXCryptoMigrationStore.swift */,
5501+
);
5502+
path = Data;
5503+
sourceTree = "<group>";
5504+
};
5505+
ED55806A296F0E18003443E3 /* Migration */ = {
5506+
isa = PBXGroup;
5507+
children = (
5508+
ED55806B296F0E1D003443E3 /* Data */,
5509+
ED55806F296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift */,
5510+
);
5511+
path = Migration;
5512+
sourceTree = "<group>";
5513+
};
5514+
ED55806B296F0E1D003443E3 /* Data */ = {
5515+
isa = PBXGroup;
5516+
children = (
5517+
ED55806C296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift */,
5518+
);
5519+
path = Data;
5520+
sourceTree = "<group>";
5521+
};
54785522
ED5C753428B3E80300D24E85 /* Logs */ = {
54795523
isa = PBXGroup;
54805524
children = (
@@ -6801,6 +6845,7 @@
68016845
32999DE022DCD183004FF987 /* MXPusher.m in Sources */,
68026846
F03EF4FF1DF014D9009DF592 /* MXMediaLoader.m in Sources */,
68036847
ECDA763227B293D9000C48CF /* MXThreadProtocol.swift in Sources */,
6848+
EDCF802D2941FF220059E774 /* MXCryptoMigrationV2.swift in Sources */,
68046849
320A8841217F4E3F002EA952 /* MXCurve25519BackupAuthData.m in Sources */,
68056850
B1A0270226162110001AADFF /* MXSpaceChildrenResponse.m in Sources */,
68066851
66398BA527A4085B00466E89 /* MXRefreshResponse.m in Sources */,
@@ -6952,6 +6997,7 @@
69526997
ED647E3E292CE64400A47519 /* MXSessionSyncProgress.swift in Sources */,
69536998
EC8A53C525B1BC77004E0802 /* MXTurnServerResponse.m in Sources */,
69546999
32A151271DABB0CB00400192 /* MXMegolmDecryption.m in Sources */,
7000+
ED558068296F0361003443E3 /* MXCryptoMigrationStore.swift in Sources */,
69557001
18121F78273E6E1E00B68ADF /* PollBuilder.swift in Sources */,
69567002
327A5F50239805F600ED6329 /* MXKeyVerificationKey.m in Sources */,
69577003
B16C56E2261D0A9D00604765 /* MXSpaceChildInfo.swift in Sources */,
@@ -7234,6 +7280,7 @@
72347280
B1F04B132811E9D300103EBE /* MXBeaconInfoSummaryStoreProtocol.swift in Sources */,
72357281
183892802702F553003F0C4F /* MXRoomNameDefaultStringLocalizer.m in Sources */,
72367282
C6F9358B1E5B3BE600FC34BF /* MXJSONModels.swift in Sources */,
7283+
ED5580732970265A003443E3 /* MXCryptoMachineLogger.swift in Sources */,
72377284
EC8A539725B1BC77004E0802 /* MXCallReplacesEventContent.m in Sources */,
72387285
B135066E27EA44C800BD3276 /* MXLocationServiceError.swift in Sources */,
72397286
32FA10C21FA1C9EE00E54233 /* MXOutgoingRoomKeyRequestManager.m in Sources */,
@@ -7271,6 +7318,7 @@
72717318
18121F75273E6D2400B68ADF /* MXPollBuilderTests.swift in Sources */,
72727319
ED7019F72886CA6C00FC31B9 /* VerificationRequestStub.swift in Sources */,
72737320
B14EECEE2578FE3F00448735 /* MXAuthenticationSessionUnitTests.swift in Sources */,
7321+
ED558070296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift in Sources */,
72747322
ED2DD11D286C4F4400F06731 /* MXCryptoRequestsUnitTests.swift in Sources */,
72757323
32832B5D1BCC048300241108 /* MXStoreMemoryStoreTests.m in Sources */,
72767324
EDB4209927DF842F0036AF39 /* MXEventFixtures.swift in Sources */,
@@ -7349,6 +7397,7 @@
73497397
ED7019FB2886CA6C00FC31B9 /* MXSASTransactionV2UnitTests.swift in Sources */,
73507398
32B0E3E723A3864C0054FF1A /* MXEventReferenceUnitTests.swift in Sources */,
73517399
32720DA2222EB5650086FFF5 /* MXAutoDiscoveryTests.m in Sources */,
7400+
ED55806D296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift in Sources */,
73527401
ED8943D427E34762000FC39C /* MXMemoryRoomStoreUnitTests.swift in Sources */,
73537402
ED5C95CE2833E85600843D82 /* MXOlmDeviceUnitTests.swift in Sources */,
73547403
327E37B91A977810007F026F /* MXLoggerUnitTests.m in Sources */,
@@ -7452,6 +7501,7 @@
74527501
ECDA763327B293D9000C48CF /* MXThreadProtocol.swift in Sources */,
74537502
B14EF1E02397E90400758AF0 /* MXRealmCryptoStore.m in Sources */,
74547503
B14EF1E12397E90400758AF0 /* MXRoomSummary.m in Sources */,
7504+
EDCF802E2941FF220059E774 /* MXCryptoMigrationV2.swift in Sources */,
74557505
66398BA627A4085B00466E89 /* MXRefreshResponse.m in Sources */,
74567506
B14EF1E22397E90400758AF0 /* MXPushRuleRoomMemberCountConditionChecker.m in Sources */,
74577507
B14EF1E32397E90400758AF0 /* MXCall.m in Sources */,
@@ -7603,6 +7653,7 @@
76037653
ED647E3F292CE64400A47519 /* MXSessionSyncProgress.swift in Sources */,
76047654
B14EF2212397E90400758AF0 /* MX3PID.swift in Sources */,
76057655
18121F79273E6E4100B68ADF /* PollBuilder.swift in Sources */,
7656+
ED558069296F0361003443E3 /* MXCryptoMigrationStore.swift in Sources */,
76067657
EC383BB325406892002FBBE6 /* MXSyncResponseStore.swift in Sources */,
76077658
ECBF658826DE3DF800AA3A99 /* MXFileRoomOutgoingMessagesStore.m in Sources */,
76087659
B14EF2222397E90400758AF0 /* MXMediaScan.m in Sources */,
@@ -7885,6 +7936,7 @@
78857936
B1F04B142811E9D300103EBE /* MXBeaconInfoSummaryStoreProtocol.swift in Sources */,
78867937
EC8A53A225B1BC77004E0802 /* MXCallSelectAnswerEventContent.m in Sources */,
78877938
183892812702F553003F0C4F /* MXRoomNameDefaultStringLocalizer.m in Sources */,
7939+
ED5580742970265A003443E3 /* MXCryptoMachineLogger.swift in Sources */,
78887940
B14EF2912397E90400758AF0 /* MXOutgoingRoomKeyRequestManager.m in Sources */,
78897941
B14EF2922397E90400758AF0 /* MXWellKnown.m in Sources */,
78907942
B1A026F926161EF5001AADFF /* MXSpaceChildSummaryResponse.m in Sources */,
@@ -7922,6 +7974,7 @@
79227974
B1E09A442397FD940057C069 /* Dummy.swift in Sources */,
79237975
ED7019F82886CA6C00FC31B9 /* VerificationRequestStub.swift in Sources */,
79247976
18121F76273E6D2400B68ADF /* MXPollBuilderTests.swift in Sources */,
7977+
ED558071296F1BEE003443E3 /* MXCryptoMigrationV2Tests.swift in Sources */,
79257978
B1E09A1A2397FCE90057C069 /* MXAggregatedEditsTests.m in Sources */,
79267979
B1E09A1F2397FCE90057C069 /* MXAutoDiscoveryTests.m in Sources */,
79277980
EDB4209A27DF842F0036AF39 /* MXEventFixtures.swift in Sources */,
@@ -8000,6 +8053,7 @@
80008053
32B4778F2638133D00EA5800 /* MXJSONModelUnitTests.m in Sources */,
80018054
B1F939F626289F2600D0E525 /* MXSpaceChildContentTests.swift in Sources */,
80028055
EC40386828A279220067D5B8 /* MXKeyBackupUnitTests.swift in Sources */,
8056+
ED55806E296F0E3A003443E3 /* MXCryptoMigrationStoreUnitTests.swift in Sources */,
80038057
B1E09A412397FD820057C069 /* MXAccountDataTests.m in Sources */,
80048058
B1E09A2D2397FD750057C069 /* MXRestClientNoAuthAPITests.m in Sources */,
80058059
ED8943D527E34762000FC39C /* MXMemoryRoomStoreUnitTests.swift in Sources */,

MatrixSDK/Background/MXBackgroundCryptoStore.m

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ - (void)performSessionOperationWithDevice:(NSString*)deviceKey andSessionId:(NSS
180180
if (olmSession)
181181
{
182182
MXLogDebug(@"[MXBackgroundCryptoStore] performSessionOperationWithDevice: Transfer data for %@ from cryptoStore to bgCryptoStore", sessionId);
183-
[bgCryptoStore storeSession:olmSession forDevice:deviceKey];
183+
[bgCryptoStore storeSession:olmSession];
184184
}
185185
}
186186

@@ -209,9 +209,21 @@ - (MXOlmSession*)sessionWithDevice:(NSString*)deviceKey andSessionId:(NSString*)
209209
return sessions;
210210
}
211211

212-
- (void)storeSession:(MXOlmSession*)session forDevice:(NSString*)deviceKey
212+
- (NSArray<MXOlmSession *> *)sessions
213213
{
214-
[bgCryptoStore storeSession:session forDevice:deviceKey];
214+
NSArray<MXOlmSession*> *bgSessions = [bgCryptoStore sessions] ?: @[];
215+
NSArray<MXOlmSession*> *appSessions = [cryptoStore sessions] ?: @[];
216+
217+
NSMutableArray<MXOlmSession*> *sessions = [NSMutableArray array];
218+
[sessions addObjectsFromArray:bgSessions];
219+
[sessions addObjectsFromArray:appSessions];
220+
221+
return sessions;
222+
}
223+
224+
- (void)storeSession:(MXOlmSession*)session
225+
{
226+
[bgCryptoStore storeSession:session];
215227
}
216228

217229

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

337+
- (NSString *)userId
338+
{
339+
NSAssert(NO, @"This method should be useless in the context of MXBackgroundCryptoStore");
340+
return nil;
341+
}
342+
325343
- (void)storeDeviceId:(NSString*)deviceId
326344
{
327345
NSAssert(NO, @"This method should be useless in the context of MXBackgroundCryptoStore");

MatrixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class MXCryptoMachine {
8080
getRoomAction: @escaping GetRoomAction
8181
) throws {
8282
let url = try Self.storeURL(for: userId)
83+
8384
machine = try OlmMachine(
8485
userId: userId,
8586
deviceId: deviceId,
@@ -93,8 +94,6 @@ class MXCryptoMachine {
9394
try await requests.queryKeys(users: users)
9495
}
9596
self.getRoomAction = getRoomAction
96-
97-
setLogger(logger: self)
9897
}
9998

10099
func start() async throws {
@@ -751,10 +750,4 @@ extension MXCryptoMachine: MXCryptoBackup {
751750
}
752751
}
753752

754-
extension MXCryptoMachine: Logger {
755-
func log(logLine: String) {
756-
MXLog.debug("[MXCryptoMachine] \(logLine)")
757-
}
758-
}
759-
760753
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Copyright 2023 The Matrix.org Foundation C.I.C
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
import Foundation
18+
19+
#if DEBUG
20+
21+
import MatrixSDKCrypto
22+
23+
/// Redirects logs originating in `MatrixSDKCrypto` into `MXLog`
24+
class MXCryptoMachineLogger: Logger {
25+
init() {
26+
setLogger(logger: self)
27+
}
28+
29+
func log(logLine: String) {
30+
// Excluding some auto-generated logs that are not useful
31+
// This will be changed in rust-sdk directly
32+
guard !logLine.contains("::uniffi_api:") else {
33+
return
34+
}
35+
36+
MXLog.debug("[MXCryptoMachine] \(logLine)")
37+
}
38+
}
39+
40+
#endif

MatrixSDK/Crypto/Data/MXOlmSession.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ NS_ASSUME_NONNULL_BEGIN
3030
@interface MXOlmSession : NSObject
3131

3232

33-
- (instancetype)initWithOlmSession:(OLMSession*)session;
33+
- (instancetype)initWithOlmSession:(OLMSession*)session
34+
deviceKey:(NSString*)deviceKey;
35+
36+
/**
37+
The curve25519 key of the other user that we share this session with.
38+
*/
39+
@property (nonatomic, readonly) NSString *deviceKey;
3440

3541
/**
3642
The associated olm session.

MatrixSDK/Crypto/Data/MXOlmSession.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919

2020
@implementation MXOlmSession
2121

22-
- (instancetype)initWithOlmSession:(OLMSession *)session
22+
- (instancetype)initWithOlmSession:(OLMSession *)session deviceKey:(NSString *)deviceKey
2323
{
2424
self = [super init];
2525
if (self)
2626
{
2727
_session = session;
28+
_deviceKey = deviceKey;
2829
_lastReceivedMessageTs = 0;
2930
}
3031
return self;

MatrixSDK/Crypto/Data/Store/MXCryptoStore.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494
*/
9595
- (void)open:(void (^)(void))onComplete failure:(void (^)(NSError *error))failure;
9696

97+
/**
98+
The user id.
99+
*/
100+
- (NSString*)userId;
101+
97102
/**
98103
Store the device id.
99104
*/
@@ -256,10 +261,9 @@
256261
/**
257262
Store a session between this device and another device.
258263
259-
@param deviceKey the public key of the other device.
260264
@param session the end-to-end session.
261265
*/
262-
- (void)storeSession:(MXOlmSession*)session forDevice:(NSString*)deviceKey;
266+
- (void)storeSession:(MXOlmSession*)session;
263267

264268
/**
265269
Retrieve an end-to-end session between this device and another device.
@@ -291,6 +295,12 @@
291295
*/
292296
- (NSArray<MXOlmSession*>*)sessionsWithDevice:(NSString*)deviceKey;
293297

298+
/**
299+
Retrieve all end-to-end sessions between this device and all other devices
300+
301+
@return a array of end-to-end sessions.
302+
*/
303+
- (NSArray<MXOlmSession*>*)sessions;
294304

295305
/**
296306
Store inbound group sessions.

0 commit comments

Comments
 (0)