Skip to content

Commit b6ad99f

Browse files
committed
Update import to use new functions
1 parent a2817bb commit b6ad99f

14 files changed

+39
-31
lines changed

Diff for: spec/integ/crypto/cross-signing.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { IDBFactory } from "fake-indexeddb";
2121
import { CRYPTO_BACKENDS, InitCrypto, syncPromise } from "../../test-utils/test-utils";
2222
import { AuthDict, createClient, CryptoEvent, MatrixClient } from "../../../src";
2323
import { mockInitialApiRequests, mockSetupCrossSigningRequests } from "../../test-utils/mockEndpoints";
24-
import { encryptAES } from "../../../src/crypto/aes";
24+
import { encryptAES } from "../../../src/utils/encryptAES";
2525
import { CryptoCallbacks, CrossSigningKey } from "../../../src/crypto-api";
2626
import { SECRET_STORAGE_ALGORITHM_V1_AES } from "../../../src/secret-storage";
2727
import { ISyncResponder, SyncResponder } from "../../test-utils/SyncResponder";

Diff for: spec/unit/crypto/secrets.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { IObject } from "../../../src/crypto/olmlib";
2020
import { MatrixEvent } from "../../../src/models/event";
2121
import { TestClient } from "../../TestClient";
2222
import { makeTestClients } from "./verification/util";
23-
import { encryptAES } from "../../../src/crypto/aes";
23+
import { encryptAES } from "../../../src/utils/encryptAES";
2424
import { createSecretStorageKey, resetCrossSigningKeys } from "./crypto-utils";
2525
import { logger } from "../../../src/logger";
2626
import { ClientEvent, ICreateClientOpts, MatrixClient } from "../../../src/client";

Diff for: spec/unit/rust-crypto/rust-crypto.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import { logger } from "../../../src/logger";
6969
import { OutgoingRequestsManager } from "../../../src/rust-crypto/OutgoingRequestsManager";
7070
import { ClientEvent, ClientEventHandlerMap } from "../../../src/client";
7171
import { Curve25519AuthData } from "../../../src/crypto-api/keybackup";
72-
import { encryptAES } from "../../../src/crypto/aes";
72+
import { encryptAES } from "../../../src/utils/encryptAES";
7373
import { CryptoStore, SecretStorePrivateKeys } from "../../../src/crypto/store/base";
7474

7575
const TEST_USER = "@alice:example.com";

Diff for: spec/unit/secret-storage.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
ServerSideSecretStorageImpl,
2626
trimTrailingEquals,
2727
} from "../../src/secret-storage";
28-
import { calculateKeyCheck } from "../../src/crypto/aes";
28+
import { calculateKeyCheck } from "../../src/utils/calculateKeyCheck";
2929
import { randomString } from "../../src/randomstring";
3030

