Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated parameters and types in CryptoApi #4670

Draft
wants to merge 5 commits into
base: florianduros/rip-out-legacy-crypto/remove-legacy-crypto
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions spec/unit/rust-crypto/rust-crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1455,16 +1455,6 @@ describe("RustCrypto", () => {
const fetched = await rustCrypto.getSessionBackupPrivateKey();
expect(new TextDecoder().decode(fetched!)).toEqual(key);
});

it("fails to save a key if version not provided", async () => {
const key = "testtesttesttesttesttesttesttest";
const rustCrypto = await makeTestRustCrypto();
await expect(() => rustCrypto.storeSessionBackupPrivateKey(new TextEncoder().encode(key))).rejects.toThrow(
"storeSessionBackupPrivateKey: version is required",
);
const fetched = await rustCrypto.getSessionBackupPrivateKey();
expect(fetched).toBeNull();
});
});

describe("getActiveSessionBackupVersion", () => {
Expand All @@ -1474,15 +1464,6 @@ describe("RustCrypto", () => {
});
});

describe("findVerificationRequestDMInProgress", () => {
it("throws an error if the userId is not provided", async () => {
const rustCrypto = await makeTestRustCrypto();
expect(() => rustCrypto.findVerificationRequestDMInProgress(testData.TEST_ROOM_ID)).toThrow(
"missing userId",
);
});
});

