mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-11-20 03:25:52 +01:00
Check verification for response as well
This commit is contained in:
parent
f8bfc384d3
commit
00479df71e
@ -36,7 +36,7 @@ type DecryptedEvent = {
|
||||
}
|
||||
|
||||
export class DecryptionResult {
|
||||
private device?: DeviceKey;
|
||||
public device?: DeviceKey;
|
||||
|
||||
constructor(
|
||||
public readonly event: DecryptedEvent,
|
||||
|
@ -188,8 +188,23 @@ export class SecretSharing {
|
||||
* @param decryptionResult Encrypted to-device event that contains the secret
|
||||
*/
|
||||
async shouldAcceptSecret(decryptionResult: DecryptionResult): Promise<string | undefined> {
|
||||
// 1. Check if we can trust this response
|
||||
const crossSigning = this.crossSigning.get();
|
||||
if (!crossSigning) {
|
||||
return;
|
||||
}
|
||||
const device = decryptionResult.device;
|
||||
if (!device) {
|
||||
return;
|
||||
}
|
||||
if (!await crossSigning.isOurUserDeviceTrusted(device)) {
|
||||
// We don't want to accept secrets from an untrusted device
|
||||
console.log("received secret, but ignoring because not verified");
|
||||
return;
|
||||
}
|
||||
const content = decryptionResult.event.content!;
|
||||
const requestId = content.request_id;
|
||||
// 2. Check if this request is in waitMap
|
||||
const obj = this.waitMap.get(requestId);
|
||||
if (obj) {
|
||||
const { name, deferred } = obj;
|
||||
@ -198,6 +213,7 @@ export class SecretSharing {
|
||||
await this.removeStoredRequestId(requestId);
|
||||
return name;
|
||||
}
|
||||
// 3. Check if we've persisted the request to storage
|
||||
const txn = await this.storage.readTxn([this.storage.storeNames.session]);
|
||||
const storedIds = await txn.session.get(STORAGE_KEY);
|
||||
const name = storedIds?.[requestId];
|
||||
|
@ -303,13 +303,13 @@ export class CrossSigning {
|
||||
});
|
||||
}
|
||||
|
||||
async isOurUserDeviceTrusted(device: DeviceKey, log: ILogItem): Promise<boolean> {
|
||||
return await log.wrap("CrossSigning.getDeviceTrust", async () => {
|
||||
const ourSSK = await this.deviceTracker.getCrossSigningKeyForUser(this.ownUserId, KeyUsage.SelfSigning, this.hsApi, log);
|
||||
async isOurUserDeviceTrusted(device: DeviceKey, log?: ILogItem): Promise<boolean> {
|
||||
return await this.platform.logger.wrapOrRun(log, "CrossSigning.getDeviceTrust", async (_log) => {
|
||||
const ourSSK = await this.deviceTracker.getCrossSigningKeyForUser(this.ownUserId, KeyUsage.SelfSigning, this.hsApi, _log);
|
||||
if (!ourSSK) {
|
||||
return false;
|
||||
}
|
||||
const verification = this.hasValidSignatureFrom(device, ourSSK, log);
|
||||
const verification = this.hasValidSignatureFrom(device, ourSSK, _log);
|
||||
if (verification === SignatureVerification.Valid) {
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user