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

(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=!