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 support for sending encrypted to-device events with OLM #2322

Merged
merged 1 commit into from
May 18, 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
8 changes: 4 additions & 4 deletions src/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3036,7 +3036,7 @@ export class Crypto extends EventEmitter {
* set of devices. Factored out from encryptAndSendKeysToDevices in
* megolm.ts.
*
* @param {object<userId, deviceInfo>} userDeviceMap
* @param {object[]} userDeviceInfoArr
* mapping from userId to deviceInfo
*
* @param {object} payload fields to include in the encrypted payload
Expand All @@ -3047,20 +3047,20 @@ export class Crypto extends EventEmitter {
* of the successfully sent messages.
*/
public encryptAndSendToDevices(
userDeviceMap: IOlmDevice<DeviceInfo>[],
userDeviceInfoArr: IOlmDevice<DeviceInfo>[],
payload: object,
): Promise<{contentMap, deviceInfoByDeviceId}> {
const contentMap = {};
const deviceInfoByDeviceId = new Map<string, DeviceInfo>();

const promises = [];
for (let i = 0; i < userDeviceMap.length; i++) {
for (let i = 0; i < userDeviceInfoArr.length; i++) {
const encryptedContent = {
algorithm: olmlib.OLM_ALGORITHM,
sender_key: this.olmDevice.deviceCurve25519Key,
ciphertext: {},
};
const val = userDeviceMap[i];
const val = userDeviceInfoArr[i];
const userId = val.userId;
const deviceInfo = val.deviceInfo;
const deviceId = deviceInfo.deviceId;
Expand Down
25 changes: 14 additions & 11 deletions src/webrtc/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2005,7 +2005,7 @@ export class MatrixCall extends EventEmitter {
* @param {Object} content
* @return {Promise}
*/
private sendVoipEvent(eventType: string, content: object): Promise<ISendEventResponse | {}> {
private async sendVoipEvent(eventType: string, content: object): Promise<ISendEventResponse | {}> {
const realContent = Object.assign({}, content, {
version: VOIP_PROTO_VERSION,
call_id: this.callId,
Expand All @@ -2030,17 +2030,20 @@ export class MatrixCall extends EventEmitter {
},
});

return this.client.sendToDevice(eventType, {
[this.invitee || this.getOpponentMember().userId]: {
[this.opponentDeviceId]: {
...realContent,
device_id: this.client.deviceId,
sender_session_id: this.client.getSessionId(),
dest_session_id: this.opponentSessionId,
seq: toDeviceSeq,
},
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 userId = this.invitee || this.getOpponentMember().userId;
const deviceInfoMap = await this.client.crypto.deviceList.downloadKeys([userId], false);
const deviceInfo = deviceInfoMap[userId][this.opponentDeviceId];
return this.client.crypto.encryptAndSendToDevices([{ userId, deviceInfo }], payload);
} else {
this.emit(CallEvent.SendVoipEvent, {
type: "sendEvent",
Expand Down