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.

2 lines
11 KiB

/*! For license information please see 2.js.LICENSE */
(window.webpackJsonp=window.webpackJsonp||[]).push([[2],{1515: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=e.document,r=function(){return e.URL||e.webkitURL||e},n=t.createElementNS("http://www.w3.org/1999/xhtml","a"),a="download"in n,o=/constructor/i.test(e.HTMLElement)||e.safari,s=/CriOS\/[\d]+/.test(navigator.userAgent),i=function(t){(e.setImmediate||e.setTimeout)((function(){throw t}),0)},c=function(e){setTimeout((function(){"string"==typeof e?r().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(t,u,p){p||(t=l(t));var d,h=this,f="application/octet-stream"===t.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){i(e)}}}(h,"writestart progress write writeend".split(" "))};if(h.readyState=h.INIT,a)return d=r().createObjectURL(t),void setTimeout((function(){var e,t;n.href=d,n.download=u,e=n,t=new MouseEvent("click"),e.dispatchEvent(t),m(),c(d),h.readyState=h.DONE}));!function(){if((s||f&&o)&&e.FileReader){var n=new FileReader;return n.onloadend=function(){var t=s?n.result:n.result.replace(/^data:[^;]*;/,"data:attachment/file;");e.open(t,"_blank")||(e.location.href=t),t=void 0,h.readyState=h.DONE,m()},n.readAsDataURL(t),void(h.readyState=h.INIT)}(d||(d=r().createObjectURL(t)),f)?e.location.href=d:e.open(d,"_blank")||(e.location.href=d);h.readyState=h.DONE,m(),c(d)}()},p=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)}:(p.abort=function(){},p.readyState=p.INIT=0,p.WRITING=1,p.DONE=2,p.error=p.onwritestart=p.onprogress=p.onwrite=p.onabort=p.onerror=p.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);e.exports?e.exports.saveAs=a:null!==r(1516)&&null!==r(1517)&&(void 0===(n=function(){return a}.call(t,r,t,e))||(e.exports=n))},1516:function(e,t){e.exports=function(){throw new Error("define cannot be used indirect")}},1517:function(e,t){(function(t){e.exports=t}).call(this,{})},1518:function(e,t,r){"use strict";r.d(t,"a",(function(){return y})),r.d(t,"b",(function(){return v}));var n=r(6),a=r.n(n),o=r(27),s=r.n(o),i=r(16),c=r.n(i),l=r(383),u=r(1),p=window.TextEncoder;p||(p=l.TextEncoder);var d=window.TextDecoder;d||(d=l.TextDecoder);var h=window.crypto.subtle||window.crypto.webkitSubtle;function f(e,t){var r=new Error(e);return r.friendlyText=t,r}function m(){return Object(u.a)("Your browser does not support the required cryptography extensions")}function y(e,t){return w.apply(this,arguments)}function w(){return(w=c()(a.a.mark((function e(t,r){var n,o,i,c,l,p,y,w,v,b,E,g,k,O;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!((n=S(t)).length<1)){e.next=3;break}throw f("Invalid file: too short",Object(u.a)("Not a valid Riot keyfile"));case 3:if(1===n[0]){e.next=6;break}throw f("Unsupported version",Object(u.a)("Not a valid Riot keyfile"));case 6:if(!((o=n.length-69)<0)){e.next=9;break}throw f("Invalid file: too short",Object(u.a)("Not a valid Riot keyfile"));case 9:return i=n.subarray(1,17),c=n.subarray(17,33),l=n[33]<<24|n[34]<<16|n[35]<<8|n[36],p=n.subarray(37,37+o),y=n.subarray(-32),e.next=16,x(i,l,r);case 16:return w=e.sent,v=s()(w,2),b=v[0],E=v[1],g=n.subarray(0,-32),e.prev=21,e.next=24,h.verify({name:"HMAC"},E,y,g);case 24:k=e.sent,e.next=30;break;case 27:throw e.prev=27,e.t0=e.catch(21),f("subtleCrypto.verify failed: "+e.t0,m());case 30:if(k){e.next=32;break}throw f("hmac mismatch",Object(u.a)("Authentication check failed: incorrect password?"));case 32:return e.prev=32,e.next=35,h.decrypt({name:"AES-CTR",counter:c,length:64},b,p);case 35:O=e.sent,e.next=41;break;case 38:throw e.prev=38,e.t1=e.catch(32),f("subtleCrypto.decrypt failed: "+e.t1,m());case 41:return e.abrupt("return",(new d).decode(new Uint8Array(O)));case 42:case"end":return e.stop()}}),e,null,[[21,27],[32,38]])})))).apply(this,arguments)}function v(e,t,r){return b.apply(this,arguments)}function b(){return(b=c()(a.a.mark((function e(t,r,n){var o,i,c,l,u,d,y,w,v,b,E,g,S,O,_,A;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=(n=n||{}).kdf_rounds||5e5,i=new Uint8Array(16),window.crypto.getRandomValues(i),c=new Uint8Array(16),window.crypto.getRandomValues(c),c[8]&=127,e.next=9,x(i,o,r);case 9:return l=e.sent,u=s()(l,2),d=u[0],y=u[1],w=(new p).encode(t),e.prev=14,e.next=17,h.encrypt({name:"AES-CTR",counter:c,length:64},d,w);case 17:v=e.sent,e.next=23;break;case 20:throw e.prev=20,e.t0=e.catch(14),f("subtleCrypto.encrypt failed: "+e.t0,m());case 23:return b=new Uint8Array(v),E=1+i.length+c.length+4+b.length+32,g=new Uint8Array(E),S=0,g[S++]=1,g.set(i,S),S+=i.length,g.set(c,S),S+=c.length,g[S++]=o>>24,g[S++]=o>>16&255,g[S++]=o>>8&255,g[S++]=255&o,g.set(b,S),S+=b.length,O=g.subarray(0,S),e.prev=39,e.next=42,h.sign({name:"HMAC"},y,O);case 42:_=e.sent,e.next=48;break;case 45:throw e.prev=45,e.t1=e.catch(39),f("subtleCrypto.sign failed: "+e.t1,m());case 48:return A=new Uint8Array(_),g.set(A,S),e.abrupt("return",k(g));case 51:case"end":return e.stop()}}),e,null,[[14,20],[39,45]])})))).apply(this,arguments)}function x(e,t,r){return E.apply(this,arguments)}function E(){return(E=c()(a.a.mark((function e(t,r,n){var o,s,i,c,l,u,d,y;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=new Date,e.prev=1,e.next=4,h.importKey("raw",(new p).encode(n),{name:"PBKDF2"},!1,["deriveBits"]);case 4:s=e.sent,e.next=10;break;case 7:throw e.prev=7,e.t0=e.catch(1),f("subtleCrypto.importKey failed: "+e.t0,m());case 10:return e.prev=10,e.next=13,h.deriveBits({name:"PBKDF2",salt:t,iterations:r,hash:"SHA-512"},s,512);case 13:i=e.sent,e.next=19;break;case 16:throw e.prev=16,e.t1=e.catch(10),f("subtleCrypto.deriveBits failed: "+e.t1,m());case 19:return c=new Date,console.log("E2e import/export: deriveKeys took "+(c-o)+"ms"),l=i.slice(0,32),u=i.slice(32),d=h.importKey("raw",l,{name:"AES-CTR"},!1,["encrypt","decrypt"]).catch((function(e){throw f("subtleCrypto.importKey failed for AES key: "+e,m())})),y=h.importKey("raw",u,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign","verify"]).catch((function(e){throw f("subtleCrypto.importKey failed for HMAC key: "+e,m())})),e.next=27,Promise.all([d,y]);case 27:return e.abrupt("return",e.sent);case 28:case"end":return e.stop()}}),e,null,[[1,7],[10,16]])})))).apply(this,arguments)}var g="-----BEGIN MEGOLM SESSION DATA-----";function S(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===g)break}for(var o=r;;){var s=t.indexOf("\n",r);if("-----END MEGOLM SESSION DATA-----"===t.slice(r,s<0?void 0:s).trim())break;if(s<0)throw new Error("Trailer line not found");r=s+1}var i=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(o,i))}function k(e){var t=Math.ceil(e.length/96),r=new Array(t+3);r[0]=g;var n,a,o,s=0;for(n=1;n<=t;n++)r[n]=(a=e.subarray(s,s+96),o=void 0,o=String.fromCharCode.apply(null,a),window.btoa(o)),s+=96;return r[n++]="-----END MEGOLM SESSION DATA-----",r[n]="",(new p).encode(r.join("\n")).buffer}},1530:function(e,t,r){"use strict";r.r(t);var n=r(1515),a=r.n(n),o=r(0),s=r.n(o),i=r(2),c=r.n(i),l=r(19),u=r.n(l),p=r(1),d=r(23),h=r(1518),f=r(3);t.default=u()({displayName:"ExportE2eKeysDialog",propTypes:{matrixClient:c.a.instanceOf(d.i).isRequired,onFinished:c.a.func.isRequired},getInitialState:function(){return{phase:1,errStr:null}},componentWillMount:function(){this._unmounted=!1,this._passphrase1=Object(o.createRef)(),this._passphrase2=Object(o.createRef)()},componentWillUnmount:function(){this._unmounted=!0},_onPassphraseFormSubmit:function(e){e.preventDefault();var t=this._passphrase1.current.value;return t!==this._passphrase2.current.value?(this.setState({errStr:Object(p.a)("Passphrases must match")}),!1):t?(this._startExport(t),!1):(this.setState({errStr:Object(p.a)("Passphrase must not be empty")}),!1)},_startExport:function(e){var t=this;Promise.resolve().then((function(){return t.props.matrixClient.exportRoomKeys()})).then((function(t){return h.b(JSON.stringify(t),e)})).then((function(e){var r=new Blob([e],{type:"text/plain;charset=us-ascii"});a.a.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||Object(p.a)("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.a("views.dialogs.BaseDialog"),t=2===this.state.phase;return s.a.createElement(e,{className:"mx_exportE2eKeysDialog",onFinished:this.props.onFinished,title:Object(p.a)("Export room keys")},s.a.createElement("form",{onSubmit:this._onPassphraseFormSubmit},s.a.createElement("div",{className:"mx_Dialog_content"},s.a.createElement("p",null,Object(p.a)("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.")),s.a.createElement("p",null,Object(p.a)("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.")),s.a.createElement("div",{className:"error"},this.state.errStr),s.a.createElement("div",{className:"mx_E2eKeysDialog_inputTable"},s.a.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},s.a.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},s.a.createElement("label",{htmlFor:"passphrase1"},Object(p.a)("Enter passphrase"))),s.a.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},s.a.createElement("input",{ref:this._passphrase1,id:"passphrase1",autoFocus:!0,size:"64",type:"password",disabled:t}))),s.a.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},s.a.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},s.a.createElement("label",{htmlFor:"passphrase2"},Object(p.a)("Confirm passphrase"))),s.a.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},s.a.createElement("input",{ref:this._passphrase2,id:"passphrase2",size:"64",type:"password",disabled:t}))))),s.a.createElement("div",{className:"mx_Dialog_buttons"},s.a.createElement("input",{className:"mx_Dialog_primary",type:"submit",value:Object(p.a)("Export"),disabled:t}),s.a.createElement("button",{onClick:this._onCancelClick,disabled:t},Object(p.a)("Cancel")))))}})}}]);