2016-09-12 22:43:00 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var React = require("react");
|
2017-05-23 14:16:31 +00:00
|
|
|
import _t from 'counterpart-riot';
|
2016-09-12 22:43:00 +00:00
|
|
|
var sdk = require('../../../index');
|
|
|
|
var MatrixClientPeg = require("../../../MatrixClientPeg");
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'EncryptedEventDialog',
|
|
|
|
|
|
|
|
propTypes: {
|
2016-09-21 09:36:23 +00:00
|
|
|
event: React.PropTypes.object.isRequired,
|
|
|
|
onFinished: React.PropTypes.func.isRequired,
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return { device: this.refreshDevice() };
|
2016-09-12 22:43:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
2016-09-21 09:36:23 +00:00
|
|
|
this._unmounted = false;
|
2016-09-12 22:43:00 +00:00
|
|
|
var client = MatrixClientPeg.get();
|
|
|
|
client.on("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
2016-09-16 01:26:09 +00:00
|
|
|
|
2016-09-21 09:36:23 +00:00
|
|
|
// no need to redownload keys if we already have the device
|
|
|
|
if (this.state.device) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-16 01:26:09 +00:00
|
|
|
client.downloadKeys([this.props.event.getSender()], true).done(()=>{
|
2016-09-21 09:36:23 +00:00
|
|
|
if (this._unmounted) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-16 01:26:09 +00:00
|
|
|
this.setState({ device: this.refreshDevice() });
|
|
|
|
}, (err)=>{
|
|
|
|
console.log("Error downloading devices", err);
|
|
|
|
});
|
2016-09-12 22:43:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
2016-09-21 09:36:23 +00:00
|
|
|
this._unmounted = true;
|
2016-09-12 22:43:00 +00:00
|
|
|
var client = MatrixClientPeg.get();
|
|
|
|
if (client) {
|
|
|
|
client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
refreshDevice: function() {
|
2016-09-21 09:36:23 +00:00
|
|
|
return MatrixClientPeg.get().getEventSenderDeviceInfo(this.props.event);
|
2016-09-12 22:43:00 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onDeviceVerificationChanged: function(userId, device) {
|
|
|
|
if (userId == this.props.event.getSender()) {
|
|
|
|
this.setState({ device: this.refreshDevice() });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-16 01:26:09 +00:00
|
|
|
onKeyDown: function(e) {
|
|
|
|
if (e.keyCode === 27) { // escape
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.onFinished(false);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-09-21 09:36:23 +00:00
|
|
|
_renderDeviceInfo: function() {
|
2016-09-12 22:43:00 +00:00
|
|
|
var device = this.state.device;
|
2016-09-21 09:36:23 +00:00
|
|
|
if (!device) {
|
2017-05-23 14:16:31 +00:00
|
|
|
return (<i>{ _t('unknown device') }</i>);
|
2016-09-21 09:36:23 +00:00
|
|
|
}
|
|
|
|
|
2017-05-23 14:16:31 +00:00
|
|
|
var verificationStatus = (<b>{ _t('NOT verified') }</b>);
|
2016-09-21 09:36:23 +00:00
|
|
|
if (device.isBlocked()) {
|
2017-05-23 14:16:31 +00:00
|
|
|
verificationStatus = (<b>{ _t('Blacklisted') }</b>);
|
2016-09-21 09:36:23 +00:00
|
|
|
} else if (device.isVerified()) {
|
2017-05-23 14:16:31 +00:00
|
|
|
verificationStatus = _t('verified');
|
2016-09-21 09:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
2017-05-23 14:16:31 +00:00
|
|
|
<td>{ _t('Name') }</td>
|
2016-09-21 09:36:23 +00:00
|
|
|
<td>{ device.getDisplayName() }</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2017-05-23 14:16:31 +00:00
|
|
|
<td>{ _t('Device ID') }</td>
|
2016-09-21 09:36:23 +00:00
|
|
|
<td><code>{ device.deviceId }</code></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2017-05-23 14:16:31 +00:00
|
|
|
<td>{ _t('Verification') }</td>
|
2016-09-21 09:36:23 +00:00
|
|
|
<td>{ verificationStatus }</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2017-05-23 14:16:31 +00:00
|
|
|
<td>{ _t('Ed25519 fingerprint') }</td>
|
2016-09-21 09:36:23 +00:00
|
|
|
<td><code>{device.getFingerprint()}</code></td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_renderEventInfo: function() {
|
|
|
|
var event = this.props.event;
|
2016-09-12 22:43:00 +00:00
|
|
|
|
2016-09-21 09:36:23 +00:00
|
|
|
return (
|
|
|
|
<table>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
2017-05-23 14:16:31 +00:00
|
|
|
<td>{ _t('User ID') }</td>
|
2016-09-21 09:36:23 +00:00
|
|
|
<td>{ event.getSender() }</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
2017-05-23 14:16:31 +00:00
|
|
|
<td>{ _t('Curve25519 identity key') }</td>
|
|
|
|
<td><code>{ event.getSenderKey() || <i>{ _t('none') }</i> }</code></td>
|
2016-09-21 09:36:23 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2017-05-23 14:16:31 +00:00
|
|
|
<td>{ _t('Claimed Ed25519 fingerprint key') }</td>
|
|
|
|
<td><code>{ event.getKeysClaimed().ed25519 || <i>{ _t('none') }</i> }</code></td>
|
2016-09-21 09:36:23 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
2017-05-23 14:16:31 +00:00
|
|
|
<td>{ _t('Algorithm') }</td>
|
|
|
|
<td>{ event.getWireContent().algorithm || <i>{ _t('unencrypted') }</i> }</td>
|
2016-09-21 09:36:23 +00:00
|
|
|
</tr>
|
|
|
|
{
|
|
|
|
event.getContent().msgtype === 'm.bad.encrypted' ? (
|
|
|
|
<tr>
|
2017-05-23 14:16:31 +00:00
|
|
|
<td>{ _t('Decryption error') }</td>
|
2016-09-21 09:36:23 +00:00
|
|
|
<td>{ event.getContent().body }</td>
|
|
|
|
</tr>
|
|
|
|
) : null
|
|
|
|
}
|
|
|
|
<tr>
|
2017-05-23 14:16:31 +00:00
|
|
|
<td>{ _t('Session ID') }</td>
|
|
|
|
<td><code>{ event.getWireContent().session_id || <i>{ _t('none') }</i> }</code></td>
|
2016-09-21 09:36:23 +00:00
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2016-09-22 18:23:34 +00:00
|
|
|
var DeviceVerifyButtons = sdk.getComponent('elements.DeviceVerifyButtons');
|
2016-09-12 22:43:00 +00:00
|
|
|
|
2016-09-21 09:36:23 +00:00
|
|
|
var buttons = null;
|
|
|
|
if (this.state.device) {
|
|
|
|
buttons = (
|
2016-09-22 18:23:34 +00:00
|
|
|
<DeviceVerifyButtons device={ this.state.device }
|
2016-09-21 09:36:23 +00:00
|
|
|
userId={ this.props.event.getSender() }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-09-12 22:43:00 +00:00
|
|
|
return (
|
2016-09-16 01:26:09 +00:00
|
|
|
<div className="mx_EncryptedEventDialog" onKeyDown={ this.onKeyDown }>
|
2016-09-12 22:43:00 +00:00
|
|
|
<div className="mx_Dialog_title">
|
2017-05-23 14:16:31 +00:00
|
|
|
{ _t('End-to-end encryption information') }
|
2016-09-12 22:43:00 +00:00
|
|
|
</div>
|
|
|
|
<div className="mx_Dialog_content">
|
2017-05-23 14:16:31 +00:00
|
|
|
<h4>{ _t('Event information') }</h4>
|
2016-09-21 09:36:23 +00:00
|
|
|
{this._renderEventInfo()}
|
|
|
|
|
2017-05-23 14:16:31 +00:00
|
|
|
<h4>{ _t('Sender device information') }</h4>
|
2016-09-21 09:36:23 +00:00
|
|
|
{this._renderDeviceInfo()}
|
2016-09-12 22:43:00 +00:00
|
|
|
</div>
|
|
|
|
<div className="mx_Dialog_buttons">
|
|
|
|
<button className="mx_Dialog_primary" onClick={ this.props.onFinished } autoFocus={ true }>
|
2017-05-23 14:16:31 +00:00
|
|
|
{ _t('OK') }
|
2016-09-12 22:43:00 +00:00
|
|
|
</button>
|
2016-09-21 09:36:23 +00:00
|
|
|
{buttons}
|
2016-09-12 22:43:00 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|