2 lines
1.2 MiB
JavaScript
Raw Normal View History

2022-02-24 20:10:01 +03:00
/*! For license information please see main.js.LICENSE.txt */
(()=>{var __webpack_modules__={93619:(e,t,r)=>{"use strict";var n=r(34155);Object.defineProperty(t,"__esModule",{value:!0}),t.DUMP_SESSION_KEYS=t.NOISE_MSG_MAX_LENGTH_BYTES_WITHOUT_TAG=t.NOISE_MSG_MAX_LENGTH_BYTES=void 0,t.NOISE_MSG_MAX_LENGTH_BYTES=65535,t.NOISE_MSG_MAX_LENGTH_BYTES_WITHOUT_TAG=t.NOISE_MSG_MAX_LENGTH_BYTES-16,t.DUMP_SESSION_KEYS=n.env.DUMP_SESSION_KEYS},14510:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.decryptStream=t.encryptStream=void 0;const n=r(48764),i=r(93619);t.encryptStream=function(e){return async function*(t){for await(const r of t){const t=n.Buffer.from(r.buffer,r.byteOffset,r.length);for(let r=0;r<t.length;r+=i.NOISE_MSG_MAX_LENGTH_BYTES_WITHOUT_TAG){let n=r+i.NOISE_MSG_MAX_LENGTH_BYTES_WITHOUT_TAG;n>t.length&&(n=t.length);const o=e.encrypt(t.slice(r,n),e.session);yield o}}}},t.decryptStream=function(e){return async function*(t){for await(const r of t){const t=n.Buffer.from(r.buffer,r.byteOffset,r.length);for(let r=0;r<t.length;r+=i.NOISE_MSG_MAX_LENGTH_BYTES){let n=r+i.NOISE_MSG_MAX_LENGTH_BYTES;n>t.length&&(n=t.length);const o=t.slice(r,n),{plaintext:s,valid:a}=await e.decrypt(o,e.session);if(!a)throw new Error("Failed to validate decrypted chunk");yield s}}}}},33477:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.decode2=t.decode1=t.decode0=t.encode2=t.encode1=t.encode0=t.uint16BEDecode=t.uint16BEEncode=void 0;const n=r(48764);t.uint16BEEncode=(e,t,r)=>((t=t||n.Buffer.allocUnsafe(2)).writeUInt16BE(e,r),t),t.uint16BEEncode.bytes=2,t.uint16BEDecode=e=>{if(e.length<2)throw RangeError("Could not decode int16BE");return e.readUInt16BE(0)},t.uint16BEDecode.bytes=2,t.encode0=function(e){return n.Buffer.concat([e.ne,e.ciphertext])},t.encode1=function(e){return n.Buffer.concat([e.ne,e.ns,e.ciphertext])},t.encode2=function(e){return n.Buffer.concat([e.ns,e.ciphertext])},t.decode0=function(e){if(e.length<32)throw new Error("Cannot decode stage 0 MessageBuffer: length less than 32 bytes.");return{ne:e.slice(0,32),ciphertext:e.slice(32,e.length),ns:n.Buffer.alloc(0)}},t.decode1=function(e){if(e.length<80)throw new Error("Cannot decode stage 1 MessageBuffer: length less than 80 bytes.");return{ne:e.slice(0,32),ns:e.slice(32,80),ciphertext:e.slice(80,e.length)}},t.decode2=function(e){if(e.length<48)throw new Error("Cannot decode stage 2 MessageBuffer: length less than 48 bytes.");return{ne:n.Buffer.alloc(0),ns:e.slice(0,48),ciphertext:e.slice(48,e.length)}}},42692:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.FailedIKError=void 0;class r extends Error{constructor(e,t){super(t),this.initialMsg=e,this.name="FailedIKhandshake"}}t.FailedIKError=r},59454:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.IKHandshake=void 0;const n=r(4240),i=r(48764),o=r(33477),s=r(48338),a=r(42692),c=r(87123);t.IKHandshake=class{constructor(e,t,r,o,s,a,c,u){this.isInitiator=e,this.payload=i.Buffer.from(t),this.prologue=r,this.staticKeypair=o,this.connection=s,c&&(this.remotePeer=c),this.ik=null!=u?u:new n.IK,this.session=this.ik.initSession(this.isInitiator,this.prologue,this.staticKeypair,a),this.remoteEarlyData=i.Buffer.alloc(0)}async stage0(){if(c.logLocalStaticKeys(this.session.hs.s),c.logRemoteStaticKey(this.session.hs.rs),this.isInitiator){c.logger("IK Stage 0 - Initiator sending message...");const e=this.ik.sendMessage(this.session,this.payload);this.connection.writeLP(o.encode1(e)),c.logger("IK Stage 0 - Initiator sent message."),c.logLocalEphemeralKeys(this.session.hs.e)}else{c.logger("IK Stage 0 - Responder receiving message...");const e=await this.connection.readLP();try{const t=o.decode1(e.slice()),{plaintext:r,valid:n}=this.ik.recvMessage(this.session,t);if(!n)throw new Error("ik handshake stage 0 decryption validation fail");c.logger("IK Stage 0 - Responder got message, going to verify payload.");const i=await s.decodePayload(r);this.remotePeer=this.remotePeer||await s.getPeerIdFromPayload(i),await s.verifySignedPayload(this.session.hs.rs,i,this.remotePeer),this.setRemoteEarlyData(i.data),c.logger("IK Stage