forked from mystiq/hydrogen-web
don't throw when we can't encrypt, just fall back to sending unencrypted
This commit is contained in:
parent
83eef2be9d
commit
a014740e72
4 changed files with 16 additions and 9 deletions
|
@ -81,16 +81,20 @@ export class Session {
|
||||||
hsApi: this._hsApi,
|
hsApi: this._hsApi,
|
||||||
encryptDeviceMessage: async (roomId, userId, deviceId, message, log) => {
|
encryptDeviceMessage: async (roomId, userId, deviceId, message, log) => {
|
||||||
if (!this._deviceTracker || !this._olmEncryption) {
|
if (!this._deviceTracker || !this._olmEncryption) {
|
||||||
throw new Error("encryption is not enabled");
|
log.set("encryption_disabled", true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
const device = await log.wrap("get device key", async log => {
|
const device = await log.wrap("get device key", async log => {
|
||||||
return this._deviceTracker.deviceForId(userId, deviceId, this._hsApi, log);
|
const device = this._deviceTracker.deviceForId(userId, deviceId, this._hsApi, log);
|
||||||
|
if (!device) {
|
||||||
|
log.set("not_found", true);
|
||||||
|
}
|
||||||
|
return device;
|
||||||
});
|
});
|
||||||
if (!device) {
|
if (device) {
|
||||||
throw new Error(`Could not find device key ${deviceId} for ${userId} in ${roomId}`);
|
const encryptedMessages = await this._olmEncryption.encrypt(message.type, message.content, [device], this._hsApi, log);
|
||||||
|
return encryptedMessages;
|
||||||
}
|
}
|
||||||
const encryptedMessages = await this._olmEncryption.encrypt(message.type, message.content, [device], this._hsApi, log);
|
|
||||||
return encryptedMessages;
|
|
||||||
},
|
},
|
||||||
storage: this._storage,
|
storage: this._storage,
|
||||||
webRTC: this._platform.webRTC,
|
webRTC: this._platform.webRTC,
|
||||||
|
|
|
@ -55,7 +55,7 @@ function getDeviceFromMemberKey(key: string): string {
|
||||||
|
|
||||||
export type Options = Omit<MemberOptions, "emitUpdate" | "confId" | "encryptDeviceMessage"> & {
|
export type Options = Omit<MemberOptions, "emitUpdate" | "confId" | "encryptDeviceMessage"> & {
|
||||||
emitUpdate: (call: GroupCall, params?: any) => void;
|
emitUpdate: (call: GroupCall, params?: any) => void;
|
||||||
encryptDeviceMessage: (roomId: string, userId: string, deviceId: string, message: SignallingMessage<MGroupCallBase>, log: ILogItem) => Promise<EncryptedMessage>,
|
encryptDeviceMessage: (roomId: string, userId: string, deviceId: string, message: SignallingMessage<MGroupCallBase>, log: ILogItem) => Promise<EncryptedMessage | undefined>,
|
||||||
storage: Storage,
|
storage: Storage,
|
||||||
logger: ILogger,
|
logger: ILogger,
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,7 +36,7 @@ export type Options = Omit<PeerCallOptions, "emitUpdate" | "sendSignallingMessag
|
||||||
// local session id of our client
|
// local session id of our client
|
||||||
sessionId: string,
|
sessionId: string,
|
||||||
hsApi: HomeServerApi,
|
hsApi: HomeServerApi,
|
||||||
encryptDeviceMessage: (userId: string, deviceId: string, message: SignallingMessage<MGroupCallBase>, log: ILogItem) => Promise<EncryptedMessage>,
|
encryptDeviceMessage: (userId: string, deviceId: string, message: SignallingMessage<MGroupCallBase>, log: ILogItem) => Promise<EncryptedMessage | undefined>,
|
||||||
emitUpdate: (participant: Member, params?: any) => void,
|
emitUpdate: (participant: Member, params?: any) => void,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -338,10 +338,13 @@ export class DeviceTracker {
|
||||||
const verifiedKeysPerUser = log.wrap("verify", log => this._filterVerifiedDeviceKeys(deviceKeyResponse["device_keys"], log));
|
const verifiedKeysPerUser = log.wrap("verify", log => this._filterVerifiedDeviceKeys(deviceKeyResponse["device_keys"], log));
|
||||||
//// END EXTRACT
|
//// END EXTRACT
|
||||||
|
|
||||||
// there should only be one device in here, but still check the HS sends us the right one
|
|
||||||
const verifiedKeys = verifiedKeysPerUser
|
const verifiedKeys = verifiedKeysPerUser
|
||||||
.find(vkpu => vkpu.userId === userId).verifiedKeys
|
.find(vkpu => vkpu.userId === userId).verifiedKeys
|
||||||
.find(vk => vk["device_id"] === deviceId);
|
.find(vk => vk["device_id"] === deviceId);
|
||||||
|
// user hasn't uploaded keys for device?
|
||||||
|
if (!verifiedKeys) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
device = deviceKeysAsDeviceIdentity(verifiedKeys);
|
device = deviceKeysAsDeviceIdentity(verifiedKeys);
|
||||||
const txn = await this._storage.readWriteTxn([
|
const txn = await this._storage.readWriteTxn([
|
||||||
this._storage.storeNames.deviceIdentities,
|
this._storage.storeNames.deviceIdentities,
|
||||||
|
|
Loading…
Reference in a new issue