From 3474f08334050645ba1b7b0d71214f3411334101 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 21 Jul 2015 12:01:18 +0100 Subject: [PATCH 1/4] Display the body of unknown message types --- skins/base/views/molecules/UnknownMessageTile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/skins/base/views/molecules/UnknownMessageTile.js b/skins/base/views/molecules/UnknownMessageTile.js index 27e801c994..b965a4a1fd 100644 --- a/skins/base/views/molecules/UnknownMessageTile.js +++ b/skins/base/views/molecules/UnknownMessageTile.js @@ -25,9 +25,10 @@ module.exports = React.createClass({ mixins: [UnknownMessageTileController], render: function() { + var content = this.props.mxEvent.getContent(); return ( - ? + {content.body} ); }, From 726ee7b50b25678dedf4f59dcc8b4048ecac41af Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 21 Jul 2015 12:03:15 +0100 Subject: [PATCH 2/4] Hook up the encrypt button when creating rooms --- skins/base/views/organisms/CreateRoom.js | 8 +++++++- src/MatrixClientPeg.js | 15 +++++++++++++++ src/controllers/organisms/CreateRoom.js | 24 +++++++++++++++++++++++- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/skins/base/views/organisms/CreateRoom.js b/skins/base/views/organisms/CreateRoom.js index 4fd7a93ee4..21769621eb 100644 --- a/skins/base/views/organisms/CreateRoom.js +++ b/skins/base/views/organisms/CreateRoom.js @@ -118,6 +118,12 @@ module.exports = React.createClass({ }) }, + onEncryptChanged: function(ev) { + this.setState({ + encrypt: ev.target.checked, + }); + }, + render: function() { var curr_phase = this.state.phase; if (curr_phase == this.phases.CREATING) { @@ -142,7 +148,7 @@ module.exports = React.createClass({
- +
{error_box} diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 1acd2a7015..322b70f48c 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -23,6 +23,16 @@ var matrixClient = null; var localStorage = window.localStorage; +function deviceId() { + var id = Math.floor(Math.random()*16777215).toString(16); + id = "W" + "000000".substring(id.length) + id; + if (localStorage) { + id = localStorage.getItem("mx_device_id") || id; + localStorage.setItem("mx_device_id", id); + } + return id; +} + function createClient(hs_url, is_url, user_id, access_token) { var opts = { baseUrl: hs_url, @@ -31,6 +41,11 @@ function createClient(hs_url, is_url, user_id, access_token) { userId: user_id }; + if (localStorage) { + opts.sessionStore = new Matrix.WebStorageSessionStore(localStorage); + opts.deviceId = deviceId(); + } + matrixClient = Matrix.createClient(opts); } diff --git a/src/controllers/organisms/CreateRoom.js b/src/controllers/organisms/CreateRoom.js index 107e94b357..52b2fd8895 100644 --- a/src/controllers/organisms/CreateRoom.js +++ b/src/controllers/organisms/CreateRoom.js @@ -19,6 +19,7 @@ limitations under the License. var React = require("react"); var MatrixClientPeg = require("../../MatrixClientPeg"); var PresetValues = require('../atoms/create_room/Presets').Presets; +var q = require('q'); module.exports = { propTypes: { @@ -97,7 +98,28 @@ module.exports = { return; } - var deferred = MatrixClientPeg.get().createRoom(options); + var deferred = cli.createRoom(options); + + var response; + + if (this.state.encrypt) { + var deferred = deferred.then(function(res) { + response = res; + return cli.downloadKeys([cli.credentials.userId]); + }).then(function(res) { + // TODO: Check the keys are valid. + return cli.downloadKeys(options.invite); + }).then(function(res) { + return cli.setRoomEncryption(response.room_id, { + algorithm: "m.olm.v1.curve25519-aes-sha2", + members: options.invite, + }); + }).then(function(res) { + var d = q.defer(); + d.resolve(response); + return d.promise; + }); + } this.setState({ phase: this.phases.CREATING, From 6bb6eafdc06ae9b660cc7166ba0d74c5174e19bd Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 21 Jul 2015 16:46:17 +0100 Subject: [PATCH 3/4] Hook up slash commands to enable and disable encryption for a room so that we can experiment with encryption while we wait for the rest of the UI to exist --- src/SlashCommands.js | 22 +++++++++++++++++++++- src/controllers/organisms/CreateRoom.js | 23 ++++++++--------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/SlashCommands.js b/src/SlashCommands.js index 26a14687d3..2ed6c64acf 100644 --- a/src/SlashCommands.js +++ b/src/SlashCommands.js @@ -18,6 +18,7 @@ limitations under the License. var MatrixClientPeg = require("./MatrixClientPeg"); var dis = require("./dispatcher"); +var encryption = require("./encryption"); var reject = function(msg) { return { @@ -42,6 +43,25 @@ var commands = { return reject("Usage: /nick "); }, + encrypt: function(room_id, args) { + if (args == "on") { + var client = MatrixClientPeg.get(); + var members = client.getRoom(room_id).currentState.members; + var user_ids = Object.keys(members); + return success( + encryption.enableEncryption(client, room_id, user_ids) + ); + } + if (args == "off") { + var client = MatrixClientPeg.get(); + return success( + encryption.disableEncryption(client, room_id) + ); + + } + return reject("Usage: encrypt "); + }, + // Change the room topic topic: function(room_id, args) { if (args) { @@ -234,4 +254,4 @@ module.exports = { } return null; // not a command } -}; \ No newline at end of file +}; diff --git a/src/controllers/organisms/CreateRoom.js b/src/controllers/organisms/CreateRoom.js index 52b2fd8895..f6404eb231 100644 --- a/src/controllers/organisms/CreateRoom.js +++ b/src/controllers/organisms/CreateRoom.js @@ -20,6 +20,7 @@ var React = require("react"); var MatrixClientPeg = require("../../MatrixClientPeg"); var PresetValues = require('../atoms/create_room/Presets').Presets; var q = require('q'); +var encryption = require("../../encryption"); module.exports = { propTypes: { @@ -103,22 +104,14 @@ module.exports = { var response; if (this.state.encrypt) { - var deferred = deferred.then(function(res) { + deferred = deferred.then(function(res) { response = res; - return cli.downloadKeys([cli.credentials.userId]); - }).then(function(res) { - // TODO: Check the keys are valid. - return cli.downloadKeys(options.invite); - }).then(function(res) { - return cli.setRoomEncryption(response.room_id, { - algorithm: "m.olm.v1.curve25519-aes-sha2", - members: options.invite, - }); - }).then(function(res) { - var d = q.defer(); - d.resolve(response); - return d.promise; - }); + return encryption.enableEncryption( + cli, response.roomId, options.invite + ); + }).then(function() { + return q(response) } + ); } this.setState({ From f036a10a7ddfd0bdb5541ab1c72d7ba9f1345295 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Tue, 21 Jul 2015 17:00:57 +0100 Subject: [PATCH 4/4] Add missing src/encryption.js file --- src/encryption.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/encryption.js diff --git a/src/encryption.js b/src/encryption.js new file mode 100644 index 0000000000..dea454a3f3 --- /dev/null +++ b/src/encryption.js @@ -0,0 +1,40 @@ +/* +Copyright 2015 OpenMarket Ltd + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +'use strict'; + +function enableEncyption(client, roomId, members) { + members = members.slice(0); + members.push(client.credentials.userId); + // TODO: Check the keys actually match what keys the user has. + // TODO: Don't redownload keys each time. + return client.downloadKeys(members, "forceDownload").then(function(res) { + return client.setRoomEncryption(roomId, { + algorithm: "m.olm.v1.curve25519-aes-sha2", + members: members, + }); + }) +} + +function disableEncryption(client, roomId) { + return client.disableRoomEncryption(roomId); +} + + +module.exports = { + enableEncryption: enableEncyption, + disableEncryption: disableEncryption, +}