Skip to content

Commit

Permalink
Merge pull request #1206 from matrix-org/bwindels/dontpassmethodstove…
Browse files Browse the repository at this point in the history
…rify

Remove methods argument to verification
  • Loading branch information
bwindels authored Feb 13, 2020
2 parents 36a945f + 00c003e commit 6684574
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
2 changes: 1 addition & 1 deletion spec/unit/crypto/verification/sas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ describe("SAS verification", function() {
});

const aliceRequest = await alice.client.requestVerificationDM(
bob.client.getUserId(), "!room_id", [verificationMethods.SAS],
bob.client.getUserId(), "!room_id",
);
await aliceRequest.waitFor(r => r.started);
aliceVerifier = aliceRequest.verifier;
Expand Down
12 changes: 4 additions & 8 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,36 +907,32 @@ async function _setDeviceVerification(
*
* @param {string} userId the user to request verification with
* @param {string} roomId the room to use for verification
* @param {Array} methods array of verification methods to use. Defaults to
* all known methods
*
* @returns {Promise<module:crypto/verification/request/VerificationRequest>} resolves to a VerificationRequest
* when the request has been sent to the other party.
*/
MatrixClient.prototype.requestVerificationDM = function(userId, roomId, methods) {
MatrixClient.prototype.requestVerificationDM = function(userId, roomId) {
if (this._crypto === null) {
throw new Error("End-to-end encryption disabled");
}
return this._crypto.requestVerificationDM(userId, roomId, methods);
return this._crypto.requestVerificationDM(userId, roomId);
};

/**
* Request a key verification from another user.
*
* @param {string} userId the user to request verification with
* @param {Array} methods array of verification methods to use. Defaults to
* all known methods
* @param {Array} devices array of device IDs to send requests to. Defaults to
* all devices owned by the user
*
* @returns {Promise<module:crypto/verification/request/VerificationRequest>} resolves to a VerificationRequest
* when the request has been sent to the other party.
*/
MatrixClient.prototype.requestVerification = function(userId, methods, devices) {
MatrixClient.prototype.requestVerification = function(userId, devices) {
if (this._crypto === null) {
throw new Error("End-to-end encryption disabled");
}
return this._crypto.requestVerification(userId, methods, devices);
return this._crypto.requestVerification(userId, devices);
};

/**
Expand Down
27 changes: 7 additions & 20 deletions src/crypto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ export function Crypto(baseApis, sessionStore, userId, deviceId,
this._clientStore = clientStore;
this._cryptoStore = cryptoStore;
this._roomList = roomList;
this._verificationMethods = new Map();
if (verificationMethods) {
this._verificationMethods = new Map();
for (const method of verificationMethods) {
if (typeof method === "string") {
if (defaultVerificationMethods[method]) {
Expand All @@ -145,8 +145,9 @@ export function Crypto(baseApis, sessionStore, userId, deviceId,
console.warn(`Excluding unknown verification method ${method}`);
}
}
} else {
this._verificationMethods = defaultVerificationMethods;
}

// track whether this device's megolm keys are being backed up incrementally
// to the server or not.
// XXX: this should probably have a single source of truth from OlmAccount
Expand Down Expand Up @@ -1618,46 +1619,32 @@ Crypto.prototype.setDeviceVerification = async function(
return deviceObj;
};

Crypto.prototype.requestVerificationDM = function(userId, roomId, methods) {
Crypto.prototype.requestVerificationDM = function(userId, roomId) {
const channel = new InRoomChannel(this._baseApis, roomId, userId);
return this._requestVerificationWithChannel(
userId,
methods,
channel,
this._inRoomVerificationRequests,
);
};

Crypto.prototype.requestVerification = function(userId, methods, devices) {
Crypto.prototype.requestVerification = function(userId, devices) {
if (!devices) {
devices = Object.keys(this._deviceList.getRawStoredDevicesForUser(userId));
}
const channel = new ToDeviceChannel(this._baseApis, userId, devices);
return this._requestVerificationWithChannel(
userId,
methods,
channel,
this._toDeviceVerificationRequests,
);
};

Crypto.prototype._requestVerificationWithChannel = async function(
userId, methods, channel, requestsMap,
userId, channel, requestsMap,
) {
let verificationMethods = this._verificationMethods;
if (methods) {
verificationMethods = methods.reduce((map, name) => {
const method = this._verificationMethods.get(name);
if (!method) {
throw new Error(`Verification method ${name} is not supported.`);
} else {
map.set(name, method);
}
return map;
}, new Map());
}
let request = new VerificationRequest(
channel, verificationMethods, this._baseApis);
channel, this._verificationMethods, this._baseApis);
await request.sendRequest();
// don't replace the request created by a racing remote echo
const racingRequest = requestsMap.getRequestByChannel(channel);
Expand Down

0 comments on commit 6684574

Please sign in to comment.