Skip to content

Commit

Permalink
Guard against overriding newly set key when auto-ratcheting
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO committed Oct 20, 2023
1 parent bc4b46a commit be1c6a7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/e2ee/worker/FrameCryptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,13 @@ export class FrameCryptor extends BaseFrameCryptor {
encryptionKey: ratchetedKeySet?.encryptionKey,
});
if (frame && ratchetedKeySet) {
this.keys.setKeySet(ratchetedKeySet, keyIndex, true);
// decryption was successful, set the new key index to reflect the ratcheted key set
this.keys.setCurrentKeyIndex(keyIndex);
// before updating the keys, make sure that the keySet used for this frame is still the same as the currently set key
// if it's not, a new key might have been set already, which we don't want to override
if (keySet === this.keys.getKeySet(keyIndex)) {
this.keys.setKeySet(ratchetedKeySet, keyIndex, true);
// decryption was successful, set the new key index to reflect the ratcheted key set
this.keys.setCurrentKeyIndex(keyIndex);
}
}
return frame;
} else {
Expand Down

0 comments on commit be1c6a7

Please sign in to comment.