First batch: remove deprecated calls on MatrixClient (#28207)

* Remove `initCrypto` mocking

* Remove `MatrixClient.downloadKeys` mocking

* Remove `MatrixClient.getStoredDevice` mocking

* Replace `MatrixClient.setGlobalBlacklistUnverifiedDevices` by `MatrixClient.CryptoApi.globalBlacklistUnverifiedDevices`

* Remove `MatrixClient.getStoredCrossSigningForUser` mocking

* Replace `MatrixClient.legacyDeviceVerification` by `MatrixClient.CryptoApi.requestDeviceVerification`

* Remove `MatrixClient.isCrossSigningReady` mock

* Replace `MatrixClient.bootstrapCrossSigning` by `MatrixClient.getCrypto.bootstrapCrossSigning`

* Replace `MatrixClient.getCryptoTrustCrossSignedDevices` by `MatrixClient.getCrypto.getTrustCrossSignedDevices`

* Replace `MatrixClient.hasSecretStorageKey` by `MatrixClient.SecretStorage.hasKey`

* Replace `MatrixClient.getDefaultSecretStorageKeyId` by `MatrixClient.SecretStorage.getDefaultKeyId`

* Remove `MatrixClient.encryptAndSendToDevices` call
This commit is contained in:
Florian Duros 2024-10-21 13:53:39 +02:00 committed by GitHub
parent 26a98e5e30
commit 46d13921d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 22 additions and 55 deletions

View file

@ -76,7 +76,7 @@ async function getSecretStorageKey({
keys: Record<string, SecretStorage.SecretStorageKeyDescription>;
}): Promise<[string, Uint8Array]> {
const cli = MatrixClientPeg.safeGet();
let keyId = await cli.getDefaultSecretStorageKeyId();
let keyId = await cli.secretStorage.getDefaultKeyId();
let keyInfo!: SecretStorage.SecretStorageKeyDescription;
if (keyId) {
// use the default SSSS key if set

View file

@ -69,7 +69,7 @@ export default class CreateKeyBackupDialog extends React.PureComponent<IProps, I
const cli = MatrixClientPeg.safeGet();
try {
// Check if 4S already set up
const secretStorageAlreadySetup = await cli.hasSecretStorageKey();
const secretStorageAlreadySetup = await cli.secretStorage.hasKey();
if (!secretStorageAlreadySetup) {
// bootstrap secret storage; that will also create a backup version

View file

@ -1709,9 +1709,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
}
}
if (cli.getCrypto()) {
const crypto = cli.getCrypto();
if (crypto) {
const blacklistEnabled = SettingsStore.getValueAt(SettingLevel.DEVICE, "blacklistUnverifiedDevices");
cli.setGlobalBlacklistUnverifiedDevices(blacklistEnabled);
crypto.globalBlacklistUnverifiedDevices = blacklistEnabled;
// With cross-signing enabled, we send to unknown devices
// without prompting. Any bad-device status the user should

View file

@ -229,7 +229,7 @@ export default class AccessSecretStorageDialog extends React.PureComponent<IProp
await accessSecretStorage(async (): Promise<void> => {
// Now reset cross-signing so everything Just Works™ again.
const cli = MatrixClientPeg.safeGet();
await cli.bootstrapCrossSigning({
await cli.getCrypto()?.bootstrapCrossSigning({
authUploadDeviceSigningKeys: async (makeRequest): Promise<void> => {
const { finished } = Modal.createDialog(InteractiveAuthDialog, {
title: _t("encryption|bootstrap_title"),

View file

@ -137,7 +137,7 @@ export default class CreateCrossSigningDialog extends React.PureComponent<IProps
try {
const cli = MatrixClientPeg.safeGet();
await cli.bootstrapCrossSigning({
await cli.getCrypto()?.bootstrapCrossSigning({
authUploadDeviceSigningKeys: this.doBootstrapUIAuth,
});
this.props.onFinished(true);

View file

@ -266,7 +266,7 @@ export default class RestoreKeyBackupDialog extends React.PureComponent<IProps,
try {
const cli = MatrixClientPeg.safeGet();
const backupInfo = await cli.getKeyBackupVersion();
const has4S = await cli.hasSecretStorageKey();
const has4S = await cli.secretStorage.hasKey();
const backupKeyStored = has4S ? await cli.isKeyBackupKeyStored() : null;
this.setState({
backupInfo,

View file

@ -140,6 +140,7 @@ export default class CryptographyPanel extends React.Component<IProps, IState> {
};
private updateBlacklistDevicesFlag = (checked: boolean): void => {
MatrixClientPeg.safeGet().setGlobalBlacklistUnverifiedDevices(checked);
const crypto = MatrixClientPeg.safeGet().getCrypto();
if (crypto) crypto.globalBlacklistUnverifiedDevices = checked;
};
}

View file

@ -7,7 +7,6 @@ Please see LICENSE files in the repository root for full details.
*/
import { User, MatrixClient, RoomMember } from "matrix-js-sdk/src/matrix";
import { VerificationMethod } from "matrix-js-sdk/src/types";
import { CrossSigningKey, VerificationRequest } from "matrix-js-sdk/src/crypto-api";
import dis from "./dispatcher/dispatcher";
@ -39,7 +38,7 @@ export async function verifyDevice(matrixClient: MatrixClient, user: User, devic
return;
}
// if cross-signing is not explicitly disabled, check if it should be enabled first.
if (matrixClient.getCryptoTrustCrossSignedDevices()) {
if (matrixClient.getCrypto()?.getTrustCrossSignedDevices()) {
if (!(await enable4SIfNeeded(matrixClient))) {
return;
}
@ -50,11 +49,9 @@ export async function verifyDevice(matrixClient: MatrixClient, user: User, devic
device,
onFinished: async (action): Promise<void> => {
if (action === "sas") {
const verificationRequestPromise = matrixClient.legacyDeviceVerification(
user.userId,
device.deviceId,
VerificationMethod.Sas,
);
const verificationRequestPromise = matrixClient
.getCrypto()
?.requestDeviceVerification(user.userId, device.deviceId);
setRightPanel({ member: user, verificationRequestPromise });
} else if (action === "legacy") {
Modal.createDialog(ManualDeviceKeyVerificationDialog, {