Quellcode durchsuchen

feat(e2ee) publish olm id key in presence

dev1
Saúl Ibarra Corretgé vor 4 Jahren
Ursprung
Commit
b65b1784df
2 geänderte Dateien mit 41 neuen und 5 gelöschten Zeilen
  1. 39
    5
      modules/e2ee/E2EEncryption.js
  2. 2
    0
      modules/e2ee/OlmAdapter.js

+ 39
- 5
modules/e2ee/E2EEncryption.js Datei anzeigen

@@ -43,17 +43,20 @@ export class E2EEncryption {
43 43
         // Participant join / leave operations. Used for key advancement / rotation.
44 44
         //
45 45
 
46
+        this.conference.on(
47
+            JitsiConferenceEvents.CONFERENCE_JOINED,
48
+            () => {
49
+                this._conferenceJoined = true;
50
+            });
51
+        this.conference.on(
52
+            JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
53
+            this._onParticipantPropertyChanged.bind(this));
46 54
         this.conference.on(
47 55
             JitsiConferenceEvents.USER_JOINED,
48 56
             this._onParticipantJoined.bind(this));
49 57
         this.conference.on(
50 58
             JitsiConferenceEvents.USER_LEFT,
51 59
             this._onParticipantLeft.bind(this));
52
-        this.conference.on(
53
-            JitsiConferenceEvents.CONFERENCE_JOINED,
54
-            () => {
55
-                this._conferenceJoined = true;
56
-            });
57 60
 
58 61
         // Conference media events in order to attach the encryptor / decryptor.
59 62
         // FIXME add events to TraceablePeerConnection which will allow to see when there's new receiver or sender
@@ -74,6 +77,9 @@ export class E2EEncryption {
74 77
             this._trackMuteChanged.bind(this));
75 78
 
76 79
         // Olm signalling events.
80
+        this._olmAdapter.on(
81
+            OlmAdapter.events.OLM_ID_KEY_READY,
82
+            this._onOlmIdKeyReady.bind(this));
77 83
         this._olmAdapter.on(
78 84
             OlmAdapter.events.PARTICIPANT_E2EE_CHANNEL_READY,
79 85
             this._onParticipantE2EEChannelReady.bind(this));
@@ -170,6 +176,17 @@ export class E2EEncryption {
170 176
         }
171 177
     }
172 178
 
179
+    /**
180
+     * Publushes our own Olmn id key in presence.
181
+     * @private
182
+     */
183
+    _onOlmIdKeyReady(idKey) {
184
+        logger.debug(`Olm id key ready: ${idKey}`);
185
+
186
+        // Publish it in presence.
187
+        this.conference.setLocalParticipantProperty('e2ee.idKey', idKey);
188
+    }
189
+
173 190
     /**
174 191
      * Advances (using ratcheting) the current key when a new participant joins the conference.
175 192
      * @private
@@ -218,6 +235,23 @@ export class E2EEncryption {
218 235
         this._e2eeCtx.setKey(id, key, index);
219 236
     }
220 237
 
238
+    /**
239
+     * Handles an update in a participant's presence property.
240
+     *
241
+     * @param {JitsiParticipant} participant - The participant.
242
+     * @param {string} name - The name of the property that changed.
243
+     * @param {*} oldValue - The property's previous value.
244
+     * @param {*} newValue - The property's new value.
245
+     * @private
246
+     */
247
+    _onParticipantPropertyChanged(participant, name, oldValue, newValue) {
248
+        switch (name) {
249
+        case 'e2ee.idKey':
250
+            logger.debug(`Participant ${participant.getId()} updated their id key: ${newValue}`);
251
+            break;
252
+        }
253
+    }
254
+
221 255
     /**
222 256
      * Advances the current key by using ratcheting.
223 257
      *

+ 2
- 0
modules/e2ee/OlmAdapter.js Datei anzeigen

@@ -25,6 +25,7 @@ const OLM_MESSAGE_TYPES = {
25 25
 const kOlmData = Symbol('OlmData');
26 26
 
27 27
 const OlmAdapterEvents = {
28
+    OLM_ID_KEY_READY: 'olm.id_key_ready',
28 29
     PARTICIPANT_E2EE_CHANNEL_READY: 'olm.participant_e2ee_channel_ready',
29 30
     PARTICIPANT_KEY_UPDATED: 'olm.partitipant_key_updated'
30 31
 };
@@ -175,6 +176,7 @@ export class OlmAdapter extends Listenable {
175 176
 
176 177
             logger.debug('Olm initialized!');
177 178
             this._init.resolve();
179
+            this.eventEmitter.emit(OlmAdapterEvents.OLM_ID_KEY_READY, this._idKey);
178 180
         } catch (e) {
179 181
             logger.error('Failed to initialize Olm', e);
180 182
             this._init.reject(e);

Laden…
Abbrechen
Speichern