don't encrypt to_device messages for now

This commit is contained in:
Bruno Windels 2022-04-07 16:50:16 +02:00
parent ad1cceac86
commit fe6e7b09b5
2 changed files with 40 additions and 16 deletions

View file

@ -38,6 +38,7 @@ export class DeviceMessageHandler {
async prepareSync(toDeviceEvents, lock, txn, log) { async prepareSync(toDeviceEvents, lock, txn, log) {
log.set("messageTypes", countBy(toDeviceEvents, e => e.type)); log.set("messageTypes", countBy(toDeviceEvents, e => e.type));
this._handleUnencryptedCallEvents(toDeviceEvents, log);
const encryptedEvents = toDeviceEvents.filter(e => e.type === "m.room.encrypted"); const encryptedEvents = toDeviceEvents.filter(e => e.type === "m.room.encrypted");
if (!this._olmDecryption) { if (!this._olmDecryption) {
log.log("can't decrypt, encryption not enabled", log.level.Warn); log.log("can't decrypt, encryption not enabled", log.level.Warn);
@ -52,19 +53,21 @@ export class DeviceMessageHandler {
log.child("decrypt_error").catch(err); log.child("decrypt_error").catch(err);
} }
const newRoomKeys = this._megolmDecryption.roomKeysFromDeviceMessages(olmDecryptChanges.results, log); const newRoomKeys = this._megolmDecryption.roomKeysFromDeviceMessages(olmDecryptChanges.results, log);
const callMessages = olmDecryptChanges.results.filter(dr => this._callHandler.handlesDeviceMessageEventType(dr.event?.type));
// load devices by sender key // const callMessages = olmDecryptChanges.results.filter(dr => this._callHandler.handlesDeviceMessageEventType(dr.event?.type));
await Promise.all(callMessages.map(async dr => { // // load devices by sender key
dr.setDevice(await this._getDevice(dr.senderCurve25519Key, txn)); // await Promise.all(callMessages.map(async dr => {
})); // dr.setDevice(await this._getDevice(dr.senderCurve25519Key, txn));
// TODO: pass this in the prep and run it in afterSync or afterSyncComplete (as callHandler can send events as well)? // }));
for (const dr of callMessages) { // // TODO: pass this in the prep and run it in afterSync or afterSyncComplete (as callHandler can send events as well)?
if (dr.device) { // for (const dr of callMessages) {
this._callHandler.handleDeviceMessage(dr.event, dr.device.userId, dr.device.deviceId, log); // if (dr.device) {
} else { // this._callHandler.handleDeviceMessage(dr.event, dr.device.userId, dr.device.deviceId, log);
console.error("could not deliver message because don't have device for sender key", dr.event); // } else {
} // console.error("could not deliver message because don't have device for sender key", dr.event);
} // }
// }
// TODO: somehow include rooms that received a call to_device message in the sync state? // TODO: somehow include rooms that received a call to_device message in the sync state?
// or have updates flow through event emitter? // or have updates flow through event emitter?
// well, we don't really need to update the room other then when a call starts or stops // well, we don't really need to update the room other then when a call starts or stops
@ -73,6 +76,15 @@ export class DeviceMessageHandler {
} }
} }
_handleUnencryptedCallEvents(toDeviceEvents, log) {
const callMessages = toDeviceEvents.filter(e => this._callHandler.handlesDeviceMessageEventType(e.type));
for (const event of callMessages) {
const userId = event.sender;
const deviceId = event.content.device_id;
this._callHandler.handleDeviceMessage(event, userId, deviceId, log);
}
}
/** check that prep is not undefined before calling this */ /** check that prep is not undefined before calling this */
async writeSync(prep, txn) { async writeSync(prep, txn) {
// write olm changes // write olm changes

View file

@ -110,10 +110,22 @@ export class Member {
sendSignallingMessage = async (message: SignallingMessage<MCallBase>, log: ILogItem): Promise<void> => { sendSignallingMessage = async (message: SignallingMessage<MCallBase>, log: ILogItem): Promise<void> => {
const groupMessage = message as SignallingMessage<MGroupCallBase>; const groupMessage = message as SignallingMessage<MGroupCallBase>;
groupMessage.content.conf_id = this.options.confId; groupMessage.content.conf_id = this.options.confId;
const encryptedMessages = await this.options.encryptDeviceMessage(this.member.userId, groupMessage, log); groupMessage.content.device_id = this.options.ownDeviceId;
const payload = formatToDeviceMessagesPayload(encryptedMessages); groupMessage.content.party_id = this.options.ownDeviceId;
groupMessage.content.sender_session_id = this.options.sessionId;
groupMessage.content.dest_session_id = this.destSessionId!;
// const encryptedMessages = await this.options.encryptDeviceMessage(this.member.userId, groupMessage, log);
// const payload = formatToDeviceMessagesPayload(encryptedMessages);
const payload = {
messages: {
[this.member.userId]: {
['*']: groupMessage.content
}
}
};
const request = this.options.hsApi.sendToDevice( const request = this.options.hsApi.sendToDevice(
"m.room.encrypted", message.type,
//"m.room.encrypted",
payload, payload,
makeTxnId(), makeTxnId(),
{log} {log}