mowetentertainment1 730de334a7 initial
2025-12-05 11:05:33 -05:00

2 lines
7.1 KiB
JavaScript

"use strict";(self.webpackChunkelement_web=self.webpackChunkelement_web||[]).push([[7211],{"./src/async-components/views/dialogs/security/ImportE2eKeysDialog.tsx":(e,t,r)=>{r.r(t),r.d(t,{default:()=>p});var n=r("./node_modules/@babel/runtime/helpers/esm/defineProperty.js"),i=r("./node_modules/react/index.js"),s=r("./node_modules/matrix-js-sdk/src/logger.ts"),o=r("./src/utils/MegolmExportEncryption.ts"),a=r("./src/languageHandler.tsx"),l=r("./src/components/views/dialogs/BaseDialog.tsx"),c=r("./src/components/views/elements/Field.tsx");var m=function(e){return e.Edit="edit",e.Importing="importing",e}(m||{});class p extends i.Component{constructor(e){super(e),(0,n.A)(this,"unmounted",!1),(0,n.A)(this,"file",(0,i.createRef)()),(0,n.A)(this,"onFormChange",()=>{var e;const t=null===(e=this.file.current)||void 0===e?void 0:e.files;this.setState({enableSubmit:""!==this.state.passphrase&&!(null==t||!t.length)})}),(0,n.A)(this,"onPassphraseChange",e=>{this.setState({passphrase:e.target.value},this.onFormChange)}),(0,n.A)(this,"onFormSubmit",e=>{var t;e.preventDefault();const r=null===(t=this.file.current)||void 0===t||null===(t=t.files)||void 0===t?void 0:t[0];return r&&this.startImport(r,this.state.passphrase),!1}),(0,n.A)(this,"onCancelClick",e=>(e.preventDefault(),this.props.onFinished(!1),!1)),this.state={enableSubmit:!1,phase:m.Edit,errStr:null,passphrase:""}}componentDidMount(){this.unmounted=!1}componentWillUnmount(){this.unmounted=!0}startImport(e,t){return this.setState({errStr:null,phase:m.Importing}),function(e){return new Promise((t,r)=>{const n=new FileReader;n.onload=e=>{var n;null!==(n=e.target)&&void 0!==n&&n.result?t(e.target.result):r(new Error("Failed to read file due to unknown error"))},n.onerror=r,n.readAsArrayBuffer(e)})}(e).then(e=>o.c(e,t)).then(e=>this.props.matrixClient.getCrypto().importRoomKeysAsJson(e)).then(()=>{this.props.onFinished(!0)}).catch(e=>{if(s.vF.error("Error importing e2e keys:",e),this.unmounted)return;const t=e.friendlyText||(0,a._t)("error|unknown");this.setState({errStr:t,phase:m.Edit})})}render(){const e=this.state.phase!==m.Edit;return i.createElement(l.A,{className:"mx_importE2eKeysDialog",onFinished:this.props.onFinished,title:(0,a._t)("settings|key_export_import|import_title")},i.createElement("form",{onSubmit:this.onFormSubmit},i.createElement("div",{className:"mx_Dialog_content"},i.createElement("p",null,(0,a._t)("settings|key_export_import|import_description_1")),i.createElement("p",null,(0,a._t)("settings|key_export_import|import_description_2")),i.createElement("div",{className:"error"},this.state.errStr),i.createElement("div",{className:"mx_E2eKeysDialog_inputTable"},i.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},i.createElement("div",{className:"mx_E2eKeysDialog_inputLabel"},i.createElement("label",{htmlFor:"importFile"},(0,a._t)("settings|key_export_import|file_to_import"))),i.createElement("div",{className:"mx_E2eKeysDialog_inputCell"},i.createElement("input",{ref:this.file,id:"importFile",type:"file",autoFocus:!0,onChange:this.onFormChange,disabled:e}))),i.createElement("div",{className:"mx_E2eKeysDialog_inputRow"},i.createElement(c.A,{label:(0,a._t)("settings|key_export_import|enter_passphrase"),value:this.state.passphrase,onChange:this.onPassphraseChange,size:64,type:"password",disabled:e})))),i.createElement("div",{className:"mx_Dialog_buttons"},i.createElement("input",{className:"mx_Dialog_primary",type:"submit",value:(0,a._t)("action|import"),disabled:!this.state.enableSubmit||e}),i.createElement("button",{onClick:this.onCancelClick,disabled:e},(0,a._t)("action|cancel")))))}}},"./src/utils/MegolmExportEncryption.ts":(e,t,r)=>{r.d(t,{L:()=>m,c:()=>c});var n=r("./node_modules/matrix-js-sdk/src/logger.ts"),i=r("./src/languageHandler.tsx"),s=r("./src/SdkConfig.ts");const o=window.crypto.subtle;function a(e,t){return{message:e,friendlyText:t}}function l(){return(0,i._t)("encryption|export_unsupported")}async function c(e,t){const r=function(e){const t=(new TextDecoder).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===d)break}const n=r;for(;;){const e=t.indexOf("\n",r);if(t.slice(r,e<0?void 0:e).trim()===u)break;if(e<0)throw new Error("Trailer line not found");r=e+1}const i=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,i))}(e),n=s.Ay.get().brand;if(r.length<1)throw a("Invalid file: too short",(0,i._t)("encryption|import_invalid_keyfile",{brand:n}));if(1!==r[0])throw a("Unsupported version",(0,i._t)("encryption|import_invalid_keyfile",{brand:n}));const c=r.length-69;if(c<0)throw a("Invalid file: too short",(0,i._t)("encryption|import_invalid_keyfile",{brand:n}));const m=r.subarray(1,17),h=r.subarray(17,33),y=r[33]<<24|r[34]<<16|r[35]<<8|r[36],f=r.subarray(37,37+c),g=r.subarray(-32),[w,_]=await p(m,y,t),b=r.subarray(0,-32);let E,v;try{E=await o.verify({name:"HMAC"},_,g,b)}catch(e){throw a("subtleCrypto.verify failed: "+e,l())}if(!E)throw a("hmac mismatch",(0,i._t)("encryption|import_invalid_passphrase"));try{v=await o.decrypt({name:"AES-CTR",counter:h,length:64},w,f)}catch(e){throw a("subtleCrypto.decrypt failed: "+e,l())}return(new TextDecoder).decode(new Uint8Array(v))}async function m(e,t,r){const n=(r=r||{}).kdf_rounds||5e5,i=new Uint8Array(16);window.crypto.getRandomValues(i);const s=new Uint8Array(16);window.crypto.getRandomValues(s),s[8]&=127;const[c,m]=await p(i,n,t),y=(new TextEncoder).encode(e);let f;try{f=await o.encrypt({name:"AES-CTR",counter:s,length:64},c,y)}catch(e){throw a("subtleCrypto.encrypt failed: "+e,l())}const g=new Uint8Array(f),w=1+i.length+s.length+4+g.length+32,_=new Uint8Array(w);let b=0;_[b++]=1,_.set(i,b),b+=i.length,_.set(s,b),b+=s.length,_[b++]=n>>24,_[b++]=n>>16&255,_[b++]=n>>8&255,_[b++]=255&n,_.set(g,b),b+=g.length;const E=_.subarray(0,b);let v;try{v=await o.sign({name:"HMAC"},m,E)}catch(e){throw a("subtleCrypto.sign failed: "+e,l())}const x=new Uint8Array(v);return _.set(x,b),function(e){const t=96,r=Math.ceil(e.length/t),n=new Array(r+3);n[0]=d;let i,s=0;for(i=1;i<=r;i++)n[i]=h(e.subarray(s,s+t)),s+=t;return n[i++]=u,n[i]="",(new TextEncoder).encode(n.join("\n")).buffer}(_)}async function p(e,t,r){const i=new Date;let s,c;try{s=await o.importKey("raw",(new TextEncoder).encode(r),{name:"PBKDF2"},!1,["deriveBits"])}catch(e){throw a("subtleCrypto.importKey failed: "+e,l())}try{c=await o.deriveBits({name:"PBKDF2",salt:e,iterations:t,hash:"SHA-512"},s,512)}catch(e){throw a("subtleCrypto.deriveBits failed: "+e,l())}const m=new Date;n.vF.log("E2e import/export: deriveKeys took "+(m.getTime()-i.getTime())+"ms");const p=c.slice(0,32),d=c.slice(32),u=o.importKey("raw",p,{name:"AES-CTR"},!1,["encrypt","decrypt"]).catch(e=>{throw a("subtleCrypto.importKey failed for AES key: "+e,l())}),h=o.importKey("raw",d,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign","verify"]).catch(e=>{throw a("subtleCrypto.importKey failed for HMAC key: "+e,l())});return Promise.all([u,h])}const d="-----BEGIN MEGOLM SESSION DATA-----",u="-----END MEGOLM SESSION DATA-----";function h(e){const t=String.fromCharCode.apply(null,Array.from(e));return window.btoa(t)}}}]);
//# sourceMappingURL=7211.js.map