Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Use new getCrossSigningKeyId instead of old getCrossSigningId (#1…
Browse files Browse the repository at this point in the history
…0885)

* Use new `getCrossSigningKeyId` instead of old `getCrossSigningId`

* Fix type error
  • Loading branch information
richvdh authored May 15, 2023
1 parent 77d18f1 commit 38c1350
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/DeviceListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/rageshake/submit-rageshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function collectBugReport(opts: IOpts = {}, gzipLogs = true): Promise<Form
keys.push(`curve25519:${client.getDeviceCurve25519Key()}`);
}
body.append("device_keys", keys.join(", "));
body.append("cross_signing_key", client.getCrossSigningId() ?? "n/a");
body.append("cross_signing_key", (await client.getCrypto()?.getCrossSigningKeyId()) ?? "n/a");

// add cross-signing status information
const crossSigning = client.crypto.crossSigningInfo;
Expand Down
10 changes: 5 additions & 5 deletions src/stores/SetupEncryptionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class SetupEncryptionStore extends EventEmitter {
}).catch(reject);
});

if (cli.getCrossSigningId()) {
if (await cli.getCrypto()?.getCrossSigningKeyId()) {
this.phase = Phase.Done;
this.emit("update");
}
Expand All @@ -164,9 +164,9 @@ export class SetupEncryptionStore extends EventEmitter {
}
}

private onUserTrustStatusChanged = (userId: string): void => {
private onUserTrustStatusChanged = async (userId: string): Promise<void> => {
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");
Expand All @@ -177,7 +177,7 @@ export class SetupEncryptionStore extends EventEmitter {
this.setActiveVerificationRequest(request);
};

public onVerificationRequestChange = (): void => {
public onVerificationRequestChange = async (): Promise<void> => {
if (this.verificationRequest?.cancelled) {
this.verificationRequest.off(VerificationRequestEvent.Change, this.onVerificationRequestChange);
this.verificationRequest = null;
Expand All @@ -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");
}
Expand Down
8 changes: 4 additions & 4 deletions src/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -33,10 +34,9 @@ import { findDMForUser } from "./utils/dm/findDMForUser";

async function enable4SIfNeeded(): Promise<boolean> {
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;
Expand Down
8 changes: 4 additions & 4 deletions test/DeviceListener-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(),
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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();

Expand All @@ -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 () => {
Expand Down

0 comments on commit 38c1350

Please sign in to comment.