added custom encryption/decryption
This commit is contained in:
@@ -3,8 +3,9 @@ import connection from './networking/connection';
|
||||
import connection_pool from './networking/connection_pool';
|
||||
import * as ops from './ops';
|
||||
|
||||
export { default as packet } from './networking/packet';
|
||||
export * as byte_order from './utils/byte_order';
|
||||
export { getCustomEncryption, setCustomEncryption } from './utils/constants';
|
||||
export { default as packet } from './networking/packet';
|
||||
|
||||
export const connect = async (host_or_ip, port, password) => {
|
||||
const conn = new connection(host_or_ip, port, password);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { randomBytes } from 'crypto';
|
||||
import { Int64BE, Uint64BE } from 'int64-buffer';
|
||||
import crypto from 'crypto';
|
||||
import { TextEncoder } from 'text-encoding';
|
||||
import { getCustomEncryption } from '../utils/constants';
|
||||
|
||||
import {
|
||||
be_ui8_array_to_i16,
|
||||
@@ -164,9 +165,18 @@ export default class packet {
|
||||
const key = Uint8Array.from(hash.digest());
|
||||
const nonce = this.buffer.slice(0, 12);
|
||||
|
||||
const customEncryption = getCustomEncryption();
|
||||
if (customEncryption) {
|
||||
this.buffer = await customEncryption.decrypt(
|
||||
key,
|
||||
nonce,
|
||||
this.buffer.slice(12)
|
||||
);
|
||||
} else {
|
||||
this.buffer = new JSChaCha20(key, nonce, 0).decrypt(
|
||||
this.buffer.slice(12)
|
||||
);
|
||||
}
|
||||
|
||||
this.decode_offset = packet.HEADER.length;
|
||||
|
||||
@@ -278,7 +288,12 @@ export default class packet {
|
||||
nonce = Uint8Array.from(randomBytes(12));
|
||||
}
|
||||
|
||||
const customEncryption = getCustomEncryption();
|
||||
if (customEncryption) {
|
||||
this.buffer = await customEncryption.encrypt(key, nonce, this.buffer);
|
||||
} else {
|
||||
this.buffer = new JSChaCha20(key, nonce, 0).encrypt(this.buffer);
|
||||
}
|
||||
this.push_buffer(nonce);
|
||||
|
||||
return this.buffer;
|
||||
|
||||
@@ -1,6 +1,16 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import _package_json from '../../package.json';
|
||||
|
||||
let customEncryption;
|
||||
|
||||
export const getCustomEncryption = () => {
|
||||
return customEncryption;
|
||||
};
|
||||
|
||||
export const setCustomEncryption = (ce) => {
|
||||
customEncryption = ce;
|
||||
};
|
||||
|
||||
export const instance_id = uuidv4();
|
||||
export const package_json = _package_json;
|
||||
export const get_version = () =>
|
||||
|
||||
Reference in New Issue
Block a user