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

encrypt for invited users if history visibility allows. #666

Merged
merged 3 commits into from
Jul 10, 2018
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
3 changes: 1 addition & 2 deletions src/crypto/algorithms/megolm.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,7 @@ MegolmEncryption.prototype._checkForUnknownDevices = function(devicesInRoom) {
* from userId to deviceId to deviceInfo
*/
MegolmEncryption.prototype._getDevicesInRoom = function(room) {
// XXX what about rooms where invitees can see the content?
const roomMembers = utils.map(room.getJoinedMembers(), function(u) {
const roomMembers = utils.map(room.getEncryptionTargetMembers(), function(u) {
return u.userId;
});

Expand Down
2 changes: 1 addition & 1 deletion src/crypto/algorithms/olm.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ OlmEncryption.prototype.encryptMessage = function(room, eventType, content) {
// TODO: there is a race condition here! What if a new user turns up
// just as you are sending a secret message?

const users = utils.map(room.getJoinedMembers(), function(u) {
const users = utils.map(room.getEncryptionTargetMembers(), function(u) {
return u.userId;
});

Expand Down
8 changes: 6 additions & 2 deletions src/crypto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ Crypto.prototype.setRoomEncryption = async function(roomId, config, inhibitDevic
throw new Error(`Unable to enable encryption in unknown room ${roomId}`);
}

const members = room.getJoinedMembers();
const members = room.getEncryptionTargetMembers();
members.forEach((m) => {
this._deviceList.startTrackingDeviceList(m.userId);
});
Expand Down Expand Up @@ -986,7 +986,7 @@ Crypto.prototype._evalDeviceListChanges = async function(deviceLists) {
Crypto.prototype._getE2eUsers = function() {
const e2eUserIds = [];
for (const room of this._getE2eRooms()) {
const members = room.getJoinedMembers();
const members = room.getEncryptionTargetMembers();
for (const member of members) {
e2eUserIds.push(member.userId);
}
Expand Down Expand Up @@ -1085,6 +1085,10 @@ Crypto.prototype._onRoomMembership = function(event, member, oldMembership) {
console.log('Join event for ' + member.userId + ' in ' + roomId);
// make sure we are tracking the deviceList for this user
this._deviceList.startTrackingDeviceList(member.userId);
} else if (member.membership == 'invite' &&
this._clientStore.getRoom(roomId).shouldEncryptForInvitedMembers()) {
console.log('Invite event for ' + member.userId + ' in ' + roomId);
this._deviceList.startTrackingDeviceList(member.userId);
}

alg.onRoomMembership(event, member, oldMembership);
Expand Down
23 changes: 22 additions & 1 deletion src/models/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,28 @@ Room.prototype.addEventsToTimeline = function(events, toStartOfTimeline,
});
};

/**
* Get a list of members we should be encrypting for in this room
* @return {RoomMember[]} A list of members who we should encrypt messages for
* in this room.
*/
Room.prototype.getEncryptionTargetMembers = function() {
let members = this.getMembersWithMembership("join");
if (this.shouldEncryptForInvitedMembers()) {
members = members.concat(this.getMembersWithMembership("invite"));
}
return members;
};

/**
* Determine whether we should encrypt messages for invited users in this room
* @return {boolean} if we should encrypt messages for invited users
*/
Room.prototype.shouldEncryptForInvitedMembers = function() {
const ev = this.currentState.getStateEvents("m.room.history_visibility", "");
return (ev && ev.getContent() && ev.getContent().history_visibility !== "joined");
};

/**
* Get the default room name (i.e. what a given user would see if the
* room had no m.room.name)
Expand Down Expand Up @@ -950,7 +972,6 @@ Room.prototype.recalculate = function(userId) {
}
};


/**
* Get a list of user IDs who have <b>read up to</b> the given event.
* @param {MatrixEvent} event the event to get read receipts for.
Expand Down