Skip to content

Commit

Permalink
attempt to fix a runtime error Jitsi meet throws when E2EE is enabled…
Browse files Browse the repository at this point in the history
… (issue jitsi#2587)
  • Loading branch information
Internxt authored and Internxt committed Oct 16, 2024
1 parent 656bec7 commit ebca941
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 1,066 deletions.
3 changes: 2 additions & 1 deletion JitsiConference.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const logger = getLogger(__filename);
* {@link ACTION_JINGLE_SI_TIMEOUT} analytics event is sent (in ms).
* @type {number}
*/
const JINGLE_SI_TIMEOUT = 50 * 1000;
const JINGLE_SI_TIMEOUT = 5 * 1000;

/**
* Checks if a given string is a valid video codec mime type.
Expand Down Expand Up @@ -1837,6 +1837,7 @@ JitsiConference.prototype._updateFeatures = function(participant) {
}

if (features.has(FEATURE_E2EE)) {
console.log(`CHECK: FEATURE_E2EE is true for ${participant.getId()}`);
participant.setProperty('features_e2ee', true);
}
})
Expand Down
1 change: 1 addition & 0 deletions JitsiParticipant.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ export default class JitsiParticipant {
const oldValue = this._properties[name];

if (value !== oldValue) {
console.log(`CHECK: setProperty is called ${name} and ${value}`);
this._properties[name] = value;
this._conference.eventEmitter.emit(
JitsiConferenceEvents.PARTICIPANT_PROPERTY_CHANGED,
Expand Down
11 changes: 0 additions & 11 deletions modules/e2ee/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export class Context {
let newKey: KeyMaterial;

if (this._sharedKey) {
console.log(`setKey shared key the key length is ${key.length}`);
const cryptoKey: CryptoKey = await crypto.subtle.importKey(
"raw",
key,
Expand All @@ -87,7 +86,6 @@ export class Context {
);
newKey = { encryptionKey: cryptoKey, material: undefined };
} else {
console.log(`setKey else the key length is ${key.length}`);
const material = await importKey(key);

newKey = await deriveKeys(material);
Expand Down Expand Up @@ -135,14 +133,8 @@ export class Context {
* 9) Enqueue the encrypted frame for sending.
*/
encodeFunction(encodedFrame, controller) {
// console.log('CHECKPOINT: Encrypt frame started');
const keyIndex = this._currentKeyIndex;

// console.log(`CHECKPOINT: Encrypt frame: index is ${keyIndex} and keyRing is ${this._cryptoKeyRing}`);
// console.log(`CHECKPOINT: the key would be
// ${JSON.stringify(this._cryptoKeyRing[keyIndex].encryptionKey)}`);
if (this._cryptoKeyRing[keyIndex]) {
// console.log('CHECKPOINT: Encrypt frame entered if');
const iv = this._makeIV(
encodedFrame.getMetadata().synchronizationSource,
encodedFrame.timestamp
Expand Down Expand Up @@ -275,7 +267,6 @@ export class Context {
initialKey = undefined,
ratchetCount = 0
) {
// console.log('CHECKPOINT: Decrypt frame started');
const { encryptionKey } = this._cryptoKeyRing[keyIndex];
let { material } = this._cryptoKeyRing[keyIndex];

Expand All @@ -288,8 +279,6 @@ export class Context {
// ---------+-------------------------+-+---------+----

try {
// console.log('CHECKPOINT: Decrypt frame entered try');
// console.log(`CHECKPOINT: Decrypt frame with ${JSON.stringify(encryptionKey)}`);
const frameHeader = new Uint8Array(
encodedFrame.data,
0,
Expand Down
2 changes: 1 addition & 1 deletion modules/e2ee/E2EEContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export default class E2EEcontext {
* @param {Number} keyIndex - the key index.
*/
setKey(participantId, key, keyIndex) {
console.log(`setKey for ${participantId} as ${key}`);
console.log(`CHECK: setKey for ${participantId} as ${key}`);
this._worker.postMessage({
operation: 'setKey',
key,
Expand Down
2 changes: 1 addition & 1 deletion modules/e2ee/E2EEncryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class E2EEncryption {
* @returns {void}
*/
setEncryptionKey(keyInfo) {
console.log(`CHECKPOINT: setEncryptionKey keyInfo ${JSON.stringify(keyInfo)} or
console.log(`CHECK: setEncryptionKey keyInfo ${JSON.stringify(keyInfo)} or
${base64js.fromByteArray(keyInfo.encryptionKey)} and index is ${keyInfo.index}`);
this._keyHandler.setKey(keyInfo);
}
Expand Down
1 change: 1 addition & 0 deletions modules/e2ee/ExternallyManagedKeyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ export class ExternallyManagedKeyHandler extends KeyHandler {
this.e2eeCtx.setKey(undefined, keyInfo.encryptionKey, keyInfo.index);
}
async _setEnabled(enabled) {
return false;
}
}
19 changes: 5 additions & 14 deletions modules/e2ee/KeyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
import RTCEvents from '../../service/RTC/RTCEvents';
import browser from '../browser';
import Listenable from '../util/Listenable';
import Deferred from '../util/Deferred';

import E2EEContext from './E2EEContext';
import JitsiConference from '../../JitsiConference';
Expand All @@ -22,10 +21,9 @@ export abstract class KeyHandler extends Listenable {
conference: JitsiConference;
e2eeCtx: E2EEContext;
enabled: boolean;
_enabling: Deferred;
_olmAdapter: any;

abstract _setEnabled(enabled: boolean): void;
abstract _setEnabled(enabled: boolean): Promise<boolean>;
abstract setKey(keyInfo: KeyInfo): void;
/**
* Build a new KeyHandler instance, which will be used in a given conference.
Expand Down Expand Up @@ -75,25 +73,18 @@ export abstract class KeyHandler extends Listenable {
* @returns {void}
*/
async setEnabled(enabled) {
logger.info('olm: setEnabled started');
this._enabling && await this._enabling;
console.log(`CHECK: setEnabled is called and enabled is ${enabled}`);
if (enabled === this.enabled) {
return;
}
this._enabling = new Deferred();
this.enabled = enabled;
this.enabled = await this._setEnabled(enabled);

if (!enabled) {
this.e2eeCtx.cleanupAll();
}

this._setEnabled && await this._setEnabled(enabled);

this.conference.setLocalParticipantProperty('e2ee.enabled', enabled);


this.conference.setLocalParticipantProperty('e2ee.enabled', enabled);
this.conference._restartMediaSessions();

this._enabling.resolve();

}

Expand Down
32 changes: 22 additions & 10 deletions modules/e2ee/ManagedKeyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,37 @@ export class ManagedKeyHandler extends KeyHandler {
* Cleans up the sessions when disabled.
*
* @param {boolean} enabled - whether E2EE should be enabled or not.
* @returns {void}
* @returns {boolean}
*/
async _setEnabled(enabled) {
async _setEnabled(enabled): Promise<boolean> {
console.log(`CHECK: _setEnabled started and is ${enabled}`);

if (!enabled) {
this._olmAdapter.clearAllParticipantsSessions();
return false;
}

try {
this._onKeyGeneration();

const { mediaKeyIndex, mediaKey }
= await this._olmAdapter.initSessionsAndSetMediaKey(this._olmKey, this._pqKey);

logger.info(`CHECK: my media key is ${base64js.fromByteArray(mediaKey)} or ${mediaKey} and
index is ${mediaKeyIndex}`);

// Set our key so we begin encrypting.
this.setKey({encryptionKey: mediaKey, index: mediaKeyIndex});

} catch(e) {
console.log(`_setEnabled got error ${e}`);
return false;
}
// Generate a random key in case we are enabling.
this._onKeyGeneration();

const { mediaKeyIndex, mediaKey }
= await this._olmAdapter.initSessionsAndSetMediaKey(this._olmKey, this._pqKey);


logger.info(`CHECKPOINT: my media key is ${base64js.fromByteArray(mediaKey)} or ${mediaKey} and
index is ${mediaKeyIndex}`);
return true;

// Set our key so we begin encrypting.
this.setKey({encryptionKey: mediaKey, index: mediaKeyIndex});
}

/**
Expand Down
Loading

0 comments on commit ebca941

Please sign in to comment.