Fix rust crypto: dont use legacy crypto store anymore. (#2587)
The logic for the legacy store was intercepting with the rustCrypto that handles all the cases itself.
This commit is contained in:
@@ -33,13 +33,10 @@ import {
|
|||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { ISyncStateData, SyncState } from "matrix-js-sdk/src/sync";
|
import { ISyncStateData, SyncState } from "matrix-js-sdk/src/sync";
|
||||||
|
import { MatrixError } from "matrix-js-sdk";
|
||||||
|
|
||||||
import { ErrorView } from "./FullScreenView";
|
import { ErrorView } from "./FullScreenView";
|
||||||
import {
|
import { fallbackICEServerAllowed, initClient } from "./utils/matrix";
|
||||||
CryptoStoreIntegrityError,
|
|
||||||
fallbackICEServerAllowed,
|
|
||||||
initClient,
|
|
||||||
} from "./utils/matrix";
|
|
||||||
import { widget } from "./widget";
|
import { widget } from "./widget";
|
||||||
import {
|
import {
|
||||||
PosthogAnalytics,
|
PosthogAnalytics,
|
||||||
@@ -380,16 +377,15 @@ async function loadClient(): Promise<InitResult | null> {
|
|||||||
passwordlessUser,
|
passwordlessUser,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof CryptoStoreIntegrityError) {
|
if (err instanceof MatrixError && err.errcode === "M_UNKNOWN_TOKEN") {
|
||||||
// We can't use this session anymore, so let's log it out
|
// We can't use this session anymore, so let's log it out
|
||||||
try {
|
try {
|
||||||
const client = await initClient(initClientParams, false); // Don't need the crypto store just to log out)
|
const client = await initClient(initClientParams, false); // Don't need the crypto store just to log out)
|
||||||
await client.logout(true);
|
await client.logout(true);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"The previous session was lost, and we couldn't log it out, " +
|
"The previous session was unable to login, and we couldn't log it out: " +
|
||||||
err +
|
err,
|
||||||
"either",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ limitations under the License.
|
|||||||
|
|
||||||
import { IndexedDBStore } from "matrix-js-sdk/src/store/indexeddb";
|
import { IndexedDBStore } from "matrix-js-sdk/src/store/indexeddb";
|
||||||
import { MemoryStore } from "matrix-js-sdk/src/store/memory";
|
import { MemoryStore } from "matrix-js-sdk/src/store/memory";
|
||||||
import { IndexedDBCryptoStore } from "matrix-js-sdk/src/crypto/store/indexeddb-crypto-store";
|
|
||||||
import { LocalStorageCryptoStore } from "matrix-js-sdk/src/crypto/store/localStorage-crypto-store";
|
|
||||||
import { MemoryCryptoStore } from "matrix-js-sdk/src/crypto/store/memory-crypto-store";
|
|
||||||
import {
|
import {
|
||||||
createClient,
|
createClient,
|
||||||
ICreateClientOpts,
|
ICreateClientOpts,
|
||||||
@@ -41,18 +38,7 @@ import { EncryptionSystem, saveKeyForRoom } from "../e2ee/sharedKeyManagement";
|
|||||||
export const fallbackICEServerAllowed =
|
export const fallbackICEServerAllowed =
|
||||||
import.meta.env.VITE_FALLBACK_STUN_ALLOWED === "true";
|
import.meta.env.VITE_FALLBACK_STUN_ALLOWED === "true";
|
||||||
|
|
||||||
export class CryptoStoreIntegrityError extends Error {
|
|
||||||
public constructor() {
|
|
||||||
super("Crypto store data was expected, but none was found");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const SYNC_STORE_NAME = "element-call-sync";
|
const SYNC_STORE_NAME = "element-call-sync";
|
||||||
// Note that the crypto store name has changed from previous versions
|
|
||||||
// deliberately in order to force a logout for all users due to
|
|
||||||
// https://github.com/vector-im/element-call/issues/464
|
|
||||||
// (It's a good opportunity to make the database names consistent.)
|
|
||||||
const CRYPTO_STORE_NAME = "element-call-crypto";
|
|
||||||
|
|
||||||
async function waitForSync(client: MatrixClient): Promise<void> {
|
async function waitForSync(client: MatrixClient): Promise<void> {
|
||||||
// If there is a saved sync, the client will fire an additional sync event
|
// If there is a saved sync, the client will fire an additional sync event
|
||||||
@@ -85,9 +71,8 @@ async function waitForSync(client: MatrixClient): Promise<void> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialises and returns a new standalone Matrix Client.
|
* Initialises and returns a new standalone Matrix Client.
|
||||||
* If true is passed for the 'restore' parameter, a check will be made
|
* If false is passed for the 'restore' parameter, corresponding crypto
|
||||||
* to ensure that corresponding crypto data is stored and recovered.
|
* data is cleared before the client initialization.
|
||||||
* If the check fails, CryptoStoreIntegrityError will be thrown.
|
|
||||||
* @param clientOptions Object of options passed through to the client
|
* @param clientOptions Object of options passed through to the client
|
||||||
* @param restore Whether the session is being restored from storage
|
* @param restore Whether the session is being restored from storage
|
||||||
* @returns The MatrixClient instance
|
* @returns The MatrixClient instance
|
||||||
@@ -124,45 +109,6 @@ export async function initClient(
|
|||||||
baseOpts.store = new MemoryStore({ localStorage });
|
baseOpts.store = new MemoryStore({ localStorage });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether we have crypto data store. If we are restoring a session
|
|
||||||
// from storage then we will have started the crypto store and therefore
|
|
||||||
// have generated keys for that device, so if we can't recover those keys,
|
|
||||||
// we must not continue or we'll generate new keys and anyone who saw our
|
|
||||||
// previous keys will not accept our new key.
|
|
||||||
// It's worth mentioning here that if support for indexeddb or localstorage
|
|
||||||
// appears or disappears between sessions (it happens) then the failure mode
|
|
||||||
// here will be that we'll try a different store, not find crypto data and
|
|
||||||
// fail to restore the session. An alternative would be to continue using
|
|
||||||
// whatever we were using before, but that could be confusing since you could
|
|
||||||
// enable indexeddb and but the app would still not be using it.
|
|
||||||
if (restore) {
|
|
||||||
if (indexedDB) {
|
|
||||||
const cryptoStoreExists = await IndexedDBCryptoStore.exists(
|
|
||||||
indexedDB,
|
|
||||||
CRYPTO_STORE_NAME,
|
|
||||||
);
|
|
||||||
if (!cryptoStoreExists) throw new CryptoStoreIntegrityError();
|
|
||||||
} else if (localStorage) {
|
|
||||||
if (!LocalStorageCryptoStore.exists(localStorage))
|
|
||||||
throw new CryptoStoreIntegrityError();
|
|
||||||
} else {
|
|
||||||
// if we get here then we're using the memory store, which cannot
|
|
||||||
// possibly have remembered a session, so it's an error.
|
|
||||||
throw new CryptoStoreIntegrityError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indexedDB) {
|
|
||||||
baseOpts.cryptoStore = new IndexedDBCryptoStore(
|
|
||||||
indexedDB,
|
|
||||||
CRYPTO_STORE_NAME,
|
|
||||||
);
|
|
||||||
} else if (localStorage) {
|
|
||||||
baseOpts.cryptoStore = new LocalStorageCryptoStore(localStorage);
|
|
||||||
} else {
|
|
||||||
baseOpts.cryptoStore = new MemoryCryptoStore();
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX: we read from the URL params in RoomPage too:
|
// XXX: we read from the URL params in RoomPage too:
|
||||||
// it would be much better to read them in one place and pass
|
// it would be much better to read them in one place and pass
|
||||||
// the values around, but we initialise the matrix client in
|
// the values around, but we initialise the matrix client in
|
||||||
@@ -184,15 +130,13 @@ export async function initClient(
|
|||||||
fallbackICEServerAllowed: fallbackICEServerAllowed,
|
fallbackICEServerAllowed: fallbackICEServerAllowed,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
// In case of registering a new matrix account caused by broken store state. This is particularly needed for:
|
||||||
await client.store.startup();
|
// - We lost the auth tokens and cannot restore the client resulting in registering a new user.
|
||||||
} catch (error) {
|
// - Need to make sure any possible leftover crypto store gets cleared.
|
||||||
logger.error(
|
// - A new account is created because of missing LocalStorage: "matrix-auth-store", but the crypto IndexDB is still available.
|
||||||
"Error starting matrix client store. Falling back to memory store.",
|
// This would result in conflicting crypto store userId vs matrixClient userId. Caused by EC 0.6.1
|
||||||
error,
|
if (!restore) {
|
||||||
);
|
client.clearStores();
|
||||||
client.store = new MemoryStore({ localStorage });
|
|
||||||
await client.store.startup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await client.initRustCrypto();
|
await client.initRustCrypto();
|
||||||
@@ -228,7 +172,7 @@ function fullAliasFromRoomName(roomName: string, client: MatrixClient): string {
|
|||||||
* @param client A matrix client object
|
* @param client A matrix client object
|
||||||
*/
|
*/
|
||||||
export function sanitiseRoomNameInput(input: string): string {
|
export function sanitiseRoomNameInput(input: string): string {
|
||||||
// check to see if the user has enetered a fully qualified room
|
// check to see if the user has entered a fully qualified room
|
||||||
// alias. If so, turn it into just the localpart because that's what
|
// alias. If so, turn it into just the localpart because that's what
|
||||||
// we use
|
// we use
|
||||||
const parts = input.split(":", 2);
|
const parts = input.split(":", 2);
|
||||||
|
|||||||
Reference in New Issue
Block a user