You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
ElementR: Update CryptoApi.userHasCrossSigningKeys (#3646)
* WIP `CryptoApi.getStoredCrossSigningForUser` * Fix QRCode * Add docs and rename * Add tests for `RustCrossSigningInfo.ts` * Do `/keys/query` instead of using `UserIdentity` * Review changes * Get rid of `CrossSigningInfo` * Merge `hasCrossSigningKeysForUser` into `userHasCrossSigningKeys` * Apply suggestions from code review * More review comments --------- Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Co-authored-by: Richard van der Hoff <richard@matrix.org>
This commit is contained in:
@@ -244,20 +244,6 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
|
||||
|
||||
public globalBlacklistUnverifiedDevices = false;
|
||||
|
||||
/**
|
||||
* Implementation of {@link CryptoApi.userHasCrossSigningKeys}.
|
||||
*/
|
||||
public async userHasCrossSigningKeys(): Promise<boolean> {
|
||||
const userId = new RustSdkCryptoJs.UserId(this.userId);
|
||||
/* make sure we have an *up-to-date* idea of the user's cross-signing keys. This is important, because if we
|
||||
* return "false" here, we will end up generating new cross-signing keys and replacing the existing ones.
|
||||
*/
|
||||
const request = this.olmMachine.queryKeysForUsers([userId]);
|
||||
await this.outgoingRequestProcessor.makeOutgoingRequest(request);
|
||||
const userIdentity = await this.olmMachine.getIdentity(userId);
|
||||
return userIdentity !== undefined;
|
||||
}
|
||||
|
||||
public prepareToEncrypt(room: Room): void {
|
||||
const encryptor = this.roomEncryptors[room.roomId];
|
||||
|
||||
@@ -289,6 +275,47 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link CryptoApi.userHasCrossSigningKeys}.
|
||||
*/
|
||||
public async userHasCrossSigningKeys(userId = this.userId, downloadUncached = false): Promise<boolean> {
|
||||
// TODO: could probably do with a more efficient way of doing this than returning the whole set and searching
|
||||
const rustTrackedUsers: Set<RustSdkCryptoJs.UserId> = await this.olmMachine.trackedUsers();
|
||||
let rustTrackedUser: RustSdkCryptoJs.UserId | undefined;
|
||||
for (const u of rustTrackedUsers) {
|
||||
if (userId === u.toString()) {
|
||||
rustTrackedUser = u;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (rustTrackedUser !== undefined) {
|
||||
if (userId === this.userId) {
|
||||
/* make sure we have an *up-to-date* idea of the user's cross-signing keys. This is important, because if we
|
||||
* return "false" here, we will end up generating new cross-signing keys and replacing the existing ones.
|
||||
*/
|
||||
const request = this.olmMachine.queryKeysForUsers([rustTrackedUser]);
|
||||
await this.outgoingRequestProcessor.makeOutgoingRequest(request);
|
||||
}
|
||||
const userIdentity = await this.olmMachine.getIdentity(rustTrackedUser);
|
||||
return userIdentity !== undefined;
|
||||
} else if (downloadUncached) {
|
||||
// Download the cross signing keys and check if the master key is available
|
||||
const keyResult = await this.downloadDeviceList(new Set([userId]));
|
||||
const keys = keyResult.master_keys?.[userId];
|
||||
|
||||
// No master key
|
||||
if (!keys) return false;
|
||||
|
||||
// `keys` is an object with { [`ed25519:${pubKey}`]: pubKey }
|
||||
// We assume only a single key, and we want the bare form without type
|
||||
// prefix, so we select the values.
|
||||
return Boolean(Object.values(keys.keys)[0]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the device information for the given list of users.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user