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

Support for .ready verification event (MSC2366) & other things #1140

Merged
merged 44 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
882d3a7
support .ready event in VerificationRequest
bwindels Dec 10, 2019
2da7253
return request instead of verifier from verification methods
bwindels Dec 10, 2019
10e2947
waitForVerifier is unused now, make it more broadly useful with callback
bwindels Dec 10, 2019
28e46a8
expose common phases as properties
bwindels Dec 10, 2019
4c6dd56
filter verification methods from argument
bwindels Dec 10, 2019
cd7cc1b
set verification request on event
bwindels Dec 10, 2019
b34a2c7
WIP
bwindels Dec 10, 2019
c4142d9
store in-room verification requests by roomId, txnId
bwindels Dec 18, 2019
5f9e822
more ready and remote echo support
bwindels Dec 19, 2019
dac4a54
make this a public prop
bwindels Dec 20, 2019
984b623
don't block remote echos to VerificationRequests
bwindels Dec 20, 2019
29c04b6
only move to PHASE_DONE when both .done events are received
bwindels Dec 20, 2019
efe2488
get other user id from channel
bwindels Dec 20, 2019
48977e6
get other party user id by inspecting initial event sender/to fields
bwindels Dec 20, 2019
883b83f
move blocking non-participating users back to InRoomChannel
bwindels Dec 20, 2019
e7bcb61
attempt at only creating verifier for live events
bwindels Dec 20, 2019
cf42ad8
WIP historical
bwindels Dec 27, 2019
0d3d27a
fixes and cleanup for historical
bwindels Jan 2, 2020
57135a8
don't mark events loaded from cache as live events
bwindels Jan 3, 2020
8ed51c8
don't cancel or timeout when verify isn't called
bwindels Jan 3, 2020
3ec8233
fixes & implement timeout
bwindels Jan 3, 2020
423c8a8
use isRemoteEcho to determine if the event is theirs or not
bwindels Jan 3, 2020
3a9dc37
new state machine relies on having remote echos, so fake for to_device
bwindels Jan 3, 2020
213bb9d
allow to move straight from UNSENT to STARTED
bwindels Jan 3, 2020
5919874
check !unsent instead of requested for emitting the crypto.request event
bwindels Jan 3, 2020
75fc25f
fix method names
bwindels Jan 3, 2020
9338d9c
commit logging
bwindels Jan 3, 2020
f44e0a8
parenthesis in wrong place broke logic
bwindels Jan 3, 2020
72fd1e4
add note to fix bug later
bwindels Jan 3, 2020
1205178
Merge branch 'develop' into bwindels/verification-right-panel
turt2live Jan 16, 2020
07cc93c
fix lint
bwindels Jan 17, 2020
59bfc45
use setTimeout of setInterval
bwindels Jan 17, 2020
cbe2965
mention reason in cancellation error
bwindels Jan 17, 2020
e51ba79
to make this work while using fake timers, don't use setTimeout
bwindels Jan 20, 2020
c34ccc9
adjust test: requestVerification returns the request instead of verifier
bwindels Jan 20, 2020
e895283
enable fake timers for consistency
bwindels Jan 20, 2020
77d0a76
fixup: another timeout
bwindels Jan 20, 2020
c12a3b6
more fixup: make sure remote echo doesn't arrive earlier for TestClient
bwindels Jan 20, 2020
121e9d0
don't overwrite a request when the remote echo arrives before event_id
bwindels Jan 20, 2020
e5c65d5
set transaction_id for remote echos in TestClient
bwindels Jan 20, 2020
bd9a2c1
implement API change in sas test for requestVerificationDM
bwindels Jan 20, 2020
aac6829
remove obsolete comment
bwindels Jan 20, 2020
d526229
update jsdoc of requestVerificationDM
bwindels Jan 20, 2020
9d6f873
remove obsolete and now broken method
bwindels Jan 20, 2020
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
6 changes: 5 additions & 1 deletion spec/unit/crypto/verification/request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {makeTestClients} from './util';

const Olm = global.Olm;

jest.useFakeTimers();

