You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-04 05:02:41 +03:00
Element-R: stub implementations of some methods (#3075)
These are all called by the react-sdk when showing an encrypted event: * `getEventEncryptionInfo` * `checkUserTrust` * `checkDeviceTrust` I don't particularly want to keep this API, but as a rapid means to an end, let's stub them for now.
This commit is contained in:
committed by
GitHub
parent
85b34b46c5
commit
d6b8332567
@@ -32,6 +32,9 @@ import { RustCrypto } from "../../src/rust-crypto/rust-crypto";
|
|||||||
import { initRustCrypto } from "../../src/rust-crypto";
|
import { initRustCrypto } from "../../src/rust-crypto";
|
||||||
import { HttpApiEvent, HttpApiEventHandlerMap, IToDeviceEvent, MatrixClient, MatrixHttpApi } from "../../src";
|
import { HttpApiEvent, HttpApiEventHandlerMap, IToDeviceEvent, MatrixClient, MatrixHttpApi } from "../../src";
|
||||||
import { TypedEventEmitter } from "../../src/models/typed-event-emitter";
|
import { TypedEventEmitter } from "../../src/models/typed-event-emitter";
|
||||||
|
import { mkEvent } from "../test-utils/test-utils";
|
||||||
|
import { CryptoBackend } from "../../src/common-crypto/CryptoBackend";
|
||||||
|
import { IEventDecryptionResult } from "../../src/@types/crypto";
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
// reset fake-indexeddb after each test, to make sure we don't leak connections
|
// reset fake-indexeddb after each test, to make sure we don't leak connections
|
||||||
@@ -245,4 +248,33 @@ describe("RustCrypto", () => {
|
|||||||
expect(outgoingRequestQueue.length).toEqual(2);
|
expect(outgoingRequestQueue.length).toEqual(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe(".getEventEncryptionInfo", () => {
|
||||||
|
let rustCrypto: RustCrypto;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const mockHttpApi = {} as MatrixClient["http"];
|
||||||
|
rustCrypto = (await initRustCrypto(mockHttpApi, TEST_USER, TEST_DEVICE_ID)) as RustCrypto;
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle unencrypted events", () => {
|
||||||
|
const event = mkEvent({ event: true, type: "m.room.message", content: { body: "xyz" } });
|
||||||
|
const res = rustCrypto.getEventEncryptionInfo(event);
|
||||||
|
expect(res.encrypted).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle encrypted events", async () => {
|
||||||
|
const event = mkEvent({ event: true, type: "m.room.encrypted", content: { algorithm: "fake_alg" } });
|
||||||
|
const mockCryptoBackend = {
|
||||||
|
decryptEvent: () =>
|
||||||
|
({
|
||||||
|
senderCurve25519Key: "1234",
|
||||||
|
} as IEventDecryptionResult),
|
||||||
|
} as unknown as CryptoBackend;
|
||||||
|
await event.attemptDecryption(mockCryptoBackend);
|
||||||
|
|
||||||
|
const res = rustCrypto.getEventEncryptionInfo(event);
|
||||||
|
expect(res.encrypted).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2507,10 +2507,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public checkUserTrust(userId: string): UserTrustLevel {
|
public checkUserTrust(userId: string): UserTrustLevel {
|
||||||
if (!this.crypto) {
|
if (!this.cryptoBackend) {
|
||||||
throw new Error("End-to-end encryption disabled");
|
throw new Error("End-to-end encryption disabled");
|
||||||
}
|
}
|
||||||
return this.crypto.checkUserTrust(userId);
|
return this.cryptoBackend.checkUserTrust(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2522,10 +2522,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
* @param deviceId - The ID of the device to check
|
* @param deviceId - The ID of the device to check
|
||||||
*/
|
*/
|
||||||
public checkDeviceTrust(userId: string, deviceId: string): DeviceTrustLevel {
|
public checkDeviceTrust(userId: string, deviceId: string): DeviceTrustLevel {
|
||||||
if (!this.crypto) {
|
if (!this.cryptoBackend) {
|
||||||
throw new Error("End-to-end encryption disabled");
|
throw new Error("End-to-end encryption disabled");
|
||||||
}
|
}
|
||||||
return this.crypto.checkDeviceTrust(userId, deviceId);
|
return this.cryptoBackend.checkDeviceTrust(userId, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2689,10 +2689,10 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
* @returns The event information.
|
* @returns The event information.
|
||||||
*/
|
*/
|
||||||
public getEventEncryptionInfo(event: MatrixEvent): IEncryptedEventInfo {
|
public getEventEncryptionInfo(event: MatrixEvent): IEncryptedEventInfo {
|
||||||
if (!this.crypto) {
|
if (!this.cryptoBackend) {
|
||||||
throw new Error("End-to-end encryption disabled");
|
throw new Error("End-to-end encryption disabled");
|
||||||
}
|
}
|
||||||
return this.crypto.getEventEncryptionInfo(event);
|
return this.cryptoBackend.getEventEncryptionInfo(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ limitations under the License.
|
|||||||
|
|
||||||
import type { IEventDecryptionResult, IMegolmSessionData } from "../@types/crypto";
|
import type { IEventDecryptionResult, IMegolmSessionData } from "../@types/crypto";
|
||||||
import type { IToDeviceEvent } from "../sync-accumulator";
|
import type { IToDeviceEvent } from "../sync-accumulator";
|
||||||
|
import type { DeviceTrustLevel, UserTrustLevel } from "../crypto/CrossSigning";
|
||||||
import { MatrixEvent } from "../models/event";
|
import { MatrixEvent } from "../models/event";
|
||||||
|
import { IEncryptedEventInfo } from "../crypto/api";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common interface for the crypto implementations
|
* Common interface for the crypto implementations
|
||||||
@@ -54,6 +56,25 @@ export interface CryptoBackend extends SyncCryptoCallbacks {
|
|||||||
*/
|
*/
|
||||||
userHasCrossSigningKeys(): Promise<boolean>;
|
userHasCrossSigningKeys(): Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the verification level for a given user
|
||||||
|
*
|
||||||
|
* TODO: define this better
|
||||||
|
*
|
||||||
|
* @param userId - user to be checked
|
||||||
|
*/
|
||||||
|
checkUserTrust(userId: string): UserTrustLevel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the verification level for a given device
|
||||||
|
*
|
||||||
|
* TODO: define this better
|
||||||
|
*
|
||||||
|
* @param userId - user to be checked
|
||||||
|
* @param deviceId - device to be checked
|
||||||
|
*/
|
||||||
|
checkDeviceTrust(userId: string, deviceId: string): DeviceTrustLevel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrypt a received event
|
* Decrypt a received event
|
||||||
*
|
*
|
||||||
@@ -62,6 +83,13 @@ export interface CryptoBackend extends SyncCryptoCallbacks {
|
|||||||
*/
|
*/
|
||||||
decryptEvent(event: MatrixEvent): Promise<IEventDecryptionResult>;
|
decryptEvent(event: MatrixEvent): Promise<IEventDecryptionResult>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about the encryption of an event
|
||||||
|
*
|
||||||
|
* @param event - event to be checked
|
||||||
|
*/
|
||||||
|
getEventEncryptionInfo(event: MatrixEvent): IEncryptedEventInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list containing all of the room keys
|
* Get a list containing all of the room keys
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -25,11 +25,13 @@ import {
|
|||||||
|
|
||||||
import type { IEventDecryptionResult, IMegolmSessionData } from "../@types/crypto";
|
import type { IEventDecryptionResult, IMegolmSessionData } from "../@types/crypto";
|
||||||
import type { IToDeviceEvent } from "../sync-accumulator";
|
import type { IToDeviceEvent } from "../sync-accumulator";
|
||||||
|
import type { IEncryptedEventInfo } from "../crypto/api";
|
||||||
import { MatrixEvent } from "../models/event";
|
import { MatrixEvent } from "../models/event";
|
||||||
import { CryptoBackend, OnSyncCompletedData } from "../common-crypto/CryptoBackend";
|
import { CryptoBackend, OnSyncCompletedData } from "../common-crypto/CryptoBackend";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
import { IHttpOpts, MatrixHttpApi, Method } from "../http-api";
|
import { IHttpOpts, MatrixHttpApi, Method } from "../http-api";
|
||||||
import { QueryDict } from "../utils";
|
import { QueryDict } from "../utils";
|
||||||
|
import { DeviceTrustLevel, UserTrustLevel } from "../crypto/CrossSigning";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common interface for all the request types returned by `OlmMachine.outgoingRequests`.
|
* Common interface for all the request types returned by `OlmMachine.outgoingRequests`.
|
||||||
@@ -78,6 +80,24 @@ export class RustCrypto implements CryptoBackend {
|
|||||||
throw new Error("not implemented");
|
throw new Error("not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getEventEncryptionInfo(event: MatrixEvent): IEncryptedEventInfo {
|
||||||
|
// TODO: make this work properly. Or better, replace it.
|
||||||
|
|
||||||
|
const ret: Partial<IEncryptedEventInfo> = {};
|
||||||
|
|
||||||
|
ret.senderKey = event.getSenderKey() ?? undefined;
|
||||||
|
ret.algorithm = event.getWireContent().algorithm;
|
||||||
|
|
||||||
|
if (!ret.senderKey || !ret.algorithm) {
|
||||||
|
ret.encrypted = false;
|
||||||
|
return ret as IEncryptedEventInfo;
|
||||||
|
}
|
||||||
|
ret.encrypted = true;
|
||||||
|
ret.authenticated = true;
|
||||||
|
ret.mismatchedSender = true;
|
||||||
|
return ret as IEncryptedEventInfo;
|
||||||
|
}
|
||||||
|
|
||||||
public async userHasCrossSigningKeys(): Promise<boolean> {
|
public async userHasCrossSigningKeys(): Promise<boolean> {
|
||||||
// TODO
|
// TODO
|
||||||
return false;
|
return false;
|
||||||
@@ -88,6 +108,16 @@ export class RustCrypto implements CryptoBackend {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public checkUserTrust(userId: string): UserTrustLevel {
|
||||||
|
// TODO
|
||||||
|
return new UserTrustLevel(false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public checkDeviceTrust(userId: string, deviceId: string): DeviceTrustLevel {
|
||||||
|
// TODO
|
||||||
|
return new DeviceTrustLevel(false, false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SyncCryptoCallbacks implementation
|
// SyncCryptoCallbacks implementation
|
||||||
|
|||||||
Reference in New Issue
Block a user