|
@@ -8,7 +8,7 @@ import { v4 as uuidv4 } from 'uuid';
|
8
|
8
|
import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
|
9
|
9
|
import Deferred from '../util/Deferred';
|
10
|
10
|
import Listenable from '../util/Listenable';
|
11
|
|
-import { JITSI_MEET_MUC_TYPE } from '../xmpp/xmpp';
|
|
11
|
+import { FEATURE_E2EE, JITSI_MEET_MUC_TYPE } from '../xmpp/xmpp';
|
12
|
12
|
|
13
|
13
|
const logger = getLogger(__filename);
|
14
|
14
|
|
|
@@ -62,39 +62,59 @@ export class OlmAdapter extends Listenable {
|
62
|
62
|
this._key = undefined;
|
63
|
63
|
this._keyIndex = -1;
|
64
|
64
|
this._reqs = new Map();
|
|
65
|
+ this._sessionInitialization = undefined;
|
65
|
66
|
|
66
|
67
|
if (OlmAdapter.isSupported()) {
|
67
|
68
|
this._bootstrapOlm();
|
68
|
69
|
|
69
|
70
|
this._conf.on(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, this._onEndpointMessageReceived.bind(this));
|
70
|
|
- this._conf.on(JitsiConferenceEvents.CONFERENCE_JOINED, this._onConferenceJoined.bind(this));
|
71
|
71
|
this._conf.on(JitsiConferenceEvents.CONFERENCE_LEFT, this._onConferenceLeft.bind(this));
|
72
|
72
|
this._conf.on(JitsiConferenceEvents.USER_LEFT, this._onParticipantLeft.bind(this));
|
|
73
|
+ this._conf.on(JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
|
|
74
|
+ this._onParticipantPropertyChanged.bind(this));
|
73
|
75
|
} else {
|
74
|
76
|
this._init.reject(new Error('Olm not supported'));
|
75
|
77
|
}
|
76
|
78
|
}
|
77
|
79
|
|
78
|
80
|
/**
|
79
|
|
- * Indicates if olm is supported on the current platform.
|
80
|
|
- *
|
81
|
|
- * @returns {boolean}
|
|
81
|
+ * Starts new olm sessions with every other participant that has the participantId "smaller" the localParticipantId.
|
82
|
82
|
*/
|
83
|
|
- static isSupported() {
|
84
|
|
- return typeof window.Olm !== 'undefined';
|
|
83
|
+ async initSessions() {
|
|
84
|
+ if (this._sessionInitialization) {
|
|
85
|
+ throw new Error('OlmAdapte initSessions called multiple times');
|
|
86
|
+ } else {
|
|
87
|
+ this._sessionInitialization = new Deferred();
|
|
88
|
+
|
|
89
|
+ await this._init;
|
|
90
|
+
|
|
91
|
+ const promises = [];
|
|
92
|
+ const localParticipantId = this._conf.myUserId();
|
|
93
|
+
|
|
94
|
+ for (const participant of this._conf.getParticipants()) {
|
|
95
|
+ const participantFeatures = await participant.getFeatures();
|
|
96
|
+
|
|
97
|
+ if (participantFeatures.has(FEATURE_E2EE) && localParticipantId < participant.getId()) {
|
|
98
|
+ promises.push(this._sendSessionInit(participant));
|
|
99
|
+ }
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ await Promise.allSettled(promises);
|
|
103
|
+
|
|
104
|
+ // TODO: retry failed ones.
|
|
105
|
+
|
|
106
|
+ this._sessionInitialization.resolve();
|
|
107
|
+ this._sessionInitialization = undefined;
|
|
108
|
+ }
|
85
|
109
|
}
|
86
|
110
|
|
87
|
111
|
/**
|
88
|
|
- * Updates the current participant key and distributes it to all participants in the conference
|
89
|
|
- * by sending a key-info message.
|
|
112
|
+ * Indicates if olm is supported on the current platform.
|
90
|
113
|
*
|
91
|
|
- * @param {Uint8Array|boolean} key - The new key.
|
92
|
|
- * @returns {number}
|
|
114
|
+ * @returns {boolean}
|
93
|
115
|
*/
|
94
|
|
- async updateCurrentKey(key) {
|
95
|
|
- this._key = key;
|
96
|
|
-
|
97
|
|
- return this._keyIndex;
|
|
116
|
+ static isSupported() {
|
|
117
|
+ return typeof window.Olm !== 'undefined';
|
98
|
118
|
}
|
99
|
119
|
|
100
|
120
|
/**
|
|
@@ -117,7 +137,6 @@ export class OlmAdapter extends Listenable {
|
117
|
137
|
const olmData = this._getParticipantOlmData(participant);
|
118
|
138
|
|
119
|
139
|
// TODO: skip those who don't support E2EE.
|
120
|
|
-
|
121
|
140
|
if (!olmData.session) {
|
122
|
141
|
logger.warn(`Tried to send key to participant ${pId} but we have no session`);
|
123
|
142
|
|
|
@@ -155,6 +174,17 @@ export class OlmAdapter extends Listenable {
|
155
|
174
|
return this._keyIndex;
|
156
|
175
|
}
|
157
|
176
|
|
|
177
|
+ /**
|
|
178
|
+ * Updates the current participant key.
|
|
179
|
+ * @param {Uint8Array|boolean} key - The new key.
|
|
180
|
+ * @returns {number}
|
|
181
|
+ */
|
|
182
|
+ updateCurrentKey(key) {
|
|
183
|
+ this._key = key;
|
|
184
|
+
|
|
185
|
+ return this._keyIndex;
|
|
186
|
+ }
|
|
187
|
+
|
158
|
188
|
/**
|
159
|
189
|
* Internal helper to bootstrap the olm library.
|
160
|
190
|
*
|
|
@@ -215,32 +245,6 @@ export class OlmAdapter extends Listenable {
|
215
|
245
|
return participant[kOlmData];
|
216
|
246
|
}
|
217
|
247
|
|
218
|
|
- /**
|
219
|
|
- * Handles the conference joined event. Upon joining a conference, the participant
|
220
|
|
- * who just joined will start new olm sessions with every other participant.
|
221
|
|
- *
|
222
|
|
- * @private
|
223
|
|
- */
|
224
|
|
- async _onConferenceJoined() {
|
225
|
|
- logger.debug('Conference joined');
|
226
|
|
-
|
227
|
|
- await this._init;
|
228
|
|
-
|
229
|
|
- const promises = [];
|
230
|
|
-
|
231
|
|
- // Establish a 1-to-1 Olm session with every participant in the conference.
|
232
|
|
- // We are forcing the last user to join the conference to start the exchange
|
233
|
|
- // so we can send some pre-established secrets in the ACK.
|
234
|
|
- for (const participant of this._conf.getParticipants()) {
|
235
|
|
- promises.push(this._sendSessionInit(participant));
|
236
|
|
- }
|
237
|
|
-
|
238
|
|
- await Promise.allSettled(promises);
|
239
|
|
-
|
240
|
|
- // TODO: retry failed ones.
|
241
|
|
- // TODO: skip participants which don't support E2EE.
|
242
|
|
- }
|
243
|
|
-
|
244
|
248
|
/**
|
245
|
249
|
* Handles leaving the conference, cleaning up olm sessions.
|
246
|
250
|
*
|
|
@@ -311,7 +315,6 @@ export class OlmAdapter extends Listenable {
|
311
|
315
|
};
|
312
|
316
|
|
313
|
317
|
this._sendMessage(ack, pId);
|
314
|
|
-
|
315
|
318
|
this.eventEmitter.emit(OlmAdapterEvents.PARTICIPANT_E2EE_CHANNEL_READY, pId);
|
316
|
319
|
}
|
317
|
320
|
break;
|
|
@@ -427,7 +430,6 @@ export class OlmAdapter extends Listenable {
|
427
|
430
|
break;
|
428
|
431
|
}
|
429
|
432
|
}
|
430
|
|
-
|
431
|
433
|
}
|
432
|
434
|
|
433
|
435
|
/**
|
|
@@ -446,6 +448,49 @@ export class OlmAdapter extends Listenable {
|
446
|
448
|
}
|
447
|
449
|
}
|
448
|
450
|
|
|
451
|
+ /**
|
|
452
|
+ * Handles an update in a participant's presence property.
|
|
453
|
+ *
|
|
454
|
+ * @param {JitsiParticipant} participant - The participant.
|
|
455
|
+ * @param {string} name - The name of the property that changed.
|
|
456
|
+ * @param {*} oldValue - The property's previous value.
|
|
457
|
+ * @param {*} newValue - The property's new value.
|
|
458
|
+ * @private
|
|
459
|
+ */
|
|
460
|
+ async _onParticipantPropertyChanged(participant, name, oldValue, newValue) {
|
|
461
|
+ switch (name) {
|
|
462
|
+ case 'e2ee.enabled':
|
|
463
|
+ if (newValue && this._conf.isE2EEEnabled()) {
|
|
464
|
+ const localParticipantId = this._conf.myUserId();
|
|
465
|
+ const participantId = participant.getId();
|
|
466
|
+ const participantFeatures = await participant.getFeatures();
|
|
467
|
+
|
|
468
|
+ if (participantFeatures.has(FEATURE_E2EE) && localParticipantId < participantId) {
|
|
469
|
+ if (this._sessionInitialization) {
|
|
470
|
+ await this._sessionInitialization;
|
|
471
|
+ }
|
|
472
|
+ await this._sendSessionInit(participant);
|
|
473
|
+
|
|
474
|
+ const olmData = this._getParticipantOlmData(participant);
|
|
475
|
+ const uuid = uuidv4();
|
|
476
|
+ const data = {
|
|
477
|
+ [JITSI_MEET_MUC_TYPE]: OLM_MESSAGE_TYPE,
|
|
478
|
+ olm: {
|
|
479
|
+ type: OLM_MESSAGE_TYPES.KEY_INFO,
|
|
480
|
+ data: {
|
|
481
|
+ ciphertext: this._encryptKeyInfo(olmData.session),
|
|
482
|
+ uuid
|
|
483
|
+ }
|
|
484
|
+ }
|
|
485
|
+ };
|
|
486
|
+
|
|
487
|
+ this._sendMessage(data, participantId);
|
|
488
|
+ }
|
|
489
|
+ }
|
|
490
|
+ break;
|
|
491
|
+ }
|
|
492
|
+ }
|
|
493
|
+
|
449
|
494
|
/**
|
450
|
495
|
* Builds and sends an error message to the target participant.
|
451
|
496
|
*
|