describe("verification request", function() {
if (!global.Olm) {
logger.warn('Not running device verification unit tests: libolm not present');
Expand Down Expand Up @@ -64,7 +66,9 @@ describe("verification request", function() {
// XXX: Private function access (but it's a test, so we're okay)
bobVerifier._endTimer();
});
const aliceVerifier = await alice.client.requestVerification("@bob:example.com");
const aliceRequest = await alice.client.requestVerification("@bob:example.com");
await aliceRequest.waitFor(r => r.started);
const aliceVerifier = aliceRequest.verifier;
expect(aliceVerifier).toBeInstanceOf(SAS);

// XXX: Private function access (but it's a test, so we're okay)
Expand Down
4 changes: 3 additions & 1 deletion spec/unit/crypto/verification/sas.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,11 @@ describe("SAS verification", function() {
});
});

aliceVerifier = await alice.client.requestVerificationDM(
const aliceRequest = await alice.client.requestVerificationDM(
bob.client.getUserId(), "!room_id", [verificationMethods.SAS],
);
await aliceRequest.waitFor(r => r.started);
aliceVerifier = aliceRequest.verifier;
aliceVerifier.on("show_sas", (e) => {
if (!e.sas.emoji || !e.sas.decimal) {
e.cancel();
Expand Down
44 changes: 27 additions & 17 deletions spec/unit/crypto/verification/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ export async function makeTestClients(userInfos, options) {
content: msg,
});
const client = clientMap[userId][deviceId];
if (event.isEncrypted()) {
event.attemptDecryption(client._crypto)
.then(() => client.emit("toDeviceEvent", event));
} else {
setTimeout(
() => client.emit("toDeviceEvent", event),
0,
);
}
const decryptionPromise = event.isEncrypted() ?
event.attemptDecryption(client._crypto) :
Promise.resolve();

decryptionPromise.then(
() => client.emit("toDeviceEvent", event),
);
}
}
}
Expand All @@ -50,21 +48,33 @@ export async function makeTestClients(userInfos, options) {
const sendEvent = function(room, type, content) {
// make up a unique ID as the event ID
const eventId = "$" + this.makeTxnId(); // eslint-disable-line babel/no-invalid-this
const event = new MatrixEvent({
const rawEvent = {
sender: this.getUserId(), // eslint-disable-line babel/no-invalid-this
type: type,
content: content,
room_id: room,
event_id: eventId,
origin_server_ts: Date.now(),
};
const event = new MatrixEvent(rawEvent);
const remoteEcho = new MatrixEvent(Object.assign({}, rawEvent, {
unsigned: {
transaction_id: this.makeTxnId(), // eslint-disable-line babel/no-invalid-this
},
}));

setImmediate(() => {
for (const tc of clients) {
if (tc.client === this) { // eslint-disable-line babel/no-invalid-this
console.log("sending remote echo!!");
tc.client.emit("Room.timeline", remoteEcho);
} else {
tc.client.emit("Room.timeline", event);
}
}
});
for (const tc of clients) {
setTimeout(
() => tc.client.emit("Room.timeline", event),
0,
);
}

return {event_id: eventId};
return Promise.resolve({event_id: eventId});
};

for (const userInfo of userInfos) {
Expand Down
24 changes: 4 additions & 20 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,8 @@ async function _setDeviceVerification(
* @param {Array} methods array of verification methods to use. Defaults to
* all known methods
*
* @returns {Promise<module:crypto/verification/Base>} resolves to a verifier
* when the request is accepted by the other user
* @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) {
if (this._crypto === null) {
Expand All @@ -863,22 +863,6 @@ MatrixClient.prototype.requestVerificationDM = function(userId, roomId, methods)
return this._crypto.requestVerificationDM(userId, roomId, methods);
};

/**
* Accept a key verification request from a DM.
*
* @param {module:models/event~MatrixEvent} event the verification request
* that is accepted
* @param {string} method the verification mmethod to use
*
* @returns {module:crypto/verification/Base} a verifier
*/
MatrixClient.prototype.acceptVerificationDM = function(event, method) {
if (this._crypto === null) {
throw new Error("End-to-end encryption disabled");
}
return this._crypto.acceptVerificationDM(event, method);
};

/**
* Request a key verification from another user.
*
Expand All @@ -888,8 +872,8 @@ MatrixClient.prototype.acceptVerificationDM = function(event, method) {
* @param {Array} devices array of device IDs to send requests to. Defaults to
* all devices owned by the user
*
* @returns {Promise<module:crypto/verification/Base>} resolves to a verifier
* when the request is accepted by the other user
* @returns {Promise<module:crypto/verification/request/VerificationRequest>} resolves to a VerificationRequest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we don't change the contract of our public functions, though in this case we're about to do a major version bump for the new build system anyways so this seems fine and convenient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, see the breaking change comment in the description.

* when the request has been sent to the other party.
*/
MatrixClient.prototype.requestVerification = function(userId, methods, devices) {
if (this._crypto === null) {
Expand Down
Loading