diff --git a/README.md b/README.md index 4fad4b1..a10b214 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,6 @@ also be set to a strong, random password. * `TEST_HOST` * `TEST_PASSWORD` * `TEST_PORT` -* To override the version being sent to `repertory`, set the following variable: - * `REPERTORY_JS_FORCE_VERSION` - * NOTE: This variable is primarily used for debugging/testing purposes and should normally - NOT be set. ## Example API Usage diff --git a/src/__tests__/constants.test.js b/src/__tests__/constants.test.js index 058a7fa..b320861 100644 --- a/src/__tests__/constants.test.js +++ b/src/__tests__/constants.test.js @@ -14,13 +14,5 @@ test(`'instance_id' is valid`, () => { test(`'version' can be read from 'package.json'`, () => { console.log(get_version()); - expect(get_version()).toBe('1.3.1-r4'); -}); - -test(`'version' can be overridden by environment variable`, () => { - console.log(process.env); - process.env.REPERTORY_JS_FORCE_VERSION = '1.3.0'; - console.log(get_version()); - expect(get_version()).toBe('1.3.0'); - console.log(process.env); + expect(get_version()).toBe('1.4.0-r1'); }); diff --git a/src/networking/packet.js b/src/networking/packet.js index c294450..de26c85 100644 --- a/src/networking/packet.js +++ b/src/networking/packet.js @@ -17,15 +17,13 @@ import { ui8_array_to_ui8, ui8_to_ui8_array, } from '../utils/byte_order'; -import {XChaCha20Poly1305} from '@stablelib/xchacha20poly1305'; +import { XChaCha20Poly1305 } from '@stablelib/xchacha20poly1305'; export default class packet { constructor(token) { this.token = token; } - static HEADER = new TextEncoder().encode(this.HEADER_STRING); - buffer = null; decode_offset = 0; token; @@ -163,7 +161,7 @@ export default class packet { const key = Uint8Array.from(hash.digest()); const nonce = this.buffer.slice(0, 24); - const mac = this.buffer.slice(24, 16); + const mac = this.buffer.slice(24, 16 + 24); const customEncryption = getCustomEncryption(); if (customEncryption) { @@ -177,9 +175,13 @@ export default class packet { 'base64' ); } else { - const aad = ui32_to_be_ui8_array(this.buffer.length); + const aad = ui32_to_be_ui8_array(this.buffer.length); + this.buffer = new Uint8Array([ + ...this.buffer.slice(nonce.length + mac.length), + ...this.buffer.slice(nonce.length, nonce.length + mac.length), + ]); this.buffer = Buffer.from( - new XChaCha20Poly1305(key).open(nonce, this.buffer.slice(24), aad), + new XChaCha20Poly1305(key).open(nonce, this.buffer, aad) ); } @@ -299,8 +301,12 @@ export default class packet { ) ); } else { - const aad = ui32_to_be_ui8_array(this.buffer.length + 40) + const aad = ui32_to_be_ui8_array(this.buffer.length + 40); this.buffer = new XChaCha20Poly1305(key).seal(nonce, this.buffer, aad); + this.buffer = new Uint8Array([ + ...this.buffer.slice(this.buffer.length - 16), + ...this.buffer.slice(0, this.buffer.length - 16), + ]); this.push_buffer(nonce); } diff --git a/src/utils/constants.js b/src/utils/constants.js index 8612c15..6590a8a 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -13,5 +13,4 @@ export const setCustomEncryption = (ce) => { export const instance_id = uuidv4(); export const package_json = _package_json; -export const get_version = () => - process.env.REPERTORY_JS_FORCE_VERSION || _package_json.version; +export const get_version = () => _package_json.version;