@@ -51,7 +51,6 @@ import {
51
51
IContent ,
52
52
IDownloadKeyResult ,
53
53
IEvent ,
54
- IndexedDBCryptoStore ,
55
54
IStartClientOpts ,
56
55
MatrixClient ,
57
56
MatrixEvent ,
@@ -1901,7 +1900,6 @@ describe("crypto", () => {
1901
1900
} ) ;
1902
1901
1903
1902
describe ( "bootstrapSecretStorage" , ( ) => {
1904
- // Doesn't work with legacy crypto, which will try to bootstrap even without private key, which is buggy.
1905
1903
it ( "should throw an error if we are unable to create a key because createSecretStorageKey is not set" , async ( ) => {
1906
1904
await expect (
1907
1905
aliceClient . getCrypto ( ) ! . bootstrapSecretStorage ( { setupNewSecretStorage : true } ) ,
@@ -1947,8 +1945,6 @@ describe("crypto", () => {
1947
1945
} ) ;
1948
1946
1949
1947
it ( "should do nothing if an AES key is already in the secret storage and setupNewSecretStorage is not set" , async ( ) => {
1950
- const awaitAccountDataClientUpdate = awaitAccountDataUpdate ( "m.secret_storage.default_key" ) ;
1951
-
1952
1948
const bootstrapPromise = aliceClient . getCrypto ( ) ! . bootstrapSecretStorage ( { createSecretStorageKey } ) ;
1953
1949
1954
1950
// Wait for the key to be uploaded in the account data
@@ -1960,9 +1956,6 @@ describe("crypto", () => {
1960
1956
// Wait for bootstrapSecretStorage to finished
1961
1957
await bootstrapPromise ;
1962
1958
1963
- // On legacy crypto we need to wait for ClientEvent.AccountData before calling bootstrap again.
1964
- await awaitAccountDataClientUpdate ;
1965
-
1966
1959
// Call again bootstrapSecretStorage
1967
1960
await aliceClient . getCrypto ( ) ! . bootstrapSecretStorage ( { createSecretStorageKey } ) ;
1968
1961
@@ -2210,7 +2203,6 @@ describe("crypto", () => {
2210
2203
2211
2204
await aliceClient . getCrypto ( ) ! . deleteKeyBackupVersion ( nextVersion ! ) ;
2212
2205
await aliceClient . getCrypto ( ) ! . checkKeyBackupAndEnable ( ) ;
2213
- // XXX Legacy crypto does not update 4S when doing that; should ensure that rust implem does it.
2214
2206
expect ( await aliceClient . getCrypto ( ) ! . getActiveSessionBackupVersion ( ) ) . toBeNull ( ) ;
2215
2207
} ) ;
2216
2208
} ) ;
@@ -2313,7 +2305,7 @@ describe("crypto", () => {
2313
2305
2314
2306
/** Guards against downgrade attacks from servers hiding or manipulating the crypto settings. */
2315
2307
describe ( "Persistent encryption settings" , ( ) => {
2316
- let persistentStoreClient : MatrixClient ;
2308
+ let client1 : MatrixClient ;
2317
2309
let client2 : MatrixClient ;
2318
2310
2319
2311
beforeEach ( async ( ) => {
@@ -2326,26 +2318,27 @@ describe("crypto", () => {
2326
2318
// For legacy crypto, these tests only work properly with a proper (indexeddb-based) CryptoStore, so
2327
2319
// rather than using the existing `aliceClient`, create a new client. Once we drop legacy crypto, we can
2328
2320
// just use `aliceClient` here.
2329
- persistentStoreClient = await makeNewClient ( homeserverurl , userId , "persistentStoreClient" ) ;
2330
- await persistentStoreClient . startClient ( { } ) ;
2321
+ // XXX: Even with the rust-crypto, we need to create to a new client. The tests fail with a timeout error.
2322
+ client1 = await makeNewClient ( homeserverurl , userId , "client1" ) ;
2323
+ await client1 . startClient ( { } ) ;
2331
2324
} ) ;
2332
2325
2333
2326
afterEach ( async ( ) => {
2334
- persistentStoreClient . stopClient ( ) ;
2327
+ client1 . stopClient ( ) ;
2335
2328
client2 ?. stopClient ( ) ;
2336
2329
} ) ;
2337
2330
2338
2331
test ( "Sending a message in a room where the server is hiding the state event does not send a plaintext event" , async ( ) => {
2339
2332
// Alice is in an encrypted room
2340
2333
const encryptionState = mkEncryptionEvent ( { algorithm : "m.megolm.v1.aes-sha2" } ) ;
2341
2334
syncResponder . sendOrQueueSyncResponse ( getSyncResponseWithState ( [ encryptionState ] ) ) ;
2342
- await syncPromise ( persistentStoreClient ) ;
2335
+ await syncPromise ( client1 ) ;
2343
2336
2344
2337
// Send a message, and expect to get an `m.room.encrypted` event.
2345
- await Promise . all ( [ persistentStoreClient . sendTextMessage ( ROOM_ID , "test" ) , expectEncryptedSendMessage ( ) ] ) ;
2338
+ await Promise . all ( [ client1 . sendTextMessage ( ROOM_ID , "test" ) , expectEncryptedSendMessage ( ) ] ) ;
2346
2339
2347
2340
// We now replace the client, and allow the new one to resync, *without* the encryption event.
2348
- client2 = await replaceClient ( persistentStoreClient ) ;
2341
+ client2 = await replaceClient ( client1 ) ;
2349
2342
syncResponder . sendOrQueueSyncResponse ( getSyncResponseWithState ( [ ] ) ) ;
2350
2343
await client2 . startClient ( { } ) ;
2351
2344
await syncPromise ( client2 ) ;
@@ -2358,11 +2351,11 @@ describe("crypto", () => {
2358
2351
// Alice is in an encrypted room, where the rotation period is set to 2 messages
2359
2352
const encryptionState = mkEncryptionEvent ( { algorithm : "m.megolm.v1.aes-sha2" , rotation_period_msgs : 2 } ) ;
2360
2353
syncResponder . sendOrQueueSyncResponse ( getSyncResponseWithState ( [ encryptionState ] ) ) ;
2361
- await syncPromise ( persistentStoreClient ) ;
2354
+ await syncPromise ( client1 ) ;
2362
2355
2363
2356
// Send a message, and expect to get an `m.room.encrypted` event.
2364
2357
const [ , msg1Content ] = await Promise . all ( [
2365
- persistentStoreClient . sendTextMessage ( ROOM_ID , "test1" ) ,
2358
+ client1 . sendTextMessage ( ROOM_ID , "test1" ) ,
2366
2359
expectEncryptedSendMessage ( ) ,
2367
2360
] ) ;
2368
2361
@@ -2376,17 +2369,17 @@ describe("crypto", () => {
2376
2369
next_batch : "1" ,
2377
2370
rooms : { join : { [ TEST_ROOM_ID ] : { timeline : { events : [ encryptionState2 ] , prev_batch : "" } } } } ,
2378
2371
} ) ;
2379
- await syncPromise ( persistentStoreClient ) ;
2372
+ await syncPromise ( client1 ) ;
2380
2373
2381
2374
// Send two more messages. The first should use the same megolm session as the first; the second should
2382
2375
// use a different one.
2383
2376
const [ , msg2Content ] = await Promise . all ( [
2384
- persistentStoreClient . sendTextMessage ( ROOM_ID , "test2" ) ,
2377
+ client1 . sendTextMessage ( ROOM_ID , "test2" ) ,
2385
2378
expectEncryptedSendMessage ( ) ,
2386
2379
] ) ;
2387
2380
expect ( msg2Content . session_id ) . toEqual ( msg1Content . session_id ) ;
2388
2381
const [ , msg3Content ] = await Promise . all ( [
2389
- persistentStoreClient . sendTextMessage ( ROOM_ID , "test3" ) ,
2382
+ client1 . sendTextMessage ( ROOM_ID , "test3" ) ,
2390
2383
expectEncryptedSendMessage ( ) ,
2391
2384
] ) ;
2392
2385
expect ( msg3Content . session_id ) . not . toEqual ( msg1Content . session_id ) ;
@@ -2396,13 +2389,13 @@ describe("crypto", () => {
2396
2389
// Alice is in an encrypted room, where the rotation period is set to 2 messages
2397
2390
const encryptionState = mkEncryptionEvent ( { algorithm : "m.megolm.v1.aes-sha2" , rotation_period_msgs : 2 } ) ;
2398
2391
syncResponder . sendOrQueueSyncResponse ( getSyncResponseWithState ( [ encryptionState ] ) ) ;
2399
- await syncPromise ( persistentStoreClient ) ;
2392
+ await syncPromise ( client1 ) ;
2400
2393
2401
2394
// Send a message, and expect to get an `m.room.encrypted` event.
2402
- await Promise . all ( [ persistentStoreClient . sendTextMessage ( ROOM_ID , "test1" ) , expectEncryptedSendMessage ( ) ] ) ;
2395
+ await Promise . all ( [ client1 . sendTextMessage ( ROOM_ID , "test1" ) , expectEncryptedSendMessage ( ) ] ) ;
2403
2396
2404
2397
// We now replace the client, and allow the new one to resync with a *different* encryption event.
2405
- client2 = await replaceClient ( persistentStoreClient ) ;
2398
+ client2 = await replaceClient ( client1 ) ;
2406
2399
const encryptionState2 = mkEncryptionEvent ( {
2407
2400
algorithm : "m.megolm.v1.aes-sha2" ,
2408
2401
rotation_period_msgs : 100 ,
@@ -2433,11 +2426,7 @@ describe("crypto", () => {
2433
2426
userId : userId ,
2434
2427
accessToken : "akjgkrgjs" ,
2435
2428
deviceId : "xzcvb" ,
2436
- cryptoCallbacks : createCryptoCallbacks ( ) ,
2437
2429
logger : logger . getChild ( loggerPrefix ) ,
2438
-
2439
- // For legacy crypto, these tests only work with a proper persistent cryptoStore.
2440
- cryptoStore : new IndexedDBCryptoStore ( indexedDB , "test" ) ,
2441
2430
} ) ;
2442
2431
await client . initRustCrypto ( ) ;
2443
2432
mockInitialApiRequests ( client . getHomeserverUrl ( ) ) ;
@@ -2446,7 +2435,7 @@ describe("crypto", () => {
2446
2435
2447
2436
function mkEncryptionEvent ( content : object ) {
2448
2437
return mkEventCustom ( {
2449
- sender : persistentStoreClient . getSafeUserId ( ) ,
2438
+ sender : client1 . getSafeUserId ( ) ,
2450
2439
type : "m.room.encryption" ,
2451
2440
state_key : "" ,
2452
2441
content : content ,
@@ -2463,7 +2452,7 @@ describe("crypto", () => {
2463
2452
events : [
2464
2453
mkMembershipCustom ( {
2465
2454
membership : KnownMembership . Join ,
2466
- sender : persistentStoreClient . getSafeUserId ( ) ,
2455
+ sender : client1 . getSafeUserId ( ) ,
2467
2456
} ) ,
2468
2457
...stateEvents ,
2469
2458
] ,
0 commit comments