|
|
@ -1,4 +1,5 @@ |
|
|
import { deflateSync as zlibDeflateSync } from 'node:zlib'; |
|
|
import { deflate } from 'node:zlib'; |
|
|
|
|
|
import { promisify } from 'node:util'; |
|
|
import { parseCidr } from 'cidr-tools'; |
|
|
import { parseCidr } from 'cidr-tools'; |
|
|
import { stringifyIp } from 'ip-bigint'; |
|
|
import { stringifyIp } from 'ip-bigint'; |
|
|
import type { ClientType } from '#db/repositories/client/types'; |
|
|
import type { ClientType } from '#db/repositories/client/types'; |
|
|
@ -6,6 +7,8 @@ import type { InterfaceType } from '#db/repositories/interface/types'; |
|
|
import type { UserConfigType } from '#db/repositories/userConfig/types'; |
|
|
import type { UserConfigType } from '#db/repositories/userConfig/types'; |
|
|
import type { HooksType } from '#db/repositories/hooks/types'; |
|
|
import type { HooksType } from '#db/repositories/hooks/types'; |
|
|
|
|
|
|
|
|
|
|
|
const zlibDeflate = promisify(deflate); |
|
|
|
|
|
|
|
|
type Options = { |
|
|
type Options = { |
|
|
enableIpv6?: boolean; |
|
|
enableIpv6?: boolean; |
|
|
}; |
|
|
}; |
|
|
@ -188,20 +191,14 @@ Endpoint = ${userConfig.host}:${userConfig.port}`; |
|
|
|
|
|
|
|
|
if (wgExecutable === 'awg') { |
|
|
if (wgExecutable === 'awg') { |
|
|
containerType = 'awg'; |
|
|
containerType = 'awg'; |
|
|
// S3, S4, i1, i2, i3, i4, i5 are not supported by AmneziaVPN app for now
|
|
|
|
|
|
const awgParams = { |
|
|
const awgParams = { |
|
|
Jc: client.jC, |
|
|
Jc: client.jC, |
|
|
Jmin: client.jMin, |
|
|
Jmin: client.jMin, |
|
|
Jmax: client.jMax, |
|
|
Jmax: client.jMax, |
|
|
S1: wgInterface.s1, |
|
|
S1: wgInterface.s1, |
|
|
S2: wgInterface.s2, |
|
|
S2: wgInterface.s2, |
|
|
// S3: wgInterface.s3,
|
|
|
S3: wgInterface.s3, |
|
|
// S4: wgInterface.s4,
|
|
|
S4: wgInterface.s4, |
|
|
// i1: client.i1,
|
|
|
|
|
|
// i2: client.i2,
|
|
|
|
|
|
// i3: client.i3,
|
|
|
|
|
|
// i4: client.i4,
|
|
|
|
|
|
// i5: client.i5,
|
|
|
|
|
|
H1: wgInterface.h1, |
|
|
H1: wgInterface.h1, |
|
|
H2: wgInterface.h2, |
|
|
H2: wgInterface.h2, |
|
|
H3: wgInterface.h3, |
|
|
H3: wgInterface.h3, |
|
|
@ -217,6 +214,12 @@ Endpoint = ${userConfig.host}:${userConfig.port}`; |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const protocolInfo: { protocol_version?: string } = {}; |
|
|
|
|
|
|
|
|
|
|
|
if (awgExtras.hasOwnProperty('S3') && awgExtras.hasOwnProperty('S4')) { |
|
|
|
|
|
protocolInfo.protocol_version = '2'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
const lastConfigObj = { |
|
|
const lastConfigObj = { |
|
|
...awgExtras, |
|
|
...awgExtras, |
|
|
allowed_ips: client.allowedIps ?? userConfig.defaultAllowedIps ?? [], |
|
|
allowed_ips: client.allowedIps ?? userConfig.defaultAllowedIps ?? [], |
|
|
@ -238,6 +241,7 @@ Endpoint = ${userConfig.host}:${userConfig.port}`; |
|
|
isThirdPartyConfig: true, |
|
|
isThirdPartyConfig: true, |
|
|
last_config: JSON.stringify(lastConfigObj), |
|
|
last_config: JSON.stringify(lastConfigObj), |
|
|
port: `${userConfig.port}`, |
|
|
port: `${userConfig.port}`, |
|
|
|
|
|
...protocolInfo, |
|
|
transport_proto: 'udp', |
|
|
transport_proto: 'udp', |
|
|
}, |
|
|
}, |
|
|
container: `amnezia-${containerType}`, |
|
|
container: `amnezia-${containerType}`, |
|
|
@ -251,14 +255,14 @@ Endpoint = ${userConfig.host}:${userConfig.port}`; |
|
|
}; |
|
|
}; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
buildAmneziaQrPack: (amneziaConfigJSON: string) => { |
|
|
buildAmneziaQrPack: async (amneziaConfigJSON: string) => { |
|
|
// Observed working QR wrapper:
|
|
|
// Observed working QR wrapper:
|
|
|
// [0..3] magic/version (0x07C00100)
|
|
|
// [0..3] magic/version (0x07C00100)
|
|
|
// [4..7] zlib_len + 4
|
|
|
// [4..7] zlib_len + 4
|
|
|
// [8..11] uncompressed_len
|
|
|
// [8..11] uncompressed_len
|
|
|
// [12..] zlib(deflate) bytes (starts with 78 DA typically)
|
|
|
// [12..] zlib(deflate) bytes (starts with 78 DA typically)
|
|
|
const plain = Buffer.from(amneziaConfigJSON, 'utf8'); |
|
|
const plain = Buffer.from(amneziaConfigJSON, 'utf8'); |
|
|
const z = zlibDeflateSync(plain); |
|
|
const z = await zlibDeflate(plain); |
|
|
|
|
|
|
|
|
const MAGIC = 0x07c00100; |
|
|
const MAGIC = 0x07c00100; |
|
|
const header = Buffer.allocUnsafe(12); |
|
|
const header = Buffer.allocUnsafe(12); |
|
|
|