Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option for e2e group call signalling #2492

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ export interface ICreateClientOpts {
*/
fallbackICEServerAllowed?: boolean;

/**
* If true, to-device signalling for group calls will be encrypted
* with Olm. Default: true.
*/
useE2eForGroupCall?: boolean;

cryptoCallbacks?: ICryptoCallbacks;
}

Expand Down Expand Up @@ -954,6 +960,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
protected sessionId: string;
protected pendingEventEncryption = new Map<string, Promise<void>>();

private useE2eForGroupCall = true;

constructor(opts: IMatrixClientCreateOpts) {
super();

Expand Down Expand Up @@ -1044,6 +1052,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
this.supportsCallTransfer = opts.supportsCallTransfer || false;
this.fallbackICEServerAllowed = opts.fallbackICEServerAllowed || false;

if (opts.useE2eForGroupCall !== undefined) this.useE2eForGroupCall = opts.useE2eForGroupCall;

// List of which rooms have encryption enabled: separate from crypto because
// we still want to know which rooms are encrypted even if crypto is disabled:
// we don't want to start sending unencrypted events to them.
Expand Down Expand Up @@ -1499,6 +1509,15 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
this.supportsCallTransfer = support;
}

/**
* Returns true if to-device signalling for group calls will be encrypted with Olm.
* If false, it will be sent unencrypted.
* @returns boolean Whether group call signalling will be encrypted
*/
public getUseE2eForGroupCall(): boolean {
return this.useE2eForGroupCall;
}

/**
* Creates a new call.
* The place*Call methods on the returned call can be used to actually place a call
Expand Down
36 changes: 23 additions & 13 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap

private async initOpponentCrypto() {
if (!this.opponentDeviceId) return;
if (!this.client.getUseE2eForGroupCall()) return;

const userId = this.invitee || this.getOpponentMember().userId;
const deviceInfoMap = await this.client.crypto.deviceList.downloadKeys([userId], false);
Expand Down Expand Up @@ -2144,21 +2145,30 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
},
});

const payload = {
type: eventType,
content: {
...realContent,
device_id: this.client.deviceId,
sender_session_id: this.client.getSessionId(),
dest_session_id: this.opponentSessionId,
seq: toDeviceSeq,
},
const content = {
...realContent,
device_id: this.client.deviceId,
sender_session_id: this.client.getSessionId(),
dest_session_id: this.opponentSessionId,
seq: toDeviceSeq,
};

const userId = this.invitee || this.getOpponentMember().userId;
return this.client.crypto.encryptAndSendToDevices([{
userId,
deviceInfo: this.opponentDeviceInfo,
}], payload);
if (this.client.getUseE2eForGroupCall()) {
return this.client.crypto.encryptAndSendToDevices([{
userId,
deviceInfo: this.opponentDeviceInfo,
}], {
type: eventType,
content,
});
} else {
return this.client.sendToDevice(eventType, {
[userId]: {
[this.opponentDeviceId]: content,
},
});
}
} else {
this.emit(CallEvent.SendVoipEvent, {
type: "sendEvent",
Expand Down