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
Serialise Olm prekey decryptions
If they overlap, they can both try to create new sessions, but this removes the OTK so it will only work once. Fixes https://github.com/vector-im/riot-web/issues/13229
This commit is contained in:
@@ -105,6 +105,9 @@ export function OlmDevice(cryptoStore) {
|
|||||||
// Keep track of sessions that we're starting, so that we don't start
|
// Keep track of sessions that we're starting, so that we don't start
|
||||||
// multiple sessions for the same device at the same time.
|
// multiple sessions for the same device at the same time.
|
||||||
this._sessionsInProgress = {};
|
this._sessionsInProgress = {};
|
||||||
|
|
||||||
|
// Used by olm to serialise prekey message decryptions
|
||||||
|
this._olmPrekeyPromise = Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -264,6 +264,23 @@ OlmDecryption.prototype.decryptEvent = async function(event) {
|
|||||||
*/
|
*/
|
||||||
OlmDecryption.prototype._decryptMessage = async function(
|
OlmDecryption.prototype._decryptMessage = async function(
|
||||||
theirDeviceIdentityKey, message,
|
theirDeviceIdentityKey, message,
|
||||||
|
) {
|
||||||
|
// This is a wrapper that serialises decryptions of prekey messages, because
|
||||||
|
// otherwise we race between deciding we have no active sessions for the message
|
||||||
|
// and creating a new one, which we can only do once because it removes the OTK.
|
||||||
|
if (message.type !== 0) {
|
||||||
|
// not a prekey message: we can safely just try & decrypt it
|
||||||
|
return this._reallyDecryptMessage(theirDeviceIdentityKey, message);
|
||||||
|
} else {
|
||||||
|
this._olmDevice._olmPrekeyPromise = this._olmDevice._olmPrekeyPromise.then(() => {
|
||||||
|
return this._reallyDecryptMessage(theirDeviceIdentityKey, message);
|
||||||
|
});
|
||||||
|
return await this._olmDevice._olmPrekeyPromise;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
OlmDecryption.prototype._reallyDecryptMessage = async function(
|
||||||
|
theirDeviceIdentityKey, message,
|
||||||
) {
|
) {
|
||||||
const sessionIds = await this._olmDevice.getSessionIdsForDevice(
|
const sessionIds = await this._olmDevice.getSessionIdsForDevice(
|
||||||
theirDeviceIdentityKey,
|
theirDeviceIdentityKey,
|
||||||
|
|||||||
Reference in New Issue
Block a user