Browse Source

AmneziaWG 2.0 (#2226)

* feat!: awg

* feat: add description to fields, add I5

* fix: awg i18n

* fix: types

* minor fixes

* Remove TODO comment from types.ts

Removed TODO comment for more validation.

---------

Co-authored-by: Bernd Storath <[email protected]>
pull/2285/head
Alexander Chepurnoy 7 months ago
committed by GitHub
parent
commit
6a282e6ab9
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 28
      src/app/components/Form/NullNumberField.vue
  2. 57
      src/app/pages/admin/config.vue
  3. 105
      src/app/pages/admin/interface.vue
  4. 56
      src/app/pages/clients/[id].vue
  5. 36
      src/i18n/locales/en.json
  6. 3
      src/server/api/information.get.ts
  7. 32
      src/server/database/migrations/0002_keen_sleepwalker.sql
  8. 976
      src/server/database/migrations/meta/0002_snapshot.json
  9. 7
      src/server/database/migrations/meta/_journal.json
  10. 8
      src/server/database/repositories/client/schema.ts
  11. 15
      src/server/database/repositories/client/service.ts
  12. 8
      src/server/database/repositories/client/types.ts
  13. 16
      src/server/database/repositories/interface/schema.ts
  14. 16
      src/server/database/repositories/interface/types.ts
  15. 8
      src/server/database/repositories/userConfig/schema.ts
  16. 8
      src/server/database/repositories/userConfig/types.ts
  17. 21
      src/server/utils/WireGuard.ts
  18. 27
      src/server/utils/config.ts
  19. 12
      src/server/utils/types.ts
  20. 73
      src/server/utils/wgHelper.ts

28
src/app/components/Form/NullNumberField.vue

@ -0,0 +1,28 @@
<template>
<div class="flex items-center">
<FormLabel :for="id">
{{ label }}
</FormLabel>
<BaseTooltip v-if="description" :text="description">
<IconsInfo class="size-4" />
</BaseTooltip>
</div>
<BaseInput :id="id" v-model.number="data" :name="id" type="number" />
</template>
<script lang="ts" setup>
defineProps<{ id: string; label: string; description?: string }>();
const data = defineModel<number | null>({
set(value) {
const temp = value ?? null;
if (temp === 0) {
return null;
}
if ((temp as string | null) === '') {
return null;
}
return temp;
},
});
</script>

57
src/app/pages/admin/config.vue

@ -47,6 +47,61 @@
:description="$t('admin.config.persistentKeepaliveDesc')"
/>
</FormGroup>
<FormGroup v-if="globalStore.information?.isAwg">
<FormHeading>{{ $t('awg.obfuscationParameters') }}</FormHeading>
<FormNullNumberField
id="jC"
v-model="data.defaultJC"
:label="$t('awg.jCLabel')"
:description="$t('awg.jCDescription')"
/>
<FormNullNumberField
id="jMin"
v-model="data.defaultJMin"
:label="$t('awg.jMinLabel')"
:description="$t('awg.jMinDescription')"
/>
<FormNullNumberField
id="jMax"
v-model="data.defaultJMax"
:label="$t('awg.jMaxLabel')"
:description="$t('awg.jMaxDescription')"
/>
<div class="col-span-full text-sm">* {{ $t('awg.mtuNote') }}</div>
<FormNullTextField
id="i1"
v-model="data.defaultI1"
:label="$t('awg.i1Label')"
:description="$t('awg.i1Description')"
/>
<FormNullTextField
id="i2"
v-model="data.defaultI2"
:label="$t('awg.i2Label')"
:description="$t('awg.i2Description')"
/>
<FormNullTextField
id="i3"
v-model="data.defaultI3"
:label="$t('awg.i3Label')"
:description="$t('awg.i3Description')"
/>
<FormNullTextField
id="i4"
v-model="data.defaultI4"
:label="$t('awg.i4Label')"
:description="$t('awg.i4Description')"
/>
<FormNullTextField
id="i5"
v-model="data.defaultI5"
:label="$t('awg.i5Label')"
:description="$t('awg.i5Description')"
/>
</FormGroup>
<FormGroup>
<FormHeading>{{ $t('form.actions') }}</FormHeading>
<FormPrimaryActionField type="submit" :label="$t('form.save')" />
@ -57,6 +112,8 @@
</template>
<script lang="ts" setup>
const globalStore = useGlobalStore();
const { data: _data, refresh } = await useFetch(`/api/admin/userconfig`, {
method: 'get',
});

105
src/app/pages/admin/interface.vue

@ -21,6 +21,109 @@
:description="$t('admin.interface.deviceDesc')"
/>
</FormGroup>
<FormGroup v-if="globalStore.information?.isAwg">
<FormHeading>{{ $t('awg.obfuscationParameters') }}</FormHeading>
<FormNullNumberField
id="jC"
v-model="data.jC"
:label="$t('awg.jCLabel')"
:description="$t('awg.jCDescription')"
/>
<FormNullNumberField
id="jMin"
v-model="data.jMin"
:label="$t('awg.jMinLabel')"
:description="$t('awg.jMinDescription')"
/>
<FormNullNumberField
id="jMax"
v-model="data.jMax"
:label="$t('awg.jMaxLabel')"
:description="$t('awg.jMaxDescription')"
/>
<FormNullNumberField
id="s1"
v-model="data.s1"
:label="$t('awg.s1Label')"
:description="$t('awg.s1Description')"
/>
<FormNullNumberField
id="s2"
v-model="data.s2"
:label="$t('awg.s2Label')"
:description="$t('awg.s2Description')"
/>
<div class="col-span-full text-sm">* {{ $t('awg.mtuNote') }}</div>
<FormNullNumberField
id="s3"
v-model="data.s3"
:label="$t('awg.s3Label')"
:description="$t('awg.s3Description')"
/>
<FormNullNumberField
id="s4"
v-model="data.s4"
:label="$t('awg.s4Label')"
:description="$t('awg.s4Description')"
/>
<FormNullTextField
id="i1"
v-model="data.i1"
:label="$t('awg.i1Label')"
:description="$t('awg.i1Description')"
/>
<FormNullTextField
id="i2"
v-model="data.i2"
:label="$t('awg.i2Label')"
:description="$t('awg.i2Description')"
/>
<FormNullTextField
id="i3"
v-model="data.i3"
:label="$t('awg.i3Label')"
:description="$t('awg.i3Description')"
/>
<FormNullTextField
id="i4"
v-model="data.i4"
:label="$t('awg.i4Label')"
:description="$t('awg.i4Description')"
/>
<FormNullTextField
id="i5"
v-model="data.i5"
:label="$t('awg.i5Label')"
:description="$t('awg.i5Description')"
/>
<FormNullNumberField
id="h1"
v-model="data.h1"
:label="$t('awg.h1Label')"
:description="$t('awg.h1Description')"
/>
<FormNullNumberField
id="h2"
v-model="data.h2"
:label="$t('awg.h2Label')"
:description="$t('awg.h2Description')"
/>
<FormNullNumberField
id="h3"
v-model="data.h3"
:label="$t('awg.h3Label')"
:description="$t('awg.h3Description')"
/>
<FormNullNumberField
id="h4"
v-model="data.h4"
:label="$t('awg.h4Label')"
:description="$t('awg.h4Description')"
/>
</FormGroup>
<FormGroup>
<FormHeading>{{ $t('form.actions') }}</FormHeading>
<FormPrimaryActionField type="submit" :label="$t('form.save')" />
@ -53,6 +156,8 @@
</template>
<script setup lang="ts">
const globalStore = useGlobalStore();
const { t } = useI18n();
const { data: _data, refresh } = await useFetch(`/api/admin/interface`, {

56
src/app/pages/clients/[id].vue

@ -82,6 +82,61 @@
:label="$t('general.persistentKeepalive')"
/>
</FormGroup>
<FormGroup v-if="globalStore.information?.isAwg">
<FormHeading>{{ $t('awg.obfuscationParameters') }}</FormHeading>
<FormNullNumberField
id="jC"
v-model="data.jC"
:label="$t('awg.jCLabel')"
:description="$t('awg.jCDescription')"
/>
<FormNullNumberField
id="Jmin"
v-model="data.jMin"
:label="$t('awg.jMinLabel')"
:description="$t('awg.jMinDescription')"
/>
<FormNullNumberField
id="Jmax"
v-model="data.jMax"
:label="$t('awg.jMaxLabel')"
:description="$t('awg.jMaxDescription')"
/>
<div class="col-span-full text-sm">* {{ $t('awg.mtuNote') }}</div>
<FormNullTextField
id="i1"
v-model="data.i1"
:label="$t('awg.i1Label')"
:description="$t('awg.i1Description')"
/>
<FormNullTextField
id="i2"
v-model="data.i2"
:label="$t('awg.i2Label')"
:description="$t('awg.i2Description')"
/>
<FormNullTextField
id="i3"
v-model="data.i3"
:label="$t('awg.i3Label')"
:description="$t('awg.i3Description')"
/>
<FormNullTextField
id="i4"
v-model="data.i4"
:label="$t('awg.i4Label')"
:description="$t('awg.i4Description')"
/>
<FormNullTextField
id="i5"
v-model="data.i5"
:label="$t('awg.i5Label')"
:description="$t('awg.i5Description')"
/>
</FormGroup>
<FormGroup>
<FormHeading :description="$t('client.hooksDescription')">
{{ $t('client.hooks') }}
@ -140,6 +195,7 @@
<script lang="ts" setup>
const authStore = useAuthStore();
const globalStore = useGlobalStore();
authStore.update();
const route = useRoute();

36
src/i18n/locales/en.json

@ -237,5 +237,41 @@
"postUp": "PostUp",
"preDown": "PreDown",
"postDown": "PostDown"
},
"awg": {
"jCLabel": "Junk packet count (Jc)",
"jCDescription": "Number of junk packets to send (1-128, recommended: 4-12)",
"jMinLabel": "Junk packet min size (Jmin)",
"jMinDescription": "Minimum size of junk packets (0-1279*, recommended: 8, must be < Jmax)",
"jMaxLabel": "Junk packet max size (Jmax)",
"jMaxDescription": "Maximum size of junk packets (1-1280*, recommended: 80, must be > Jmin)",
"s1Label": "Init packet junk size (S1)",
"s1Description": "Init packet junk size (0-1132[1280* - 148 = 1132], recommended: 15-150, S1+56 ≠ S2)",
"s2Label": "Response packet junk size (S2)",
"s2Description": "Response packet junk size (0-1188[1280* - 92 = 1188], recommended: 15-150)",
"s3Label": "Cookie reply packet junk size (S3)",
"s3Description": "Cookie reply packet junk size",
"s4Label": "Transport packet junk size (S4)",
"s4Description": "Transport packet junk size",
"i1Label": "Special junk packet 1 (I1)",
"i1Description": "Protocol mimic packet in hex format: <b 0x...>",
"i2Label": "Special junk packet 2 (I2)",
"i2Description": "Protocol mimic packet in hex format: <b 0x...>",
"i3Label": "Special junk packet 3 (I3)",
"i3Description": "Protocol mimic packet in hex format: <b 0x...>",
"i4Label": "Special junk packet 4 (I4)",
"i4Description": "Protocol mimic packet in hex format: <b 0x...>",
"i5Label": "Special junk packet 5 (I5)",
"i5Description": "Protocol mimic packet in hex format: <b 0x...>",
"h1Label": "Init magic header (H1)",
"h1Description": "Init packet header value (5-2147483647, must be unique from H2-H4)",
"h2Label": "Response magic header (H2)",
"h2Description": "Response packet header value (5-2147483647, must be unique from H1, H3, H4)",
"h3Label": "Cookie reply magic header (H3)",
"h3Description": "Cookie reply packet header value (5-2147483647, must be unique from H1, H2, H4)",
"h4Label": "Transport magic header (H4)",
"h4Description": "Transport packet header value (5-2147483647, must be unique from H1-H3)",
"mtuNote": "Values depend on the MTU",
"obfuscationParameters": "AmneziaWG Obfuscation Parameters"
}
}

3
src/server/api/information.get.ts

@ -4,10 +4,13 @@ export default defineEventHandler(async () => {
const latestRelease = await cachedFetchLatestRelease();
const updateAvailable = gt(latestRelease.version, RELEASE);
const insecure = WG_ENV.INSECURE;
const isAwg = WG_ENV.WG_EXECUTABLE === 'awg';
return {
currentRelease: RELEASE,
latestRelease: latestRelease,
updateAvailable,
insecure,
isAwg,
};
});

32
src/server/database/migrations/0002_keen_sleepwalker.sql

@ -0,0 +1,32 @@
ALTER TABLE `clients_table` ADD `j_c` integer;--> statement-breakpoint
ALTER TABLE `clients_table` ADD `j_min` integer;--> statement-breakpoint
ALTER TABLE `clients_table` ADD `j_max` integer;--> statement-breakpoint
ALTER TABLE `clients_table` ADD `i1` text;--> statement-breakpoint
ALTER TABLE `clients_table` ADD `i2` text;--> statement-breakpoint
ALTER TABLE `clients_table` ADD `i3` text;--> statement-breakpoint
ALTER TABLE `clients_table` ADD `i4` text;--> statement-breakpoint
ALTER TABLE `clients_table` ADD `i5` text;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `j_c` integer DEFAULT 7;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `j_min` integer DEFAULT 10;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `j_max` integer DEFAULT 1000;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `s1` integer DEFAULT 128;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `s2` integer DEFAULT 56;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `s3` integer;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `s4` integer;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `i1` text;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `i2` text;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `i3` text;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `i4` text;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `i5` text;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `h1` integer DEFAULT 0;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `h2` integer DEFAULT 0;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `h3` integer DEFAULT 0;--> statement-breakpoint
ALTER TABLE `interfaces_table` ADD `h4` integer DEFAULT 0;--> statement-breakpoint
ALTER TABLE `user_configs_table` ADD `default_j_c` integer DEFAULT 7;--> statement-breakpoint
ALTER TABLE `user_configs_table` ADD `default_j_min` integer DEFAULT 10;--> statement-breakpoint
ALTER TABLE `user_configs_table` ADD `default_j_max` integer DEFAULT 1000;--> statement-breakpoint
ALTER TABLE `user_configs_table` ADD `default_i1` text;--> statement-breakpoint
ALTER TABLE `user_configs_table` ADD `default_i2` text;--> statement-breakpoint
ALTER TABLE `user_configs_table` ADD `default_i3` text;--> statement-breakpoint
ALTER TABLE `user_configs_table` ADD `default_i4` text;--> statement-breakpoint
ALTER TABLE `user_configs_table` ADD `default_i5` text;

976
src/server/database/migrations/meta/0002_snapshot.json

@ -0,0 +1,976 @@
{
"version": "6",
"dialect": "sqlite",
"id": "e09bc17a-dab6-45a3-a09c-57af222b08fb",
"prevId": "78de2e52-c4a8-4900-86c5-92f34739623a",
"tables": {
"clients_table": {
"name": "clients_table",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"user_id": {
"name": "user_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"interface_id": {
"name": "interface_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"ipv4_address": {
"name": "ipv4_address",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"ipv6_address": {
"name": "ipv6_address",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"pre_up": {
"name": "pre_up",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "''"
},
"post_up": {
"name": "post_up",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "''"
},
"pre_down": {
"name": "pre_down",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "''"
},
"post_down": {
"name": "post_down",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "''"
},
"private_key": {
"name": "private_key",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"public_key": {
"name": "public_key",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"pre_shared_key": {
"name": "pre_shared_key",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"expires_at": {
"name": "expires_at",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"allowed_ips": {
"name": "allowed_ips",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"server_allowed_ips": {
"name": "server_allowed_ips",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"persistent_keepalive": {
"name": "persistent_keepalive",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"mtu": {
"name": "mtu",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"j_c": {
"name": "j_c",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"j_min": {
"name": "j_min",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"j_max": {
"name": "j_max",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"i1": {
"name": "i1",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"i2": {
"name": "i2",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"i3": {
"name": "i3",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"i4": {
"name": "i4",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"i5": {
"name": "i5",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"dns": {
"name": "dns",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"server_endpoint": {
"name": "server_endpoint",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"enabled": {
"name": "enabled",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
}
},
"indexes": {
"clients_table_ipv4_address_unique": {
"name": "clients_table_ipv4_address_unique",
"columns": [
"ipv4_address"
],
"isUnique": true
},
"clients_table_ipv6_address_unique": {
"name": "clients_table_ipv6_address_unique",
"columns": [
"ipv6_address"
],
"isUnique": true
}
},
"foreignKeys": {
"clients_table_user_id_users_table_id_fk": {
"name": "clients_table_user_id_users_table_id_fk",
"tableFrom": "clients_table",
"tableTo": "users_table",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "restrict",
"onUpdate": "cascade"
},
"clients_table_interface_id_interfaces_table_name_fk": {
"name": "clients_table_interface_id_interfaces_table_name_fk",
"tableFrom": "clients_table",
"tableTo": "interfaces_table",
"columnsFrom": [
"interface_id"
],
"columnsTo": [
"name"
],
"onDelete": "cascade",
"onUpdate": "cascade"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"general_table": {
"name": "general_table",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": false,
"default": 1
},
"setup_step": {
"name": "setup_step",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"session_password": {
"name": "session_password",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"session_timeout": {
"name": "session_timeout",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"metrics_prometheus": {
"name": "metrics_prometheus",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"metrics_json": {
"name": "metrics_json",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"metrics_password": {
"name": "metrics_password",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"hooks_table": {
"name": "hooks_table",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"pre_up": {
"name": "pre_up",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"post_up": {
"name": "post_up",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"pre_down": {
"name": "pre_down",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"post_down": {
"name": "post_down",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
}
},
"indexes": {},
"foreignKeys": {
"hooks_table_id_interfaces_table_name_fk": {
"name": "hooks_table_id_interfaces_table_name_fk",
"tableFrom": "hooks_table",
"tableTo": "interfaces_table",
"columnsFrom": [
"id"
],
"columnsTo": [
"name"
],
"onDelete": "cascade",
"onUpdate": "cascade"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"interfaces_table": {
"name": "interfaces_table",
"columns": {
"name": {
"name": "name",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"device": {
"name": "device",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"port": {
"name": "port",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"private_key": {
"name": "private_key",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"public_key": {
"name": "public_key",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"ipv4_cidr": {
"name": "ipv4_cidr",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"ipv6_cidr": {
"name": "ipv6_cidr",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"mtu": {
"name": "mtu",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"j_c": {
"name": "j_c",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 7
},
"j_min": {
"name": "j_min",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 10
},
"j_max": {
"name": "j_max",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 1000
},
"s1": {
"name": "s1",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 128
},
"s2": {
"name": "s2",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 56
},
"s3": {
"name": "s3",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"s4": {
"name": "s4",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"i1": {
"name": "i1",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"i2": {
"name": "i2",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"i3": {
"name": "i3",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"i4": {
"name": "i4",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"i5": {
"name": "i5",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"h1": {
"name": "h1",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"h2": {
"name": "h2",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"h3": {
"name": "h3",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"h4": {
"name": "h4",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 0
},
"enabled": {
"name": "enabled",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
}
},
"indexes": {
"interfaces_table_port_unique": {
"name": "interfaces_table_port_unique",
"columns": [
"port"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"one_time_links_table": {
"name": "one_time_links_table",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"one_time_link": {
"name": "one_time_link",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"expires_at": {
"name": "expires_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
}
},
"indexes": {
"one_time_links_table_one_time_link_unique": {
"name": "one_time_links_table_one_time_link_unique",
"columns": [
"one_time_link"
],
"isUnique": true
}
},
"foreignKeys": {
"one_time_links_table_id_clients_table_id_fk": {
"name": "one_time_links_table_id_clients_table_id_fk",
"tableFrom": "one_time_links_table",
"tableTo": "clients_table",
"columnsFrom": [
"id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "cascade"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"users_table": {
"name": "users_table",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"username": {
"name": "username",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"password": {
"name": "password",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"role": {
"name": "role",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"totp_key": {
"name": "totp_key",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"totp_verified": {
"name": "totp_verified",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"enabled": {
"name": "enabled",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
}
},
"indexes": {
"users_table_username_unique": {
"name": "users_table_username_unique",
"columns": [
"username"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"user_configs_table": {
"name": "user_configs_table",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"default_mtu": {
"name": "default_mtu",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"default_persistent_keepalive": {
"name": "default_persistent_keepalive",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"default_dns": {
"name": "default_dns",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"default_allowed_ips": {
"name": "default_allowed_ips",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"default_j_c": {
"name": "default_j_c",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 7
},
"default_j_min": {
"name": "default_j_min",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 10
},
"default_j_max": {
"name": "default_j_max",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false,
"default": 1000
},
"default_i1": {
"name": "default_i1",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"default_i2": {
"name": "default_i2",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"default_i3": {
"name": "default_i3",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"default_i4": {
"name": "default_i4",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"default_i5": {
"name": "default_i5",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"host": {
"name": "host",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"port": {
"name": "port",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "(CURRENT_TIMESTAMP)"
}
},
"indexes": {},
"foreignKeys": {
"user_configs_table_id_interfaces_table_name_fk": {
"name": "user_configs_table_id_interfaces_table_name_fk",
"tableFrom": "user_configs_table",
"tableTo": "interfaces_table",
"columnsFrom": [
"id"
],
"columnsTo": [
"name"
],
"onDelete": "cascade",
"onUpdate": "cascade"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}

7
src/server/database/migrations/meta/_journal.json

@ -15,6 +15,13 @@
"when": 1748427001203,
"tag": "0001_classy_the_stranger",
"breakpoints": true
},
{
"idx": 2,
"version": "6",
"when": 1761298328460,
"tag": "0002_keen_sleepwalker",
"breakpoints": true
}
]
}

8
src/server/database/repositories/client/schema.ts

@ -36,6 +36,14 @@ export const client = sqliteTable('clients_table', {
.notNull(),
persistentKeepalive: int('persistent_keepalive').notNull(),
mtu: int().notNull(),
jC: int('j_c'),
jMin: int('j_min'),
jMax: int('j_max'),
i1: text(),
i2: text(),
i3: text(),
i4: text(),
i5: text(),
dns: text({ mode: 'json' }).$type<string[]>(),
serverEndpoint: text('server_endpoint'),
enabled: int({ mode: 'boolean' }).notNull(),

15
src/server/database/repositories/client/service.ts

@ -214,6 +214,14 @@ export class ClientService {
ipv4Address,
ipv6Address,
mtu: clientConfig.defaultMtu,
jC: clientConfig.defaultJC,
jMin: clientConfig.defaultJMin,
jMax: clientConfig.defaultJMax,
i1: clientConfig.defaultI1,
i2: clientConfig.defaultI2,
i3: clientConfig.defaultI3,
i4: clientConfig.defaultI4,
i5: clientConfig.defaultI5,
persistentKeepalive: clientConfig.defaultPersistentKeepalive,
serverAllowedIps: [],
enabled: true,
@ -278,6 +286,13 @@ export class ClientService {
ipv4Address,
ipv6Address,
mtu: clientConfig.defaultMtu,
jC: clientConfig.defaultJC,
jMin: clientConfig.defaultJMin,
jMax: clientConfig.defaultJMax,
i1: clientConfig.defaultI1,
i2: clientConfig.defaultI2,
i3: clientConfig.defaultI3,
i4: clientConfig.defaultI4,
allowedIps: clientConfig.defaultAllowedIps,
dns: clientConfig.defaultDns,
persistentKeepalive: clientConfig.defaultPersistentKeepalive,

8
src/server/database/repositories/client/types.ts

@ -72,6 +72,14 @@ export const ClientUpdateSchema = schemaForType<UpdateClientType>()(
allowedIps: AllowedIpsSchema.nullable(),
serverAllowedIps: serverAllowedIps,
mtu: MtuSchema,
jC: JcSchema,
jMin: JminSchema,
jMax: JmaxSchema,
i1: ISchema,
i2: ISchema,
i3: ISchema,
i4: ISchema,
i5: ISchema,
persistentKeepalive: PersistentKeepaliveSchema,
serverEndpoint: AddressSchema.nullable(),
dns: DnsSchema.nullable(),

16
src/server/database/repositories/interface/schema.ts

@ -13,6 +13,22 @@ export const wgInterface = sqliteTable('interfaces_table', {
ipv4Cidr: text('ipv4_cidr').notNull(),
ipv6Cidr: text('ipv6_cidr').notNull(),
mtu: int().notNull(),
jC: int('j_c').default(7),
jMin: int('j_min').default(10),
jMax: int('j_max').default(1000),
s1: int().default(128),
s2: int().default(56),
s3: int(),
s4: int(),
i1: text(),
i2: text(),
i3: text(),
i4: text(),
i5: text(),
h1: int().default(0),
h2: int().default(0),
h3: int().default(0),
h4: int().default(0),
// does nothing yet
enabled: int({ mode: 'boolean' }).notNull(),
createdAt: text('created_at')

16
src/server/database/repositories/interface/types.ts

@ -31,6 +31,22 @@ export const InterfaceUpdateSchema = schemaForType<InterfaceUpdateType>()(
ipv4Cidr: cidr,
ipv6Cidr: cidr,
mtu: MtuSchema,
jC: JcSchema,
jMin: JminSchema,
jMax: JmaxSchema,
s1: SSchema,
s2: SSchema,
s3: SSchema,
s4: SSchema,
i1: ISchema,
i2: ISchema,
i3: ISchema,
i4: ISchema,
i5: ISchema,
h1: HSchema,
h2: HSchema,
h3: HSchema,
h4: HSchema,
port: PortSchema,
device: device,
enabled: EnabledSchema,

8
src/server/database/repositories/userConfig/schema.ts

@ -18,6 +18,14 @@ export const userConfig = sqliteTable('user_configs_table', {
defaultAllowedIps: text('default_allowed_ips', { mode: 'json' })
.$type<string[]>()
.notNull(),
defaultJC: int('default_j_c').default(7),
defaultJMin: int('default_j_min').default(10),
defaultJMax: int('default_j_max').default(1000),
defaultI1: text('default_i1'),
defaultI2: text('default_i2'),
defaultI3: text('default_i3'),
defaultI4: text('default_i4'),
defaultI5: text('default_i5'),
host: text().notNull(),
port: int().notNull(),
createdAt: text('created_at')

8
src/server/database/repositories/userConfig/types.ts

@ -26,6 +26,14 @@ export const UserConfigUpdateSchema = schemaForType<UserConfigUpdateType>()(
defaultPersistentKeepalive: PersistentKeepaliveSchema,
defaultDns: DnsSchema,
defaultAllowedIps: AllowedIpsSchema,
defaultJC: JcSchema,
defaultJMin: JminSchema,
defaultJMax: JmaxSchema,
defaultI1: ISchema,
defaultI2: ISchema,
defaultI3: ISchema,
defaultI4: ISchema,
defaultI5: ISchema,
host: host,
})
);

21
src/server/utils/WireGuard.ts

@ -5,6 +5,9 @@ import type { InterfaceType } from '#db/repositories/interface/types';
const WG_DEBUG = debug('WireGuard');
const generateRandomHeaderValue = () =>
Math.floor(Math.random() * 2147483642) + 5;
class WireGuard {
/**
* Save and sync config
@ -196,6 +199,24 @@ class WireGuard {
wgInterface = await Database.interfaces.get();
WG_DEBUG('New Wireguard Keys generated successfully.');
}
if (WG_ENV.WG_EXECUTABLE === 'awg' && wgInterface.h1 === 0) {
WG_DEBUG('Generating random AmneziaWG obfuscation parameters...');
const headers = new Set<number>();
while (headers.size < 4) {
headers.add(generateRandomHeaderValue());
}
const [h1, h2, h3, h4] = Array.from(headers);
wgInterface.h1 = h1!;
wgInterface.h2 = h2!;
wgInterface.h3 = h3!;
wgInterface.h4 = h4!;
Database.interfaces.update(wgInterface);
}
WG_DEBUG(`Starting Wireguard Interface ${wgInterface.name}...`);
await this.#saveWireguardConfig(wgInterface);
await wg.down(wgInterface.name).catch(() => {});

27
src/server/utils/config.ts

@ -12,7 +12,23 @@ export const OLD_ENV = {
PASSWORD_HASH: process.env.PASSWORD_HASH,
};
const OVERRIDE_AUTO_AWG = process.env.OVERRIDE_AUTO_AWG?.toLowerCase();
const detectAwg = async (): Promise<'awg' | 'wg'> => {
/** TODO: delete on next major version */
if (process.env.EXPERIMENTAL_AWG === 'true') {
const OVERRIDE_AUTO_AWG = process.env.OVERRIDE_AUTO_AWG?.toLowerCase();
if (
OVERRIDE_AUTO_AWG === ('wg' as const) ||
OVERRIDE_AUTO_AWG === ('awg' as const)
) {
return OVERRIDE_AUTO_AWG;
} else {
return await exec('modinfo amneziawg')
.then(() => 'awg' as const)
.catch(() => 'wg' as const);
}
} else return 'wg';
};
export const WG_ENV = {
/** UI is hosted on HTTP instead of HTTPS */
@ -21,14 +37,7 @@ export const WG_ENV = {
PORT: assertEnv('PORT'),
/** If IPv6 should be disabled */
DISABLE_IPV6: process.env.DISABLE_IPV6 === 'true',
/** Override automatic detection */
OVERRIDE_AUTO_AWG:
OVERRIDE_AUTO_AWG === ('wg' as const) ||
OVERRIDE_AUTO_AWG === ('awg' as const)
? OVERRIDE_AUTO_AWG
: undefined,
/** TODO: delete on next major version */
EXPERIMENTAL_AWG: process.env.EXPERIMENTAL_AWG === 'true',
WG_EXECUTABLE: await detectAwg(),
};
export const WG_INITIAL_ENV = {

12
src/server/utils/types.ts

@ -26,6 +26,18 @@ export const MtuSchema = z
.min(1024, { message: t('zod.mtu') })
.max(9000, { message: t('zod.mtu') });
export const JcSchema = z.number().min(1).max(128).nullable();
export const JminSchema = z.number().max(1279).nullable();
export const JmaxSchema = z.number().max(1280).nullable();
export const SSchema = z.number().max(1132).nullable();
export const HSchema = z.number().min(5).max(2147483647).nullable();
export const ISchema = z.string().nullable();
export const PortSchema = z
.number({ message: t('zod.port') })
.min(1, { message: t('zod.port') })

73
src/server/utils/wgHelper.ts

@ -9,17 +9,7 @@ type Options = {
enableIpv6?: boolean;
};
let wgExecutable: 'awg' | 'wg' = 'wg';
if (WG_ENV.EXPERIMENTAL_AWG) {
if (WG_ENV.OVERRIDE_AUTO_AWG !== undefined) {
wgExecutable = WG_ENV.OVERRIDE_AUTO_AWG;
} else {
wgExecutable = await exec('modinfo amneziawg')
.then(() => 'awg' as const)
.catch(() => 'wg' as const);
}
}
const wgExecutable = WG_ENV.WG_EXECUTABLE;
export const wg = {
generateServerPeer: (
@ -62,6 +52,35 @@ AllowedIPs = ${allowedIps.join(', ')}${extraLines.length ? `\n${extraLines.join(
`${ipv4Addr}/${cidr4.prefix}` +
(enableIpv6 ? `, ${ipv6Addr}/${cidr6.prefix}` : '');
let awgLines: string[] = [];
if (wgExecutable === 'awg') {
const parameters = {
Jc: wgInterface.jC,
Jmin: wgInterface.jMin,
Jmax: wgInterface.jMax,
S1: wgInterface.s1,
S2: wgInterface.s2,
S3: wgInterface.s3,
S4: wgInterface.s4,
i1: wgInterface.i1,
i2: wgInterface.i2,
i3: wgInterface.i3,
i4: wgInterface.i4,
i5: wgInterface.i5,
H1: wgInterface.h1,
H2: wgInterface.h2,
H3: wgInterface.h3,
H4: wgInterface.h4,
} as const;
awgLines = Object.entries(parameters)
.filter(([_, value]) => !!value)
.map(([key, value]) => `${key} = ${value}`);
}
const extraLines = [...awgLines].filter((v) => v !== null);
return `# Note: Do not edit this file directly.
# Your changes will be overwritten!
@ -71,6 +90,7 @@ PrivateKey = ${wgInterface.privateKey}
Address = ${address}
ListenPort = ${wgInterface.port}
MTU = ${wgInterface.mtu}
${extraLines.length ? `${extraLines.join('\n')}\n` : ''}
PreUp = ${iptablesTemplate(hooks.preUp, wgInterface)}
PostUp = ${iptablesTemplate(hooks.postUp, wgInterface)}
PreDown = ${iptablesTemplate(hooks.preDown, wgInterface)}
@ -100,7 +120,36 @@ PostDown = ${iptablesTemplate(hooks.postDown, wgInterface)}`;
const dnsLine =
dnsServers.length > 0 ? `DNS = ${dnsServers.join(', ')}` : null;
const extraLines = [dnsLine, ...hookLines].filter((v) => v !== null);
let awgLines: string[] = [];
if (wgExecutable === 'awg') {
const parameters = {
Jc: client.jC,
Jmin: client.jMin,
Jmax: client.jMax,
S1: wgInterface.s1,
S2: wgInterface.s2,
S3: wgInterface.s3,
S4: wgInterface.s4,
i1: client.i1,
i2: client.i2,
i3: client.i3,
i4: client.i4,
i5: client.i5,
H1: wgInterface.h1,
H2: wgInterface.h2,
H3: wgInterface.h3,
H4: wgInterface.h4,
} as const;
awgLines = Object.entries(parameters)
.filter(([_, value]) => !!value)
.map(([key, value]) => `${key} = ${value}`);
}
const extraLines = [dnsLine, ...hookLines, ...awgLines].filter(
(v) => v !== null
);
return `[Interface]
PrivateKey = ${client.privateKey}

Loading…
Cancel
Save