Skip to content

Commit

Permalink
Element-R: implement userHasCrossSigningKeys (#3488)
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Jun 19, 2023
1 parent 9c62d15 commit 80cdbe1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
32 changes: 31 additions & 1 deletion spec/unit/rust-crypto/rust-crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import { IHttpOpts, IToDeviceEvent, MatrixClient, MatrixHttpApi } from "../../..
import { mkEvent } from "../../test-utils/test-utils";
import { CryptoBackend } from "../../../src/common-crypto/CryptoBackend";
import { IEventDecryptionResult } from "../../../src/@types/crypto";
import { OutgoingRequestProcessor } from "../../../src/rust-crypto/OutgoingRequestProcessor";
import { OutgoingRequest, OutgoingRequestProcessor } from "../../../src/rust-crypto/OutgoingRequestProcessor";
import { ServerSideSecretStorage } from "../../../src/secret-storage";
import { ImportRoomKeysOpts } from "../../../src/crypto-api";
import * as testData from "../../test-utils/test-data";

afterEach(() => {
// reset fake-indexeddb after each test, to make sure we don't leak connections
Expand Down Expand Up @@ -357,6 +358,35 @@ describe("RustCrypto", () => {
});
});

describe("userHasCrossSigningKeys", () => {
let rustCrypto: RustCrypto;

beforeEach(async () => {
rustCrypto = await makeTestRustCrypto(undefined, testData.TEST_USER_ID);
});

it("returns false if there is no cross-signing identity", async () => {
await expect(rustCrypto.userHasCrossSigningKeys()).resolves.toBe(false);
});

it("returns true if OlmMachine has a cross-signing identity", async () => {
// @ts-ignore private field
const olmMachine = rustCrypto.olmMachine;

const outgoingRequests: OutgoingRequest[] = await olmMachine.outgoingRequests();
// pick out the KeysQueryRequest, and respond to it with the cross-signing keys
const req = outgoingRequests.find((r) => r instanceof KeysQueryRequest)!;
await olmMachine.markRequestAsSent(
req.id!,
req.type,
JSON.stringify(testData.SIGNED_CROSS_SIGNING_KEYS_DATA),
);

// ... and we should now have cross-signing keys.
await expect(rustCrypto.userHasCrossSigningKeys()).resolves.toBe(true);
});
});

describe("createRecoveryKeyFromPassphrase", () => {
let rustCrypto: RustCrypto;

Expand Down
7 changes: 5 additions & 2 deletions src/rust-crypto/rust-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,12 @@ export class RustCrypto implements CryptoBackend {

public globalBlacklistUnverifiedDevices = false;

/**
* Implementation of {@link CryptoApi.userHasCrossSigningKeys}.
*/
public async userHasCrossSigningKeys(): Promise<boolean> {
// TODO
return false;
const userIdentity = await this.olmMachine.getIdentity(new RustSdkCryptoJs.UserId(this.userId));
return userIdentity !== undefined;
}

public prepareToEncrypt(room: Room): void {
Expand Down

0 comments on commit 80cdbe1

Please sign in to comment.