Explorar el Código

fix(e2ee) fix key index after ratchetting

- After ratchet do not set it as new key for current index. Set it to correct position in crypto ring.
dev1
Ahmet Sarı hace 4 años
padre
commit
16aaa125dd
No account linked to committer's email address
Se han modificado 1 ficheros con 8 adiciones y 3 borrados
  1. 8
    3
      modules/e2ee/Context.js

+ 8
- 3
modules/e2ee/Context.js Ver fichero

@@ -96,10 +96,15 @@ export class Context {
96 96
      * Sets a set of keys and resets the sendCount.
97 97
      * decryption.
98 98
      * @param {Object} keys set of keys.
99
+     * @param {Number} keyIndex optional
99 100
      * @private
100 101
      */
101
-    _setKeys(keys) {
102
-        this._cryptoKeyRing[this._currentKeyIndex] = keys;
102
+    _setKeys(keys, keyIndex = -1) {
103
+        if (keyIndex >= 0) {
104
+            this._cryptoKeyRing[keyIndex] = keys;
105
+        } else {
106
+            this._cryptoKeyRing[this._currentKeyIndex] = keys;
107
+        }
103 108
         this._sendCount = BigInt(0); // eslint-disable-line new-cap
104 109
     }
105 110
 
@@ -322,7 +327,7 @@ export class Context {
322 327
                         new Uint8Array(calculatedTag.slice(0, DIGEST_LENGTH[encodedFrame.type])))) {
323 328
                     validAuthTag = true;
324 329
                     if (distance > 0) {
325
-                        this._setKeys(newKeys);
330
+                        this._setKeys(newKeys, keyIndex);
326 331
                     }
327 332
                     break;
328 333
                 }

Loading…
Cancelar
Guardar