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
7.0 KiB
2 lines
7.0 KiB
(window.webpackJsonp=window.webpackJsonp||[]).push([[25],{1373:function(e,t,r){"use strict";r.r(t),r.d(t,"default",(function(){return d}));var n=r(83),a=r.n(n),o=r(82),i=r.n(o),s=r(86),l=r.n(s),c=r(171),h=r(488),u=r(87),p=r(84);class d extends i.a.Component{constructor(e){super(e),a()(this,"_onFormChange",e=>{const t=this._file.current.files||[];this.setState({enableSubmit:""!==this._passphrase.current.value&&t.length>0})}),a()(this,"_onFormSubmit",e=>(e.preventDefault(),this._startImport(this._file.current.files[0],this._passphrase.current.value),!1)),a()(this,"_onCancelClick",e=>(e.preventDefault(),this.props.onFinished(!1),!1)),this._unmounted=!1,this._file=Object(o.createRef)(),this._passphrase=Object(o.createRef)(),this.state={enableSubmit:!1,phase:1,errStr:null}}componentWillUnmount(){this._unmounted=!0}_startImport(e,t){return this.setState({errStr:null,phase:2}),function(e){return new Promise((t,r)=>{const n=new FileReader;n.onload=e=>{t(e.target.result)},n.onerror=r,n.readAsArrayBuffer(e)})}(e).then(e=>h.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})})}render(){const e=u.getComponent("views.dialogs.BaseDialog"),t=1!==this.state.phase;return i.a.createElement(e,{className:"mx_importE2eKeysDialog",onFinished:this.props.onFinished,title:Object(p.a)("Import room keys")},i.a.createElement("form",{onSubmit:this._onFormSubmit},i.a.createElement("div",{className:"mx_Dialog_content"},i.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.")),i.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.")),i.a.createElement("div",{className:"error"},this.state.errStr),i.a.createElement("div",{className:"mx_E2eKeysDialog_inputTable"},i.a.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},i.a.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},i.a.createElement("label",{htmlFor:"importFile"},Object(p.a)("File to import"))),i.a.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},i.a.createElement("input",{ref:this._file,id:"importFile",type:"file",autoFocus:!0,onChange:this._onFormChange,disabled:t}))),i.a.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},i.a.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},i.a.createElement("label",{htmlFor:"passphrase"},Object(p.a)("Enter passphrase"))),i.a.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},i.a.createElement("input",{ref:this._passphrase,id:"passphrase",size:"64",type:"password",onChange:this._onFormChange,disabled:t}))))),i.a.createElement("div",{className:"mx_Dialog_buttons"},i.a.createElement("input",{className:"mx_Dialog_primary",type:"submit",value:Object(p.a)("Import"),disabled:!this.state.enableSubmit||t}),i.a.createElement("button",{onClick:this._onCancelClick,disabled:t},Object(p.a)("Cancel")))))}}a()(d,"propTypes",{matrixClient:l.a.instanceOf(c.b).isRequired,onFinished:l.a.func.isRequired})},488:function(e,t,r){"use strict";r.d(t,"a",(function(){return u})),r.d(t,"b",(function(){return p}));var n=r(304),a=r(84),o=r(94);let i=window.TextEncoder;i||(i=n.TextEncoder);let s=window.TextDecoder;s||(s=n.TextDecoder);const l=window.crypto.subtle||window.crypto.webkitSubtle;function c(e,t){const r=new Error(e);return r.friendlyText=t,r}function h(){return Object(a.a)("Your browser does not support the required cryptography extensions")}async function u(e,t){const r=function(e){const t=(new s).decode(new Uint8Array(e));let r=0;for(;;){const e=t.indexOf("\n",r);if(e<0)throw new Error("Header line not found");const n=t.slice(r,e).trim();if(r=e+1,n===m)break}const n=r;for(;;){const e=t.indexOf("\n",r);if("-----END MEGOLM SESSION DATA-----"===t.slice(r,e<0?void 0:e).trim())break;if(e<0)throw new Error("Trailer line not found");r=e+1}const a=r;return function(e){const t=window.atob(e),r=new Uint8Array(t.length);for(let e=0;e<t.length;e++)r[e]=t.charCodeAt(e);return r}(t.slice(n,a))}(e),n=o.a.get().brand;if(r.length<1)throw c("Invalid file: too short",Object(a.a)("Not a valid %(brand)s keyfile",{brand:n}));if(1!==r[0])throw c("Unsupported version",Object(a.a)("Not a valid %(brand)s keyfile",{brand:n}));const i=r.length-69;if(i<0)throw c("Invalid file: too short",Object(a.a)("Not a valid %(brand)s keyfile",{brand:n}));const u=r.subarray(1,17),p=r.subarray(17,33),y=r[33]<<24|r[34]<<16|r[35]<<8|r[36],w=r.subarray(37,37+i),f=r.subarray(-32),[b,E]=await d(u,y,t),g=r.subarray(0,-32);let _,C;try{_=await l.verify({name:"HMAC"},E,f,g)}catch(e){throw c("subtleCrypto.verify failed: "+e,h())}if(!_)throw c("hmac mismatch",Object(a.a)("Authentication check failed: incorrect password?"));try{C=await l.decrypt({name:"AES-CTR",counter:p,length:64},b,w)}catch(e){throw c("subtleCrypto.decrypt failed: "+e,h())}return(new s).decode(new Uint8Array(C))}async function p(e,t,r){const n=(r=r||{}).kdf_rounds||5e5,a=new Uint8Array(16);window.crypto.getRandomValues(a);const o=new Uint8Array(16);window.crypto.getRandomValues(o),o[8]&=127;const[s,u]=await d(a,n,t),p=(new i).encode(e);let w;try{w=await l.encrypt({name:"AES-CTR",counter:o,length:64},s,p)}catch(e){throw c("subtleCrypto.encrypt failed: "+e,h())}const f=new Uint8Array(w),b=1+a.length+o.length+4+f.length+32,E=new Uint8Array(b);let g=0;E[g++]=1,E.set(a,g),g+=a.length,E.set(o,g),g+=o.length,E[g++]=n>>24,E[g++]=n>>16&255,E[g++]=n>>8&255,E[g++]=255&n,E.set(f,g),g+=f.length;const _=E.subarray(0,g);let C;try{C=await l.sign({name:"HMAC"},u,_)}catch(e){throw c("subtleCrypto.sign failed: "+e,h())}const v=new Uint8Array(C);return E.set(v,g),function(e){const t=Math.ceil(e.length/96),r=new Array(t+3);r[0]=m;let n,a=0;for(n=1;n<=t;n++)r[n]=y(e.subarray(a,a+96)),a+=96;return r[n++]="-----END MEGOLM SESSION DATA-----",r[n]="",(new i).encode(r.join("\n")).buffer}(E)}async function d(e,t,r){const n=new Date;let a,o;try{a=await l.importKey("raw",(new i).encode(r),{name:"PBKDF2"},!1,["deriveBits"])}catch(e){throw c("subtleCrypto.importKey failed: "+e,h())}try{o=await l.deriveBits({name:"PBKDF2",salt:e,iterations:t,hash:"SHA-512"},a,512)}catch(e){throw c("subtleCrypto.deriveBits failed: "+e,h())}const s=new Date;console.log("E2e import/export: deriveKeys took "+(s-n)+"ms");const u=o.slice(0,32),p=o.slice(32),d=l.importKey("raw",u,{name:"AES-CTR"},!1,["encrypt","decrypt"]).catch(e=>{throw c("subtleCrypto.importKey failed for AES key: "+e,h())}),m=l.importKey("raw",p,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign","verify"]).catch(e=>{throw c("subtleCrypto.importKey failed for HMAC key: "+e,h())});return await Promise.all([d,m])}const m="-----BEGIN MEGOLM SESSION DATA-----";function y(e){const t=String.fromCharCode.apply(null,e);return window.btoa(t)}}}]);
|
|
//# sourceMappingURL=25.js.map
|