You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 lines
19 KiB

(window.webpackJsonp=window.webpackJsonp||[]).push([[9],{180:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=p(r(31)),a=p(r(65)),i=p(r(729)),o=p(r(0)),s=p(r(1)),l=r(2),u=d(r(17)),c=d(r(486)),f=p(r(3));function d(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function p(e){return e&&e.__esModule?e:{default:e}}t.default=o.default.createClass({displayName:"ExportE2eKeysDialog",propTypes:{matrixClient:s.default.instanceOf(u.MatrixClient).isRequired,onFinished:s.default.func.isRequired},getInitialState:function(){return{phase:1,errStr:null}},componentWillMount:function(){this._unmounted=!1},componentWillUnmount:function(){this._unmounted=!0},_onPassphraseFormSubmit:function(e){e.preventDefault();var t=this.refs.passphrase1.value;return t!==this.refs.passphrase2.value?(this.setState({errStr:(0,l._t)("Passphrases must match")}),!1):t?(this._startExport(t),!1):(this.setState({errStr:(0,l._t)("Passphrase must not be empty")}),!1)},_startExport:function(e){var t=this;a.default.resolve().then(function(){return t.props.matrixClient.exportRoomKeys()}).then(function(t){return c.encryptMegolmKeyFile((0,n.default)(t),e)}).then(function(e){var r=new Blob([e],{type:"text/plain;charset=us-ascii"});i.default.saveAs(r,"riot-keys.txt"),t.props.onFinished(!0)}).catch(function(e){if(console.error("Error exporting e2e keys:",e),!t._unmounted){var r=e.friendlyText||(0,l._t)("Unknown error");t.setState({errStr:r,phase:1})}}),this.setState({errStr:null,phase:2})},_onCancelClick:function(e){return e.preventDefault(),this.props.onFinished(!1),!1},render:function(){var e=f.default.getComponent("views.dialogs.BaseDialog"),t=2===this.state.phase;return o.default.createElement(e,{className:"mx_exportE2eKeysDialog",onFinished:this.props.onFinished,title:(0,l._t)("Export room keys")},o.default.createElement("form",{onSubmit:this._onPassphraseFormSubmit},o.default.createElement("div",{className:"mx_Dialog_content"},o.default.createElement("p",null,(0,l._t)("This process allows you to export the keys for messages you have received in encrypted rooms to a local file. You will then be able to import the file into another Matrix client in the future, so that client will also be able to decrypt these messages.")),o.default.createElement("p",null,(0,l._t)("The exported file will allow anyone who can read it to decrypt any encrypted messages that you can see, so you should be careful to keep it secure. To help with this, you should enter a passphrase below, which will be used to encrypt the exported data. It will only be possible to import the data by using the same passphrase.")),o.default.createElement("div",{className:"error"},this.state.errStr),o.default.createElement("div",{className:"mx_E2eKeysDialog_inputTable"},o.default.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},o.default.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},o.default.createElement("label",{htmlFor:"passphrase1"},(0,l._t)("Enter passphrase"))),o.default.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},o.default.createElement("input",{ref:"passphrase1",id:"passphrase1",autoFocus:!0,size:"64",type:"password",disabled:t}))),o.default.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},o.default.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},o.default.createElement("label",{htmlFor:"passphrase2"},(0,l._t)("Confirm passphrase"))),o.default.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},o.default.createElement("input",{ref:"passphrase2",id:"passphrase2",size:"64",type:"password",disabled:t}))))),o.default.createElement("div",{className:"mx_Dialog_buttons"},o.default.createElement("input",{className:"mx_Dialog_primary",type:"submit",value:(0,l._t)("Export"),disabled:t}),o.default.createElement("button",{onClick:this._onCancelClick,disabled:t},(0,l._t)("Cancel")))))}}),e.exports=t.default},485:function(e,t,r){"use strict";function n(e,t,r){return t<=e&&e<=r}function a(e){if(void 0===e)return{};if(e===Object(e))return e;throw TypeError("Could not convert argument to dictionary")}r.r(t),r.d(t,"TextEncoder",function(){return f}),r.d(t,"TextDecoder",function(){return c});var i=-1;function o(e){this.tokens=[].slice.call(e)}o.prototype={endOfStream:function(){return!this.tokens.length},read:function(){return this.tokens.length?this.tokens.shift():i},prepend:function(e){if(Array.isArray(e))for(var t=e;t.length;)this.tokens.unshift(t.pop());else this.tokens.unshift(e)},push:function(e){if(Array.isArray(e))for(var t=e;t.length;)this.tokens.push(t.shift());else this.tokens.push(e)}};var s=-1;function l(e,t){if(e)throw TypeError("Decoder error");return t||65533}var u="utf-8";function c(e,t){if(!(this instanceof c))return new c(e,t);if((e=void 0!==e?String(e).toLowerCase():u)!==u)throw new Error("Encoding not supported. Only utf-8 is supported");t=a(t),this._streaming=!1,this._BOMseen=!1,this._decoder=null,this._fatal=Boolean(t.fatal),this._ignoreBOM=Boolean(t.ignoreBOM),Object.defineProperty(this,"encoding",{value:"utf-8"}),Object.defineProperty(this,"fatal",{value:this._fatal}),Object.defineProperty(this,"ignoreBOM",{value:this._ignoreBOM})}function f(e,t){if(!(this instanceof f))return new f(e,t);if((e=void 0!==e?String(e).toLowerCase():u)!==u)throw new Error("Encoding not supported. Only utf-8 is supported");t=a(t),this._streaming=!1,this._encoder=null,this._options={fatal:Boolean(t.fatal)},Object.defineProperty(this,"encoding",{value:"utf-8"})}c.prototype={decode:function(e,t){var r;r="object"==typeof e&&e instanceof ArrayBuffer?new Uint8Array(e):"object"==typeof e&&"buffer"in e&&e.buffer instanceof ArrayBuffer?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(0),t=a(t),this._streaming||(this._decoder=new function(e){var t=e.fatal,r=0,a=0,o=0,u=128,c=191;this.handler=function(e,f){if(f===i&&0!==o)return o=0,l(t);if(f===i)return s;if(0===o){if(n(f,0,127))return f;if(n(f,194,223))o=1,r=f-192;else if(n(f,224,239))224===f&&(u=160),237===f&&(c=159),o=2,r=f-224;else{if(!n(f,240,244))return l(t);240===f&&(u=144),244===f&&(c=143),o=3,r=f-240}return r<<=6*o,null}if(!n(f,u,c))return r=o=a=0,u=128,c=191,e.prepend(f),l(t);if(u=128,c=191,r+=f-128<<6*(o-(a+=1)),a!==o)return null;var d=r;return r=o=a=0,d}}({fatal:this._fatal}),this._BOMseen=!1),this._streaming=Boolean(t.stream);for(var u,c=new o(r),f=[];!c.endOfStream()&&(u=this._decoder.handler(c,c.read()))!==s;)null!==u&&(Array.isArray(u)?f.push.apply(f,u):f.push(u));if(!this._streaming){do{if((u=this._decoder.handler(c,c.read()))===s)break;null!==u&&(Array.isArray(u)?f.push.apply(f,u):f.push(u))}while(!c.endOfStream());this._decoder=null}return f.length&&(-1===["utf-8"].indexOf(this.encoding)||this._ignoreBOM||this._BOMseen||(65279===f[0]?(this._BOMseen=!0,f.shift()):this._BOMseen=!0)),function(e){for(var t="",r=0;r<e.length;++r){var n=e[r];n<=65535?t+=String.fromCharCode(n):(n-=65536,t+=String.fromCharCode(55296+(n>>10),56320+(1023&n)))}return t}(f)}},f.prototype={encode:function(e,t){e=e?String(e):"",t=a(t),this._streaming||(this._encoder=new function(e){e.fatal;this.handler=function(e,t){if(t===i)return s;if(n(t,0,127))return t;var r,a;n(t,128,2047)?(r=1,a=192):n(t,2048,65535)?(r=2,a=224):n(t,65536,1114111)&&(r=3,a=240);for(var o=[(t>>6*r)+a];r>0;){var l=t>>6*(r-1);o.push(128|63&l),r-=1}return o}}(this._options)),this._streaming=Boolean(t.stream);for(var r,l=[],u=new o(function(e){for(var t=String(e),r=t.length,n=0,a=[];n<r;){var i=t.charCodeAt(n);if(i<55296||i>57343)a.push(i);else if(56320<=i&&i<=57343)a.push(65533);else if(55296<=i&&i<=56319)if(n===r-1)a.push(65533);else{var o=e.charCodeAt(n+1);if(56320<=o&&o<=57343){var s=1023&i,l=1023&o;a.push(65536+(s<<10)+l),n+=1}else a.push(65533)}n+=1}return a}(e));!u.endOfStream()&&(r=this._encoder.handler(u,u.read()))!==s;)Array.isArray(r)?l.push.apply(l,r):l.push(r);if(!this._streaming){for(;(r=this._encoder.handler(u,u.read()))!==s;)Array.isArray(r)?l.push.apply(l,r):l.push(r);this._encoder=null}return new Uint8Array(l)}}},486:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.encryptMegolmKeyFile=t.decryptMegolmKeyFile=void 0;var n=c(r(65)),a=c(r(19)),i=c(r(149)),o=r(9),s=(t.decryptMegolmKeyFile=function(){var e=(0,o.coroutine)(a.default.mark(function e(t,r){var n,l,c,f,y,v,_,b,g,E,x,S,C,k;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!((n=w(t)).length<1)){e.next=3;break}throw h("Invalid file: too short",(0,u._t)("Not a valid Riot keyfile"));case 3:if(1===n[0]){e.next=6;break}throw h("Unsupported version",(0,u._t)("Not a valid Riot keyfile"));case 6:if(!((l=n.length-69)<0)){e.next=9;break}throw h("Invalid file: too short",(0,u._t)("Not a valid Riot keyfile"));case 9:return c=n.subarray(1,17),f=n.subarray(17,33),y=n[33]<<24|n[34]<<16|n[35]<<8|n[36],v=n.subarray(37,37+l),_=n.subarray(-32),e.next=16,(0,o.resolve)(s(c,y,r));case 16:return b=e.sent,g=(0,i.default)(b,2),E=g[0],x=g[1],S=n.subarray(0,-32),C=void 0,e.prev=22,e.next=25,(0,o.resolve)(p.verify({name:"HMAC"},x,_,S));case 25:C=e.sent,e.next=31;break;case 28:throw e.prev=28,e.t0=e.catch(22),h("subtleCrypto.verify failed: "+e.t0,m());case 31:if(C){e.next=33;break}throw h("hmac mismatch",(0,u._t)("Authentication check failed: incorrect password?"));case 33:return k=void 0,e.prev=34,e.next=37,(0,o.resolve)(p.decrypt({name:"AES-CTR",counter:f,length:64},E,v));case 37:k=e.sent,e.next=43;break;case 40:throw e.prev=40,e.t1=e.catch(34),h("subtleCrypto.decrypt failed: "+e.t1,m());case 43:return e.abrupt("return",(new d).decode(new Uint8Array(k)));case 44:case"end":return e.stop()}},e,this,[[22,28],[34,40]])}));return function(t,r){return e.apply(this,arguments)}}(),t.encryptMegolmKeyFile=function(){var e=(0,o.coroutine)(a.default.mark(function e(t,r,n){var l,u,c,d,y,v,w,b,g,E,x,S,C,k,O,A;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return l=(n=n||{}).kdf_rounds||5e5,u=new Uint8Array(16),window.crypto.getRandomValues(u),c=new Uint8Array(16),window.crypto.getRandomValues(c),c[9]&=127,e.next=9,(0,o.resolve)(s(u,l,r));case 9:return d=e.sent,y=(0,i.default)(d,2),v=y[0],w=y[1],b=(new f).encode(t),g=void 0,e.prev=15,e.next=18,(0,o.resolve)(p.encrypt({name:"AES-CTR",counter:c,length:64},v,b));case 18:g=e.sent,e.next=24;break;case 21:throw e.prev=21,e.t0=e.catch(15),h("subtleCrypto.encrypt failed: "+e.t0,m());case 24:return E=new Uint8Array(g),x=1+u.length+c.length+4+E.length+32,S=new Uint8Array(x),C=0,S[C++]=1,S.set(u,C),C+=u.length,S.set(c,C),C+=c.length,S[C++]=l>>24,S[C++]=l>>16&255,S[C++]=l>>8&255,S[C++]=255&l,S.set(E,C),C+=E.length,k=S.subarray(0,C),O=void 0,e.prev=41,e.next=44,(0,o.resolve)(p.sign({name:"HMAC"},w,k));case 44:O=e.sent,e.next=50;break;case 47:throw e.prev=47,e.t1=e.catch(41),h("subtleCrypto.sign failed: "+e.t1,m());case 50:return A=new Uint8Array(O),S.set(A,C),e.abrupt("return",_(S));case 53:case"end":return e.stop()}},e,this,[[15,21],[41,47]])}));return function(t,r,n){return e.apply(this,arguments)}}(),function(){var e=(0,o.coroutine)(a.default.mark(function e(t,r,i){var s,l,u,c,d,y,v,w;return a.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=new Date,l=void 0,e.prev=2,e.next=5,(0,o.resolve)(p.importKey("raw",(new f).encode(i),{name:"PBKDF2"},!1,["deriveBits"]));case 5:l=e.sent,e.next=11;break;case 8:throw e.prev=8,e.t0=e.catch(2),h("subtleCrypto.importKey failed: "+e.t0,m());case 11:return u=void 0,e.prev=12,e.next=15,(0,o.resolve)(p.deriveBits({name:"PBKDF2",salt:t,iterations:r,hash:"SHA-512"},l,512));case 15:u=e.sent,e.next=21;break;case 18:throw e.prev=18,e.t1=e.catch(12),h("subtleCrypto.deriveBits failed: "+e.t1,m());case 21:return c=new Date,console.log("E2e import/export: deriveKeys took "+(c-s)+"ms"),d=u.slice(0,32),y=u.slice(32),v=p.importKey("raw",d,{name:"AES-CTR"},!1,["encrypt","decrypt"]).catch(function(e){throw h("subtleCrypto.importKey failed for AES key: "+e,m())}),w=p.importKey("raw",y,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign","verify"]).catch(function(e){throw h("subtleCrypto.importKey failed for HMAC key: "+e,m())}),e.next=29,(0,o.resolve)(n.default.all([v,w]));case 29:return e.abrupt("return",e.sent);case 30:case"end":return e.stop()}},e,this,[[2,8],[12,18]])}));return function(t,r,n){return e.apply(this,arguments)}}()),l=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(r(485)),u=r(2);function c(e){return e&&e.__esModule?e:{default:e}}var f=window.TextEncoder;f||(f=l.TextEncoder);var d=window.TextDecoder;d||(d=l.TextDecoder);var p=window.crypto.subtle||window.crypto.webkitSubtle;function h(e,t){var r=new Error(e);return r.friendlyText=t,r}function m(){return(0,u._t)("Your browser does not support the required cryptography extensions")}var y="-----BEGIN MEGOLM SESSION DATA-----",v="-----END MEGOLM SESSION DATA-----";function w(e){for(var t=(new d).decode(new Uint8Array(e)),r=0;;){var n=t.indexOf("\n",r);if(n<0)throw new Error("Header line not found");var a=t.slice(r,n).trim();if(r=n+1,a===y)break}for(var i=r;;){var o=t.indexOf("\n",r);if(t.slice(r,o<0?void 0:o).trim()===v)break;if(o<0)throw new Error("Trailer line not found");r=o+1}var s=r;return function(e){for(var t=window.atob(e),r=new Uint8Array(t.length),n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}(t.slice(i,s))}function _(e){var t=Math.ceil(e.length/96),r=new Array(t+3);r[0]=y;var n=0,a=void 0;for(a=1;a<=t;a++)r[a]=b(e.subarray(n,n+96)),n+=96;return r[a++]=v,r[a]="",(new f).encode(r.join("\n")).buffer}function b(e){var t=String.fromCharCode.apply(null,e);return window.btoa(t)}},493:function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=f(r(65)),a=f(r(0)),i=f(r(1)),o=c(r(17)),s=c(r(486)),l=f(r(3)),u=r(2);function c(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function f(e){return e&&e.__esModule?e:{default:e}}t.default=a.default.createClass({displayName:"ImportE2eKeysDialog",propTypes:{matrixClient:i.default.instanceOf(o.MatrixClient).isRequired,onFinished:i.default.func.isRequired},getInitialState:function(){return{enableSubmit:!1,phase:1,errStr:null}},componentWillMount:function(){this._unmounted=!1},componentWillUnmount:function(){this._unmounted=!0},_onFormChange:function(e){var t=this.refs.file.files||[];this.setState({enableSubmit:""!==this.refs.passphrase.value&&t.length>0})},_onFormSubmit:function(e){return e.preventDefault(),this._startImport(this.refs.file.files[0],this.refs.passphrase.value),!1},_startImport:function(e,t){var r=this;return this.setState({errStr:null,phase:2}),function(e){return new n.default(function(t,r){var n=new FileReader;n.onload=function(e){t(e.target.result)},n.onerror=r,n.readAsArrayBuffer(e)})}(e).then(function(e){return s.decryptMegolmKeyFile(e,t)}).then(function(e){return r.props.matrixClient.importRoomKeys(JSON.parse(e))}).then(function(){r.props.onFinished(!0)}).catch(function(e){if(console.error("Error importing e2e keys:",e),!r._unmounted){var t=e.friendlyText||(0,u._t)("Unknown error");r.setState({errStr:t,phase:1})}})},_onCancelClick:function(e){return e.preventDefault(),this.props.onFinished(!1),!1},render:function(){var e=l.default.getComponent("views.dialogs.BaseDialog"),t=1!==this.state.phase;return a.default.createElement(e,{className:"mx_importE2eKeysDialog",onFinished:this.props.onFinished,title:(0,u._t)("Import room keys")},a.default.createElement("form",{onSubmit:this._onFormSubmit},a.default.createElement("div",{className:"mx_Dialog_content"},a.default.createElement("p",null,(0,u._t)("This process allows you to import encryption keys that you had previously exported from another Matrix client. You will then be able to decrypt any messages that the other client could decrypt.")),a.default.createElement("p",null,(0,u._t)("The export file will be protected with a passphrase. You should enter the passphrase here, to decrypt the file.")),a.default.createElement("div",{className:"error"},this.state.errStr),a.default.createElement("div",{className:"mx_E2eKeysDialog_inputTable"},a.default.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},a.default.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},a.default.createElement("label",{htmlFor:"importFile"},(0,u._t)("File to import"))),a.default.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},a.default.createElement("input",{ref:"file",id:"importFile",type:"file",autoFocus:!0,onChange:this._onFormChange,disabled:t}))),a.default.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},a.default.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},a.default.createElement("label",{htmlFor:"passphrase"},(0,u._t)("Enter passphrase"))),a.default.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},a.default.createElement("input",{ref:"passphrase",id:"passphrase",size:"64",type:"password",onChange:this._onFormChange,disabled:t}))))),a.default.createElement("div",{className:"mx_Dialog_buttons"},a.default.createElement("input",{className:"mx_Dialog_primary",type:"submit",value:(0,u._t)("Import"),disabled:!this.state.enableSubmit||t}),a.default.createElement("button",{onClick:this._onCancelClick,disabled:t},(0,u._t)("Cancel")))))}}),e.exports=t.default},729:function(e,t,r){var n,a=a||function(e){"use strict";if(!(void 0===e||"undefined"!=typeof navigator&&/MSIE [1-9]\./.test(navigator.userAgent))){var t=function(){return e.URL||e.webkitURL||e},r=e.document.createElementNS("http://www.w3.org/1999/xhtml","a"),n="download"in r,a=/constructor/i.test(e.HTMLElement)||e.safari,i=/CriOS\/[\d]+/.test(navigator.userAgent),o=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},s=function(e){setTimeout(function(){"string"==typeof e?t().revokeObjectURL(e):e.remove()},4e4)},l=function(e){return/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob([String.fromCharCode(65279),e],{type:e.type}):e},u=function(u,c,f){f||(u=l(u));var d,p=this,h="application/octet-stream"===u.type,m=function(){!function(e,t,r){for(var n=(t=[].concat(t)).length;n--;){var a=e["on"+t[n]];if("function"==typeof a)try{a.call(e,r||e)}catch(e){o(e)}}}(p,"writestart progress write writeend".split(" "))};if(p.readyState=p.INIT,n)return d=t().createObjectURL(u),void setTimeout(function(){r.href=d,r.download=c,function(e){var t=new MouseEvent("click");e.dispatchEvent(t)}(r),m(),s(d),p.readyState=p.DONE});!function(){if((i||h&&a)&&e.FileReader){var r=new FileReader;return r.onloadend=function(){var t=i?r.result:r.result.replace(/^data:[^;]*;/,"data:attachment/file;");e.open(t,"_blank")||(e.location.href=t),t=void 0,p.readyState=p.DONE,m()},r.readAsDataURL(u),void(p.readyState=p.INIT)}d||(d=t().createObjectURL(u)),h?e.location.href=d:e.open(d,"_blank")||(e.location.href=d);p.readyState=p.DONE,m(),s(d)}()},c=u.prototype;return"undefined"!=typeof navigator&&navigator.msSaveOrOpenBlob?function(e,t,r){return t=t||e.name||"download",r||(e=l(e)),navigator.msSaveOrOpenBlob(e,t)}:(c.abort=function(){},c.readyState=c.INIT=0,c.WRITING=1,c.DONE=2,c.error=c.onwritestart=c.onprogress=c.onwrite=c.onabort=c.onerror=c.onwriteend=null,function(e,t,r){return new u(e,t||e.name||"download",r)})}}("undefined"!=typeof self&&self||"undefined"!=typeof window&&window||this.content);
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */void 0!==e&&e.exports?e.exports.saveAs=a:null!==r(730)&&null!==r(492)&&(void 0===(n=function(){return a}.call(t,r,t,e))||(e.exports=n))},730:function(e,t){e.exports=function(){throw new Error("define cannot be used indirect")}}}]);
//# sourceMappingURL=vendors~e2e-export.js.map