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.
1 line
8.4 KiB
1 line
8.4 KiB
(window.webpackJsonp=window.webpackJsonp||[]).push([[11],{1518:function(e,t,r){"use strict";r.d(t,"a",(function(){return y})),r.d(t,"b",(function(){return w}));var n=r(6),a=r.n(n),i=r(27),o=r.n(i),s=r(16),c=r.n(s),l=r(383),u=r(1),p=window.TextEncoder;p||(p=l.TextEncoder);var h=window.TextDecoder;h||(h=l.TextDecoder);var m=window.crypto.subtle||window.crypto.webkitSubtle;function d(e,t){var r=new Error(e);return r.friendlyText=t,r}function f(){return Object(u.a)("Your browser does not support the required cryptography extensions")}function y(e,t){return b.apply(this,arguments)}function b(){return(b=c()(a.a.mark((function e(t,r){var n,i,s,c,l,p,y,b,w,v,x,g,k,C;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!((n=_(t)).length<1)){e.next=3;break}throw d("Invalid file: too short",Object(u.a)("Not a valid Riot keyfile"));case 3:if(1===n[0]){e.next=6;break}throw d("Unsupported version",Object(u.a)("Not a valid Riot keyfile"));case 6:if(!((i=n.length-69)<0)){e.next=9;break}throw d("Invalid file: too short",Object(u.a)("Not a valid Riot keyfile"));case 9:return s=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+i),y=n.subarray(-32),e.next=16,E(s,l,r);case 16:return b=e.sent,w=o()(b,2),v=w[0],x=w[1],g=n.subarray(0,-32),e.prev=21,e.next=24,m.verify({name:"HMAC"},x,y,g);case 24:k=e.sent,e.next=30;break;case 27:throw e.prev=27,e.t0=e.catch(21),d("subtleCrypto.verify failed: "+e.t0,f());case 30:if(k){e.next=32;break}throw d("hmac mismatch",Object(u.a)("Authentication check failed: incorrect password?"));case 32:return e.prev=32,e.next=35,m.decrypt({name:"AES-CTR",counter:c,length:64},v,p);case 35:C=e.sent,e.next=41;break;case 38:throw e.prev=38,e.t1=e.catch(32),d("subtleCrypto.decrypt failed: "+e.t1,f());case 41:return e.abrupt("return",(new h).decode(new Uint8Array(C)));case 42:case"end":return e.stop()}}),e,null,[[21,27],[32,38]])})))).apply(this,arguments)}function w(e,t,r){return v.apply(this,arguments)}function v(){return(v=c()(a.a.mark((function e(t,r,n){var i,s,c,l,u,h,y,b,w,v,x,g,_,C,S,A;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=(n=n||{}).kdf_rounds||5e5,s=new Uint8Array(16),window.crypto.getRandomValues(s),c=new Uint8Array(16),window.crypto.getRandomValues(c),c[8]&=127,e.next=9,E(s,i,r);case 9:return l=e.sent,u=o()(l,2),h=u[0],y=u[1],b=(new p).encode(t),e.prev=14,e.next=17,m.encrypt({name:"AES-CTR",counter:c,length:64},h,b);case 17:w=e.sent,e.next=23;break;case 20:throw e.prev=20,e.t0=e.catch(14),d("subtleCrypto.encrypt failed: "+e.t0,f());case 23:return v=new Uint8Array(w),x=1+s.length+c.length+4+v.length+32,g=new Uint8Array(x),_=0,g[_++]=1,g.set(s,_),_+=s.length,g.set(c,_),_+=c.length,g[_++]=i>>24,g[_++]=i>>16&255,g[_++]=i>>8&255,g[_++]=255&i,g.set(v,_),_+=v.length,C=g.subarray(0,_),e.prev=39,e.next=42,m.sign({name:"HMAC"},y,C);case 42:S=e.sent,e.next=48;break;case 45:throw e.prev=45,e.t1=e.catch(39),d("subtleCrypto.sign failed: "+e.t1,f());case 48:return A=new Uint8Array(S),g.set(A,_),e.abrupt("return",k(g));case 51:case"end":return e.stop()}}),e,null,[[14,20],[39,45]])})))).apply(this,arguments)}function E(e,t,r){return x.apply(this,arguments)}function x(){return(x=c()(a.a.mark((function e(t,r,n){var i,o,s,c,l,u,h,y;return a.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=new Date,e.prev=1,e.next=4,m.importKey("raw",(new p).encode(n),{name:"PBKDF2"},!1,["deriveBits"]);case 4:o=e.sent,e.next=10;break;case 7:throw e.prev=7,e.t0=e.catch(1),d("subtleCrypto.importKey failed: "+e.t0,f());case 10:return e.prev=10,e.next=13,m.deriveBits({name:"PBKDF2",salt:t,iterations:r,hash:"SHA-512"},o,512);case 13:s=e.sent,e.next=19;break;case 16:throw e.prev=16,e.t1=e.catch(10),d("subtleCrypto.deriveBits failed: "+e.t1,f());case 19:return c=new Date,console.log("E2e import/export: deriveKeys took "+(c-i)+"ms"),l=s.slice(0,32),u=s.slice(32),h=m.importKey("raw",l,{name:"AES-CTR"},!1,["encrypt","decrypt"]).catch((function(e){throw d("subtleCrypto.importKey failed for AES key: "+e,f())})),y=m.importKey("raw",u,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign","verify"]).catch((function(e){throw d("subtleCrypto.importKey failed for HMAC key: "+e,f())})),e.next=27,Promise.all([h,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 _(e){for(var t=(new h).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 i=r;;){var o=t.indexOf("\n",r);if("-----END MEGOLM SESSION DATA-----"===t.slice(r,o<0?void 0:o).trim())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 k(e){var t=Math.ceil(e.length/96),r=new Array(t+3);r[0]=g;var n,a,i,o=0;for(n=1;n<=t;n++)r[n]=(a=e.subarray(o,o+96),i=void 0,i=String.fromCharCode.apply(null,a),window.btoa(i)),o+=96;return r[n++]="-----END MEGOLM SESSION DATA-----",r[n]="",(new p).encode(r.join("\n")).buffer}},1531:function(e,t,r){"use strict";r.r(t);var n=r(0),a=r.n(n),i=r(2),o=r.n(i),s=r(19),c=r.n(s),l=r(23),u=r(1518),p=r(3),h=r(1);t.default=c()({displayName:"ImportE2eKeysDialog",propTypes:{matrixClient:o.a.instanceOf(l.i).isRequired,onFinished:o.a.func.isRequired},getInitialState:function(){return{enableSubmit:!1,phase:1,errStr:null}},componentWillMount:function(){this._unmounted=!1,this._file=Object(n.createRef)(),this._passphrase=Object(n.createRef)()},componentWillUnmount:function(){this._unmounted=!0},_onFormChange:function(e){var t=this._file.current.files||[];this.setState({enableSubmit:""!==this._passphrase.current.value&&t.length>0})},_onFormSubmit:function(e){return e.preventDefault(),this._startImport(this._file.current.files[0],this._passphrase.current.value),!1},_startImport:function(e,t){var r=this;return this.setState({errStr:null,phase:2}),function(e){return new Promise((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 u.a(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||Object(h.a)("Unknown error");r.setState({errStr:t,phase:1})}}))},_onCancelClick:function(e){return e.preventDefault(),this.props.onFinished(!1),!1},render:function(){var e=p.a("views.dialogs.BaseDialog"),t=1!==this.state.phase;return a.a.createElement(e,{className:"mx_importE2eKeysDialog",onFinished:this.props.onFinished,title:Object(h.a)("Import room keys")},a.a.createElement("form",{onSubmit:this._onFormSubmit},a.a.createElement("div",{className:"mx_Dialog_content"},a.a.createElement("p",null,Object(h.a)("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.a.createElement("p",null,Object(h.a)("The export file will be protected with a passphrase. You should enter the passphrase here, to decrypt the file.")),a.a.createElement("div",{className:"error"},this.state.errStr),a.a.createElement("div",{className:"mx_E2eKeysDialog_inputTable"},a.a.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},a.a.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},a.a.createElement("label",{htmlFor:"importFile"},Object(h.a)("File to import"))),a.a.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},a.a.createElement("input",{ref:this._file,id:"importFile",type:"file",autoFocus:!0,onChange:this._onFormChange,disabled:t}))),a.a.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},a.a.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},a.a.createElement("label",{htmlFor:"passphrase"},Object(h.a)("Enter passphrase"))),a.a.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},a.a.createElement("input",{ref:this._passphrase,id:"passphrase",size:"64",type:"password",onChange:this._onFormChange,disabled:t}))))),a.a.createElement("div",{className:"mx_Dialog_buttons"},a.a.createElement("input",{className:"mx_Dialog_primary",type:"submit",value:Object(h.a)("Import"),disabled:!this.state.enableSubmit||t}),a.a.createElement("button",{onClick:this._onCancelClick,disabled:t},Object(h.a)("Cancel")))))}})}}]); |