/* 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. */ const React = require("react"); import PropTypes from 'prop-types'; import { _t } from '../../../languageHandler'; const sdk = require('../../../index'); const MatrixClientPeg = require("../../../MatrixClientPeg"); module.exports = React.createClass({ displayName: 'EncryptedEventDialog', propTypes: { event: PropTypes.object.isRequired, onFinished: PropTypes.func.isRequired, }, getInitialState: function() { return { device: null }; }, componentWillMount: function() { this._unmounted = false; const client = MatrixClientPeg.get(); // first try to load the device from our store. // this.refreshDevice().then((dev) => { if (dev) { return dev; } // tell the client to try to refresh the device list for this user return client.downloadKeys([this.props.event.getSender()], true).then(() => { return this.refreshDevice(); }); }).then((dev) => { if (this._unmounted) { return; } this.setState({ device: dev }); client.on("deviceVerificationChanged", this.onDeviceVerificationChanged); }, (err)=>{ console.log("Error downloading devices", err); }); }, componentWillUnmount: function() { this._unmounted = true; const client = MatrixClientPeg.get(); if (client) { client.removeListener("deviceVerificationChanged", this.onDeviceVerificationChanged); } }, refreshDevice: function() { // Promise.resolve to handle transition from static result to promise; can be removed // in future return Promise.resolve(MatrixClientPeg.get().getEventSenderDeviceInfo(this.props.event)); }, onDeviceVerificationChanged: function(userId, device) { if (userId == this.props.event.getSender()) { this.refreshDevice().then((dev) => { this.setState({ device: dev }); }); } }, onKeyDown: function(e) { if (e.keyCode === 27) { // escape e.stopPropagation(); e.preventDefault(); this.props.onFinished(false); } }, _renderDeviceInfo: function() { const device = this.state.device; if (!device) { return ({ _t('unknown device') }); } let verificationStatus = ({ _t('NOT verified') }); if (device.isBlocked()) { verificationStatus = ({ _t('Blacklisted') }); } else if (device.isVerified()) { verificationStatus = _t('verified'); } return (
{ _t('Name') } { device.getDisplayName() }
{ _t('Device ID') } { device.deviceId }
{ _t('Verification') } { verificationStatus }
{ _t('Ed25519 fingerprint') } { device.getFingerprint() }
); }, _renderEventInfo: function() { const event = this.props.event; return ( { event.getContent().msgtype === 'm.bad.encrypted' ? ( ) : null }
{ _t('User ID') } { event.getSender() }
{ _t('Curve25519 identity key') } { event.getSenderKey() || { _t('none') } }
{ _t('Claimed Ed25519 fingerprint key') } { event.getKeysClaimed().ed25519 || { _t('none') } }
{ _t('Algorithm') } { event.getWireContent().algorithm || { _t('unencrypted') } }
{ _t('Decryption error') } { event.getContent().body }
{ _t('Session ID') } { event.getWireContent().session_id || { _t('none') } }
); }, render: function() { const DeviceVerifyButtons = sdk.getComponent('elements.DeviceVerifyButtons'); let buttons = null; if (this.state.device) { buttons = ( ); } return (
{ _t('End-to-end encryption information') }

{ _t('Event information') }

{ this._renderEventInfo() }

{ _t('Sender device information') }

{ this._renderDeviceInfo() }
{ buttons }
); }, });