Fix MAC location

This commit is contained in:
2021-07-30 18:32:25 -05:00
parent 7fe1420876
commit d428445f00
4 changed files with 15 additions and 22 deletions

View File

@@ -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');
});

View File

@@ -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);
}

View File

@@ -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;