3131
describe("ServerSideSecretStorageImpl", function () {

Diff for: src/crypto-api/keybackup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import { ISigned } from "../@types/signed.ts";
18-
import { IEncryptedPayload } from "../crypto/aes.ts";
18+
import { SecretEncryptedPayload } from "../utils/encryptAES.ts";
1919

2020
export interface Curve25519AuthData {
2121
public_key: string;
@@ -77,7 +77,7 @@ export interface Curve25519SessionData {
7777
}
7878

7979
/* eslint-disable camelcase */
80-
export interface KeyBackupSession<T = Curve25519SessionData | IEncryptedPayload> {
80+
export interface KeyBackupSession<T = Curve25519SessionData | SecretEncryptedPayload> {
8181
first_message_index: number;
8282
forwarded_count: number;
8383
is_verified: boolean;

Diff for: src/crypto/CrossSigning.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import type { PkSigning } from "@matrix-org/olm";
2222
import { IObject, pkSign, pkVerify } from "./olmlib.ts";
2323
import { logger } from "../logger.ts";
2424
import { IndexedDBCryptoStore } from "../crypto/store/indexeddb-crypto-store.ts";
25-
import { decryptAES, encryptAES } from "./aes.ts";
2625
import { DeviceInfo } from "./deviceinfo.ts";
2726
import { ISignedKey, MatrixClient } from "../client.ts";
2827
import { OlmDevice } from "./OlmDevice.ts";
@@ -36,6 +35,8 @@ import {
3635
UserVerificationStatus as UserTrustLevel,
3736
} from "../crypto-api/index.ts";
3837
import { decodeBase64, encodeBase64 } from "../base64.ts";
38+
import { encryptAES } from "../utils/encryptAES.ts";
39+
import { decryptAES } from "../utils/decryptAES.ts";
3940

4041
// backwards-compatibility re-exports
4142
export { UserTrustLevel };

Diff for: src/crypto/backup.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { DeviceTrustLevel } from "./CrossSigning.ts";
2727
import { keyFromPassphrase } from "./key_passphrase.ts";
2828
import { encodeUri, safeSet, sleep } from "../utils.ts";
2929
import { IndexedDBCryptoStore } from "./store/indexeddb-crypto-store.ts";
30-
import { calculateKeyCheck, decryptAES, encryptAES, IEncryptedPayload } from "./aes.ts";
3130
import {
3231
Curve25519SessionData,
3332
IAes256AuthData,
@@ -41,6 +40,9 @@ import { ClientPrefix, HTTPError, MatrixError, Method } from "../http-api/index.
4140
import { BackupTrustInfo } from "../crypto-api/keybackup.ts";
4241
import { BackupDecryptor } from "../common-crypto/CryptoBackend.ts";
4342
import { encodeRecoveryKey } from "../crypto-api/index.ts";
43+
import { decryptAES } from "../utils/decryptAES.ts";
44+
import { calculateKeyCheck } from "../utils/calculateKeyCheck.ts";
45+
import { encryptAES, SecretEncryptedPayload } from "../utils/encryptAES.ts";
4446

4547
const KEY_BACKUP_KEYS_PER_REQUEST = 200;
4648
const KEY_BACKUP_CHECK_RATE_LIMIT = 5000; // ms
@@ -94,7 +96,7 @@ interface BackupAlgorithmClass {
9496

9597
interface BackupAlgorithm {
9698
untrusted: boolean;
97-
encryptSession(data: Record<string, any>): Promise<Curve25519SessionData | IEncryptedPayload>;
99+
encryptSession(data: Record<string, any>): Promise<Curve25519SessionData | SecretEncryptedPayload>;
98100
decryptSessions(ciphertexts: Record<string, IKeyBackupSession>): Promise<IMegolmSessionData[]>;
99101
authData: AuthData;
100102
keyMatches(key: ArrayLike<number>): Promise<boolean>;
@@ -825,7 +827,7 @@ export class Aes256 implements BackupAlgorithm {
825827
return false;
826828
}
827829

828-
public encryptSession(data: Record<string, any>): Promise<IEncryptedPayload> {
830+
public encryptSession(data: Record<string, any>): Promise<SecretEncryptedPayload> {
829831
const plainText: Record<string, any> = Object.assign({}, data);
830832
delete plainText.session_id;
831833
delete plainText.room_id;
@@ -834,7 +836,7 @@ export class Aes256 implements BackupAlgorithm {
834836
}
835837

836838
public async decryptSessions(
837-
sessions: Record<string, IKeyBackupSession<IEncryptedPayload>>,
839+
sessions: Record<string, IKeyBackupSession<SecretEncryptedPayload>>,
838840
): Promise<IMegolmSessionData[]> {
839841
const keys: IMegolmSessionData[] = [];
840842

Diff for: src/crypto/dehydration.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import anotherjson from "another-json";
1919
import type { IDeviceKeys, IOneTimeKey } from "../@types/crypto.ts";
2020
import { decodeBase64, encodeBase64 } from "../base64.ts";
2121
import { IndexedDBCryptoStore } from "../crypto/store/indexeddb-crypto-store.ts";
22-
import { decryptAES, encryptAES } from "./aes.ts";
2322
import { logger } from "../logger.ts";
2423
import { Crypto } from "./index.ts";
2524
import { Method } from "../http-api/index.ts";
2625
import { SecretStorageKeyDescription } from "../secret-storage.ts";
26+
import { decryptAES } from "../utils/decryptAES.ts";
27+
import { encryptAES } from "../utils/encryptAES.ts";
2728

2829
export interface IDehydratedDevice {
2930
device_id: string; // eslint-disable-line camelcase

Diff for: src/crypto/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import { InRoomChannel, InRoomRequests } from "./verification/request/InRoomChan
4747
import { Request, ToDeviceChannel, ToDeviceRequests } from "./verification/request/ToDeviceChannel.ts";
4848
import { IllegalMethod } from "./verification/IllegalMethod.ts";
4949
import { KeySignatureUploadError } from "../errors.ts";
50-
import { calculateKeyCheck, decryptAES, encryptAES, IEncryptedPayload } from "./aes.ts";
5150
import { DehydrationManager } from "./dehydration.ts";
5251
import { BackupManager, LibOlmBackupDecryptor, backupTrustInfoFromLegacyTrustInfo } from "./backup.ts";
5352
import { IStore } from "../store/index.ts";
@@ -107,6 +106,9 @@ import { deviceInfoToDevice } from "./device-converter.ts";
107106
import { ClientPrefix, MatrixError, Method } from "../http-api/index.ts";
108107
import { decodeBase64, encodeBase64 } from "../base64.ts";
109108
import { KnownMembership } from "../@types/membership.ts";
109+
import { calculateKeyCheck } from "../utils/calculateKeyCheck.ts";
110+
import { decryptAES } from "../utils/decryptAES.ts";
111+
import { encryptAES, SecretEncryptedPayload } from "../utils/encryptAES.ts";
110112

111113
/* re-exports for backwards compatibility */
112114
export type {
@@ -1323,7 +1325,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
13231325
* @returns the key, if any, or null
13241326
*/
13251327
public async getSessionBackupPrivateKey(): Promise<Uint8Array | null> {
1326-
const encodedKey = await new Promise<Uint8Array | IEncryptedPayload | string | null>((resolve) => {
1328+
const encodedKey = await new Promise<Uint8Array | SecretEncryptedPayload | string | null>((resolve) => {
13271329
this.cryptoStore.doTxn("readonly", [IndexedDBCryptoStore.STORE_ACCOUNT], (txn) => {
13281330
this.cryptoStore.getSecretStorePrivateKey(txn, resolve, "m.megolm_backup.v1");
13291331
});

Diff for: src/crypto/store/base.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import { Logger } from "../../logger.ts";
2525
import { InboundGroupSessionData } from "../OlmDevice.ts";
2626
import { MatrixEvent } from "../../models/event.ts";
2727
import { DehydrationManager } from "../dehydration.ts";
28-
import { IEncryptedPayload } from "../aes.ts";
2928
import { CrossSigningKeyInfo } from "../../crypto-api/index.ts";
29+
import { SecretEncryptedPayload } from "../../utils/encryptAES.ts";
3030

3131
/**
3232
* Internal module. Definitions for storage for the crypto module
@@ -35,11 +35,11 @@ import { CrossSigningKeyInfo } from "../../crypto-api/index.ts";
3535
export interface SecretStorePrivateKeys {
3636
"dehydration": {
3737
keyInfo: DehydrationManager["keyInfo"];
38-
key: IEncryptedPayload;
38+
key: SecretEncryptedPayload;
3939
deviceDisplayName: string;
4040
time: number;
4141
} | null;
42-
"m.megolm_backup.v1": IEncryptedPayload;
42+
"m.megolm_backup.v1": SecretEncryptedPayload;
4343
}
4444

4545
/**

Diff for: src/rust-crypto/backup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ import { encodeUri, logDuration } from "../utils.ts";
3333
import { OutgoingRequestProcessor } from "./OutgoingRequestProcessor.ts";
3434
import { sleep } from "../utils.ts";
3535
import { BackupDecryptor } from "../common-crypto/CryptoBackend.ts";
36-
import { IEncryptedPayload } from "../crypto/aes.ts";
3736
import { ImportRoomKeyProgressData, ImportRoomKeysOpts } from "../crypto-api/index.ts";
3837
import { IKeyBackupInfo } from "../crypto/keybackup.ts";
3938
import { IKeyBackup } from "../crypto/backup.ts";
39+
import { SecretEncryptedPayload } from "../utils/encryptAES.ts";
4040

4141
/** Authentification of the backup info, depends on algorithm */
4242
type AuthData = KeyBackupInfo["auth_data"];
@@ -622,7 +622,7 @@ export class RustBackupDecryptor implements BackupDecryptor {
622622
* Implements {@link BackupDecryptor#decryptSessions}
623623
*/
624624
public async decryptSessions(
625-
ciphertexts: Record<string, KeyBackupSession<Curve25519SessionData | IEncryptedPayload>>,
625+
ciphertexts: Record<string, KeyBackupSession<Curve25519SessionData | SecretEncryptedPayload>>,
626626
): Promise<IMegolmSessionData[]> {
627627
const keys: IMegolmSessionData[] = [];
628628
for (const [sessionId, sessionData] of Object.entries(ciphertexts)) {

Diff for: src/rust-crypto/libolm_migration.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import * as RustSdkCryptoJs from "@matrix-org/matrix-sdk-crypto-wasm";
1919
import { Logger } from "../logger.ts";
2020
import { CryptoStore, MigrationState, SecretStorePrivateKeys } from "../crypto/store/base.ts";
2121
import { IndexedDBCryptoStore } from "../crypto/store/indexeddb-crypto-store.ts";
22-
import { decryptAES, IEncryptedPayload } from "../crypto/aes.ts";
2322
import { IHttpOpts, MatrixHttpApi } from "../http-api/index.ts";
2423
import { requestKeyBackupVersion } from "./backup.ts";
2524
import { IRoomEncryption } from "../crypto/RoomList.ts";
@@ -28,6 +27,8 @@ import { RustCrypto } from "./rust-crypto.ts";
2827
import { KeyBackupInfo } from "../crypto-api/keybackup.ts";
2928
import { sleep } from "../utils.ts";
3029
import { encodeBase64 } from "../base64.ts";
30+
import { decryptAES } from "../utils/decryptAES.ts";
31+
import { SecretEncryptedPayload } from "../utils/encryptAES.ts";
3132

3233
/**
3334
* Determine if any data needs migrating from the legacy store, and do so.
@@ -421,7 +422,7 @@ async function getAndDecryptCachedSecretKey(
421422
});
422423

423424
if (key && key.ciphertext && key.iv && key.mac) {
424-
return await decryptAES(key as IEncryptedPayload, legacyPickleKey, name);
425+
return await decryptAES(key as SecretEncryptedPayload, legacyPickleKey, name);
425426
} else if (key instanceof Uint8Array) {
426427
// This is a legacy backward compatibility case where the key was stored in clear.
427428
return encodeBase64(key);

Diff for: src/secret-storage.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ limitations under the License.
2323
import { TypedEventEmitter } from "./models/typed-event-emitter.ts";
2424
import { ClientEvent, ClientEventHandlerMap } from "./client.ts";
2525
import { MatrixEvent } from "./models/event.ts";
26-
import { calculateKeyCheck, decryptAES, encryptAES, IEncryptedPayload } from "./crypto/aes.ts";
2726
import { randomString } from "./randomstring.ts";
2827
import { logger } from "./logger.ts";
28+
import { calculateKeyCheck } from "./utils/calculateKeyCheck.ts";
29+
import { encryptAES, SecretEncryptedPayload } from "./utils/encryptAES.ts";
30+
import { decryptAES } from "./utils/decryptAES.ts";
2931

3032
export const SECRET_STORAGE_ALGORITHM_V1_AES = "m.secret_storage.v1.aes-hmac-sha2";
3133

@@ -200,13 +202,13 @@ export interface SecretStorageCallbacks {
200202

201203
interface SecretInfo {
202204
encrypted: {
203-
[keyId: string]: IEncryptedPayload;
205+
[keyId: string]: SecretEncryptedPayload;
204206
};
205207
}
206208

207209
interface Decryptors {
208-
encrypt: (plaintext: string) => Promise<IEncryptedPayload>;
209-
decrypt: (ciphertext: IEncryptedPayload) => Promise<string>;
210+
encrypt: (plaintext: string) => Promise<SecretEncryptedPayload>;
211+
decrypt: (ciphertext: SecretEncryptedPayload) => Promise<string>;
210212
}
211213

212214
/**
@@ -491,7 +493,7 @@ export class ServerSideSecretStorageImpl implements ServerSideSecretStorage {
491493
* @param keys - The IDs of the keys to use to encrypt the secret, or null/undefined to use the default key.
492494
*/
493495
public async store(name: string, secret: string, keys?: string[] | null): Promise<void> {
494-
const encrypted: Record<string, IEncryptedPayload> = {};
496+
const encrypted: Record<string, SecretEncryptedPayload> = {};
495497

496498
if (!keys) {
497499
const defaultKeyId = await this.getDefaultKeyId();
@@ -638,10 +640,10 @@ export class ServerSideSecretStorageImpl implements ServerSideSecretStorage {
638640

639641
if (keys[keyId].algorithm === SECRET_STORAGE_ALGORITHM_V1_AES) {
640642
const decryption = {
641-
encrypt: function (secret: string): Promise<IEncryptedPayload> {
643+
encrypt: function (secret: string): Promise<SecretEncryptedPayload> {
642644
return encryptAES(secret, privateKey, name);
643645
},
644-
decrypt: function (encInfo: IEncryptedPayload): Promise<string> {
646+
decrypt: function (encInfo: SecretEncryptedPayload): Promise<string> {
645647
return decryptAES(encInfo, privateKey, name);
646648
},
647649
};

Diff for: src/utils/calculateKeyCheck.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
// string of zeroes, for calculating the key check
18-
import { SecretEncryptedPayload } from "../@types/secretEncryptedPayload.ts";
19-
import { encryptAES } from "./encryptAES.ts";
17+
import { encryptAES, SecretEncryptedPayload } from "./encryptAES.ts";
2018

19+
// string of zeroes, for calculating the key check
2120
const ZERO_STR = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
2221

2322
/** Calculate the MAC for checking the key.

0 commit comments

Comments
 (0)