1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

Tests pass 1

This commit is contained in:
Travis Ralston
2021-06-01 21:47:47 -06:00
parent 40f55b2964
commit 71dc0bac56
4 changed files with 58 additions and 53 deletions

View File

@@ -64,8 +64,8 @@ describe("Cross Signing", function() {
); );
alice.uploadDeviceSigningKeys = jest.fn(async (auth, keys) => { alice.uploadDeviceSigningKeys = jest.fn(async (auth, keys) => {
await olmlib.verifySignature( await olmlib.verifySignature(
alice._crypto._olmDevice, keys.master_key, "@alice:example.com", alice.crypto._olmDevice, keys.master_key, "@alice:example.com",
"Osborne2", alice._crypto._olmDevice.deviceEd25519Key, "Osborne2", alice.crypto._olmDevice.deviceEd25519Key,
); );
}); });
alice.uploadKeySignatures = async () => {}; alice.uploadKeySignatures = async () => {};
@@ -138,7 +138,7 @@ describe("Cross Signing", function() {
// set Alice's cross-signing key // set Alice's cross-signing key
await resetCrossSigningKeys(alice); await resetCrossSigningKeys(alice);
// Alice downloads Bob's device key // Alice downloads Bob's device key
alice._crypto._deviceList.storeCrossSigningForUser("@bob:example.com", { alice.crypto._deviceList.storeCrossSigningForUser("@bob:example.com", {
keys: { keys: {
master: { master: {
user_id: "@bob:example.com", user_id: "@bob:example.com",
@@ -202,12 +202,12 @@ describe("Cross Signing", function() {
const uploadSigsPromise = new Promise((resolve, reject) => { const uploadSigsPromise = new Promise((resolve, reject) => {
alice.uploadKeySignatures = jest.fn(async (content) => { alice.uploadKeySignatures = jest.fn(async (content) => {
await olmlib.verifySignature( await olmlib.verifySignature(
alice._crypto._olmDevice, alice.crypto._olmDevice,
content["@alice:example.com"][ content["@alice:example.com"][
"nqOvzeuGWT/sRx3h7+MHoInYj3Uk2LD/unI9kDYcHwk" "nqOvzeuGWT/sRx3h7+MHoInYj3Uk2LD/unI9kDYcHwk"
], ],
"@alice:example.com", "@alice:example.com",
"Osborne2", alice._crypto._olmDevice.deviceEd25519Key, "Osborne2", alice.crypto._olmDevice.deviceEd25519Key,
); );
olmlib.pkVerify( olmlib.pkVerify(
content["@alice:example.com"]["Osborne2"], content["@alice:example.com"]["Osborne2"],
@@ -218,7 +218,7 @@ describe("Cross Signing", function() {
}); });
}); });
const deviceInfo = alice._crypto._deviceList._devices["@alice:example.com"] const deviceInfo = alice.crypto._deviceList._devices["@alice:example.com"]
.Osborne2; .Osborne2;
const aliceDevice = { const aliceDevice = {
user_id: "@alice:example.com", user_id: "@alice:example.com",
@@ -226,7 +226,7 @@ describe("Cross Signing", function() {
}; };
aliceDevice.keys = deviceInfo.keys; aliceDevice.keys = deviceInfo.keys;
aliceDevice.algorithms = deviceInfo.algorithms; aliceDevice.algorithms = deviceInfo.algorithms;
await alice._crypto._signObject(aliceDevice); await alice.crypto._signObject(aliceDevice);
olmlib.pkSign(aliceDevice, selfSigningKey, "@alice:example.com"); olmlib.pkSign(aliceDevice, selfSigningKey, "@alice:example.com");
// feed sync result that includes master key, ssk, device key // feed sync result that includes master key, ssk, device key
@@ -354,7 +354,7 @@ describe("Cross Signing", function() {
["ed25519:" + bobMasterPubkey]: sskSig, ["ed25519:" + bobMasterPubkey]: sskSig,
}, },
}; };
alice._crypto._deviceList.storeCrossSigningForUser("@bob:example.com", { alice.crypto._deviceList.storeCrossSigningForUser("@bob:example.com", {
keys: { keys: {
master: { master: {
user_id: "@bob:example.com", user_id: "@bob:example.com",
@@ -383,7 +383,7 @@ describe("Cross Signing", function() {
["ed25519:" + bobPubkey]: sig, ["ed25519:" + bobPubkey]: sig,
}, },
}; };
alice._crypto._deviceList.storeDevicesForUser("@bob:example.com", { alice.crypto._deviceList.storeDevicesForUser("@bob:example.com", {
Dynabook: bobDevice, Dynabook: bobDevice,
}); });
// Bob's device key should be TOFU // Bob's device key should be TOFU
@@ -417,8 +417,8 @@ describe("Cross Signing", function() {
null, null,
aliceKeys, aliceKeys,
); );
alice._crypto._deviceList.startTrackingDeviceList("@bob:example.com"); alice.crypto._deviceList.startTrackingDeviceList("@bob:example.com");
alice._crypto._deviceList.stopTrackingAllDeviceLists = () => {}; alice.crypto._deviceList.stopTrackingAllDeviceLists = () => {};
alice.uploadDeviceSigningKeys = async () => {}; alice.uploadDeviceSigningKeys = async () => {};
alice.uploadKeySignatures = async () => {}; alice.uploadKeySignatures = async () => {};
@@ -433,14 +433,14 @@ describe("Cross Signing", function() {
]); ]);
const keyChangePromise = new Promise((resolve, reject) => { const keyChangePromise = new Promise((resolve, reject) => {
alice._crypto._deviceList.once("userCrossSigningUpdated", (userId) => { alice.crypto._deviceList.once("userCrossSigningUpdated", (userId) => {
if (userId === "@bob:example.com") { if (userId === "@bob:example.com") {
resolve(); resolve();
} }
}); });
}); });
const deviceInfo = alice._crypto._deviceList._devices["@alice:example.com"] const deviceInfo = alice.crypto._deviceList._devices["@alice:example.com"]
.Osborne2; .Osborne2;
const aliceDevice = { const aliceDevice = {
user_id: "@alice:example.com", user_id: "@alice:example.com",
@@ -448,7 +448,7 @@ describe("Cross Signing", function() {
}; };
aliceDevice.keys = deviceInfo.keys; aliceDevice.keys = deviceInfo.keys;
aliceDevice.algorithms = deviceInfo.algorithms; aliceDevice.algorithms = deviceInfo.algorithms;
await alice._crypto._signObject(aliceDevice); await alice.crypto._signObject(aliceDevice);
const bobOlmAccount = new global.Olm.Account(); const bobOlmAccount = new global.Olm.Account();
bobOlmAccount.create(); bobOlmAccount.create();
@@ -602,7 +602,7 @@ describe("Cross Signing", function() {
["ed25519:" + bobMasterPubkey]: sskSig, ["ed25519:" + bobMasterPubkey]: sskSig,
}, },
}; };
alice._crypto._deviceList.storeCrossSigningForUser("@bob:example.com", { alice.crypto._deviceList.storeCrossSigningForUser("@bob:example.com", {
keys: { keys: {
master: { master: {
user_id: "@bob:example.com", user_id: "@bob:example.com",
@@ -625,7 +625,7 @@ describe("Cross Signing", function() {
"ed25519:Dynabook": "someOtherPubkey", "ed25519:Dynabook": "someOtherPubkey",
}, },
}; };
alice._crypto._deviceList.storeDevicesForUser("@bob:example.com", { alice.crypto._deviceList.storeDevicesForUser("@bob:example.com", {
Dynabook: bobDevice, Dynabook: bobDevice,
}); });
// Bob's device key should be untrusted // Bob's device key should be untrusted
@@ -669,7 +669,7 @@ describe("Cross Signing", function() {
["ed25519:" + bobMasterPubkey]: sskSig, ["ed25519:" + bobMasterPubkey]: sskSig,
}, },
}; };
alice._crypto._deviceList.storeCrossSigningForUser("@bob:example.com", { alice.crypto._deviceList.storeCrossSigningForUser("@bob:example.com", {
keys: { keys: {
master: { master: {
user_id: "@bob:example.com", user_id: "@bob:example.com",
@@ -697,7 +697,7 @@ describe("Cross Signing", function() {
bobDevice.signatures = {}; bobDevice.signatures = {};
bobDevice.signatures["@bob:example.com"] = {}; bobDevice.signatures["@bob:example.com"] = {};
bobDevice.signatures["@bob:example.com"]["ed25519:" + bobPubkey] = sig; bobDevice.signatures["@bob:example.com"]["ed25519:" + bobPubkey] = sig;
alice._crypto._deviceList.storeDevicesForUser("@bob:example.com", { alice.crypto._deviceList.storeDevicesForUser("@bob:example.com", {
Dynabook: bobDevice, Dynabook: bobDevice,
}); });
// Alice verifies Bob's SSK // Alice verifies Bob's SSK
@@ -729,7 +729,7 @@ describe("Cross Signing", function() {
["ed25519:" + bobMasterPubkey2]: sskSig2, ["ed25519:" + bobMasterPubkey2]: sskSig2,
}, },
}; };
alice._crypto._deviceList.storeCrossSigningForUser("@bob:example.com", { alice.crypto._deviceList.storeCrossSigningForUser("@bob:example.com", {
keys: { keys: {
master: { master: {
user_id: "@bob:example.com", user_id: "@bob:example.com",
@@ -766,7 +766,7 @@ describe("Cross Signing", function() {
// Alice gets new signature for device // Alice gets new signature for device
const sig2 = bobSigning2.sign(bobDeviceString); const sig2 = bobSigning2.sign(bobDeviceString);
bobDevice.signatures["@bob:example.com"]["ed25519:" + bobPubkey2] = sig2; bobDevice.signatures["@bob:example.com"]["ed25519:" + bobPubkey2] = sig2;
alice._crypto._deviceList.storeDevicesForUser("@bob:example.com", { alice.crypto._deviceList.storeDevicesForUser("@bob:example.com", {
Dynabook: bobDevice, Dynabook: bobDevice,
}); });
@@ -801,20 +801,20 @@ describe("Cross Signing", function() {
bob.uploadKeySignatures = async () => {}; bob.uploadKeySignatures = async () => {};
// set Bob's cross-signing key // set Bob's cross-signing key
await resetCrossSigningKeys(bob); await resetCrossSigningKeys(bob);
alice._crypto._deviceList.storeDevicesForUser("@bob:example.com", { alice.crypto._deviceList.storeDevicesForUser("@bob:example.com", {
Dynabook: { Dynabook: {
algorithms: ["m.olm.curve25519-aes-sha256", "m.megolm.v1.aes-sha"], algorithms: ["m.olm.curve25519-aes-sha256", "m.megolm.v1.aes-sha"],
keys: { keys: {
"curve25519:Dynabook": bob._crypto._olmDevice.deviceCurve25519Key, "curve25519:Dynabook": bob.crypto._olmDevice.deviceCurve25519Key,
"ed25519:Dynabook": bob._crypto._olmDevice.deviceEd25519Key, "ed25519:Dynabook": bob.crypto._olmDevice.deviceEd25519Key,
}, },
verified: 1, verified: 1,
known: true, known: true,
}, },
}); });
alice._crypto._deviceList.storeCrossSigningForUser( alice.crypto._deviceList.storeCrossSigningForUser(
"@bob:example.com", "@bob:example.com",
bob._crypto._crossSigningInfo.toStorage(), bob.crypto._crossSigningInfo.toStorage(),
); );
alice.uploadDeviceSigningKeys = async () => {}; alice.uploadDeviceSigningKeys = async () => {};
@@ -834,7 +834,7 @@ describe("Cross Signing", function() {
expect(bobTrust.isTofu()).toBeTruthy(); expect(bobTrust.isTofu()).toBeTruthy();
// "forget" that Bob is trusted // "forget" that Bob is trusted
delete alice._crypto._deviceList._crossSigningInfo["@bob:example.com"] delete alice.crypto._deviceList._crossSigningInfo["@bob:example.com"]
.keys.master.signatures["@alice:example.com"]; .keys.master.signatures["@alice:example.com"];
const bobTrust2 = alice.checkUserTrust("@bob:example.com"); const bobTrust2 = alice.checkUserTrust("@bob:example.com");
@@ -844,9 +844,9 @@ describe("Cross Signing", function() {
upgradePromise = new Promise((resolve) => { upgradePromise = new Promise((resolve) => {
upgradeResolveFunc = resolve; upgradeResolveFunc = resolve;
}); });
alice._crypto._deviceList.emit("userCrossSigningUpdated", "@bob:example.com"); alice.crypto._deviceList.emit("userCrossSigningUpdated", "@bob:example.com");
await new Promise((resolve) => { await new Promise((resolve) => {
alice._crypto.on("userTrustStatusChanged", resolve); alice.crypto.on("userTrustStatusChanged", resolve);
}); });
await upgradePromise; await upgradePromise;

View File

@@ -99,11 +99,11 @@ describe("Secrets", function() {
}, },
}, },
); );
alice._crypto._crossSigningInfo.setKeys({ alice.crypto._crossSigningInfo.setKeys({
master: signingkeyInfo, master: signingkeyInfo,
}); });
const secretStorage = alice._crypto._secretStorage; const secretStorage = alice.crypto._secretStorage;
alice.setAccountData = async function(eventType, contents, callback) { alice.setAccountData = async function(eventType, contents, callback) {
alice.store.storeAccountDataEvents([ alice.store.storeAccountDataEvents([
@@ -120,7 +120,7 @@ describe("Secrets", function() {
const keyAccountData = { const keyAccountData = {
algorithm: SECRET_STORAGE_ALGORITHM_V1_AES, algorithm: SECRET_STORAGE_ALGORITHM_V1_AES,
}; };
await alice._crypto._crossSigningInfo.signObject(keyAccountData, 'master'); await alice.crypto._crossSigningInfo.signObject(keyAccountData, 'master');
alice.store.storeAccountDataEvents([ alice.store.storeAccountDataEvents([
new MatrixEvent({ new MatrixEvent({
@@ -249,7 +249,7 @@ describe("Secrets", function() {
}, },
}, },
}); });
vax.client.crypto.deviceList.storeDevicesForUser("@alice:example.com", { vax.client.crypto._deviceList.storeDevicesForUser("@alice:example.com", {
"Osborne2": { "Osborne2": {
user_id: "@alice:example.com", user_id: "@alice:example.com",
device_id: "Osborne2", device_id: "Osborne2",
@@ -334,8 +334,8 @@ describe("Secrets", function() {
createSecretStorageKey, createSecretStorageKey,
}); });
const crossSigning = bob._crypto._crossSigningInfo; const crossSigning = bob.crypto._crossSigningInfo;
const secretStorage = bob._crypto._secretStorage; const secretStorage = bob.crypto._secretStorage;
expect(crossSigning.getId()).toBeTruthy(); expect(crossSigning.getId()).toBeTruthy();
expect(await crossSigning.isStoredInSecretStorage(secretStorage)) expect(await crossSigning.isStoredInSecretStorage(secretStorage))
@@ -376,10 +376,10 @@ describe("Secrets", function() {
]); ]);
this.emit("accountData", event); this.emit("accountData", event);
}; };
bob._crypto.checkKeyBackup = async () => {}; bob.crypto.checkKeyBackup = async () => {};
const crossSigning = bob._crypto._crossSigningInfo; const crossSigning = bob.crypto._crossSigningInfo;
const secretStorage = bob._crypto._secretStorage; const secretStorage = bob.crypto._secretStorage;
// Set up cross-signing keys from scratch with specific storage key // Set up cross-signing keys from scratch with specific storage key
await bob.bootstrapCrossSigning({ await bob.bootstrapCrossSigning({
@@ -394,7 +394,7 @@ describe("Secrets", function() {
}); });
// Clear local cross-signing keys and read from secret storage // Clear local cross-signing keys and read from secret storage
bob._crypto._deviceList.storeCrossSigningForUser( bob.crypto._deviceList.storeCrossSigningForUser(
"@bob:example.com", "@bob:example.com",
crossSigning.toStorage(), crossSigning.toStorage(),
); );
@@ -479,7 +479,7 @@ describe("Secrets", function() {
}, },
}), }),
]); ]);
alice._crypto._deviceList.storeCrossSigningForUser("@alice:example.com", { alice.crypto._deviceList.storeCrossSigningForUser("@alice:example.com", {
keys: { keys: {
master: { master: {
user_id: "@alice:example.com", user_id: "@alice:example.com",
@@ -619,7 +619,7 @@ describe("Secrets", function() {
}, },
}), }),
]); ]);
alice._crypto._deviceList.storeCrossSigningForUser("@alice:example.com", { alice.crypto._deviceList.storeCrossSigningForUser("@alice:example.com", {
keys: { keys: {
master: { master: {
user_id: "@alice:example.com", user_id: "@alice:example.com",

View File

@@ -394,6 +394,8 @@ export class MatrixClient extends EventEmitter {
public supportsCallTransfer = false; // XXX: Intended private, used in code. public supportsCallTransfer = false; // XXX: Intended private, used in code.
public forceTURN = false; // XXX: Intended private, used in code. public forceTURN = false; // XXX: Intended private, used in code.
public iceCandidatePoolSize = 0; // XXX: Intended private, used in code. public iceCandidatePoolSize = 0; // XXX: Intended private, used in code.
public idBaseUrl: string;
public baseUrl: string;
private canSupportVoip = false; private canSupportVoip = false;
private peekSync: SyncApi = null; private peekSync: SyncApi = null;
@@ -429,8 +431,6 @@ export class MatrixClient extends EventEmitter {
private turnServersExpiry = 0; private turnServersExpiry = 0;
private checkTurnServersIntervalID: number; private checkTurnServersIntervalID: number;
private exportedOlmDeviceToImport: IOlmDevice; private exportedOlmDeviceToImport: IOlmDevice;
private baseUrl: string;
private idBaseUrl: string;
private txnCtr = 0; private txnCtr = 0;
constructor(opts: IMatrixClientCreateOpts) { constructor(opts: IMatrixClientCreateOpts) {
@@ -671,11 +671,12 @@ export class MatrixClient extends EventEmitter {
this.syncApi = new SyncApi(this, this.clientOpts); this.syncApi = new SyncApi(this, this.clientOpts);
this.syncApi.sync(); this.syncApi.sync();
if (opts.clientWellKnownPollPeriod !== undefined) { if (this.clientOpts.clientWellKnownPollPeriod !== undefined) {
this.clientWellKnownIntervalID = this.clientWellKnownIntervalID =
// XXX: Typecast on timer ID because we know better
setInterval(() => { setInterval(() => {
this.fetchClientWellKnown(); this.fetchClientWellKnown();
}, 1000 * opts.clientWellKnownPollPeriod) as any as number; // XXX: Typecast because we know better }, 1000 * this.clientOpts.clientWellKnownPollPeriod) as any as number;
this.fetchClientWellKnown(); this.fetchClientWellKnown();
} }
} }
@@ -1249,7 +1250,7 @@ export class MatrixClient extends EventEmitter {
*/ */
public downloadKeys( public downloadKeys(
userIds: string[], userIds: string[],
forceDownload: boolean, forceDownload?: boolean,
): Promise<Record<string, Record<string, DeviceInfo>>> { ): Promise<Record<string, Record<string, DeviceInfo>>> {
if (!this.crypto) { if (!this.crypto) {
return Promise.reject(new Error("End-to-end encryption disabled")); return Promise.reject(new Error("End-to-end encryption disabled"));
@@ -2512,9 +2513,10 @@ export class MatrixClient extends EventEmitter {
targetRoomId: string, targetRoomId: string,
targetSessionId: string, targetSessionId: string,
backupInfo: IKeyBackupVersion, backupInfo: IKeyBackupVersion,
opts: IKeyBackupRestoreOpts, opts?: IKeyBackupRestoreOpts,
): Promise<IKeyBackupRestoreResult> { ): Promise<IKeyBackupRestoreResult> {
const { cacheCompleteCallback, progressCallback } = opts; const cacheCompleteCallback = opts?.cacheCompleteCallback;
const progressCallback = opts?.progressCallback;
if (!this.crypto) { if (!this.crypto) {
throw new Error("End-to-end encryption disabled"); throw new Error("End-to-end encryption disabled");
@@ -3376,7 +3378,7 @@ export class MatrixClient extends EventEmitter {
* @return {Promise} Resolves: TODO * @return {Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response. * @return {module:http-api.MatrixError} Rejects: with an error response.
*/ */
public sendMessage(roomId: string, content: any, txnId: string, callback?: Callback): Promise<ISendEventResponse> { public sendMessage(roomId: string, content: any, txnId?: string, callback?: Callback): Promise<ISendEventResponse> {
if (utils.isFunction(txnId)) { if (utils.isFunction(txnId)) {
callback = txnId as any as Callback; // for legacy callback = txnId as any as Callback; // for legacy
txnId = undefined; txnId = undefined;
@@ -6008,7 +6010,7 @@ export class MatrixClient extends EventEmitter {
* authenticates with CAS. * authenticates with CAS.
* @return {string} The HS URL to hit to begin the CAS login process. * @return {string} The HS URL to hit to begin the CAS login process.
*/ */
public getCasLoginUrl(redirectUrl: string): Promise<string> { public getCasLoginUrl(redirectUrl: string): string {
return this.getSsoLoginUrl(redirectUrl, "cas"); return this.getSsoLoginUrl(redirectUrl, "cas");
} }
@@ -6020,7 +6022,7 @@ export class MatrixClient extends EventEmitter {
* @param {string} idpId The ID of the Identity Provider being targeted, optional. * @param {string} idpId The ID of the Identity Provider being targeted, optional.
* @return {string} The HS URL to hit to begin the SSO login process. * @return {string} The HS URL to hit to begin the SSO login process.
*/ */
public getSsoLoginUrl(redirectUrl: string, loginType = "sso", idpId?: string): Promise<string> { public getSsoLoginUrl(redirectUrl: string, loginType = "sso", idpId?: string): string {
let url = "/login/" + loginType + "/redirect"; let url = "/login/" + loginType + "/redirect";
if (idpId) { if (idpId) {
url += "/" + idpId; url += "/" + idpId;
@@ -6648,7 +6650,10 @@ export class MatrixClient extends EventEmitter {
* determined by this.opts.onlyData, opts.rawResponse, and * determined by this.opts.onlyData, opts.rawResponse, and
* opts.onlyContentUri. Rejects with an error (usually a MatrixError). * opts.onlyContentUri. Rejects with an error (usually a MatrixError).
*/ */
public uploadContent(file: File | String | Buffer | ReadStream, opts: IUploadOpts): Promise<any> { // TODO: Advanced types public uploadContent(
file: File | String | Buffer | ReadStream | Blob,
opts: IUploadOpts,
): Promise<any> { // TODO: Advanced types
return this.http.uploadContent(file, opts); return this.http.uploadContent(file, opts);
} }

View File

@@ -101,10 +101,10 @@ export interface ICreateSecretStorageOpts {
/** /**
* Function called to get the user's * Function called to get the user's
* current key backup passphrase. Should return a promise that resolves with a Buffer * current key backup passphrase. Should return a promise that resolves with a Uint8Array
* containing the key, or rejects if the key cannot be obtained. * containing the key, or rejects if the key cannot be obtained.
*/ */
getKeyBackupPassphrase?: () => Promise<Buffer>; getKeyBackupPassphrase?: () => Promise<Uint8Array>;
} }
export interface ISecretStorageKey { export interface ISecretStorageKey {