From 38c13509fd21ba6152f2d9b83eb07a53275322be Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Mon, 15 May 2023 19:30:43 +0100 Subject: [PATCH] Use new `getCrossSigningKeyId` instead of old `getCrossSigningId` (#10885) * Use new `getCrossSigningKeyId` instead of old `getCrossSigningId` * Fix type error --- src/DeviceListener.ts | 2 +- src/rageshake/submit-rageshake.ts | 2 +- src/stores/SetupEncryptionStore.ts | 10 +++++----- src/verification.ts | 8 ++++---- test/DeviceListener-test.ts | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/DeviceListener.ts b/src/DeviceListener.ts index b1b3208230..e01bc54b60 100644 --- a/src/DeviceListener.ts +++ b/src/DeviceListener.ts @@ -289,7 +289,7 @@ export default class DeviceListener { // cross signing isn't enabled - nag to enable it // There are 3 different toasts for: - if (!cli.getCrossSigningId() && cli.getStoredCrossSigningForUser(cli.getUserId()!)) { + if (!(await crypto.getCrossSigningKeyId()) && cli.getStoredCrossSigningForUser(cli.getUserId()!)) { // Cross-signing on account but this device doesn't trust the master key (verify this session) showSetupEncryptionToast(SetupKind.VERIFY_THIS_SESSION); this.checkKeyBackupStatus(); diff --git a/src/rageshake/submit-rageshake.ts b/src/rageshake/submit-rageshake.ts index b62688325f..47b76625cd 100644 --- a/src/rageshake/submit-rageshake.ts +++ b/src/rageshake/submit-rageshake.ts @@ -87,7 +87,7 @@ async function collectBugReport(opts: IOpts = {}, gzipLogs = true): Promise
{ + private onUserTrustStatusChanged = async (userId: string): Promise => { if (userId !== MatrixClientPeg.get().getUserId()) return; - const publicKeysTrusted = MatrixClientPeg.get().getCrossSigningId(); + const publicKeysTrusted = await MatrixClientPeg.get().getCrypto()?.getCrossSigningKeyId(); if (publicKeysTrusted) { this.phase = Phase.Done; this.emit("update"); @@ -177,7 +177,7 @@ export class SetupEncryptionStore extends EventEmitter { this.setActiveVerificationRequest(request); }; - public onVerificationRequestChange = (): void => { + public onVerificationRequestChange = async (): Promise => { if (this.verificationRequest?.cancelled) { this.verificationRequest.off(VerificationRequestEvent.Change, this.onVerificationRequestChange); this.verificationRequest = null; @@ -188,7 +188,7 @@ export class SetupEncryptionStore extends EventEmitter { // At this point, the verification has finished, we just need to wait for // cross signing to be ready to use, so wait for the user trust status to // change (or change to DONE if it's already ready). - const publicKeysTrusted = MatrixClientPeg.get().getCrossSigningId(); + const publicKeysTrusted = await MatrixClientPeg.get().getCrypto()?.getCrossSigningKeyId(); this.phase = publicKeysTrusted ? Phase.Done : Phase.Busy; this.emit("update"); } diff --git a/src/verification.ts b/src/verification.ts index 83411d5650..50456ce3d4 100644 --- a/src/verification.ts +++ b/src/verification.ts @@ -18,6 +18,7 @@ import { User } from "matrix-js-sdk/src/models/user"; import { verificationMethods as VerificationMethods } from "matrix-js-sdk/src/crypto"; import { RoomMember } from "matrix-js-sdk/src/matrix"; import { VerificationRequest } from "matrix-js-sdk/src/crypto/verification/request/VerificationRequest"; +import { CrossSigningKey } from "matrix-js-sdk/src/crypto-api"; import { MatrixClientPeg } from "./MatrixClientPeg"; import dis from "./dispatcher/dispatcher"; @@ -33,10 +34,9 @@ import { findDMForUser } from "./utils/dm/findDMForUser"; async function enable4SIfNeeded(): Promise { const cli = MatrixClientPeg.get(); - if (!cli.isCryptoEnabled()) { - return false; - } - const usk = cli.getCrossSigningId("user_signing"); + const crypto = cli.getCrypto(); + if (!crypto) return false; + const usk = await crypto.getCrossSigningKeyId(CrossSigningKey.UserSigning); if (!usk) { await accessSecretStorage(); return false; diff --git a/test/DeviceListener-test.ts b/test/DeviceListener-test.ts index 95214ef006..34c3d56a5f 100644 --- a/test/DeviceListener-test.ts +++ b/test/DeviceListener-test.ts @@ -80,6 +80,7 @@ describe("DeviceListener", () => { getDeviceVerificationStatus: jest.fn().mockResolvedValue({ crossSigningVerified: false, }), + getCrossSigningKeyId: jest.fn(), getUserDeviceInfo: jest.fn().mockResolvedValue(new Map()), isCrossSigningReady: jest.fn().mockResolvedValue(true), isSecretStorageReady: jest.fn().mockResolvedValue(true), @@ -93,7 +94,6 @@ describe("DeviceListener", () => { isVersionSupported: jest.fn().mockResolvedValue(true), isInitialSyncComplete: jest.fn().mockReturnValue(true), getKeyBackupEnabled: jest.fn(), - getCrossSigningId: jest.fn(), getStoredCrossSigningForUser: jest.fn(), waitForClientWellKnown: jest.fn(), isRoomEncrypted: jest.fn(), @@ -298,7 +298,7 @@ describe("DeviceListener", () => { describe("when user does not have a cross signing id on this device", () => { beforeEach(() => { - mockClient!.getCrossSigningId.mockReturnValue(null); + mockCrypto!.getCrossSigningKeyId.mockResolvedValue(null); }); it("shows verify session toast when account has cross signing", async () => { @@ -312,7 +312,7 @@ describe("DeviceListener", () => { }); it("checks key backup status when when account has cross signing", async () => { - mockClient!.getCrossSigningId.mockReturnValue(null); + mockCrypto!.getCrossSigningKeyId.mockResolvedValue(null); mockClient!.getStoredCrossSigningForUser.mockReturnValue(new CrossSigningInfo(userId)); await createAndStart(); @@ -322,7 +322,7 @@ describe("DeviceListener", () => { describe("when user does have a cross signing id on this device", () => { beforeEach(() => { - mockClient!.getCrossSigningId.mockReturnValue("abc"); + mockCrypto!.getCrossSigningKeyId.mockResolvedValue("abc"); }); it("shows upgrade encryption toast when user has a key backup available", async () => {