You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-01 04:43:29 +03:00
Merge pull request #586 from matrix-org/dbkr/crypto_store_migrate_warning
Emit an event for crypto store migration
This commit is contained in:
@@ -391,6 +391,7 @@ MatrixClient.prototype.initCrypto = async function() {
|
|||||||
this.reEmitter.reEmit(crypto, [
|
this.reEmitter.reEmit(crypto, [
|
||||||
"crypto.roomKeyRequest",
|
"crypto.roomKeyRequest",
|
||||||
"crypto.roomKeyRequestCancellation",
|
"crypto.roomKeyRequestCancellation",
|
||||||
|
"crypto.warning",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await crypto.init();
|
await crypto.init();
|
||||||
|
|||||||
@@ -166,7 +166,6 @@ OlmDevice.getOlmVersion = function() {
|
|||||||
|
|
||||||
OlmDevice.prototype._migrateFromSessionStore = async function() {
|
OlmDevice.prototype._migrateFromSessionStore = async function() {
|
||||||
// account
|
// account
|
||||||
let migratedAccount = false;
|
|
||||||
await this._cryptoStore.doTxn(
|
await this._cryptoStore.doTxn(
|
||||||
'readwrite', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => {
|
'readwrite', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => {
|
||||||
this._cryptoStore.getAccount(txn, (pickledAccount) => {
|
this._cryptoStore.getAccount(txn, (pickledAccount) => {
|
||||||
@@ -175,7 +174,6 @@ OlmDevice.prototype._migrateFromSessionStore = async function() {
|
|||||||
pickledAccount = this._sessionStore.getEndToEndAccount();
|
pickledAccount = this._sessionStore.getEndToEndAccount();
|
||||||
if (pickledAccount !== null) {
|
if (pickledAccount !== null) {
|
||||||
console.log("Migrating account from session store");
|
console.log("Migrating account from session store");
|
||||||
migratedAccount = true;
|
|
||||||
this._cryptoStore.storeAccount(txn, pickledAccount);
|
this._cryptoStore.storeAccount(txn, pickledAccount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,10 +181,9 @@ OlmDevice.prototype._migrateFromSessionStore = async function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// only remove this once it's safely saved to the crypto store
|
// remove the old account now the transaction has completed. Either we've
|
||||||
if (migratedAccount) {
|
// migrated it or decided not to, either way we want to blow away the old data.
|
||||||
this._sessionStore.removeEndToEndAccount();
|
this._sessionStore.removeEndToEndAccount();
|
||||||
}
|
|
||||||
|
|
||||||
// sessions
|
// sessions
|
||||||
const sessions = this._sessionStore.getAllEndToEndSessions();
|
const sessions = this._sessionStore.getAllEndToEndSessions();
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ const DeviceVerification = DeviceInfo.DeviceVerification;
|
|||||||
const DeviceList = require('./DeviceList').default;
|
const DeviceList = require('./DeviceList').default;
|
||||||
|
|
||||||
import OutgoingRoomKeyRequestManager from './OutgoingRoomKeyRequestManager';
|
import OutgoingRoomKeyRequestManager from './OutgoingRoomKeyRequestManager';
|
||||||
|
import IndexedDBCryptoStore from './store/indexeddb-crypto-store';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cryptography bits
|
* Cryptography bits
|
||||||
@@ -108,6 +109,24 @@ utils.inherits(Crypto, EventEmitter);
|
|||||||
* Returns a promise which resolves once the crypto module is ready for use.
|
* Returns a promise which resolves once the crypto module is ready for use.
|
||||||
*/
|
*/
|
||||||
Crypto.prototype.init = async function() {
|
Crypto.prototype.init = async function() {
|
||||||
|
const sessionStoreHasAccount = Boolean(this._sessionStore.getEndToEndAccount());
|
||||||
|
let cryptoStoreHasAccount;
|
||||||
|
await this._cryptoStore.doTxn(
|
||||||
|
'readonly', [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => {
|
||||||
|
this._cryptoStore.getAccount(txn, (pickledAccount) => {
|
||||||
|
cryptoStoreHasAccount = Boolean(pickledAccount);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (sessionStoreHasAccount && !cryptoStoreHasAccount) {
|
||||||
|
// we're about to migrate to the crypto store
|
||||||
|
this.emit("crypto.warning", 'CRYPTO_WARNING_ACCOUNT_MIGRATED');
|
||||||
|
} else if (sessionStoreHasAccount && cryptoStoreHasAccount) {
|
||||||
|
// There's an account in both stores: an old version of
|
||||||
|
// the code has been run against this store.
|
||||||
|
this.emit("crypto.warning", 'CRYPTO_WARNING_OLD_VERSION_DETECTED');
|
||||||
|
}
|
||||||
|
|
||||||
await this._olmDevice.init();
|
await this._olmDevice.init();
|
||||||
|
|
||||||
// build our device keys: these will later be uploaded
|
// build our device keys: these will later be uploaded
|
||||||
@@ -1332,5 +1351,24 @@ class IncomingRoomKeyRequestCancellation {
|
|||||||
* @param {module:crypto~IncomingRoomKeyRequestCancellation} req
|
* @param {module:crypto~IncomingRoomKeyRequestCancellation} req
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fires when the app may wish to warn the user about something related
|
||||||
|
* the end-to-end crypto.
|
||||||
|
*
|
||||||
|
* Comes with a type which is one of:
|
||||||
|
* * CRYPTO_WARNING_ACCOUNT_MIGRATED: Account data has been migrated from an older
|
||||||
|
* version of the store in such a way that older clients will no longer be
|
||||||
|
* able to read it. The app may wish to warn the user against going back to
|
||||||
|
* an older version of the app.
|
||||||
|
* * CRYPTO_WARNING_OLD_VERSION_DETECTED: js-sdk has detected that an older version
|
||||||
|
* of js-sdk has been run against the same store after a migration has been
|
||||||
|
* performed. This is likely have caused unexpected behaviour in the old
|
||||||
|
* version. For example, the old version and the new version may have two
|
||||||
|
* different identity keys.
|
||||||
|
*
|
||||||
|
* @event module:client~MatrixClient#"crypto.warning"
|
||||||
|
* @param {string} type One of the strings listed above
|
||||||
|
*/
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
module.exports = Crypto;
|
module.exports = Crypto;
|
||||||
|
|||||||
Reference in New Issue
Block a user