Use new `getCrossSigningKeyId` instead of old `getCrossSigningId` (#10885)

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

* Fix type error
pull/28217/head
Richard van der Hoff 2023-05-15 19:30:43 +01:00 committed by GitHub
parent 77d18f1a43
commit 38c13509fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 15 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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");
}
@ -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");
@ -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;
@ -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");
}

View File

@ -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<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;

View File

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