@@ -1276,6 +1276,24 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
1276
1276
this . checkKeyBackupAndEnable ( ) ;
1277
1277
}
1278
1278
1279
+ /**
1280
+ * Implementation of {@link CryptoApi#disableKeyStorage}.
1281
+ */
1282
+ public async disableKeyStorage ( ) : Promise < void > {
1283
+ // Get the key backup version we're using
1284
+ const info = await this . getKeyBackupInfo ( ) ;
1285
+ if ( info ?. version ) {
1286
+ await this . deleteKeyBackupVersion ( info . version ) ;
1287
+ } else {
1288
+ logger . error ( "Can't delete key backup version: no version available" ) ;
1289
+ }
1290
+
1291
+ // also turn off 4S, since this is also storing keys on the server.
1292
+ await this . deleteSecretStorage ( ) ;
1293
+
1294
+ await this . dehydratedDeviceManager . delete ( ) ;
1295
+ }
1296
+
1279
1297
/**
1280
1298
* Signs the given object with the current device and current identity (if available).
1281
1299
* As defined in {@link https://spec.matrix.org/v1.8/appendices/#signing-json | Signing JSON}.
@@ -1447,17 +1465,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
1447
1465
// Disable backup, and delete all the backups from the server
1448
1466
await this . backupManager . deleteAllKeyBackupVersions ( ) ;
1449
1467
1450
- // Remove the stored secrets in the secret storage
1451
- await this . secretStorage . store ( "m.cross_signing.master" , null ) ;
1452
- await this . secretStorage . store ( "m.cross_signing.self_signing" , null ) ;
1453
- await this . secretStorage . store ( "m.cross_signing.user_signing" , null ) ;
1454
- await this . secretStorage . store ( "m.megolm_backup.v1" , null ) ;
1455
-
1456
- // Remove the recovery key
1457
- const defaultKeyId = await this . secretStorage . getDefaultKeyId ( ) ;
1458
- if ( defaultKeyId ) await this . secretStorage . store ( `m.secret_storage.key.${ defaultKeyId } ` , null ) ;
1459
- // Disable the recovery key and the secret storage
1460
- await this . secretStorage . setDefaultKeyId ( null ) ;
1468
+ this . deleteSecretStorage ( ) ;
1461
1469
1462
1470
// Reset the cross-signing keys
1463
1471
await this . crossSigningIdentity . bootstrapCrossSigning ( {
@@ -1471,6 +1479,24 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
1471
1479
this . logger . debug ( "resetEncryption: ended" ) ;
1472
1480
}
1473
1481
1482
+ /**
1483
+ * Removes the secret storage key, default key pointer and all (known) secret storage data
1484
+ * from the user's account data
1485
+ */
1486
+ private async deleteSecretStorage ( ) : Promise < void > {
1487
+ // Remove the stored secrets in the secret storage
1488
+ await this . secretStorage . store ( "m.cross_signing.master" , null ) ;
1489
+ await this . secretStorage . store ( "m.cross_signing.self_signing" , null ) ;
1490
+ await this . secretStorage . store ( "m.cross_signing.user_signing" , null ) ;
1491
+ await this . secretStorage . store ( "m.megolm_backup.v1" , null ) ;
1492
+
1493
+ // Remove the recovery key
1494
+ const defaultKeyId = await this . secretStorage . getDefaultKeyId ( ) ;
1495
+ if ( defaultKeyId ) await this . secretStorage . store ( `m.secret_storage.key.${ defaultKeyId } ` , null ) ;
1496
+ // Disable the recovery key and the secret storage
1497
+ await this . secretStorage . setDefaultKeyId ( null ) ;
1498
+ }
1499
+
1474
1500
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1475
1501
//
1476
1502
// SyncCryptoCallbacks implementation
0 commit comments