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
6.9 KiB
1 line
6.9 KiB
(window.webpackJsonp=window.webpackJsonp||[]).push([[12],{1502:function(e,t,n){"use strict";n.d(t,"a",(function(){return u})),n.d(t,"b",(function(){return h}));var r=n(352),a=n(1);let o=window.TextEncoder;o||(o=r.TextEncoder);let i=window.TextDecoder;i||(i=r.TextDecoder);const s=window.crypto.subtle||window.crypto.webkitSubtle;function l(e,t){const n=new Error(e);return n.friendlyText=t,n}function c(){return Object(a.a)("Your browser does not support the required cryptography extensions")}async function u(e,t){const n=function(e){const t=(new i).decode(new Uint8Array(e));let n=0;for(;;){const e=t.indexOf("\n",n);if(e<0)throw new Error("Header line not found");const r=t.slice(n,e).trim();if(n=e+1,r===m)break}const r=n;for(;;){const e=t.indexOf("\n",n);if("-----END MEGOLM SESSION DATA-----"===t.slice(n,e<0?void 0:e).trim())break;if(e<0)throw new Error("Trailer line not found");n=e+1}const a=n;return function(e){const t=window.atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}(t.slice(r,a))}(e);if(n.length<1)throw l("Invalid file: too short",Object(a.a)("Not a valid Riot keyfile"));if(1!==n[0])throw l("Unsupported version",Object(a.a)("Not a valid Riot keyfile"));const r=n.length-69;if(r<0)throw l("Invalid file: too short",Object(a.a)("Not a valid Riot keyfile"));const o=n.subarray(1,17),u=n.subarray(17,33),h=n[33]<<24|n[34]<<16|n[35]<<8|n[36],d=n.subarray(37,37+r),y=n.subarray(-32),[f,w]=await p(o,h,t),b=n.subarray(0,-32);let E,g;try{E=await s.verify({name:"HMAC"},w,y,b)}catch(e){throw l("subtleCrypto.verify failed: "+e,c())}if(!E)throw l("hmac mismatch",Object(a.a)("Authentication check failed: incorrect password?"));try{g=await s.decrypt({name:"AES-CTR",counter:u,length:64},f,d)}catch(e){throw l("subtleCrypto.decrypt failed: "+e,c())}return(new i).decode(new Uint8Array(g))}async function h(e,t,n){const r=(n=n||{}).kdf_rounds||5e5,a=new Uint8Array(16);window.crypto.getRandomValues(a);const i=new Uint8Array(16);window.crypto.getRandomValues(i),i[8]&=127;const[u,h]=await p(a,r,t),y=(new o).encode(e);let f;try{f=await s.encrypt({name:"AES-CTR",counter:i,length:64},u,y)}catch(e){throw l("subtleCrypto.encrypt failed: "+e,c())}const w=new Uint8Array(f),b=1+a.length+i.length+4+w.length+32,E=new Uint8Array(b);let g=0;E[g++]=1,E.set(a,g),g+=a.length,E.set(i,g),g+=i.length,E[g++]=r>>24,E[g++]=r>>16&255,E[g++]=r>>8&255,E[g++]=255&r,E.set(w,g),g+=w.length;const _=E.subarray(0,g);let v;try{v=await s.sign({name:"HMAC"},h,_)}catch(e){throw l("subtleCrypto.sign failed: "+e,c())}const C=new Uint8Array(v);return E.set(C,g),function(e){const t=Math.ceil(e.length/96),n=new Array(t+3);n[0]=m;let r,a=0;for(r=1;r<=t;r++)n[r]=d(e.subarray(a,a+96)),a+=96;return n[r++]="-----END MEGOLM SESSION DATA-----",n[r]="",(new o).encode(n.join("\n")).buffer}(E)}async function p(e,t,n){const r=new Date;let a,i;try{a=await s.importKey("raw",(new o).encode(n),{name:"PBKDF2"},!1,["deriveBits"])}catch(e){throw l("subtleCrypto.importKey failed: "+e,c())}try{i=await s.deriveBits({name:"PBKDF2",salt:e,iterations:t,hash:"SHA-512"},a,512)}catch(e){throw l("subtleCrypto.deriveBits failed: "+e,c())}const u=new Date;console.log("E2e import/export: deriveKeys took "+(u-r)+"ms");const h=i.slice(0,32),p=i.slice(32),m=s.importKey("raw",h,{name:"AES-CTR"},!1,["encrypt","decrypt"]).catch(e=>{throw l("subtleCrypto.importKey failed for AES key: "+e,c())}),d=s.importKey("raw",p,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign","verify"]).catch(e=>{throw l("subtleCrypto.importKey failed for HMAC key: "+e,c())});return await Promise.all([m,d])}const m="-----BEGIN MEGOLM SESSION DATA-----";function d(e){const t=String.fromCharCode.apply(null,e);return window.btoa(t)}},1517:function(e,t,n){"use strict";n.r(t);var r=n(0),a=n.n(r),o=n(2),i=n.n(o),s=n(11),l=n.n(s),c=n(13),u=n(1502),h=n(3),p=n(1);t.default=l()({displayName:"ImportE2eKeysDialog",propTypes:{matrixClient:i.a.instanceOf(c.j).isRequired,onFinished:i.a.func.isRequired},getInitialState:function(){return{enableSubmit:!1,phase:1,errStr:null}},componentWillMount:function(){this._unmounted=!1,this._file=Object(r.createRef)(),this._passphrase=Object(r.createRef)()},componentWillUnmount:function(){this._unmounted=!0},_onFormChange:function(e){const 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){return this.setState({errStr:null,phase:2}),function(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=e=>{t(e.target.result)},r.onerror=n,r.readAsArrayBuffer(e)})}(e).then(e=>u.a(e,t)).then(e=>this.props.matrixClient.importRoomKeys(JSON.parse(e))).then(()=>{this.props.onFinished(!0)}).catch(e=>{if(console.error("Error importing e2e keys:",e),this._unmounted)return;const t=e.friendlyText||Object(p.a)("Unknown error");this.setState({errStr:t,phase:1})})},_onCancelClick:function(e){return e.preventDefault(),this.props.onFinished(!1),!1},render:function(){const e=h.a("views.dialogs.BaseDialog"),t=1!==this.state.phase;return a.a.createElement(e,{className:"mx_importE2eKeysDialog",onFinished:this.props.onFinished,title:Object(p.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(p.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(p.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(p.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(p.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(p.a)("Import"),disabled:!this.state.enableSubmit||t}),a.a.createElement("button",{onClick:this._onCancelClick,disabled:t},Object(p.a)("Cancel")))))}})}}]); |