Parcourir la source

fix(e2ee) restore initial key when RATCHET_WINDOW_SIZE reached

release-8443
tmoldovan8x8 il y a 4 ans
Parent
révision
2e1ca64654
Aucun compte lié à l'adresse e-mail de l'auteur
1 fichiers modifiés avec 10 ajouts et 0 suppressions
  1. 10
    0
      modules/e2ee/Context.js

+ 10
- 0
modules/e2ee/Context.js Voir le fichier

@@ -207,6 +207,7 @@ export class Context {
207 207
     async _decryptFrame(
208 208
             encodedFrame,
209 209
             keyIndex,
210
+            initialKey = undefined,
210 211
             ratchetCount = 0) {
211 212
 
212 213
         const { encryptionKey } = this._cryptoKeyRing[keyIndex];
@@ -260,9 +261,18 @@ export class Context {
260 261
                 return await this._decryptFrame(
261 262
                     encodedFrame,
262 263
                     keyIndex,
264
+                    initialKey ?? this._cryptoKeyRing[this._currentKeyIndex],
263 265
                     ratchetCount + 1);
264 266
             }
265 267
 
268
+            /*
269
+               Since the key it is first send and only afterwards actually used for encrypting, there were
270
+               situations when the decrypting failed due to the fact that the received frame was not encrypted
271
+               yet and ratcheting, of course, did not solve the problem. So if we fail RATCHET_WINDOW_SIZE times,
272
+               we come back to the initial key.
273
+            */
274
+            this._setKeys(initialKey);
275
+
266 276
             // TODO: notify the application about error status.
267 277
         }
268 278
 

Chargement…
Annuler
Enregistrer