describe("requestVerificationDM", () => {
it("send verification request to an unknown user", async () => {
const rustCrypto = await makeTestRustCrypto();
Expand Down Expand Up @@ -1514,7 +1495,6 @@ describe("RustCrypto", () => {
it("returns an unverified UserVerificationStatus when there is no UserIdentity", async () => {
const userVerificationStatus = await rustCrypto.getUserVerificationStatus(testData.TEST_USER_ID);
expect(userVerificationStatus.isVerified()).toBeFalsy();
expect(userVerificationStatus.isTofu()).toBeFalsy();
expect(userVerificationStatus.isCrossSigningVerified()).toBeFalsy();
expect(userVerificationStatus.wasCrossSigningVerified()).toBeFalsy();
});
Expand All @@ -1528,7 +1508,6 @@ describe("RustCrypto", () => {

const userVerificationStatus = await rustCrypto.getUserVerificationStatus(testData.TEST_USER_ID);
expect(userVerificationStatus.isVerified()).toBeTruthy();
expect(userVerificationStatus.isTofu()).toBeFalsy();
expect(userVerificationStatus.isCrossSigningVerified()).toBeTruthy();
expect(userVerificationStatus.wasCrossSigningVerified()).toBeTruthy();
});
Expand Down
119 changes: 0 additions & 119 deletions src/crypto-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,16 +424,6 @@ export interface CryptoApi {
*/
getVerificationRequestsToDeviceInProgress(userId: string): VerificationRequest[];

/**
* Finds a DM verification request that is already in progress for the given room id
*
* @param roomId - the room to use for verification
*
* @returns the VerificationRequest that is in progress, if any
* @deprecated prefer `userId` parameter variant.
*/
findVerificationRequestDMInProgress(roomId: string): VerificationRequest | undefined;

/**
* Finds a DM verification request that is already in progress for the given room and user.
*
Expand Down Expand Up @@ -501,18 +491,6 @@ export interface CryptoApi {
*/
getSessionBackupPrivateKey(): Promise<Uint8Array | null>;

/**
* Store the backup decryption key.
*
* This should be called if the client has received the key from another device via secret sharing (gossiping).
* It is the responsability of the caller to check that the decryption key is valid for the current backup version.
*
* @param key - the backup decryption key
*
* @deprecated prefer the variant with a `version` parameter.
*/
storeSessionBackupPrivateKey(key: Uint8Array): Promise<void>;

/**
* Store the backup decryption key.
*
Expand Down Expand Up @@ -732,45 +710,6 @@ export enum DecryptionFailureCode {

/** Unknown or unclassified error. */
UNKNOWN_ERROR = "UNKNOWN_ERROR",

/** @deprecated only used in legacy crypto */
MEGOLM_BAD_ROOM = "MEGOLM_BAD_ROOM",

/** @deprecated only used in legacy crypto */
MEGOLM_MISSING_FIELDS = "MEGOLM_MISSING_FIELDS",

/** @deprecated only used in legacy crypto */
OLM_DECRYPT_GROUP_MESSAGE_ERROR = "OLM_DECRYPT_GROUP_MESSAGE_ERROR",

/** @deprecated only used in legacy crypto */
OLM_BAD_ENCRYPTED_MESSAGE = "OLM_BAD_ENCRYPTED_MESSAGE",

/** @deprecated only used in legacy crypto */
OLM_BAD_RECIPIENT = "OLM_BAD_RECIPIENT",

/** @deprecated only used in legacy crypto */
OLM_BAD_RECIPIENT_KEY = "OLM_BAD_RECIPIENT_KEY",

/** @deprecated only used in legacy crypto */
OLM_BAD_ROOM = "OLM_BAD_ROOM",

/** @deprecated only used in legacy crypto */
OLM_BAD_SENDER_CHECK_FAILED = "OLM_BAD_SENDER_CHECK_FAILED",

/** @deprecated only used in legacy crypto */
OLM_BAD_SENDER = "OLM_BAD_SENDER",

/** @deprecated only used in legacy crypto */
OLM_FORWARDED_MESSAGE = "OLM_FORWARDED_MESSAGE",

/** @deprecated only used in legacy crypto */
OLM_MISSING_CIPHERTEXT = "OLM_MISSING_CIPHERTEXT",

/** @deprecated only used in legacy crypto */
OLM_NOT_INCLUDED_IN_RECIPIENTS = "OLM_NOT_INCLUDED_IN_RECIPIENTS",

/** @deprecated only used in legacy crypto */
UNKNOWN_ENCRYPTION_ALGORITHM = "UNKNOWN_ENCRYPTION_ALGORITHM",
}

/** Base {@link DeviceIsolationMode} kind. */
Expand Down Expand Up @@ -862,7 +801,6 @@ export class UserVerificationStatus {
public constructor(
private readonly crossSigningVerified: boolean,
private readonly crossSigningVerifiedBefore: boolean,
private readonly tofu: boolean,
needsUserApproval: boolean = false,
) {
this.needsUserApproval = needsUserApproval;
Expand All @@ -889,15 +827,6 @@ export class UserVerificationStatus {
public wasCrossSigningVerified(): boolean {
return this.crossSigningVerifiedBefore;
}

/**
* @returns true if this user's key is trusted on first use
*
* @deprecated No longer supported, with the Rust crypto stack.
*/
public isTofu(): boolean {
return this.tofu;
}
}

export class DeviceVerificationStatus {
Expand Down Expand Up @@ -981,10 +910,6 @@ export interface ImportRoomKeyProgressData {
export interface ImportRoomKeysOpts {
/** Reports ongoing progress of the import process. Can be used for feedback. */
progressCallback?: (stage: ImportRoomKeyProgressData) => void;
/** @deprecated the rust SDK will always such imported keys as untrusted */
untrusted?: boolean;
/** @deprecated not useful externally */
source?: string;
}

/**
Expand Down Expand Up @@ -1070,13 +995,6 @@ export interface CryptoCallbacks {
name: string,
) => Promise<[string, Uint8Array] | null>;

/** @deprecated: unused with the Rust crypto stack. */
getCrossSigningKey?: (keyType: string, pubKey: string) => Promise<Uint8Array | null>;
/** @deprecated: unused with the Rust crypto stack. */
saveCrossSigningKeys?: (keys: Record<string, Uint8Array>) => void;
/** @deprecated: unused with the Rust crypto stack. */
shouldUpgradeDeviceVerifications?: (users: Record<string, any>) => Promise<string[]>;

/**
* Called by {@link CryptoApi.bootstrapSecretStorage} when a new default secret storage key is created.
*
Expand All @@ -1088,24 +1006,6 @@ export interface CryptoCallbacks {
* @param key - private key to store
*/
cacheSecretStorageKey?: (keyId: string, keyInfo: SecretStorageKeyDescription, key: Uint8Array) => void;

/** @deprecated: unused with the Rust crypto stack. */
onSecretRequested?: (
userId: string,
deviceId: string,
requestId: string,
secretName: string,
deviceTrust: DeviceVerificationStatus,
) => Promise<string | undefined>;

/** @deprecated: unused with the Rust crypto stack. */
getDehydrationKey?: (
keyInfo: SecretStorageKeyDescription,
checkFunc: (key: Uint8Array) => void,
) => Promise<Uint8Array>;

/** @deprecated: unused with the Rust crypto stack. */
getBackupKey?: () => Promise<Uint8Array>;
}

/**
Expand All @@ -1120,13 +1020,6 @@ export interface CreateSecretStorageOpts {
*/
createSecretStorageKey?: () => Promise<GeneratedSecretStorageKey>;

/**
* The current key backup object. If passed,
* the passphrase and recovery key from this backup will be used.
* @deprecated Not used by the Rust crypto stack.
*/
keyBackupInfo?: KeyBackupInfo;

/**
* If true, a new key backup version will be
* created and the private key stored in the new SSSS store. Ignored if keyBackupInfo
Expand All @@ -1138,18 +1031,6 @@ export interface CreateSecretStorageOpts {
* Reset even if keys already exist.
*/
setupNewSecretStorage?: boolean;

/**
* Function called to get the user's current key backup passphrase.
*
* Should return a promise that resolves with a Uint8Array
* containing the key, or rejects if the key cannot be obtained.
*
* Only used when the client has existing key backup, but no secret storage.
*
* @deprecated Not used by the Rust crypto stack.
*/
getKeyBackupPassphrase?: () => Promise<Uint8Array>;
}

/** Types of cross-signing key */
Expand Down
15 changes: 4 additions & 11 deletions src/rust-crypto/rust-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
const userIdentity: RustSdkCryptoJs.OtherUserIdentity | RustSdkCryptoJs.OwnUserIdentity | undefined =
await this.getOlmMachineOrThrow().getIdentity(new RustSdkCryptoJs.UserId(userId));
if (userIdentity === undefined) {
return new UserVerificationStatus(false, false, false);
return new UserVerificationStatus(false, false);
}

const verified = userIdentity.isVerified();
Expand All @@ -667,7 +667,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
? userIdentity.identityNeedsUserApproval()
: false;
userIdentity.free();
return new UserVerificationStatus(verified, wasVerified, false, needsUserApproval);
return new UserVerificationStatus(verified, wasVerified, needsUserApproval);
}

/**
Expand Down Expand Up @@ -1030,9 +1030,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
* @returns the VerificationRequest that is in progress, if any
*
*/
public findVerificationRequestDMInProgress(roomId: string, userId?: string): VerificationRequest | undefined {
if (!userId) throw new Error("missing userId");

public findVerificationRequestDMInProgress(roomId: string, userId: string): VerificationRequest | undefined {
const requests: RustSdkCryptoJs.VerificationRequest[] = this.olmMachine.getVerificationRequests(
new RustSdkCryptoJs.UserId(userId),
);
Expand Down Expand Up @@ -1223,13 +1221,8 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
* @param key - the backup decryption key
* @param version - the backup version for this key.
*/
public async storeSessionBackupPrivateKey(key: Uint8Array, version?: string): Promise<void> {
public async storeSessionBackupPrivateKey(key: Uint8Array, version: string): Promise<void> {
const base64Key = encodeBase64(key);

if (!version) {
throw new Error("storeSessionBackupPrivateKey: version is required");
}

await this.backupManager.saveBackupDecryptionKey(
RustSdkCryptoJs.BackupDecryptionKey.fromBase64(base64Key),
version,
Expand Down
Loading