Fix MAC location
This commit is contained in:
@@ -47,10 +47,6 @@ also be set to a strong, random password.
|
|||||||
* `TEST_HOST`
|
* `TEST_HOST`
|
||||||
* `TEST_PASSWORD`
|
* `TEST_PASSWORD`
|
||||||
* `TEST_PORT`
|
* `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
|
## Example API Usage
|
||||||
|
|
||||||
|
|||||||
@@ -14,13 +14,5 @@ test(`'instance_id' is valid`, () => {
|
|||||||
|
|
||||||
test(`'version' can be read from 'package.json'`, () => {
|
test(`'version' can be read from 'package.json'`, () => {
|
||||||
console.log(get_version());
|
console.log(get_version());
|
||||||
expect(get_version()).toBe('1.3.1-r4');
|
expect(get_version()).toBe('1.4.0-r1');
|
||||||
});
|
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,15 +17,13 @@ import {
|
|||||||
ui8_array_to_ui8,
|
ui8_array_to_ui8,
|
||||||
ui8_to_ui8_array,
|
ui8_to_ui8_array,
|
||||||
} from '../utils/byte_order';
|
} from '../utils/byte_order';
|
||||||
import {XChaCha20Poly1305} from '@stablelib/xchacha20poly1305';
|
import { XChaCha20Poly1305 } from '@stablelib/xchacha20poly1305';
|
||||||
|
|
||||||
export default class packet {
|
export default class packet {
|
||||||
constructor(token) {
|
constructor(token) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HEADER = new TextEncoder().encode(this.HEADER_STRING);
|
|
||||||
|
|
||||||
buffer = null;
|
buffer = null;
|
||||||
decode_offset = 0;
|
decode_offset = 0;
|
||||||
token;
|
token;
|
||||||
@@ -163,7 +161,7 @@ export default class packet {
|
|||||||
|
|
||||||
const key = Uint8Array.from(hash.digest());
|
const key = Uint8Array.from(hash.digest());
|
||||||
const nonce = this.buffer.slice(0, 24);
|
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();
|
const customEncryption = getCustomEncryption();
|
||||||
if (customEncryption) {
|
if (customEncryption) {
|
||||||
@@ -178,8 +176,12 @@ export default class packet {
|
|||||||
);
|
);
|
||||||
} else {
|
} 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(
|
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 {
|
} 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 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);
|
this.push_buffer(nonce);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,5 +13,4 @@ export const setCustomEncryption = (ce) => {
|
|||||||
|
|
||||||
export const instance_id = uuidv4();
|
export const instance_id = uuidv4();
|
||||||
export const package_json = _package_json;
|
export const package_json = _package_json;
|
||||||
export const get_version = () =>
|
export const get_version = () => _package_json.version;
|
||||||
process.env.REPERTORY_JS_FORCE_VERSION || _package_json.version;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user