Skip to content

Commit

Permalink
Log & expose device ID and identity at startup for visibility (#374)
Browse files Browse the repository at this point in the history
* Log & expose device ID and identity at startup for visibility

* appease the linter

* copy/paste more test

* force-set device ID
  • Loading branch information
turt2live authored Jan 27, 2025
1 parent 6174c38 commit 9d63bfd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/e2ee/CryptoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export class CryptoClient {
return this.deviceId;
}

/**
* The device's Ed25519 identity
*/
public get clientDeviceEd25519(): string {
return this.deviceEd25519;
}

/**
* Whether or not the crypto client is ready to be used. If not ready, prepare() should be called.
* @see prepare
Expand Down Expand Up @@ -84,7 +91,7 @@ export class CryptoClient {
await this.client.cryptoStore.setDeviceId(this.deviceId);
}

LogService.debug("CryptoClient", "Starting with device ID:", this.deviceId);
LogService.info("CryptoClient", "Starting with device ID:", this.deviceId); // info so all bots know for debugging

const machine = await OlmMachine.initialize(
new UserId(await this.client.getUserId()),
Expand All @@ -99,6 +106,8 @@ export class CryptoClient {
this.deviceCurve25519 = identity.curve25519.toBase64();
this.deviceEd25519 = identity.ed25519.toBase64();

LogService.debug("CryptoClient", "Running with device Ed25519 identity:", this.deviceEd25519); // info so all bots know for debugging

this.ready = true;
}

Expand Down
13 changes: 13 additions & 0 deletions test/encryption/CryptoClientTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ describe('CryptoClient', () => {
expect(whoamiSpy.callCount).toEqual(0);
expect(client.crypto.clientDeviceId).toEqual(TEST_DEVICE_ID);
}));

it('should expose the device Ed25519 identity', () => testCryptoStores(async (cryptoStoreType) => {
const userId = "@alice:example.org";
const { client, http } = createTestClient(null, userId, cryptoStoreType);

await client.cryptoStore.setDeviceId(TEST_DEVICE_ID);
bindNullEngine(http);
await Promise.all([
client.crypto.prepare([]),
http.flushAllExpected(),
]);
expect(client.crypto.clientDeviceEd25519).toBeTruthy();
}));
});

describe('isRoomEncrypted', () => {
Expand Down

0 comments on commit 9d63bfd

Please sign in to comment.