@@ -68,7 +68,7 @@ import {
68
68
mockSetupMegolmBackupRequests ,
69
69
} from "../../test-utils/mockEndpoints" ;
70
70
import { AddSecretStorageKeyOpts , SECRET_STORAGE_ALGORITHM_V1_AES } from "../../../src/secret-storage" ;
71
- import { CryptoCallbacks , KeyBackupInfo } from "../../../src/crypto-api" ;
71
+ import { CrossSigningKey , CryptoCallbacks , KeyBackupInfo } from "../../../src/crypto-api" ;
72
72
import { E2EKeyResponder } from "../../test-utils/E2EKeyResponder" ;
73
73
74
74
afterEach ( ( ) => {
@@ -2247,7 +2247,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
2247
2247
}
2248
2248
2249
2249
/**
2250
- * Add all mocks needed to set up cross-signing, key backup, 4S and then
2250
+ * Add all mocks needed to setup cross-signing, key backup, 4S and then
2251
2251
* configure the account to have recovery.
2252
2252
*
2253
2253
* @param backupVersion - The version of the created backup
@@ -2295,7 +2295,6 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
2295
2295
await bootstrapPromise ;
2296
2296
// Finally ensure backup is working
2297
2297
await aliceClient . getCrypto ( ) ! . checkKeyBackupAndEnable ( ) ;
2298
-
2299
2298
await backupStatusUpdate ;
2300
2299
}
2301
2300
@@ -2346,7 +2345,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
2346
2345
} ,
2347
2346
) ;
2348
2347
2349
- newBackendOnly ( "should create a new key" , async ( ) => {
2348
+ it ( "should create a new key" , async ( ) => {
2350
2349
const bootstrapPromise = aliceClient
2351
2350
. getCrypto ( ) !
2352
2351
. bootstrapSecretStorage ( { setupNewSecretStorage : true , createSecretStorageKey } ) ;
@@ -2389,46 +2388,43 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
2389
2388
} ,
2390
2389
) ;
2391
2390
2392
- newBackendOnly (
2393
- "should create a new key if setupNewSecretStorage is at true even if an AES key is already in the secret storage" ,
2394
- async ( ) => {
2395
- let bootstrapPromise = aliceClient
2396
- . getCrypto ( ) !
2397
- . bootstrapSecretStorage ( { setupNewSecretStorage : true , createSecretStorageKey } ) ;
2391
+ it ( "should create a new key if setupNewSecretStorage is at true even if an AES key is already in the secret storage" , async ( ) => {
2392
+ let bootstrapPromise = aliceClient
2393
+ . getCrypto ( ) !
2394
+ . bootstrapSecretStorage ( { setupNewSecretStorage : true , createSecretStorageKey } ) ;
2398
2395
2399
- // Wait for the key to be uploaded in the account data
2400
- let secretStorageKey = await awaitSecretStorageKeyStoredInAccountData ( ) ;
2396
+ // Wait for the key to be uploaded in the account data
2397
+ let secretStorageKey = await awaitSecretStorageKeyStoredInAccountData ( ) ;
2401
2398
2402
- // Return the newly created key in the sync response
2403
- sendSyncResponse ( secretStorageKey ) ;
2399
+ // Return the newly created key in the sync response
2400
+ sendSyncResponse ( secretStorageKey ) ;
2404
2401
2405
- // Wait for bootstrapSecretStorage to finished
2406
- await bootstrapPromise ;
2402
+ // Wait for bootstrapSecretStorage to finished
2403
+ await bootstrapPromise ;
2407
2404
2408
- // Call again bootstrapSecretStorage
2409
- bootstrapPromise = aliceClient
2410
- . getCrypto ( ) !
2411
- . bootstrapSecretStorage ( { setupNewSecretStorage : true , createSecretStorageKey } ) ;
2405
+ // Call again bootstrapSecretStorage
2406
+ bootstrapPromise = aliceClient
2407
+ . getCrypto ( ) !
2408
+ . bootstrapSecretStorage ( { setupNewSecretStorage : true , createSecretStorageKey } ) ;
2412
2409
2413
- // Wait for the key to be uploaded in the account data
2414
- secretStorageKey = await awaitSecretStorageKeyStoredInAccountData ( ) ;
2410
+ // Wait for the key to be uploaded in the account data
2411
+ secretStorageKey = await awaitSecretStorageKeyStoredInAccountData ( ) ;
2415
2412
2416
- // Return the newly created key in the sync response
2417
- sendSyncResponse ( secretStorageKey ) ;
2413
+ // Return the newly created key in the sync response
2414
+ sendSyncResponse ( secretStorageKey ) ;
2418
2415
2419
- // Wait for bootstrapSecretStorage to finished
2420
- await bootstrapPromise ;
2416
+ // Wait for bootstrapSecretStorage to finished
2417
+ await bootstrapPromise ;
2421
2418
2422
- // createSecretStorageKey should have been called twice, one time every bootstrapSecretStorage call
2423
- expect ( createSecretStorageKey ) . toHaveBeenCalledTimes ( 2 ) ;
2424
- } ,
2425
- ) ;
2419
+ // createSecretStorageKey should have been called twice, one time every bootstrapSecretStorage call
2420
+ expect ( createSecretStorageKey ) . toHaveBeenCalledTimes ( 2 ) ;
2421
+ } ) ;
2426
2422
2427
- newBackendOnly ( "should upload cross signing keys" , async ( ) => {
2423
+ it ( "should upload cross signing keys" , async ( ) => {
2428
2424
mockSetupCrossSigningRequests ( ) ;
2429
2425
2430
2426
// Before setting up secret-storage, bootstrap cross-signing, so that the client has cross-signing keys.
2431
- await aliceClient . getCrypto ( ) ? .bootstrapCrossSigning ( { } ) ;
2427
+ await aliceClient . getCrypto ( ) ! . bootstrapCrossSigning ( { } ) ;
2432
2428
2433
2429
// Now, when we bootstrap secret-storage, the cross-signing keys should be uploaded.
2434
2430
const bootstrapPromise = aliceClient
@@ -2457,16 +2453,24 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
2457
2453
expect ( selfSigningKey [ secretStorageKey ] ) . toBeDefined ( ) ;
2458
2454
} ) ;
2459
2455
2460
- oldBackendOnly ( "should create a new megolm backup" , async ( ) => {
2456
+ it ( "should create a new megolm backup" , async ( ) => {
2461
2457
const backupVersion = "abc" ;
2462
2458
await bootstrapSecurity ( backupVersion ) ;
2463
2459
2464
2460
// Expect a backup to be available and used
2465
2461
const activeBackup = await aliceClient . getCrypto ( ) ! . getActiveSessionBackupVersion ( ) ;
2466
2462
expect ( activeBackup ) . toStrictEqual ( backupVersion ) ;
2463
+
2464
+ // check that there is a MSK signature
2465
+ const signatures = ( await aliceClient . getCrypto ( ) ! . checkKeyBackupAndEnable ( ) ) ! . backupInfo . auth_data !
2466
+ . signatures ;
2467
+ expect ( signatures ) . toBeDefined ( ) ;
2468
+ expect ( signatures ! [ aliceClient . getUserId ( ) ! ] ) . toBeDefined ( ) ;
2469
+ const mskId = await aliceClient . getCrypto ( ) ! . getCrossSigningKeyId ( CrossSigningKey . Master ) ! ;
2470
+ expect ( signatures ! [ aliceClient . getUserId ( ) ! ] [ `ed25519:${ mskId } ` ] ) . toBeDefined ( ) ;
2467
2471
} ) ;
2468
2472
2469
- oldBackendOnly ( "Reset key backup should create a new backup and update 4S" , async ( ) => {
2473
+ it ( "Reset key backup should create a new backup and update 4S" , async ( ) => {
2470
2474
// First set up 4S and key backup
2471
2475
const backupVersion = "1" ;
2472
2476
await bootstrapSecurity ( backupVersion ) ;
@@ -2539,10 +2543,11 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("crypto (%s)", (backend: string,
2539
2543
expect ( nextVersion ) . not . toEqual ( currentVersion ) ;
2540
2544
expect ( nextKey ) . not . toEqual ( currentBackupKey ) ;
2541
2545
2542
- // Test deletion of the backup
2543
- await aliceClient . getCrypto ( ) ! . deleteKeyBackupVersion ( nextVersion ! ) ;
2546
+ // The `deleteKeyBackupVersion` API is deprecated but has been modified to work with both crypto backend
2547
+ // ensure that it works anyhow
2548
+ await aliceClient . deleteKeyBackupVersion ( nextVersion ! ) ;
2544
2549
await aliceClient . getCrypto ( ) ! . checkKeyBackupAndEnable ( ) ;
2545
- // XXX Legacy crypto does not update 4S when deleting backup ; should ensure that rust implem does it.
2550
+ // XXX Legacy crypto does not update 4S when doing that ; should ensure that rust implem does it.
2546
2551
expect ( await aliceClient . getCrypto ( ) ! . getActiveSessionBackupVersion ( ) ) . toBeNull ( ) ;
2547
2552
} ) ;
2548
2553
} ) ;
0 commit comments