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 m.new_device support #483

Merged
merged 1 commit into from
Jul 6, 2017
Merged
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
54 changes: 0 additions & 54 deletions spec/integ/matrix-client-crypto.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,60 +647,6 @@ describe("MatrixClient crypto", function() {
}).then(aliRecvMessage);
});


it("Ali does a key query when she gets a new_device event", function() {
return q()
.then(() => aliTestClient.start())
.then(() => firstSync(aliTestClient))

// ali will only care about bob's new_device if she is tracking
// bob's devices, which she will do if we enable encryption
.then(aliEnablesEncryption)

.then(() => {
aliTestClient.expectKeyQuery({
device_keys: {
[aliUserId]: {},
[bobUserId]: {},
},
});
return aliTestClient.httpBackend.flush('/keys/query', 1);
})

// make sure that the initial key download has completed
// (downloadKeys will wait until it does)
.then(() => {
return aliTestClient.client.downloadKeys([bobUserId]);
})

.then(function() {
const syncData = {
next_batch: '2',
to_device: {
events: [
testUtils.mkEvent({
content: {
device_id: 'TEST_DEVICE',
rooms: [],
},
sender: bobUserId,
type: 'm.new_device',
}),
],
},
};
aliTestClient.httpBackend.when('GET', '/sync').respond(200, syncData);
return aliTestClient.httpBackend.flush('/sync', 1);
}).then(() => {
aliTestClient.expectKeyQuery({
device_keys: {
[bobUserId]: {},
},
});
return aliTestClient.httpBackend.flush('/keys/query', 1);
});
});

it("Ali does a key query when encryption is enabled", function() {
// enabling encryption in the room should make alice download devices
// for both members.
Expand Down
84 changes: 0 additions & 84 deletions src/crypto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ function _registerEventHandlers(crypto, eventEmitter) {
if (event.getType() == "m.room_key"
|| event.getType() == "m.forwarded_room_key") {
crypto._onRoomKeyEvent(event);
} else if (event.getType() == "m.new_device") {
crypto._onNewDeviceEvent(event);
} else if (event.getType() == "m.room_key_request") {
crypto._onRoomKeyRequestEvent(event);
}
Expand Down Expand Up @@ -875,9 +873,6 @@ Crypto.prototype._onSyncCompleted = function(syncData) {
if (!syncData.oldSyncToken) {
console.log("Completed initial sync");

// an initialsync.
this._sendNewDeviceEvents();

// if we have a deviceSyncToken, we can tell the deviceList to
// invalidate devices which have changed since then.
const oldSyncToken = this._sessionStore.getEndToEndDeviceSyncToken();
Expand Down Expand Up @@ -926,57 +921,6 @@ Crypto.prototype._onSyncCompleted = function(syncData) {
}
};

/**
* Send m.new_device messages to any devices we share a room with.
*
* (TODO: we can get rid of this once a suitable number of homeservers and
* clients support the more reliable device list update stream mechanism)
*
* @private
*/
Crypto.prototype._sendNewDeviceEvents = function() {
if (this._sessionStore.getDeviceAnnounced()) {
return;
}

// we need to tell all the devices in all the rooms we are members of that
// we have arrived.
// build a list of rooms for each user.
const roomsByUser = {};
for (const room of this._getE2eRooms()) {
const members = room.getJoinedMembers();
for (let j = 0; j < members.length; j++) {
const m = members[j];
if (!roomsByUser[m.userId]) {
roomsByUser[m.userId] = [];
}
roomsByUser[m.userId].push(room.roomId);
}
}

// build a per-device message for each user
const content = {};
for (const userId in roomsByUser) {
if (!roomsByUser.hasOwnProperty(userId)) {
continue;
}
content[userId] = {
"*": {
device_id: this._deviceId,
rooms: roomsByUser[userId],
},
};
}

const self = this;
this._baseApis.sendToDevice(
"m.new_device", // OH HAI!
content,
).done(function() {
self._sessionStore.setDeviceAnnounced();
});
};

/**
* Ask the server which users have new devices since a given token,
* and invalidate them
Expand Down Expand Up @@ -1083,34 +1027,6 @@ Crypto.prototype._onRoomMembership = function(event, member, oldMembership) {
};


/**
* Called when a new device announces itself
*
* @private
* @param {module:models/event.MatrixEvent} event announcement event
*/
Crypto.prototype._onNewDeviceEvent = function(event) {
const content = event.getContent();
const userId = event.getSender();
const deviceId = content.device_id;
const rooms = content.rooms;

if (!rooms || !deviceId) {
console.warn("new_device event missing keys");
return;
}

console.log("m.new_device event from " + userId + ":" + deviceId +
" for rooms " + rooms);

if (this.getStoredDevice(userId, deviceId)) {
console.log("Known device; ignoring");
return;
}

this._deviceList.invalidateUserDeviceList(userId);
};

/**
* Called when we get an m.room_key_request event.
*
Expand Down
17 changes: 0 additions & 17 deletions src/store/session/webstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,6 @@ WebStorageSessionStore.prototype = {
return this.store.getItem(KEY_END_TO_END_ACCOUNT);
},

/**
* Store a flag indicating that we have announced the new device.
*/
setDeviceAnnounced: function() {
this.store.setItem(KEY_END_TO_END_ANNOUNCED, "true");
},

/**
* Check if the "device announced" flag is set
*
* @return {boolean} true if the "device announced" flag has been set.
*/
getDeviceAnnounced: function() {
return this.store.getItem(KEY_END_TO_END_ANNOUNCED) == "true";
},

/**
* Stores the known devices for a user.
* @param {string} userId The user's ID.
Expand Down Expand Up @@ -208,7 +192,6 @@ WebStorageSessionStore.prototype = {
};

const KEY_END_TO_END_ACCOUNT = E2E_PREFIX + "account";
const KEY_END_TO_END_ANNOUNCED = E2E_PREFIX + "announced";
const KEY_END_TO_END_DEVICE_SYNC_TOKEN = E2E_PREFIX + "device_sync_token";
const KEY_END_TO_END_DEVICE_LIST_TRACKING_STATUS = E2E_PREFIX + "device_tracking";

Expand Down