@@ -1276,6 +1276,24 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
12761276 this . checkKeyBackupAndEnable ( ) ;
12771277 }
12781278
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+
12791297 /**
12801298 * Signs the given object with the current device and current identity (if available).
12811299 * 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
14471465 // Disable backup, and delete all the backups from the server
14481466 await this . backupManager . deleteAllKeyBackupVersions ( ) ;
14491467
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 ( ) ;
14611469
14621470 // Reset the cross-signing keys
14631471 await this . crossSigningIdentity . bootstrapCrossSigning ( {
@@ -1471,6 +1479,24 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
14711479 this . logger . debug ( "resetEncryption: ended" ) ;
14721480 }
14731481
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+
14741500 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
14751501 //
14761502 // SyncCryptoCallbacks implementation
0 commit comments