|
@@ -30,6 +30,7 @@ export class E2EEncryption {
|
30
|
30
|
this._conferenceJoined = false;
|
31
|
31
|
this._enabled = false;
|
32
|
32
|
this._initialized = false;
|
|
33
|
+ this._key = undefined;
|
33
|
34
|
|
34
|
35
|
this._e2eeCtx = new E2EEContext();
|
35
|
36
|
this._olmAdapter = new OlmAdapter(conference);
|
|
@@ -125,12 +126,12 @@ export class E2EEncryption {
|
125
|
126
|
}
|
126
|
127
|
|
127
|
128
|
// Generate a random key in case we are enabling.
|
128
|
|
- const key = enabled ? this._generateKey() : false;
|
|
129
|
+ this._key = enabled ? this._generateKey() : false;
|
129
|
130
|
|
130
|
131
|
// Send it to others using the E2EE olm channel.
|
131
|
|
- this._olmAdapter.updateKey(key).then(index => {
|
|
132
|
+ this._olmAdapter.updateKey(this._key).then(index => {
|
132
|
133
|
// Set our key so we begin encrypting.
|
133
|
|
- this._e2eeCtx.setKey(this.conference.myUserId(), key, index);
|
|
134
|
+ this._e2eeCtx.setKey(this.conference.myUserId(), this._key, index);
|
134
|
135
|
});
|
135
|
136
|
}
|
136
|
137
|
|
|
@@ -224,10 +225,19 @@ export class E2EEncryption {
|
224
|
225
|
async _ratchetKeyImpl() {
|
225
|
226
|
logger.debug('Ratchetting key');
|
226
|
227
|
|
227
|
|
- this._e2eeCtx.ratchet(this.conference.myUserId());
|
|
228
|
+ const material = await crypto.subtle.importKey('raw', this._key, 'HKDF', false, [ 'deriveBits' ]);
|
|
229
|
+ const newKey = await crypto.subtle.deriveBits({
|
|
230
|
+ name: 'HKDF',
|
|
231
|
+ salt: new TextEncoder().encode('JFrameRatchetKey'),
|
|
232
|
+ hash: 'SHA-256',
|
|
233
|
+ info: new ArrayBuffer()
|
|
234
|
+ }, material, 256);
|
228
|
235
|
|
229
|
|
- // TODO: how do we tell the olm adapter which might need to send the current ratchet key
|
230
|
|
- // to the other side?
|
|
236
|
+ this._key = new Uint8Array(newKey);
|
|
237
|
+
|
|
238
|
+ const index = await this._olmAdapter.updateCurrentKey(this._key);
|
|
239
|
+
|
|
240
|
+ this._e2eeCtx.setKey(this.conference.myUserId(), this._key, index);
|
231
|
241
|
}
|
232
|
242
|
|
233
|
243
|
/**
|
|
@@ -239,10 +249,10 @@ export class E2EEncryption {
|
239
|
249
|
async _rotateKeyImpl() {
|
240
|
250
|
logger.debug('Rotating key');
|
241
|
251
|
|
242
|
|
- const key = this._generateKey();
|
243
|
|
- const index = await this._olmAdapter.updateKey(key);
|
|
252
|
+ this._key = this._generateKey();
|
|
253
|
+ const index = await this._olmAdapter.updateKey(this._key);
|
244
|
254
|
|
245
|
|
- this._e2eeCtx.setKey(this.conference.myUserId(), key, index);
|
|
255
|
+ this._e2eeCtx.setKey(this.conference.myUserId(), this._key, index);
|
246
|
256
|
}
|
247
|
257
|
|
248
|
258
|
/**
|