@@ -7,13 +7,13 @@ import { v4 as uuidv4 } from 'uuid';
77import JitsiConference from '../../JitsiConference' ;
88import * as JitsiConferenceEvents from '../../JitsiConferenceEvents' ;
99import JitsiParticipant from '../../JitsiParticipant' ;
10- import type { IOlmAccount , IOlmIdKeys , IOlmSAS , IOlmSession } from './olm' ;
1110import Deferred from '../util/Deferred' ;
1211import Listenable from '../util/Listenable' ;
1312import { FEATURE_E2EE , JITSI_MEET_MUC_TYPE } from '../xmpp/xmpp' ;
1413
1514import { E2EEErrors } from './E2EEErrors' ;
1615import { generateSas } from './SAS' ;
16+ import type { IOlmAccount , IOlmIdKeys , IOlmSAS , IOlmSession } from './olm' ;
1717
1818interface IDSasVerificationData {
1919 isInitiator ?: boolean ;
@@ -137,6 +137,15 @@ export class OlmAdapter extends Listenable {
137137 return this . _conf . myUserId ( ) ;
138138 }
139139
140+ /**
141+ * Indicates if olm is supported on the current platform.
142+ *
143+ * @returns {boolean }
144+ */
145+ static isSupported ( ) : boolean {
146+ return typeof window . Olm !== 'undefined' ;
147+ }
148+
140149 /**
141150 * Starts new olm sessions with every other participant that has the participantId "smaller" the localParticipantId.
142151 */
@@ -166,106 +175,6 @@ export class OlmAdapter extends Listenable {
166175 }
167176 }
168177
169- /**
170- * Indicates if olm is supported on the current platform.
171- *
172- * @returns {boolean }
173- */
174- static isSupported ( ) : boolean {
175- return typeof window . Olm !== 'undefined' ;
176- }
177-
178- /**
179- * Updates the current participant key and distributes it to all participants in the conference
180- * by sending a key-info message.
181- *
182- * @param {Uint8Array|boolean } key - The new key.
183- * @returns {Promise<Number> }
184- */
185- public async updateKey ( key : Optional < Uint8Array | boolean > ) : Promise < number > {
186- // Store it locally for new sessions.
187- this . _mediaKey = key ;
188- this . _mediaKeyIndex ++ ;
189-
190- // Broadcast it.
191- const promises = [ ] ;
192-
193- for ( const participant of this . _conf . getParticipants ( ) ) {
194- const pId = participant . getId ( ) ;
195- const olmData = this . _getParticipantOlmData ( participant ) ;
196-
197- // TODO: skip those who don't support E2EE.
198- if ( ! olmData . session ) {
199- logger . warn ( `Tried to send key to participant ${ pId } but we have no session` ) ;
200-
201- // eslint-disable-next-line no-continue
202- continue ;
203- }
204-
205- const uuid = uuidv4 ( ) ;
206- const data = {
207- [ JITSI_MEET_MUC_TYPE ] : OLM_MESSAGE_TYPE ,
208- olm : {
209- data : {
210- ciphertext : this . _encryptKeyInfo ( olmData . session ) ,
211- uuid
212- } ,
213- type : OLM_MESSAGE_TYPES . KEY_INFO
214- }
215- } ;
216- const d = new Deferred ( ) ;
217-
218- d . setRejectTimeout ( REQ_TIMEOUT ) ;
219- d . catch ( ( ) => {
220- this . _reqs . delete ( uuid ) ;
221- } ) ;
222- this . _reqs . set ( uuid , d ) ;
223- promises . push ( d ) ;
224-
225- this . _sendMessage ( data , pId ) ;
226- }
227-
228- await Promise . allSettled ( promises ) ;
229-
230- // TODO: retry failed ones?
231-
232- return this . _mediaKeyIndex ;
233- }
234-
235- /**
236- * Updates the current participant key.
237- * @param {Uint8Array|boolean } key - The new key.
238- * @returns {number }
239- */
240- public updateCurrentMediaKey ( key : Uint8Array | boolean ) : number {
241- this . _mediaKey = key ;
242-
243- return this . _mediaKeyIndex ;
244- }
245-
246- /**
247- * Frees the olmData session for the given participant.
248- *
249- */
250- public clearParticipantSession ( participant : JitsiParticipant ) : void {
251- const olmData = this . _getParticipantOlmData ( participant ) ;
252-
253- if ( olmData . session ) {
254- olmData . session . free ( ) ;
255- olmData . session = undefined ;
256- }
257- }
258-
259- /**
260- * Frees the olmData sessions for all participants.
261- *
262- */
263- public clearAllParticipantsSessions ( ) : void {
264- for ( const participant of this . _conf . getParticipants ( ) ) {
265- this . clearParticipantSession ( participant ) ;
266- }
267- }
268-
269178 /**
270179 * Sends sacMac if channel verification waas successful.
271180 *
@@ -1128,6 +1037,99 @@ export class OlmAdapter extends Listenable {
11281037
11291038 return commitment ;
11301039 }
1040+
1041+
1042+ /**
1043+ * Updates the current participant key and distributes it to all participants in the conference
1044+ * by sending a key-info message.
1045+ *
1046+ * @param {Uint8Array|boolean } key - The new key.
1047+ * @returns {Promise<Number> }
1048+ */
1049+ public async updateKey ( key : Optional < Uint8Array | boolean > ) : Promise < number > {
1050+ // Store it locally for new sessions.
1051+ this . _mediaKey = key ;
1052+ this . _mediaKeyIndex ++ ;
1053+
1054+ // Broadcast it.
1055+ const promises = [ ] ;
1056+
1057+ for ( const participant of this . _conf . getParticipants ( ) ) {
1058+ const pId = participant . getId ( ) ;
1059+ const olmData = this . _getParticipantOlmData ( participant ) ;
1060+
1061+ // TODO: skip those who don't support E2EE.
1062+ if ( ! olmData . session ) {
1063+ logger . warn ( `Tried to send key to participant ${ pId } but we have no session` ) ;
1064+
1065+ // eslint-disable-next-line no-continue
1066+ continue ;
1067+ }
1068+
1069+ const uuid = uuidv4 ( ) ;
1070+ const data = {
1071+ [ JITSI_MEET_MUC_TYPE ] : OLM_MESSAGE_TYPE ,
1072+ olm : {
1073+ data : {
1074+ ciphertext : this . _encryptKeyInfo ( olmData . session ) ,
1075+ uuid
1076+ } ,
1077+ type : OLM_MESSAGE_TYPES . KEY_INFO
1078+ }
1079+ } ;
1080+ const d = new Deferred ( ) ;
1081+
1082+ d . setRejectTimeout ( REQ_TIMEOUT ) ;
1083+ d . catch ( ( ) => {
1084+ this . _reqs . delete ( uuid ) ;
1085+ } ) ;
1086+ this . _reqs . set ( uuid , d ) ;
1087+ promises . push ( d ) ;
1088+
1089+ this . _sendMessage ( data , pId ) ;
1090+ }
1091+
1092+ await Promise . allSettled ( promises ) ;
1093+
1094+ // TODO: retry failed ones?
1095+
1096+ return this . _mediaKeyIndex ;
1097+ }
1098+
1099+ /**
1100+ * Updates the current participant key.
1101+ * @param {Uint8Array|boolean } key - The new key.
1102+ * @returns {number }
1103+ */
1104+ public updateCurrentMediaKey ( key : Uint8Array | boolean ) : number {
1105+ this . _mediaKey = key ;
1106+
1107+ return this . _mediaKeyIndex ;
1108+ }
1109+
1110+ /**
1111+ * Frees the olmData session for the given participant.
1112+ *
1113+ */
1114+ public clearParticipantSession ( participant : JitsiParticipant ) : void {
1115+ const olmData = this . _getParticipantOlmData ( participant ) ;
1116+
1117+ if ( olmData . session ) {
1118+ olmData . session . free ( ) ;
1119+ olmData . session = undefined ;
1120+ }
1121+ }
1122+
1123+ /**
1124+ * Frees the olmData sessions for all participants.
1125+ *
1126+ */
1127+ public clearAllParticipantsSessions ( ) : void {
1128+ for ( const participant of this . _conf . getParticipants ( ) ) {
1129+ this . clearParticipantSession ( participant ) ;
1130+ }
1131+ }
1132+
11311133}
11321134
11331135/**
0 commit comments