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
9.6 KiB

(window.webpackJsonp=window.webpackJsonp||[]).push([[1],{520:function(e,r,t){"use strict";function n(e,r,t){return r<=e&&e<=t}function i(e){if(void 0===e)return{};if(e===Object(e))return e;throw TypeError("Could not convert argument to dictionary")}t.r(r),t.d(r,"TextEncoder",function(){return l}),t.d(r,"TextDecoder",function(){return c});var o=-1;function a(e){this.tokens=[].slice.call(e)}a.prototype={endOfStream:function(){return!this.tokens.length},read:function(){return this.tokens.length?this.tokens.shift():o},prepend:function(e){if(Array.isArray(e))for(var r=e;r.length;)this.tokens.unshift(r.pop());else this.tokens.unshift(e)},push:function(e){if(Array.isArray(e))for(var r=e;r.length;)this.tokens.push(r.shift());else this.tokens.push(e)}};var s=-1;function u(e,r){if(e)throw TypeError("Decoder error");return r||65533}var f="utf-8";function c(e,r){if(!(this instanceof c))return new c(e,r);if((e=void 0!==e?String(e).toLowerCase():f)!==f)throw new Error("Encoding not supported. Only utf-8 is supported");r=i(r),this._streaming=!1,this._BOMseen=!1,this._decoder=null,this._fatal=Boolean(r.fatal),this._ignoreBOM=Boolean(r.ignoreBOM),Object.defineProperty(this,"encoding",{value:"utf-8"}),Object.defineProperty(this,"fatal",{value:this._fatal}),Object.defineProperty(this,"ignoreBOM",{value:this._ignoreBOM})}function l(e,r){if(!(this instanceof l))return new l(e,r);if((e=void 0!==e?String(e).toLowerCase():f)!==f)throw new Error("Encoding not supported. Only utf-8 is supported");r=i(r),this._streaming=!1,this._encoder=null,this._options={fatal:Boolean(r.fatal)},Object.defineProperty(this,"encoding",{value:"utf-8"})}c.prototype={decode:function(e,r){var t;t="object"==typeof e&&e instanceof ArrayBuffer?new Uint8Array(e):"object"==typeof e&&"buffer"in e&&e.buffer instanceof ArrayBuffer?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(0),r=i(r),this._streaming||(this._decoder=new function(e){var r=e.fatal,t=0,i=0,a=0,f=128,c=191;this.handler=function(e,l){if(l===o&&0!==a)return a=0,u(r);if(l===o)return s;if(0===a){if(n(l,0,127))return l;if(n(l,194,223))a=1,t=l-192;else if(n(l,224,239))224===l&&(f=160),237===l&&(c=159),a=2,t=l-224;else{if(!n(l,240,244))return u(r);240===l&&(f=144),244===l&&(c=143),a=3,t=l-240}return t<<=6*a,null}if(!n(l,f,c))return t=a=i=0,f=128,c=191,e.prepend(l),u(r);if(f=128,c=191,t+=l-128<<6*(a-(i+=1)),i!==a)return null;var h=t;return t=a=i=0,h}}({fatal:this._fatal}),this._BOMseen=!1),this._streaming=Boolean(r.stream);for(var f,c=new a(t),l=[];!c.endOfStream()&&(f=this._decoder.handler(c,c.read()))!==s;)null!==f&&(Array.isArray(f)?l.push.apply(l,f):l.push(f));if(!this._streaming){do{if((f=this._decoder.handler(c,c.read()))===s)break;null!==f&&(Array.isArray(f)?l.push.apply(l,f):l.push(f))}while(!c.endOfStream());this._decoder=null}return l.length&&(-1===["utf-8"].indexOf(this.encoding)||this._ignoreBOM||this._BOMseen||(65279===l[0]?(this._BOMseen=!0,l.shift()):this._BOMseen=!0)),function(e){for(var r="",t=0;t<e.length;++t){var n=e[t];n<=65535?r+=String.fromCharCode(n):(n-=65536,r+=String.fromCharCode(55296+(n>>10),56320+(1023&n)))}return r}(l)}},l.prototype={encode:function(e,r){e=e?String(e):"",r=i(r),this._streaming||(this._encoder=new function(e){e.fatal;this.handler=function(e,r){if(r===o)return s;if(n(r,0,127))return r;var t,i;n(r,128,2047)?(t=1,i=192):n(r,2048,65535)?(t=2,i=224):n(r,65536,1114111)&&(t=3,i=240);for(var a=[(r>>6*t)+i];t>0;){var u=r>>6*(t-1);a.push(128|63&u),t-=1}return a}}(this._options)),this._streaming=Boolean(r.stream);for(var t,u=[],f=new a(function(e){for(var r=String(e),t=r.length,n=0,i=[];n<t;){var o=r.charCodeAt(n);if(o<55296||o>57343)i.push(o);else if(56320<=o&&o<=57343)i.push(65533);else if(55296<=o&&o<=56319)if(n===t-1)i.push(65533);else{var a=e.charCodeAt(n+1);if(56320<=a&&a<=57343){var s=1023&o,u=1023&a;i.push(65536+(s<<10)+u),n+=1}else i.push(65533)}n+=1}return i}(e));!f.endOfStream()&&(t=this._encoder.handler(f,f.read()))!==s;)Array.isArray(t)?u.push.apply(u,t):u.push(t);if(!this._streaming){for(;(t=this._encoder.handler(f,f.read()))!==s;)Array.isArray(t)?u.push.apply(u,t):u.push(t);this._encoder=null}return new Uint8Array(u)}}},527:function(e,r,t){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.encryptMegolmKeyFile=r.decryptMegolmKeyFile=void 0;var n=c(t(54)),i=c(t(16)),o=c(t(66)),a=t(12),s=(r.decryptMegolmKeyFile=function(){var e=(0,a.coroutine)(i.default.mark(function e(r,t){var n,u,c,l,v,w,b,m,A,_,k,x,O,C;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!((n=g(r)).length<1)){e.next=3;break}throw p("Invalid file: too short",(0,f._t)("Not a valid Riot keyfile"));case 3:if(1===n[0]){e.next=6;break}throw p("Unsupported version",(0,f._t)("Not a valid Riot keyfile"));case 6:if(!((u=n.length-69)<0)){e.next=9;break}throw p("Invalid file: too short",(0,f._t)("Not a valid Riot keyfile"));case 9:return c=n.subarray(1,17),l=n.subarray(17,33),v=n[33]<<24|n[34]<<16|n[35]<<8|n[36],w=n.subarray(37,37+u),b=n.subarray(-32),e.next=16,(0,a.resolve)(s(c,v,t));case 16:return m=e.sent,A=(0,o.default)(m,2),_=A[0],k=A[1],x=n.subarray(0,-32),O=void 0,e.prev=22,e.next=25,(0,a.resolve)(d.verify({name:"HMAC"},k,b,x));case 25:O=e.sent,e.next=31;break;case 28:throw e.prev=28,e.t0=e.catch(22),p("subtleCrypto.verify failed: "+e.t0,y());case 31:if(O){e.next=33;break}throw p("hmac mismatch",(0,f._t)("Authentication check failed: incorrect password?"));case 33:return C=void 0,e.prev=34,e.next=37,(0,a.resolve)(d.decrypt({name:"AES-CTR",counter:l,length:64},_,w));case 37:C=e.sent,e.next=43;break;case 40:throw e.prev=40,e.t1=e.catch(34),p("subtleCrypto.decrypt failed: "+e.t1,y());case 43:return e.abrupt("return",(new h).decode(new Uint8Array(C)));case 44:case"end":return e.stop()}},e,this,[[22,28],[34,40]])}));return function(r,t){return e.apply(this,arguments)}}(),r.encryptMegolmKeyFile=function(){var e=(0,a.coroutine)(i.default.mark(function e(r,t,n){var u,f,c,h,v,w,g,m,A,_,k,x,O,C,M,S;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return u=(n=n||{}).kdf_rounds||5e5,f=new Uint8Array(16),window.crypto.getRandomValues(f),c=new Uint8Array(16),window.crypto.getRandomValues(c),c[9]&=127,e.next=9,(0,a.resolve)(s(f,u,t));case 9:return h=e.sent,v=(0,o.default)(h,2),w=v[0],g=v[1],m=(new l).encode(r),A=void 0,e.prev=15,e.next=18,(0,a.resolve)(d.encrypt({name:"AES-CTR",counter:c,length:64},w,m));case 18:A=e.sent,e.next=24;break;case 21:throw e.prev=21,e.t0=e.catch(15),p("subtleCrypto.encrypt failed: "+e.t0,y());case 24:return _=new Uint8Array(A),k=1+f.length+c.length+4+_.length+32,x=new Uint8Array(k),O=0,x[O++]=1,x.set(f,O),O+=f.length,x.set(c,O),O+=c.length,x[O++]=u>>24,x[O++]=u>>16&255,x[O++]=u>>8&255,x[O++]=255&u,x.set(_,O),O+=_.length,C=x.subarray(0,O),M=void 0,e.prev=41,e.next=44,(0,a.resolve)(d.sign({name:"HMAC"},g,C));case 44:M=e.sent,e.next=50;break;case 47:throw e.prev=47,e.t1=e.catch(41),p("subtleCrypto.sign failed: "+e.t1,y());case 50:return S=new Uint8Array(M),x.set(S,O),e.abrupt("return",b(x));case 53:case"end":return e.stop()}},e,this,[[15,21],[41,47]])}));return function(r,t,n){return e.apply(this,arguments)}}(),function(){var e=(0,a.coroutine)(i.default.mark(function e(r,t,o){var s,u,f,c,h,v,w,g;return i.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return s=new Date,u=void 0,e.prev=2,e.next=5,(0,a.resolve)(d.importKey("raw",(new l).encode(o),{name:"PBKDF2"},!1,["deriveBits"]));case 5:u=e.sent,e.next=11;break;case 8:throw e.prev=8,e.t0=e.catch(2),p("subtleCrypto.importKey failed: "+e.t0,y());case 11:return f=void 0,e.prev=12,e.next=15,(0,a.resolve)(d.deriveBits({name:"PBKDF2",salt:r,iterations:t,hash:"SHA-512"},u,512));case 15:f=e.sent,e.next=21;break;case 18:throw e.prev=18,e.t1=e.catch(12),p("subtleCrypto.deriveBits failed: "+e.t1,y());case 21:return c=new Date,console.log("E2e import/export: deriveKeys took "+(c-s)+"ms"),h=f.slice(0,32),v=f.slice(32),w=d.importKey("raw",h,{name:"AES-CTR"},!1,["encrypt","decrypt"]).catch(function(e){throw p("subtleCrypto.importKey failed for AES key: "+e,y())}),g=d.importKey("raw",v,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign","verify"]).catch(function(e){throw p("subtleCrypto.importKey failed for HMAC key: "+e,y())}),e.next=29,(0,a.resolve)(n.default.all([w,g]));case 29:return e.abrupt("return",e.sent);case 30:case"end":return e.stop()}},e,this,[[2,8],[12,18]])}));return function(r,t,n){return e.apply(this,arguments)}}()),u=function(e){if(e&&e.__esModule)return e;var r={};if(null!=e)for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t]);return r.default=e,r}(t(520)),f=t(2);function c(e){return e&&e.__esModule?e:{default:e}}var l=window.TextEncoder;l||(l=u.TextEncoder);var h=window.TextDecoder;h||(h=u.TextDecoder);var d=window.crypto.subtle||window.crypto.webkitSubtle;function p(e,r){var t=new Error(e);return t.friendlyText=r,t}function y(){return(0,f._t)("Your browser does not support the required cryptography extensions")}var v="-----BEGIN MEGOLM SESSION DATA-----",w="-----END MEGOLM SESSION DATA-----";function g(e){for(var r=(new h).decode(new Uint8Array(e)),t=0;;){var n=r.indexOf("\n",t);if(n<0)throw new Error("Header line not found");var i=r.slice(t,n).trim();if(t=n+1,i===v)break}for(var o=t;;){var a=r.indexOf("\n",t);if(r.slice(t,a<0?void 0:a).trim()===w)break;if(a<0)throw new Error("Trailer line not found");t=a+1}var s=t;return function(e){for(var r=window.atob(e),t=new Uint8Array(r.length),n=0;n<r.length;n++)t[n]=r.charCodeAt(n);return t}(r.slice(o,s))}function b(e){var r=Math.ceil(e.length/96),t=new Array(r+3);t[0]=v;var n=0,i=void 0;for(i=1;i<=r;i++)t[i]=m(e.subarray(n,n+96)),n+=96;return t[i++]=w,t[i]="",(new l).encode(t.join("\n")).buffer}function m(e){var r=String.fromCharCode.apply(null,e);return window.btoa(r)}}}]);
//# sourceMappingURL=1.js.map