From 4c12402c1f91fde73b8ad98c647e625267c83cc6 Mon Sep 17 00:00:00 2001
From: Mark Puha
Date: Fri, 4 Jul 2025 11:29:02 +0200
Subject: [PATCH] Awg 1.5 (#25)
awg-1.5
---
contrib/embeddable-wg-library/wireguard.c | 15 +-
contrib/json/wg-json | 11 +-
contrib/peer-approver/approve.sh | 3 +-
contrib/peer-approver/notification-listener.c | 21 +-
src/config.c | 221 ++++++++++++++++--
src/containers.h | 38 ++-
src/ipc-freebsd.h | 167 +++++++++++--
src/ipc-linux.h | 122 ++++++++++
src/ipc-openbsd.h | 130 ++++++++++-
src/ipc-uapi.h | 69 ++++++
src/ipc-windows.h | 139 +++++++++++
src/set.c | 2 +-
src/show.c | 71 +++++-
src/showconf.c | 25 ++
src/uapi/linux/linux/wireguard.h | 19 ++
src/uapi/openbsd/net/if_wg.h | 47 +++-
src/uapi/windows/wireguard.h | 31 ++-
src/wg-quick/android.c | 23 +-
src/wg.c | 2 +-
19 files changed, 1079 insertions(+), 77 deletions(-)
diff --git a/contrib/embeddable-wg-library/wireguard.c b/contrib/embeddable-wg-library/wireguard.c
index 500f33d..26de0e9 100644
--- a/contrib/embeddable-wg-library/wireguard.c
+++ b/contrib/embeddable-wg-library/wireguard.c
@@ -53,17 +53,29 @@ enum wgdevice_attribute {
WGDEVICE_A_JMAX,
WGDEVICE_A_S1,
WGDEVICE_A_S2,
+ WGDEVICE_A_S3,
+ WGDEVICE_A_S4,
WGDEVICE_A_H1,
WGDEVICE_A_H2,
WGDEVICE_A_H3,
WGDEVICE_A_H4,
+ WGDEVICE_A_I1,
+ WGDEVICE_A_I2,
+ WGDEVICE_A_I3,
+ WGDEVICE_A_I4,
+ WGDEVICE_A_I5,
+ WGDEVICE_A_J1,
+ WGDEVICE_A_J2,
+ WGDEVICE_A_J3,
+ WGDEVICE_A_ITIME,
__WGDEVICE_A_LAST
};
enum wgpeer_flag {
WGPEER_F_REMOVE_ME = 1U << 0,
WGPEER_F_REPLACE_ALLOWEDIPS = 1U << 1,
- WGPEER_F_HAS_ADVANCED_SECURITY = 1U << 3
+ WGPEER_F_HAS_ADVANCED_SECURITY = 1U << 3,
+ WGPEER_F_HAS_SPECIAL_HANDSHAKE = 1U << 4
};
enum wgpeer_attribute {
WGPEER_A_UNSPEC,
@@ -78,6 +90,7 @@ enum wgpeer_attribute {
WGPEER_A_ALLOWEDIPS,
WGPEER_A_PROTOCOL_VERSION,
WGPEER_A_ADVANCED_SECURITY,
+ WGPEER_A_SPECIAL_HANDSHAKE,
__WGPEER_A_LAST
};
diff --git a/contrib/json/wg-json b/contrib/json/wg-json
index 83ab135..d24296a 100755
--- a/contrib/json/wg-json
+++ b/contrib/json/wg-json
@@ -11,7 +11,7 @@ while read -r -d $'\t' device; do
if [[ $device != "$last_device" ]]; then
[[ -z $last_device ]] && printf '\n' || printf '%s,\n' "$end"
last_device="$device"
- read -r private_key public_key listen_port jc jmin jmax s1 s2 h1 h2 h3 h4 fwmark
+ read -r private_key public_key listen_port jc jmin jmax s1 s2 h1 h2 h3 h4 i1 i2 i3 i4 i5 j1 j2 j3 itime fwmark
printf '\t"%s": {' "$device"
delim=$'\n'
[[ $private_key == "(none)" ]] || { printf '%s\t\t"privateKey": "%s"' "$delim" "$private_key"; delim=$',\n'; }
@@ -26,6 +26,15 @@ while read -r -d $'\t' device; do
[[ $h2 == "2" ]] || { printf '%s\t\t"h2": %u' "$delim" $(( $h2 )); delim=$',\n'; }
[[ $h3 == "3" ]] || { printf '%s\t\t"h3": %u' "$delim" $(( $h3 )); delim=$',\n'; }
[[ $h4 == "4" ]] || { printf '%s\t\t"h4": %u' "$delim" $(( $h4 )); delim=$',\n'; }
+ [[ $i1 == "(none)" ]] || { printf '%s\t\t"i1": "%s"' "$delim" "$i1"; delim=$',\n'; }
+ [[ $i2 == "(none)" ]] || { printf '%s\t\t"i2": "%s"' "$delim" "$i2"; delim=$',\n'; }
+ [[ $i3 == "(none)" ]] || { printf '%s\t\t"i3": "%s"' "$delim" "$i3"; delim=$',\n'; }
+ [[ $i4 == "(none)" ]] || { printf '%s\t\t"i4": "%s"' "$delim" "$i4"; delim=$',\n'; }
+ [[ $i5 == "(none)" ]] || { printf '%s\t\t"i5": "%s"' "$delim" "$i5"; delim=$',\n'; }
+ [[ $j1 == "(none)" ]] || { printf '%s\t\t"j1": "%s"' "$delim" "$j1"; delim=$',\n'; }
+ [[ $j2 == "(none)" ]] || { printf '%s\t\t"j2": "%s"' "$delim" "$j2"; delim=$',\n'; }
+ [[ $j3 == "(none)" ]] || { printf '%s\t\t"j3": "%s"' "$delim" "$j3"; delim=$',\n'; }
+ [[ $itime == "0" ]] || { printf '%s\t\t"itime": %u' "$delim" $(( itime )); delim=$',\n'; }
[[ $fwmark == "off" ]] || { printf '%s\t\t"fwmark": %u' "$delim" $(( $fwmark )); delim=$',\n'; }
printf '%s\t\t"peers": {' "$delim"; end=$'\n\t\t}\n\t}'
delim=$'\n'
diff --git a/contrib/peer-approver/approve.sh b/contrib/peer-approver/approve.sh
index b4ecfe9..e711a6c 100755
--- a/contrib/peer-approver/approve.sh
+++ b/contrib/peer-approver/approve.sh
@@ -5,6 +5,7 @@ INTERFACE_NAME=$2
PUBLIC_KEY=$3
ENDPOINT=$4
ADVANCED_SECURITY=$5
+SPECIAL_HANDSHAKE=$6
ACCOUNT_STR=`grep "${PUBLIC_KEY}" "${ACCOUNTS_FILE}"`
@@ -19,7 +20,7 @@ PSK=$(echo ${ACCOUNT[2]}|tr -d '"')
PSK_FILE=$(tempfile)
echo "${PSK}" > "${PSK_FILE}"
-awg set "${INTERFACE_NAME}" peer "${PUBLIC_KEY}" allowed-ips "${ALLOWED_IPS}" endpoint "${ENDPOINT}" allowed-ips "${ALLOWED_IPS}" preshared-key "${PSK_FILE}" advanced-security "${ADVANCED_SECURITY}"
+awg set "${INTERFACE_NAME}" peer "${PUBLIC_KEY}" allowed-ips "${ALLOWED_IPS}" endpoint "${ENDPOINT}" allowed-ips "${ALLOWED_IPS}" preshared-key "${PSK_FILE}" advanced-security "${ADVANCED_SECURITY}" special-handshake "${SPECIAL_HANDSHAKE}"
EXIT_CODE=$?
rm -f "{$PSK_FILE}"
diff --git a/contrib/peer-approver/notification-listener.c b/contrib/peer-approver/notification-listener.c
index a264673..0057e71 100644
--- a/contrib/peer-approver/notification-listener.c
+++ b/contrib/peer-approver/notification-listener.c
@@ -116,18 +116,19 @@ static int get_endpoint(struct nlattr *peer[], char **endpoint_ip)
return 0;
}
-static int run_callback(char *ifname, char *pubkey, char *endpoint_ip, bool advanced_security)
+static int run_callback(char *ifname, char *pubkey, char *endpoint_ip, bool advanced_security, bool special_handshake)
{
char** new_argv = malloc((cb_argc + 2) * sizeof *new_argv);
new_argv[0] = cb_argv[1];
- for (int i = 2; i < cb_argc - 3; i++) {
+ for (int i = 2; i < cb_argc - 4; i++) {
new_argv[i - 1] = cb_argv[i];
}
- new_argv[cb_argc - 4] = ifname;
- new_argv[cb_argc - 3] = pubkey;
- new_argv[cb_argc - 2] = endpoint_ip;
- new_argv[cb_argc - 1] = (advanced_security ? "on\0" : "off\0");
+ new_argv[cb_argc - 5] = ifname;
+ new_argv[cb_argc - 4] = pubkey;
+ new_argv[cb_argc - 3] = endpoint_ip;
+ new_argv[cb_argc - 2] = (advanced_security ? "on\0" : "off\0");
+ new_argv[cb_argc - 1] = (special_handshake ? "on\0" : "off\0");
new_argv[cb_argc] = NULL;
int child_pid = fork(), ret;
@@ -156,6 +157,7 @@ static int netlink_callback(struct nl_msg *msg, void *arg)
char *ifname, *pubkey, *endpoint_ip;
bool advanced_security = false;
+ bool special_handshake = false;
int cb_ret;
switch (gnlh->cmd) {
@@ -179,7 +181,10 @@ static int netlink_callback(struct nl_msg *msg, void *arg)
if (nla_get_flag(peer[WGPEER_A_ADVANCED_SECURITY])) {
advanced_security = true;
}
- if (cb_ret = run_callback(ifname, pubkey, endpoint_ip, advanced_security)) {
+ if (nla_get_flag(peer[WGPEER_A_SPECIAL_HANDSHAKE])) {
+ special_handshake = true;
+ }
+ if (cb_ret = run_callback(ifname, pubkey, endpoint_ip, advanced_security, special_handshake)) {
prerr("failed to execute callback script: %d!\n", cb_ret);
return NL_SKIP;
}
@@ -260,4 +265,4 @@ int main(int argc, char *argv[])
}
cleanup_and_exit(EXIT_FAILURE);
-}
\ No newline at end of file
+}
diff --git a/src/config.c b/src/config.c
index f663b7d..a2b35f1 100644
--- a/src/config.c
+++ b/src/config.c
@@ -22,6 +22,13 @@
#define COMMENT_CHAR '#'
+// Keys that should return empty string instead of NULL when not found
+static const char *awg_optional_keys[] = {
+ "I1", "I2", "I3", "I4", "I5",
+ "J1", "J2", "J3",
+ NULL
+};
+
static const char *get_value(const char *line, const char *key)
{
size_t linelen = strlen(line);
@@ -33,6 +40,7 @@ static const char *get_value(const char *line, const char *key)
if (strncasecmp(line, key, keylen))
return NULL;
+
return line + keylen;
}
@@ -410,13 +418,29 @@ err:
return false;
}
+static inline bool parse_awg_string(char **device_value, const char *name, const char *value) {
+ size_t len = strlen(value);
+ if (!len) {
+ *device_value = "";
+ return true;
+ }
+
+ if( len >= MAX_AWG_JUNK_LEN) {
+ fprintf(stderr, "Unable to process string for: %s; longer than: %d\n", name, MAX_AWG_JUNK_LEN);
+ return false;
+ }
+ *device_value = strdup(value);
+
+ return true;
+}
+
static inline bool parse_uint16(uint16_t *device_value, const char *name, const char *value) {
if (!strlen(value)) {
fprintf(stderr, "Unable to parse empty string\n");
return false;
}
-
+
char *end;
uint32_t ret;
ret = strtoul(value, &end, 10);
@@ -542,6 +566,14 @@ static bool process_line(struct config_ctx *ctx, const char *line)
ret = parse_uint16(&ctx->device->response_packet_junk_size, "S2", value);
if (ret)
ctx->device->flags |= WGDEVICE_HAS_S2;
+ } else if (key_match("S3")) {
+ ret = parse_uint16(&ctx->device->cookie_reply_packet_junk_size, "S3", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_S3;
+ } else if (key_match("S4")) {
+ ret = parse_uint16(&ctx->device->transport_packet_junk_size, "S4", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_S4;
} else if (key_match("H1")) {
ret = parse_uint32(&ctx->device->init_packet_magic_header, "H1", value);
if (ret)
@@ -558,8 +590,52 @@ static bool process_line(struct config_ctx *ctx, const char *line)
ret = parse_uint32(&ctx->device->transport_packet_magic_header, "H4", value);
if (ret)
ctx->device->flags |= WGDEVICE_HAS_H4;
- } else
+ } else if (key_match("I1")) {
+ ret = parse_awg_string(&ctx->device->i1, "I1", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_I1;
+ } else if (key_match("I2")) {
+ ret = parse_awg_string(&ctx->device->i2, "I2", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_I2;
+ } else if (key_match("I3")) {
+ ret = parse_awg_string(&ctx->device->i3, "I3", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_I3;
+ } else if (key_match("I4")) {
+ ret = parse_awg_string(&ctx->device->i4, "I4", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_I4;
+ } else if (key_match("I5")) {
+ ret = parse_awg_string(&ctx->device->i5, "I5", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_I5;
+ } else if (key_match("J1")) {
+ ret = parse_awg_string(&ctx->device->j1, "J1", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_J1;
+ } else if (key_match("J2")) {
+ ret = parse_awg_string(&ctx->device->j2, "J2", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_J2;
+ } else if (key_match("J3")) {
+ ret = parse_awg_string(&ctx->device->j3, "J3", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_J3;
+ } else if (key_match("Itime")) {
+ ret = parse_uint32(&ctx->device->itime, "Itime", value);
+ if (ret)
+ ctx->device->flags |= WGDEVICE_HAS_ITIME;
+ } else {
+ // Check if this is an AWG optional key
+ if (strlen(line) == 3) {
+ for (int i = 0; awg_optional_keys[i] != NULL; i++) {
+ if (!strncasecmp(line, awg_optional_keys[i], 2))
+ return true;
+ }
+ }
goto error;
+ }
} else if (ctx->is_peer_section) {
if (key_match("Endpoint"))
ret = parse_endpoint(&ctx->last_peer->endpoint.addr, value);
@@ -579,6 +655,10 @@ static bool process_line(struct config_ctx *ctx, const char *line)
ret = parse_bool(&ctx->last_peer->advanced_security, "AdvancedSecurity", value);
if (ret)
ctx->last_peer->flags |= WGPEER_HAS_ADVANCED_SECURITY;
+ } else if (key_match("SpecialHandshake")) {
+ ret = parse_bool(&ctx->last_peer->special_handshake, "SpecialHandshake", value);
+ if (ret)
+ ctx->last_peer->flags |= WGPEER_HAS_SPECIAL_HANDSHAKE;
} else
goto error;
} else
@@ -597,6 +677,9 @@ bool config_read_line(struct config_ctx *ctx, const char *input)
size_t len, cleaned_len = 0;
char *line, *comment;
bool ret = true;
+ bool found_equals = false;
+ bool found_value_start = false;
+ size_t value_end = 0;
/* This is what strchrnul is for, but that isn't portable. */
comment = strchr(input, COMMENT_CHAR);
@@ -612,10 +695,37 @@ bool config_read_line(struct config_ctx *ctx, const char *input)
goto out;
}
- for (size_t i = 0; i < len; ++i) {
- if (!char_is_space(input[i]))
- line[cleaned_len++] = input[i];
+ /* Remove preceding and trailing whitespaces before value
+ First pass: find the actual end of the value (trim trailing spaces) */
+ for (size_t i = len; i > 0; --i) {
+ if (!char_is_space(input[i - 1])) {
+ value_end = i;
+ break;
+ }
}
+
+ /* Second pass: clean according to KEY = VALUE rules */
+ for (size_t i = 0; i < value_end; ++i) {
+ if (!found_equals) {
+ /* Before '=': remove all whitespace */
+ if (input[i] == '=') {
+ line[cleaned_len++] = input[i];
+ found_equals = true;
+ } else if (!char_is_space(input[i])) {
+ line[cleaned_len++] = input[i];
+ }
+ } else if (!found_value_start) {
+ /* After '=' but before value: skip whitespace until first non-space */
+ if (!char_is_space(input[i])) {
+ line[cleaned_len++] = input[i];
+ found_value_start = true;
+ }
+ } else {
+ /* Within value: preserve all characters including spaces */
+ line[cleaned_len++] = input[i];
+ }
+ }
+
if (!cleaned_len)
goto out;
ret = process_line(ctx, line);
@@ -703,66 +813,143 @@ struct wgdevice *config_read_cmd(const char *argv[], int argc)
} else if (!strcmp(argv[0], "jc") && argc >= 2 && !peer) {
if (!parse_uint16(&device->junk_packet_count, "jc", argv[1]))
goto error;
-
+
device->flags |= WGDEVICE_HAS_JC;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "jmin") && argc >= 2 && !peer) {
if (!parse_uint16(&device->junk_packet_min_size, "jmin", argv[1]))
goto error;
-
+
device->flags |= WGDEVICE_HAS_JMIN;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "jmax") && argc >= 2 && !peer) {
if (!parse_uint16(&device->junk_packet_max_size, "jmax", argv[1]))
goto error;
-
+
device->flags |= WGDEVICE_HAS_JMAX;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "s1") && argc >= 2 && !peer) {
if (!parse_uint16(&device->init_packet_junk_size, "s1", argv[1]))
goto error;
-
+
device->flags |= WGDEVICE_HAS_S1;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "s2") && argc >= 2 && !peer) {
if (!parse_uint16(&device->response_packet_junk_size, "s2", argv[1]))
goto error;
-
+
device->flags |= WGDEVICE_HAS_S2;
argv += 2;
argc -= 2;
+ } else if (!strcmp(argv[0], "s3") && argc >= 2 && !peer) {
+ if (!parse_uint16(&device->cookie_reply_packet_junk_size, "s3", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_S3;
+ argv += 2;
+ argc -= 2;
+ } else if (!strcmp(argv[0], "s4") && argc >= 2 && !peer) {
+ if (!parse_uint16(&device->transport_packet_junk_size, "s4", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_S4;
+ argv += 2;
+ argc -= 2;
} else if (!strcmp(argv[0], "h1") && argc >= 2 && !peer) {
if (!parse_uint32(&device->init_packet_magic_header, "h1", argv[1]))
goto error;
-
+
device->flags |= WGDEVICE_HAS_H1;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "h2") && argc >= 2 && !peer) {
if (!parse_uint32(&device->response_packet_magic_header, "h2", argv[1]))
goto error;
-
+
device->flags |= WGDEVICE_HAS_H2;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "h3") && argc >= 2 && !peer) {
if (!parse_uint32(&device->underload_packet_magic_header, "h3", argv[1]))
goto error;
-
+
device->flags |= WGDEVICE_HAS_H3;
argv += 2;
argc -= 2;
} else if (!strcmp(argv[0], "h4") && argc >= 2 && !peer) {
if (!parse_uint32(&device->transport_packet_magic_header, "h4", argv[1]))
goto error;
-
+
device->flags |= WGDEVICE_HAS_H4;
argv += 2;
argc -= 2;
+ } else if (!strcmp(argv[0], "i1") && argc >= 2 && !peer) {
+ if (!parse_awg_string(&device->i1, "i1", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_I1;
+ argv += 2;
+ argc -= 2;
+ } else if (!strcmp(argv[0], "i2") && argc >= 2 && !peer) {
+ if (!parse_awg_string(&device->i2, "i2", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_I2;
+ argv += 2;
+ argc -=2;
+ } else if (!strcmp(argv[0], "i3") && argc >= 2 && !peer) {
+ if (!parse_awg_string(&device->i3, "i3", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_I3;
+ argv += 2;
+ argc -=2;
+ } else if (!strcmp(argv[0], "i4") && argc >= 2 && !peer) {
+ if (!parse_awg_string(&device->i4, "i4", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_I4;
+ argv += 2;
+ argc -=2;
+ } else if (!strcmp(argv[0], "i5") && argc >= 2 && !peer) {
+ if (!parse_awg_string(&device->i5, "i5", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_I5;
+ argv += 2;
+ argc -=2;
+ } else if (!strcmp(argv[0], "j1") && argc >= 2 && !peer) {
+ if (!parse_awg_string(&device->j1, "j1", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_J1;
+ argv += 2;
+ argc -=2;
+ } else if (!strcmp(argv[0], "j2") && argc >= 2 && !peer) {
+ if (!parse_awg_string(&device->j2, "j2", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_J2;
+ argv += 2;
+ argc -=2;
+ } else if (!strcmp(argv[0], "j3") && argc >= 2 && !peer) {
+ if (!parse_awg_string(&device->j3, "j3", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_J3;
+ argv += 2;
+ argc -=2;
+ } else if (!strcmp(argv[0], "itime") && argc >= 2 && !peer) {
+ if (!parse_uint32(&device->itime, "itime", argv[1]))
+ goto error;
+
+ device->flags |= WGDEVICE_HAS_ITIME;
+ argv += 2;
+ argc -=2;
} else if (!strcmp(argv[0], "peer") && argc >= 2) {
struct wgpeer *new_peer = calloc(1, sizeof(*new_peer));
@@ -819,6 +1006,12 @@ struct wgdevice *config_read_cmd(const char *argv[], int argc)
peer->flags |= WGPEER_HAS_ADVANCED_SECURITY;
argv += 2;
argc -= 2;
+ } else if (!strcmp(argv[0], "special-handshake") && argc >= 2 && peer) {
+ if (!parse_bool(&peer->special_handshake, "SpecialHandshake", argv[1]))
+ goto error;
+ peer->flags |= WGPEER_HAS_SPECIAL_HANDSHAKE;
+ argv += 2;
+ argc -= 2;
} else {
fprintf(stderr, "Invalid argument: %s\n", argv[0]);
goto error;
diff --git a/src/containers.h b/src/containers.h
index 8f93bb5..09ff619 100644
--- a/src/containers.h
+++ b/src/containers.h
@@ -23,6 +23,10 @@
#define WG_KEY_LEN 32
#endif
+#ifndef MAX_AWG_JUNK_LEN
+#define MAX_AWG_JUNK_LEN 5 * 1024
+#endif
+
/* Cross platform __kernel_timespec */
struct timespec64 {
int64_t tv_sec;
@@ -45,7 +49,8 @@ enum {
WGPEER_HAS_PUBLIC_KEY = 1U << 2,
WGPEER_HAS_PRESHARED_KEY = 1U << 3,
WGPEER_HAS_PERSISTENT_KEEPALIVE_INTERVAL = 1U << 4,
- WGPEER_HAS_ADVANCED_SECURITY = 1U << 5
+ WGPEER_HAS_ADVANCED_SECURITY = 1U << 5,
+ WGPEER_HAS_SPECIAL_HANDSHAKE = 1U << 6
};
struct wgpeer {
@@ -65,6 +70,7 @@ struct wgpeer {
uint16_t persistent_keepalive_interval;
bool advanced_security;
+ bool special_handshake;
struct wgallowedip *first_allowedip, *last_allowedip;
struct wgpeer *next_peer;
@@ -81,10 +87,21 @@ enum {
WGDEVICE_HAS_JMAX = 1U << 7,
WGDEVICE_HAS_S1 = 1U << 8,
WGDEVICE_HAS_S2 = 1U << 9,
- WGDEVICE_HAS_H1 = 1U << 10,
- WGDEVICE_HAS_H2 = 1U << 11,
- WGDEVICE_HAS_H3 = 1U << 12,
- WGDEVICE_HAS_H4 = 1U << 13
+ WGDEVICE_HAS_S3 = 1U << 10,
+ WGDEVICE_HAS_S4 = 1U << 11,
+ WGDEVICE_HAS_H1 = 1U << 12,
+ WGDEVICE_HAS_H2 = 1U << 12,
+ WGDEVICE_HAS_H3 = 1U << 13,
+ WGDEVICE_HAS_H4 = 1U << 14,
+ WGDEVICE_HAS_I1 = 1U << 15,
+ WGDEVICE_HAS_I2 = 1U << 16,
+ WGDEVICE_HAS_I3 = 1U << 17,
+ WGDEVICE_HAS_I4 = 1U << 18,
+ WGDEVICE_HAS_I5 = 1U << 19,
+ WGDEVICE_HAS_J1 = 1U << 20,
+ WGDEVICE_HAS_J2 = 1U << 21,
+ WGDEVICE_HAS_J3 = 1U << 22,
+ WGDEVICE_HAS_ITIME = 1U << 23
};
struct wgdevice {
@@ -106,10 +123,21 @@ struct wgdevice {
uint16_t junk_packet_max_size;
uint16_t init_packet_junk_size;
uint16_t response_packet_junk_size;
+ uint16_t cookie_reply_packet_junk_size;
+ uint16_t transport_packet_junk_size;
uint32_t init_packet_magic_header;
uint32_t response_packet_magic_header;
uint32_t underload_packet_magic_header;
uint32_t transport_packet_magic_header;
+ char* i1;
+ char* i2;
+ char* i3;
+ char* i4;
+ char* i5;
+ char* j1;
+ char* j2;
+ char* j3;
+ uint32_t itime;
};
#define for_each_wgpeer(__dev, __peer) for ((__peer) = (__dev)->first_peer; (__peer); (__peer) = (__peer)->next_peer)
diff --git a/src/ipc-freebsd.h b/src/ipc-freebsd.h
index 1acddc4..206ebcd 100644
--- a/src/ipc-freebsd.h
+++ b/src/ipc-freebsd.h
@@ -91,68 +91,163 @@ static int kernel_get_device(struct wgdevice **device, const char *ifname)
dev->flags |= WGDEVICE_HAS_LISTEN_PORT;
}
}
- if (nvlist_exists_number(nvl_device, "jc")) {
+ if (nvlist_exists_number(nvl_device, "jc")) {
number = nvlist_get_number(nvl_device, "jc");
if (number <= UINT16_MAX){
dev->junk_packet_count = number;
dev->flags |= WGDEVICE_HAS_JC;
}
}
- if (nvlist_exists_number(nvl_device, "jmin")) {
+ if (nvlist_exists_number(nvl_device, "jmin")) {
number = nvlist_get_number(nvl_device, "jmin");
if (number <= UINT16_MAX){
- dev->junk_packet_min_size = number;
+ dev->junk_packet_min_size = number;
dev->flags |= WGDEVICE_HAS_JMIN;
- }
+ }
}
- if (nvlist_exists_number(nvl_device, "jmax")) {
+ if (nvlist_exists_number(nvl_device, "jmax")) {
number = nvlist_get_number(nvl_device, "jmax");
if (number <= UINT16_MAX){
- dev->junk_packet_max_size = number;
+ dev->junk_packet_max_size = number;
dev->flags |= WGDEVICE_HAS_JMAX;
- }
+ }
}
- if (nvlist_exists_number(nvl_device, "s1")) {
+ if (nvlist_exists_number(nvl_device, "s1")) {
number = nvlist_get_number(nvl_device, "s1");
if (number <= UINT16_MAX){
- dev->init_packet_junk_size = number;
+ dev->init_packet_junk_size = number;
dev->flags |= WGDEVICE_HAS_S1;
- }
+ }
}
- if (nvlist_exists_number(nvl_device, "s2")) {
+ if (nvlist_exists_number(nvl_device, "s2")) {
number = nvlist_get_number(nvl_device, "s2");
if (number <= UINT16_MAX){
- dev->response_packet_junk_size = number;
+ dev->response_packet_junk_size = number;
dev->flags |= WGDEVICE_HAS_S2;
- }
+ }
}
- if (nvlist_exists_number(nvl_device, "h1")) {
+ if (nvlist_exists_number(nvl_device, "s3")) {
+ number = nvlist_get_number(nvl_device, "s3");
+ if (number <= UINT16_MAX){
+ dev->cookie_reply_packet_junk_size = number;
+ dev->flags |= WGDEVICE_HAS_S3;
+ }
+ }
+ if (nvlist_exists_number(nvl_device, "s4")) {
+ number = nvlist_get_number(nvl_device, "s4");
+ if (number <= UINT16_MAX){
+ dev->transport_packet_junk_size = number;
+ dev->flags |= WGDEVICE_HAS_S4;
+ }
+ }
+ if (nvlist_exists_number(nvl_device, "h1")) {
number = nvlist_get_number(nvl_device, "h1");
if (number <= UINT32_MAX){
- dev->init_packet_magic_header = number;
+ dev->init_packet_magic_header = number;
dev->flags |= WGDEVICE_HAS_H1;
- }
+ }
}
- if (nvlist_exists_number(nvl_device, "h2")) {
+ if (nvlist_exists_number(nvl_device, "h2")) {
number = nvlist_get_number(nvl_device, "h2");
if (number <= UINT32_MAX){
- dev->response_packet_magic_header = number;
+ dev->response_packet_magic_header = number;
dev->flags |= WGDEVICE_HAS_H2;
- }
+ }
}
- if (nvlist_exists_number(nvl_device, "h3")) {
+ if (nvlist_exists_number(nvl_device, "h3")) {
number = nvlist_get_number(nvl_device, "h3");
if (number <= UINT32_MAX){
- dev->underload_packet_magic_header = number;
+ dev->underload_packet_magic_header = number;
dev->flags |= WGDEVICE_HAS_H3;
- }
+ }
}
- if (nvlist_exists_number(nvl_device, "h4")) {
+ if (nvlist_exists_number(nvl_device, "h4")) {
number = nvlist_get_number(nvl_device, "h4");
if (number <= UINT32_MAX){
- dev->transport_packet_magic_header = number;
+ dev->transport_packet_magic_header = number;
dev->flags |= WGDEVICE_HAS_H4;
- }
+ }
+ }
+ if (nvlist_exists_binary(nvl_device, "i1"))
+ {
+ binary = nvlist_get_binary(nvl_device, "i1", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->i1 = strdup((const char*)binary);
+ dev->flags |= WGDEVICE_HAS_I1;
+ }
+ }
+ if (nvlist_exists_binary(nvl_device, "i2"))
+ {
+ binary = nvlist_get_binary(nvl_device, "i2", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->i2 = strdup((const char*)binary);
+ dev->flags |= WGDEVICE_HAS_I2;
+ }
+ }
+ if (nvlist_exists_binary(nvl_device, "i3"))
+ {
+ binary = nvlist_get_binary(nvl_device, "i3", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->i3 = strdup((const char*)binary);
+ dev->flags |= WGDEVICE_HAS_I3;
+ }
+ }
+ if (nvlist_exists_binary(nvl_device, "i4"))
+ {
+ binary = nvlist_get_binary(nvl_device, "i4", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->i4 = strdup((const char*)binary);
+ dev->flags |= WGDEVICE_HAS_I4;
+ }
+ }
+ if (nvlist_exists_binary(nvl_device, "i5"))
+ {
+ binary = nvlist_get_binary(nvl_device, "i5", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->i5 = strdup((const char*)binary);
+ dev->flags |= WGDEVICE_HAS_I5;
+ }
+ }
+ if (nvlist_exists_binary(nvl_device, "j1"))
+ {
+ binary = nvlist_get_binary(nvl_device, "j1", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->j1 = strdup((const char*)binary);
+ dev->flags |= WGDEVICE_HAS_J1;
+ }
+ }
+ if (nvlist_exists_binary(nvl_device, "j2"))
+ {
+ binary = nvlist_get_binary(nvl_device, "j2", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->j2 = strdup((const char*)binary);
+ dev->flags |= WGDEVICE_HAS_J2;
+ }
+ }
+ if (nvlist_exists_binary(nvl_device, "j3"))
+ {
+ binary = nvlist_get_binary(nvl_device, "j3", &size);
+ if (binary && size < MAX_AWG_JUNK_LEN)
+ {
+ dev->j3 = strdup((const char*)binary);
+ dev->flags |= WGDEVICE_HAS_J3;
+ }
+ }
+ if (nvlist_exists_binary(nvl_device, "itime"))
+ {
+ number = nvlist_get_number(nvl_device, "itime");
+ if (number <= UINT32_MAX)
+ {
+ dev->itime = number;
+ dev->flags |= WGDEVICE_HAS_ITIME;
+ }
}
if (nvlist_exists_number(nvl_device, "user-cookie")) {
@@ -346,6 +441,10 @@ static int kernel_set_device(struct wgdevice *dev)
nvlist_add_number(nvl_device, "s1", dev->init_packet_junk_size);
if (dev->flags & WGDEVICE_HAS_S2)
nvlist_add_number(nvl_device, "s2", dev->response_packet_junk_size);
+ if (dev->flags & WGDEVICE_HAS_S3)
+ nvlist_add_number(nvl_device, "s3", dev->cookie_reply_packet_junk_size);
+ if (dev->flags & WGDEVICE_HAS_S4)
+ nvlist_add_number(nvl_device, "s4", dev->transport_packet_junk_size);
if (dev->flags & WGDEVICE_HAS_H1)
nvlist_add_number(nvl_device, "h1", dev->init_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H2)
@@ -354,6 +453,24 @@ static int kernel_set_device(struct wgdevice *dev)
nvlist_add_number(nvl_device, "h3", dev->underload_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H4)
nvlist_add_number(nvl_device, "h4", dev->transport_packet_magic_header);
+ if (dev->flags & WGDEVICE_HAS_I1)
+ nvlist_add_binary(nvl_device, "i1", dev->i1, strlen(dev->i1) + 1);
+ if (dev->flags & WGDEVICE_HAS_I2)
+ nvlist_add_binary(nvl_device, "i2", dev->i2, strlen(dev->i2) + 1);
+ if (dev->flags & WGDEVICE_HAS_I3)
+ nvlist_add_binary(nvl_device, "i3", dev->i3, strlen(dev->i3) + 1);
+ if (dev->flags & WGDEVICE_HAS_I4)
+ nvlist_add_binary(nvl_device, "i4", dev->i4, strlen(dev->i4) + 1);
+ if (dev->flags & WGDEVICE_HAS_I5)
+ nvlist_add_binary(nvl_device, "i5", dev->i5, strlen(dev->i5) + 1);
+ if (dev->flags & WGDEVICE_HAS_J1)
+ nvlist_add_binary(nvl_device, "j1", dev->j1, strlen(dev->j1) + 1);
+ if (dev->flags & WGDEVICE_HAS_J2)
+ nvlist_add_binary(nvl_device, "j2", dev->j2, strlen(dev->j2) + 1);
+ if (dev->flags & WGDEVICE_HAS_J3)
+ nvlist_add_binary(nvl_device, "j3", dev->j3, strlen(dev->j3) + 1);
+ if (dev->flags & WGDEVICE_HAS_ITIME)
+ nvlist_add_number(nvl_device, "itime", dev->itime);
if (dev->flags & WGDEVICE_HAS_FWMARK)
nvlist_add_number(nvl_device, "user-cookie", dev->fwmark);
if (dev->flags & WGDEVICE_REPLACE_PEERS)
diff --git a/src/ipc-linux.h b/src/ipc-linux.h
index c6d9847..0531ff5 100644
--- a/src/ipc-linux.h
+++ b/src/ipc-linux.h
@@ -173,6 +173,10 @@ again:
mnl_attr_put_u16(nlh, WGDEVICE_A_S1, dev->init_packet_junk_size);
if (dev->flags & WGDEVICE_HAS_S2)
mnl_attr_put_u16(nlh, WGDEVICE_A_S2, dev->response_packet_junk_size);
+ if (dev->flags & WGDEVICE_HAS_S3)
+ mnl_attr_put_u16(nlh, WGDEVICE_A_S3, dev->cookie_reply_packet_junk_size);
+ if (dev->flags & WGDEVICE_HAS_S4)
+ mnl_attr_put_u16(nlh, WGDEVICE_A_S4, dev->transport_packet_junk_size);
if (dev->flags & WGDEVICE_HAS_H1)
mnl_attr_put_u32(nlh, WGDEVICE_A_H1, dev->init_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H2)
@@ -181,6 +185,24 @@ again:
mnl_attr_put_u32(nlh, WGDEVICE_A_H3, dev->underload_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H4)
mnl_attr_put_u32(nlh, WGDEVICE_A_H4, dev->transport_packet_magic_header);
+ if (dev->flags & WGDEVICE_HAS_I1)
+ mnl_attr_put_strz(nlh, WGDEVICE_A_I1, dev->i1);
+ if (dev->flags & WGDEVICE_HAS_I2)
+ mnl_attr_put_strz(nlh, WGDEVICE_A_I2, dev->i2);
+ if (dev->flags & WGDEVICE_HAS_I3)
+ mnl_attr_put_strz(nlh, WGDEVICE_A_I3, dev->i3);
+ if (dev->flags & WGDEVICE_HAS_I4)
+ mnl_attr_put_strz(nlh, WGDEVICE_A_I4, dev->i4);
+ if (dev->flags & WGDEVICE_HAS_I5)
+ mnl_attr_put_strz(nlh, WGDEVICE_A_I5, dev->i5);
+ if (dev->flags & WGDEVICE_HAS_J1)
+ mnl_attr_put_strz(nlh, WGDEVICE_A_J1, dev->j1);
+ if (dev->flags & WGDEVICE_HAS_J2)
+ mnl_attr_put_strz(nlh, WGDEVICE_A_J2, dev->j2);
+ if (dev->flags & WGDEVICE_HAS_J3)
+ mnl_attr_put_strz(nlh, WGDEVICE_A_J3, dev->j3);
+ if (dev->flags & WGDEVICE_HAS_ITIME)
+ mnl_attr_put_u32(nlh, WGDEVICE_A_ITIME, dev->itime);
if (dev->flags & WGDEVICE_HAS_FWMARK)
mnl_attr_put_u32(nlh, WGDEVICE_A_FWMARK, dev->fwmark);
if (dev->flags & WGDEVICE_REPLACE_PEERS)
@@ -226,6 +248,13 @@ again:
mnl_attr_put_check(nlh, SOCKET_BUFFER_SIZE, WGPEER_A_ADVANCED_SECURITY, 0, NULL);
flags |= WGPEER_F_HAS_ADVANCED_SECURITY;
}
+ if (peer->flags & WGPEER_HAS_SPECIAL_HANDSHAKE)
+ {
+ if (peer->special_handshake)
+ mnl_attr_put_check(
+ nlh, SOCKET_BUFFER_SIZE, WGPEER_A_SPECIAL_HANDSHAKE, 0, NULL);
+ flags |= WGPEER_F_HAS_SPECIAL_HANDSHAKE;
+ }
if (flags) {
if (!mnl_attr_put_u32_check(nlh, SOCKET_BUFFER_SIZE, WGPEER_A_FLAGS, flags))
goto toobig_peers;
@@ -402,6 +431,13 @@ static int parse_peer(const struct nlattr *attr, void *data)
peer->flags |= WGPEER_HAS_ADVANCED_SECURITY;
peer->advanced_security = false;
}
+ if (
+ flags & WGPEER_F_HAS_SPECIAL_HANDSHAKE &&
+ !(peer->flags & WGPEER_HAS_SPECIAL_HANDSHAKE))
+ {
+ peer->flags |= WGPEER_HAS_SPECIAL_HANDSHAKE;
+ peer->special_handshake = false;
+ }
}
break;
case WGPEER_A_ADVANCED_SECURITY:
@@ -413,6 +449,17 @@ static int parse_peer(const struct nlattr *attr, void *data)
}
}
break;
+ case WGPEER_A_SPECIAL_HANDSHAKE:
+ if (!mnl_attr_validate(attr, MNL_TYPE_FLAG))
+ {
+ peer->special_handshake = true;
+
+ if (!(peer->flags & WGPEER_HAS_SPECIAL_HANDSHAKE))
+ {
+ peer->flags |= WGPEER_HAS_SPECIAL_HANDSHAKE;
+ }
+ }
+ break;
case WGPEER_A_ALLOWEDIPS:
return mnl_attr_parse_nested(attr, parse_allowedips, peer);
}
@@ -513,6 +560,18 @@ static int parse_device(const struct nlattr *attr, void *data)
device->flags |= WGDEVICE_HAS_S2;
}
break;
+ case WGDEVICE_A_S3:
+ if (!mnl_attr_validate(attr, MNL_TYPE_U16)) {
+ device->cookie_reply_packet_junk_size = mnl_attr_get_u16(attr);
+ device->flags |= WGDEVICE_HAS_S3;
+ }
+ break;
+ case WGDEVICE_A_S4:
+ if (!mnl_attr_validate(attr, MNL_TYPE_U16)) {
+ device->transport_packet_junk_size = mnl_attr_get_u16(attr);
+ device->flags |= WGDEVICE_HAS_S4;
+ }
+ break;
case WGDEVICE_A_H1:
if (!mnl_attr_validate(attr, MNL_TYPE_U32)) {
device->init_packet_magic_header = mnl_attr_get_u32(attr);
@@ -537,6 +596,69 @@ static int parse_device(const struct nlattr *attr, void *data)
device->flags |= WGDEVICE_HAS_H4;
}
break;
+ case WGDEVICE_A_I1:
+ if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
+ {
+ device->i1 = strdup(mnl_attr_get_str(attr));
+ device->flags |= WGDEVICE_HAS_I1;
+ }
+ break;
+ case WGDEVICE_A_I2:
+ if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
+ {
+ device->i2 = strdup(mnl_attr_get_str(attr));
+ device->flags |= WGDEVICE_HAS_I2;
+ }
+ break;
+ case WGDEVICE_A_I3:
+ if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
+ {
+ device->i3 = strdup(mnl_attr_get_str(attr));
+ device->flags |= WGDEVICE_HAS_I3;
+ }
+ break;
+ case WGDEVICE_A_I4:
+ if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
+ {
+ device->i4 = strdup(mnl_attr_get_str(attr));
+ device->flags |= WGDEVICE_HAS_I4;
+ }
+ break;
+ case WGDEVICE_A_I5:
+ if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
+ {
+ device->i5 = strdup(mnl_attr_get_str(attr));
+ device->flags |= WGDEVICE_HAS_I5;
+ }
+ break;
+ case WGDEVICE_A_J1:
+ if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
+ {
+ device->j1 = strdup(mnl_attr_get_str(attr));
+ device->flags |= WGDEVICE_HAS_J1;
+ }
+ break;
+ case WGDEVICE_A_J2:
+ if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
+ {
+ device->j2 = strdup(mnl_attr_get_str(attr));
+ device->flags |= WGDEVICE_HAS_J2;
+ }
+ break;
+ case WGDEVICE_A_J3:
+ if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
+ {
+ device->j3 = strdup(mnl_attr_get_str(attr));
+ device->flags |= WGDEVICE_HAS_J3;
+ }
+ break;
+ case WGDEVICE_A_ITIME:
+ if (!mnl_attr_validate(attr, MNL_TYPE_STRING))
+ {
+ device->itime = mnl_attr_get_u32(attr);
+ device->flags |= WGDEVICE_HAS_ITIME;
+ }
+ break;
}
return MNL_CB_OK;
diff --git a/src/ipc-openbsd.h b/src/ipc-openbsd.h
index 1b0955d..dd063ae 100644
--- a/src/ipc-openbsd.h
+++ b/src/ipc-openbsd.h
@@ -135,6 +135,16 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
dev->flags |= WGDEVICE_HAS_S2;
}
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_S3) {
+ dev->cookie_reply_packet_junk_size = wg_iface->i_cookie_reply_packet_junk_size;
+ dev->flags |= WGDEVICE_HAS_S3;
+ }
+
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_S4) {
+ dev->transport_packet_junk_size = wg_iface->i_transport_packet_junk_size;
+ dev->flags |= WGDEVICE_HAS_S4;
+ }
+
if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_H1) {
dev->init_packet_magic_header = wg_iface->i_init_packet_magic_header;
dev->flags |= WGDEVICE_HAS_H1;
@@ -154,7 +164,61 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
dev->transport_packet_magic_header = wg_iface->i_transport_packet_magic_header;
dev->flags |= WGDEVICE_HAS_H4;
}
-
+
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I1)
+ {
+ dev->i1 = strdup(wg_iface->i_i1);
+ dev->flags |= WGDEVICE_HAS_I1;
+ }
+
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I2)
+ {
+ dev->i2 = strdup(wg_iface->i_i2);
+ dev->flags |= WGDEVICE_HAS_I2;
+ }
+
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I3)
+ {
+ dev->i3 = strdup(wg_iface->i_i3);
+ dev->flags |= WGDEVICE_HAS_I3;
+ }
+
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I4)
+ {
+ dev->i4 = strdup(wg_iface->i_i4);
+ dev->flags |= WGDEVICE_HAS_I4;
+ }
+
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_I5)
+ {
+ dev->i5 = strdup(wg_iface->i_i5);
+ dev->flags |= WGDEVICE_HAS_I5;
+ }
+
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_J1)
+ {
+ dev->j1 = strdup(wg_iface->i_j1);
+ dev->flags |= WGDEVICE_HAS_J1;
+ }
+
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_J2)
+ {
+ dev->j2 = strdup(wg_iface->i_j2);
+ dev->flags |= WGDEVICE_HAS_J2;
+ }
+
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_J3)
+ {
+ dev->j3 = strdup(wg_iface->i_j3);
+ dev->flags |= WGDEVICE_HAS_J3;
+ }
+
+ if (wg_iface->i_flags & WG_INTERFACE_DEVICE_HAS_ITIME)
+ {
+ dev->itime = wg_iface->i_itime ;
+ dev->flags |= WGDEVICE_HAS_ITIME;
+ }
+
wg_peer = &wg_iface->i_peers[0];
for (size_t i = 0; i < wg_iface->i_peers_count; ++i) {
peer = calloc(1, sizeof(*peer));
@@ -292,6 +356,16 @@ static int kernel_set_device(struct wgdevice *dev)
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_S2;
}
+ if (dev->flags & WGDEVICE_HAS_S3) {
+ wg_iface->i_cookie_reply_packet_junk_size = dev->cookie_reply_packet_junk_size;
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_S3;
+ }
+
+ if (dev->flags & WGDEVICE_HAS_S4) {
+ wg_iface->i_transport_packet_junk_size = dev->transport_packet_junk_size;
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_S4;
+ }
+
if (dev->flags & WGDEVICE_HAS_H1) {
wg_iface->i_init_packet_magic_header = dev->init_packet_magic_header;
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_H1;
@@ -312,6 +386,60 @@ static int kernel_set_device(struct wgdevice *dev)
wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_H4;
}
+ if (dev->flags & WGDEVICE_HAS_I1)
+ {
+ wg_iface->i_i1 = strdup(dev->i1);
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_I1;
+ }
+
+ if (dev->flags & WGDEVICE_HAS_I2)
+ {
+ wg_iface->i_i2 = strdup(dev->i2);
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_I2;
+ }
+
+ if (dev->flags & WGDEVICE_HAS_I3)
+ {
+ wg_iface->i_i3 = strdup(dev->i3);
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_I3;
+ }
+
+ if (dev->flags & WGDEVICE_HAS_I4)
+ {
+ wg_iface->i_i4 = strdup(dev->i4);
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_I4;
+ }
+
+ if (dev->flags & WGDEVICE_HAS_I5)
+ {
+ wg_iface->i_i5 = strdup(dev->i5);
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_I5;
+ }
+
+ if (dev->flags & WGDEVICE_HAS_J1)
+ {
+ wg_iface->i_j1 = strdup(dev->j1);
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_J1;
+ }
+
+ if (dev->flags & WGDEVICE_HAS_J2)
+ {
+ wg_iface->i_j2 = strdup(dev->j2);
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_J2;
+ }
+
+ if (dev->flags & WGDEVICE_HAS_J3)
+ {
+ wg_iface->i_j3 = strdup(dev->j3);
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_J3;
+ }
+
+ if (dev->flags & WGDEVICE_HAS_ITIME)
+ {
+ wg_iface->i_itime = dev->itime;
+ wg_iface->i_flags |= WG_INTERFACE_DEVICE_HAS_ITIME;
+ }
+
peer_count = 0;
wg_peer = &wg_iface->i_peers[0];
for_each_wgpeer(dev, peer) {
diff --git a/src/ipc-uapi.h b/src/ipc-uapi.h
index 250606c..32be0d8 100644
--- a/src/ipc-uapi.h
+++ b/src/ipc-uapi.h
@@ -61,6 +61,10 @@ static int userspace_set_device(struct wgdevice *dev)
fprintf(f, "s1=%u\n", dev->init_packet_junk_size);
if (dev->flags & WGDEVICE_HAS_S2)
fprintf(f, "s2=%u\n", dev->response_packet_junk_size);
+ if (dev->flags & WGDEVICE_HAS_S3)
+ fprintf(f, "s3=%u\n", dev->cookie_reply_packet_junk_size);
+ if (dev->flags & WGDEVICE_HAS_S4)
+ fprintf(f, "s4=%u\n", dev->transport_packet_junk_size);
if (dev->flags & WGDEVICE_HAS_H1)
fprintf(f, "h1=%u\n", dev->init_packet_magic_header);
if (dev->flags & WGDEVICE_HAS_H2)
@@ -70,6 +74,25 @@ static int userspace_set_device(struct wgdevice *dev)
if (dev->flags & WGDEVICE_HAS_H4)
fprintf(f, "h4=%u\n", dev->transport_packet_magic_header);
+ if (dev->flags & WGDEVICE_HAS_I1)
+ fprintf(f, "i1=%s\n", dev->i1);
+ if (dev->flags & WGDEVICE_HAS_I2)
+ fprintf(f, "i2=%s\n", dev->i2);
+ if (dev->flags & WGDEVICE_HAS_I3)
+ fprintf(f, "i3=%s\n", dev->i3);
+ if (dev->flags & WGDEVICE_HAS_I4)
+ fprintf(f, "i4=%s\n", dev->i4);
+ if (dev->flags & WGDEVICE_HAS_I5)
+ fprintf(f, "i5=%s\n", dev->i5);
+ if (dev->flags & WGDEVICE_HAS_J1)
+ fprintf(f, "j1=%s\n", dev->j1);
+ if (dev->flags & WGDEVICE_HAS_J2)
+ fprintf(f, "j2=%s\n", dev->j2);
+ if (dev->flags & WGDEVICE_HAS_J3)
+ fprintf(f, "j3=%s\n", dev->j3);
+ if (dev->flags & WGDEVICE_HAS_ITIME)
+ fprintf(f, "itime=%u\n", dev->itime);
+
for_each_wgpeer(dev, peer) {
key_to_hex(hex, peer->public_key);
fprintf(f, "public_key=%s\n", hex);
@@ -77,6 +100,11 @@ static int userspace_set_device(struct wgdevice *dev)
ret = -EINVAL;
goto out;
}
+ if (peer->flags & WGPEER_HAS_SPECIAL_HANDSHAKE)
+ {
+ ret = -EINVAL;
+ goto out;
+ }
if (peer->flags & WGPEER_REMOVE_ME) {
fprintf(f, "remove=true\n");
continue;
@@ -220,6 +248,12 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
} else if(!peer && !strcmp(key, "s2")) {
dev->response_packet_junk_size = NUM(0xffffU);
dev->flags |= WGDEVICE_HAS_S2;
+ } else if(!peer && !strcmp(key, "s3")) {
+ dev->cookie_reply_packet_junk_size = NUM(0xffffU);
+ dev->flags |= WGDEVICE_HAS_S3;
+ } else if(!peer && !strcmp(key, "s4")) {
+ dev->transport_packet_junk_size = NUM(0xffffU);
+ dev->flags |= WGDEVICE_HAS_S4;
} else if(!peer && !strcmp(key, "h1")) {
dev->init_packet_magic_header = NUM(0xffffffffU);
dev->flags |= WGDEVICE_HAS_H1;
@@ -232,6 +266,41 @@ static int userspace_get_device(struct wgdevice **out, const char *iface)
} else if(!peer && !strcmp(key, "h4")) {
dev->transport_packet_magic_header = NUM(0xffffffffU);
dev->flags |= WGDEVICE_HAS_H4;
+ } else if (!peer && !strcmp(key, "i1")) {
+ dev->i1 = strdup(value);
+ dev->flags |= WGDEVICE_HAS_I1;
+ }
+ else if (!peer && !strcmp(key, "i2")) {
+ dev->i2 = strdup(value);
+ dev->flags |= WGDEVICE_HAS_I2;
+ }
+ else if (!peer && !strcmp(key, "i3")) {
+ dev->i3 = strdup(value);
+ dev->flags |= WGDEVICE_HAS_I3;
+ }
+ else if (!peer && !strcmp(key, "i4")) {
+ dev->i4 = strdup(value);
+ dev->flags |= WGDEVICE_HAS_I4;
+ }
+ else if (!peer && !strcmp(key, "i5")) {
+ dev->i5 = strdup(value);
+ dev->flags |= WGDEVICE_HAS_I5;
+ }
+ else if (!peer && !strcmp(key, "j1")) {
+ dev->j1 = strdup(value);
+ dev->flags |= WGDEVICE_HAS_J1;
+ }
+ else if (!peer && !strcmp(key, "j2")) {
+ dev->j2 = strdup(value);
+ dev->flags |= WGDEVICE_HAS_J2;
+ }
+ else if (!peer && !strcmp(key, "j3")) {
+ dev->j3 = strdup(value);
+ dev->flags |= WGDEVICE_HAS_J3;
+ }
+ else if (!peer && !strcmp(key, "itime")) {
+ dev->itime = NUM(0xffffffffU);
+ dev->flags |= WGDEVICE_HAS_ITIME;
} else if (!strcmp(key, "public_key")) {
struct wgpeer *new_peer = calloc(1, sizeof(*new_peer));
diff --git a/src/ipc-windows.h b/src/ipc-windows.h
index 7925cf0..faa8b8f 100644
--- a/src/ipc-windows.h
+++ b/src/ipc-windows.h
@@ -283,6 +283,14 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
dev->response_packet_junk_size = wg_iface->ResponsePacketJunkSize;
dev->flags |= WGDEVICE_HAS_S2;
}
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_S3) {
+ dev->cookie_reply_packet_junk_size = wg_iface->CookieReplyPacketJunkSize;
+ dev->flags |= WGDEVICE_HAS_S3;
+ }
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_S4) {
+ dev->transport_packet_junk_size = wg_iface->TransportPacketJunkSize;
+ dev->flags |= WGDEVICE_HAS_S4;
+ }
if (wg_iface->Flags & WG_IOCTL_INTERFACE_H1) {
dev->init_packet_magic_header = wg_iface->InitPacketMagicHeader;
dev->flags |= WGDEVICE_HAS_H1;
@@ -299,6 +307,67 @@ static int kernel_get_device(struct wgdevice **device, const char *iface)
dev->transport_packet_magic_header = wg_iface->TransportPacketMagicHeader;
dev->flags |= WGDEVICE_HAS_H4;
}
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_I1)
+ {
+ const size_t i1_size = strlen((char*)wg_iface->I1) + 1;
+ dev->i1 = (char*)malloc(i1_size);
+ memcpy(dev->i1, wg_iface->I1, i1_size);
+ dev->flags |= WGDEVICE_HAS_I1;
+ }
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_I2)
+ {
+ const size_t i2_size = strlen((char*)wg_iface->I2) + 1;
+ dev->i2 = (char*)malloc(i2_size);
+ memcpy(dev->i2, wg_iface->I2, i2_size);
+ dev->flags |= WGDEVICE_HAS_I2;
+ }
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_I3)
+ {
+ const size_t i3_size = strlen((char*)wg_iface->I3) + 1;
+ dev->i3 = (char*)malloc(i3_size);
+ memcpy(dev->i3, wg_iface->I3, i3_size);
+ dev->flags |= WGDEVICE_HAS_I3;
+ }
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_I4)
+ {
+ const size_t i4_size = strlen((char*)wg_iface->I4) + 1;
+ dev->i4 = (char*)malloc(i4_size);
+ memcpy(dev->i4, wg_iface->I4, i4_size);
+ dev->flags |= WGDEVICE_HAS_I4;
+ }
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_I5)
+ {
+ const size_t i5_size = strlen((char*)wg_iface->I5) + 1;
+ dev->i5 = (char*)malloc(i5_size);
+ memcpy(dev->i5, wg_iface->I5, i5_size);
+ dev->flags |= WGDEVICE_HAS_I5;
+ }
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_J1)
+ {
+ const size_t j1_size = strlen((char*)wg_iface->J1) + 1;
+ dev->j1 = (char*)malloc(j1_size);
+ memcpy(dev->j1, wg_iface->J1, j1_size);
+ dev->flags |= WGDEVICE_HAS_J1;
+ }
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_J2)
+ {
+ const size_t j2_size = strlen((char*)wg_iface->J2) + 1;
+ dev->j2 = (char*)malloc(j2_size);
+ memcpy(dev->j2, wg_iface->J2, j2_size);
+ dev->flags |= WGDEVICE_HAS_J2;
+ }
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_J3)
+ {
+ const size_t j3_size = strlen((char*)wg_iface->J3) + 1;
+ dev->j3 = (char*)malloc(j3_size);
+ memcpy(dev->j3, wg_iface->J3, j3_size);
+ dev->flags |= WGDEVICE_HAS_J3;
+ }
+ if (wg_iface->Flags & WG_IOCTL_INTERFACE_ITIME)
+ {
+ dev->itime = wg_iface->Itime;
+ dev->flags |= WGDEVICE_HAS_ITIME;
+ }
wg_peer = buf + sizeof(WG_IOCTL_INTERFACE);
for (ULONG i = 0; i < wg_iface->PeersCount; ++i) {
@@ -446,6 +515,14 @@ static int kernel_set_device(struct wgdevice *dev)
wg_iface->ResponsePacketJunkSize = dev->response_packet_junk_size;
wg_iface->Flags |= WG_IOCTL_INTERFACE_S2;
}
+ if (dev->flags & WGDEVICE_HAS_S3) {
+ wg_iface->CookieReplyPacketJunkSize = dev->cookie_reply_packet_junk_size;
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_S3;
+ }
+ if (dev->flags & WGDEVICE_HAS_S4) {
+ wg_iface->TransportPacketJunkSize = dev->transport_packet_junk_size;
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_S4;
+ }
if (dev->flags & WGDEVICE_HAS_H1) {
wg_iface->InitPacketMagicHeader = dev->init_packet_magic_header;
@@ -467,6 +544,68 @@ static int kernel_set_device(struct wgdevice *dev)
wg_iface->Flags |= WG_IOCTL_INTERFACE_H4;
}
+ if (dev->flags & WGDEVICE_HAS_I1)
+ {
+ const size_t i1_size = strlen(dev->i1) + 1;
+ wg_iface->I1 = (UCHAR*)malloc(i1_size);
+ memcpy(wg_iface->I1, dev->i1, i1_size);
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_I1;
+ }
+ if (dev->flags & WGDEVICE_HAS_I2)
+ {
+ const size_t i2_size = strlen(dev->i2) + 1;
+ wg_iface->I2 = (UCHAR*)malloc(i2_size);
+ memcpy(wg_iface->I2, dev->i2, i2_size);
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_I2;
+ }
+ if (dev->flags & WGDEVICE_HAS_I3)
+ {
+ const size_t i3_size = strlen(dev->i3) + 1;
+ wg_iface->I3 = (UCHAR*)malloc(i3_size);
+ memcpy(wg_iface->I3, dev->i3, i3_size);
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_I3;
+ }
+ if (dev->flags & WGDEVICE_HAS_I4)
+ {
+ const size_t i4_size = strlen(dev->i4) + 1;
+ wg_iface->I4 = (UCHAR*)malloc(i4_size);
+ memcpy(wg_iface->I4, dev->i4, i4_size);
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_I4;
+ }
+ if (dev->flags & WGDEVICE_HAS_I5)
+ {
+ const size_t i5_size = strlen(dev->i5) + 1;
+ wg_iface->I5 = (UCHAR*)malloc(i5_size);
+ memcpy(wg_iface->I5, dev->i5, i5_size);
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_I5;
+ }
+ if (dev->flags & WGDEVICE_HAS_J1)
+ {
+ const size_t j1_size = strlen(dev->j1) + 1;
+ wg_iface->J1 = (UCHAR*)malloc(j1_size);
+ memcpy(wg_iface->J1, dev->j1, j1_size);
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_J1;
+ }
+ if (dev->flags & WGDEVICE_HAS_J2)
+ {
+ const size_t j2_size = strlen(dev->j2) + 1;
+ wg_iface->J2 = (UCHAR*)malloc(j2_size);
+ memcpy(wg_iface->J2, dev->j2, j2_size);
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_J2;
+ }
+ if (dev->flags & WGDEVICE_HAS_J3)
+ {
+ const size_t j3_size = strlen(dev->j3) + 1;
+ wg_iface->J3 = (UCHAR*)malloc(j3_size);
+ memcpy(wg_iface->J3, dev->j3, j3_size);
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_J3;
+ }
+ if (dev->flags & WGDEVICE_HAS_ITIME)
+ {
+ wg_iface->Itime = dev->itime;
+ wg_iface->Flags |= WG_IOCTL_INTERFACE_ITIME;
+ }
+
peer_count = 0;
wg_peer = (void *)wg_iface + sizeof(WG_IOCTL_INTERFACE);
for_each_wgpeer(dev, peer) {
diff --git a/src/set.c b/src/set.c
index 8f749b1..6bec30a 100644
--- a/src/set.c
+++ b/src/set.c
@@ -18,7 +18,7 @@ int set_main(int argc, const char *argv[])
int ret = 1;
if (argc < 3) {
- fprintf(stderr, "Usage: %s %s [listen-port ] [fwmark ] [private-key ] [peer [remove] [preshared-key ] [endpoint :] [persistent-keepalive ] [allowed-ips /[,/] [advanced-security ]...] ]...\n", PROG_NAME, argv[0]);
+ fprintf(stderr, "Usage: %s %s [listen-port ] [fwmark ] [private-key ] [jc ] [jmin ] [jmax ] [s1 ] [s2 ] [h1 ] [h2 ] [h3 ] [h4 ] [i1 \"\"] [i2 \"\"] [i3 \"\"] [i4 \"\"] [i5 \"\"] [j1 \"\"] [j2 \"\"] [j3 \"\"] [itime ][peer [remove] [preshared-key ] [endpoint :] [persistent-keepalive ] [allowed-ips /[,/] [advanced-security ]...] ]...\n", PROG_NAME, argv[0]);
return 1;
}
diff --git a/src/show.c b/src/show.c
index 001ca1d..9b047c9 100644
--- a/src/show.c
+++ b/src/show.c
@@ -202,7 +202,7 @@ static char *bytes(uint64_t b)
static const char *COMMAND_NAME;
static void show_usage(void)
{
- fprintf(stderr, "Usage: %s %s { | all | interfaces } [public-key | private-key | listen-port | fwmark | peers | preshared-keys | endpoints | allowed-ips | latest-handshakes | transfer | persistent-keepalive | dump]\n", PROG_NAME, COMMAND_NAME);
+ fprintf(stderr, "Usage: %s %s { | all | interfaces } [public-key | private-key | listen-port | fwmark | peers | preshared-keys | endpoints | allowed-ips | latest-handshakes | transfer | persistent-keepalive | dump | jc | jmin | jmax | s1 | s2 | h1 | h2 | h3 | h4 | i1 | i2 | i3 | i4 | i5 | j1 | j2 | j3 | itime]\n", PROG_NAME, COMMAND_NAME);
}
static void pretty_print(struct wgdevice *device)
@@ -230,6 +230,10 @@ static void pretty_print(struct wgdevice *device)
terminal_printf(" " TERMINAL_BOLD "s1" TERMINAL_RESET ": %u\n", device->init_packet_junk_size);
if (device->response_packet_junk_size)
terminal_printf(" " TERMINAL_BOLD "s2" TERMINAL_RESET ": %u\n", device->response_packet_junk_size);
+ if (device->cookie_reply_packet_junk_size)
+ terminal_printf(" " TERMINAL_BOLD "s3" TERMINAL_RESET ": %u\n", device->cookie_reply_packet_junk_size);
+ if (device->transport_packet_junk_size)
+ terminal_printf(" " TERMINAL_BOLD "s4" TERMINAL_RESET ": %u\n", device->transport_packet_junk_size);
if (device->init_packet_magic_header)
terminal_printf(" " TERMINAL_BOLD "h1" TERMINAL_RESET ": %u\n", device->init_packet_magic_header);
if (device->response_packet_magic_header)
@@ -238,6 +242,25 @@ static void pretty_print(struct wgdevice *device)
terminal_printf(" " TERMINAL_BOLD "h3" TERMINAL_RESET ": %u\n", device->underload_packet_magic_header);
if (device->transport_packet_magic_header)
terminal_printf(" " TERMINAL_BOLD "h4" TERMINAL_RESET ": %u\n", device->transport_packet_magic_header);
+ if (device->i1)
+ terminal_printf(" " TERMINAL_BOLD "i1" TERMINAL_RESET ": %s\n", device->i1);
+ if (device->i2)
+ terminal_printf(" " TERMINAL_BOLD "i2" TERMINAL_RESET ": %s\n", device->i2);
+ if (device->i3)
+ terminal_printf(" " TERMINAL_BOLD "i3" TERMINAL_RESET ": %s\n", device->i3);
+ if (device->i4)
+ terminal_printf(" " TERMINAL_BOLD "i4" TERMINAL_RESET ": %s\n", device->i4);
+ if (device->i5)
+ terminal_printf(" " TERMINAL_BOLD "i5" TERMINAL_RESET ": %s\n", device->i5);
+ if (device->j1)
+ terminal_printf(" " TERMINAL_BOLD "j1" TERMINAL_RESET ": %s\n", device->j1);
+ if (device->j2)
+ terminal_printf(" " TERMINAL_BOLD "j2" TERMINAL_RESET ": %s\n", device->j2);
+ if (device->j3)
+ terminal_printf(" " TERMINAL_BOLD "j3" TERMINAL_RESET ": %s\n", device->j3);
+ if (device->itime)
+ terminal_printf(" " TERMINAL_BOLD "itime" TERMINAL_RESET ": %u\n", device->itime);
+
if (device->first_peer) {
sort_peers(device);
terminal_printf("\n");
@@ -287,6 +310,16 @@ static void dump_print(struct wgdevice *device, bool with_interface)
printf("%u\t", device->response_packet_magic_header);
printf("%u\t", device->underload_packet_magic_header);
printf("%u\t", device->transport_packet_magic_header);
+ printf("%s\t", device->i1);
+ printf("%s\t", device->i2);
+ printf("%s\t", device->i3);
+ printf("%s\t", device->i4);
+ printf("%s\t", device->i5);
+ printf("%s\t", device->j1);
+ printf("%s\t", device->j2);
+ printf("%s\t", device->j3);
+ printf("%u\t", device->itime);
+
if (device->fwmark)
printf("0x%x\n", device->fwmark);
else
@@ -374,6 +407,42 @@ static bool ugly_print(struct wgdevice *device, const char *param, bool with_int
if (with_interface)
printf("%s\t", device->name);
printf("%u\n", device->transport_packet_magic_header);
+ } else if(!strcmp(param, "i1")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%s\n", device->i1);
+ } else if(!strcmp(param, "i2")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%s\n", device->i2);
+ } else if(!strcmp(param, "i3")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%s\n", device->i3);
+ } else if(!strcmp(param, "i4")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%s\n", device->i4);
+ } else if(!strcmp(param, "i5")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%s\n", device->i5);
+ } else if(!strcmp(param, "j1")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%s\n", device->j1);
+ } else if(!strcmp(param, "j2")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%s\n", device->j2);
+ } else if(!strcmp(param, "j3")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%s\n", device->j3);
+ } else if(!strcmp(param, "itime")) {
+ if (with_interface)
+ printf("%s\t", device->name);
+ printf("%u\n", device->itime);
} else if (!strcmp(param, "endpoints")) {
for_each_wgpeer(device, peer) {
if (with_interface)
diff --git a/src/showconf.c b/src/showconf.c
index 424b2be..b049f6e 100644
--- a/src/showconf.c
+++ b/src/showconf.c
@@ -56,6 +56,10 @@ int showconf_main(int argc, const char *argv[])
printf("S1 = %u\n", device->init_packet_junk_size);
if (device->flags & WGDEVICE_HAS_S2)
printf("S2 = %u\n", device->response_packet_junk_size);
+ if (device->flags & WGDEVICE_HAS_S3)
+ printf("S3 = %u\n", device->cookie_reply_packet_junk_size);
+ if (device->flags & WGDEVICE_HAS_S4)
+ printf("S4 = %u\n", device->transport_packet_junk_size);
if (device->flags & WGDEVICE_HAS_H1)
printf("H1 = %u\n", device->init_packet_magic_header);
if (device->flags & WGDEVICE_HAS_H2)
@@ -64,6 +68,24 @@ int showconf_main(int argc, const char *argv[])
printf("H3 = %u\n", device->underload_packet_magic_header);
if (device->flags & WGDEVICE_HAS_H4)
printf("H4 = %u\n", device->transport_packet_magic_header);
+ if (device->flags & WGDEVICE_HAS_I1)
+ printf("I1 = %s\n", device->i1);
+ if (device->flags & WGDEVICE_HAS_I2)
+ printf("I2 = %s\n", device->i2);
+ if (device->flags & WGDEVICE_HAS_I3)
+ printf("I3 = %s\n", device->i3);
+ if (device->flags & WGDEVICE_HAS_I4)
+ printf("I4 = %s\n", device->i4);
+ if (device->flags & WGDEVICE_HAS_I5)
+ printf("I5 = %s\n", device->i5);
+ if (device->flags & WGDEVICE_HAS_J1)
+ printf("J1 = %s\n", device->j1);
+ if (device->flags & WGDEVICE_HAS_J2)
+ printf("J2 = %s\n", device->j2);
+ if (device->flags & WGDEVICE_HAS_J3)
+ printf("J3 = %s\n", device->j3);
+ if (device->flags & WGDEVICE_HAS_ITIME)
+ printf("Itime = %u\n", device->itime);
printf("\n");
for_each_wgpeer(device, peer) {
@@ -76,6 +98,9 @@ int showconf_main(int argc, const char *argv[])
if (peer->flags & WGPEER_HAS_ADVANCED_SECURITY) {
printf("AdvancedSecurity = %s\n", peer->advanced_security ? "on" : "off");
}
+ if (peer->flags & WGPEER_HAS_SPECIAL_HANDSHAKE) {
+ printf("SpecialHandshake = %s\n", peer->special_handshake ? "on" : "off");
+ }
if (peer->first_allowedip)
printf("AllowedIPs = ");
for_each_wgallowedip(peer, allowedip) {
diff --git a/src/uapi/linux/linux/wireguard.h b/src/uapi/linux/linux/wireguard.h
index 8d38c90..4438e83 100644
--- a/src/uapi/linux/linux/wireguard.h
+++ b/src/uapi/linux/linux/wireguard.h
@@ -114,6 +114,9 @@
* WGPEER_A_ADVANCED_SECURITY: flag indicating that advanced security
* techniques provided by AmneziaWG should
* be used.
+ * WGPEER_A_SPECIAL_HANDSHAKE: flag indicating that special handshake
+ * techniques provided by AmneziaWG should
+ * be used.
* 0: NLA_NESTED
* ...
* ...
@@ -147,6 +150,9 @@
* WGPEER_A_ADVANCED_SECURITY: flag indicating that advanced security
* techniques provided by AmneziaWG should
* be used.
+ * WGPEER_A_SPECIAL_HANDSHAKE: flag indicating that special handshake
+ * techniques provided by AmneziaWG should
+ * be used.
*
*/
@@ -187,10 +193,21 @@ enum wgdevice_attribute {
WGDEVICE_A_JMAX,
WGDEVICE_A_S1,
WGDEVICE_A_S2,
+ WGDEVICE_A_S3,
+ WGDEVICE_A_S4,
WGDEVICE_A_H1,
WGDEVICE_A_H2,
WGDEVICE_A_H3,
WGDEVICE_A_H4,
+ WGDEVICE_A_I1,
+ WGDEVICE_A_I2,
+ WGDEVICE_A_I3,
+ WGDEVICE_A_I4,
+ WGDEVICE_A_I5,
+ WGDEVICE_A_J1,
+ WGDEVICE_A_J2,
+ WGDEVICE_A_J3,
+ WGDEVICE_A_ITIME,
WGDEVICE_A_PEER,
__WGDEVICE_A_LAST
};
@@ -201,6 +218,7 @@ enum wgpeer_flag {
WGPEER_F_REPLACE_ALLOWEDIPS = 1U << 1,
WGPEER_F_UPDATE_ONLY = 1U << 2,
WGPEER_F_HAS_ADVANCED_SECURITY = 1U << 3,
+ WGPEER_F_HAS_SPECIAL_HANDSHAKE = 1U << 4,
__WGPEER_F_ALL = WGPEER_F_REMOVE_ME | WGPEER_F_REPLACE_ALLOWEDIPS |
WGPEER_F_UPDATE_ONLY
};
@@ -217,6 +235,7 @@ enum wgpeer_attribute {
WGPEER_A_ALLOWEDIPS,
WGPEER_A_PROTOCOL_VERSION,
WGPEER_A_ADVANCED_SECURITY,
+ WGPEER_A_SPECIAL_HANDSHAKE,
__WGPEER_A_LAST
};
#define WGPEER_A_MAX (__WGPEER_A_LAST - 1)
diff --git a/src/uapi/openbsd/net/if_wg.h b/src/uapi/openbsd/net/if_wg.h
index f768a32..1f30572 100644
--- a/src/uapi/openbsd/net/if_wg.h
+++ b/src/uapi/openbsd/net/if_wg.h
@@ -67,20 +67,31 @@ struct wg_peer_io {
struct wg_aip_io p_aips[];
};
-#define WG_INTERFACE_HAS_PUBLIC (1 << 0)
-#define WG_INTERFACE_HAS_PRIVATE (1 << 1)
-#define WG_INTERFACE_HAS_PORT (1 << 2)
-#define WG_INTERFACE_HAS_RTABLE (1 << 3)
-#define WG_INTERFACE_REPLACE_PEERS (1 << 4)
-#define WG_INTERFACE_DEVICE_HAS_JC (1 << 5)
+#define WG_INTERFACE_HAS_PUBLIC (1 << 0)
+#define WG_INTERFACE_HAS_PRIVATE (1 << 1)
+#define WG_INTERFACE_HAS_PORT (1 << 2)
+#define WG_INTERFACE_HAS_RTABLE (1 << 3)
+#define WG_INTERFACE_REPLACE_PEERS (1 << 4)
+#define WG_INTERFACE_DEVICE_HAS_JC (1 << 5)
#define WG_INTERFACE_DEVICE_HAS_JMIN (1 << 6)
#define WG_INTERFACE_DEVICE_HAS_JMAX (1 << 7)
-#define WG_INTERFACE_DEVICE_HAS_S1 (1 << 8)
-#define WG_INTERFACE_DEVICE_HAS_S2 (1 << 9)
-#define WG_INTERFACE_DEVICE_HAS_H1 (1 << 10)
-#define WG_INTERFACE_DEVICE_HAS_H2 (1 << 11)
-#define WG_INTERFACE_DEVICE_HAS_H3 (1 << 12)
-#define WG_INTERFACE_DEVICE_HAS_H4 (1 << 13)
+#define WG_INTERFACE_DEVICE_HAS_S1 (1 << 8)
+#define WG_INTERFACE_DEVICE_HAS_S2 (1 << 9)
+#define WG_INTERFACE_DEVICE_HAS_S3 (1 << 10)
+#define WG_INTERFACE_DEVICE_HAS_S4 (1 << 11)
+#define WG_INTERFACE_DEVICE_HAS_H1 (1 << 12)
+#define WG_INTERFACE_DEVICE_HAS_H2 (1 << 13)
+#define WG_INTERFACE_DEVICE_HAS_H3 (1 << 14)
+#define WG_INTERFACE_DEVICE_HAS_H4 (1 << 15)
+#define WG_INTERFACE_DEVICE_HAS_I1 (1 << 16)
+#define WG_INTERFACE_DEVICE_HAS_I2 (1 << 17)
+#define WG_INTERFACE_DEVICE_HAS_I3 (1 << 18)
+#define WG_INTERFACE_DEVICE_HAS_I4 (1 << 19)
+#define WG_INTERFACE_DEVICE_HAS_I5 (1 << 20)
+#define WG_INTERFACE_DEVICE_HAS_J1 (1 << 21)
+#define WG_INTERFACE_DEVICE_HAS_J2 (1 << 22)
+#define WG_INTERFACE_DEVICE_HAS_J3 (1 << 23)
+#define WG_INTERFACE_DEVICE_HAS_ITIME (1 << 24)
struct wg_interface_io {
uint16_t i_flags;
@@ -96,10 +107,22 @@ struct wg_interface_io {
uint16_t i_junk_packet_max_size;
uint16_t i_init_packet_junk_size;
uint16_t i_response_packet_junk_size;
+ uint16_t i_cookie_reply_packet_junk_size;
+ uint16_t i_transport_packet_junk_size;
uint32_t i_init_packet_magic_header;
uint32_t i_response_packet_magic_header;
uint32_t i_underload_packet_magic_header;
uint32_t i_transport_packet_magic_header;
+
+ uint8_t* i_i1;
+ uint8_t* i_i2;
+ uint8_t* i_i3;
+ uint8_t* i_i4;
+ uint8_t* i_i5;
+ uint8_t* i_j1;
+ uint8_t* i_j2;
+ uint8_t* i_j3;
+ uint32_t i_itime;
};
struct wg_data_io {
diff --git a/src/uapi/windows/wireguard.h b/src/uapi/windows/wireguard.h
index 917d785..a076b46 100644
--- a/src/uapi/windows/wireguard.h
+++ b/src/uapi/windows/wireguard.h
@@ -63,10 +63,21 @@ typedef enum
WG_IOCTL_INTERFACE_JMAX = 1 << 7,
WG_IOCTL_INTERFACE_S1 = 1 << 8,
WG_IOCTL_INTERFACE_S2 = 1 << 9,
- WG_IOCTL_INTERFACE_H1 = 1 << 10,
- WG_IOCTL_INTERFACE_H2 = 1 << 11,
- WG_IOCTL_INTERFACE_H3 = 1 << 12,
- WG_IOCTL_INTERFACE_H4 = 1 << 13
+ WG_IOCTL_INTERFACE_S3 = 1 << 10,
+ WG_IOCTL_INTERFACE_S4 = 1 << 11,
+ WG_IOCTL_INTERFACE_H1 = 1 << 12,
+ WG_IOCTL_INTERFACE_H2 = 1 << 12,
+ WG_IOCTL_INTERFACE_H3 = 1 << 13,
+ WG_IOCTL_INTERFACE_H4 = 1 << 14,
+ WG_IOCTL_INTERFACE_I1 = 1U << 15,
+ WG_IOCTL_INTERFACE_I2 = 1U << 16,
+ WG_IOCTL_INTERFACE_I3 = 1U << 17,
+ WG_IOCTL_INTERFACE_I4 = 1U << 18,
+ WG_IOCTL_INTERFACE_I5 = 1U << 19,
+ WG_IOCTL_INTERFACE_J1 = 1U << 20,
+ WG_IOCTL_INTERFACE_J2 = 1U << 21,
+ WG_IOCTL_INTERFACE_J3 = 1U << 22,
+ WG_IOCTL_INTERFACE_ITIME = 1U << 23
} WG_IOCTL_INTERFACE_FLAG;
typedef struct _WG_IOCTL_INTERFACE
@@ -81,10 +92,22 @@ typedef struct _WG_IOCTL_INTERFACE
USHORT JunkPacketMaxSize;
USHORT InitPacketJunkSize;
USHORT ResponsePacketJunkSize;
+ USHORT CookieReplyPacketJunkSize;
+ USHORT TransportPacketJunkSize;
ULONG InitPacketMagicHeader;
ULONG ResponsePacketMagicHeader;
ULONG UnderloadPacketMagicHeader;
ULONG TransportPacketMagicHeader;
+
+ UCHAR* I1;
+ UCHAR* I2;
+ UCHAR* I3;
+ UCHAR* I4;
+ UCHAR* I5;
+ UCHAR* J1;
+ UCHAR* J2;
+ UCHAR* J3;
+ ULONG Itime;
} __attribute__((aligned(8))) WG_IOCTL_INTERFACE;
#define WG_IOCTL_GET CTL_CODE(45208U, 321, METHOD_OUT_DIRECT, FILE_READ_DATA | FILE_WRITE_DATA)
diff --git a/src/wg-quick/android.c b/src/wg-quick/android.c
index 425a068..167c6d6 100644
--- a/src/wg-quick/android.c
+++ b/src/wg-quick/android.c
@@ -42,6 +42,7 @@ static bool is_exiting = false;
static bool binder_available = false;
static unsigned int sdk_version;
static bool is_asecurity_on = false;
+static bool is_special_handshake_on = false;
static void *xmalloc(size_t size)
{
@@ -633,7 +634,7 @@ static void auto_su(int argc, char *argv[])
static void add_if(const char *iface)
{
- if (is_asecurity_on)
+ if (is_asecurity_on || is_special_handshake_on)
cmd("amneziawg-go %s", iface);
else
cmd("ip link add %s type amneziawg", iface);
@@ -1278,6 +1279,24 @@ static void parse_options(char **iface, char **config, unsigned int *mtu, char *
is_asecurity_on = true;
} else if (!strncasecmp(clean, "H4=", 3) && j > 4) {
is_asecurity_on = true;
+ } else if (!strncasecmp(clean, "I1=", 3) && j > 4) {
+ is_special_handshake_on = true;
+ } else if (!strncasecmp(clean, "I2=", 3) && j > 4) {
+ is_special_handshake_on = true;
+ } else if (!strncasecmp(clean, "I3=", 3) && j > 4) {
+ is_special_handshake_on = true;
+ } else if (!strncasecmp(clean, "I4=", 3) && j > 4) {
+ is_special_handshake_on = true;
+ } else if (!strncasecmp(clean, "I5=", 3) && j > 4) {
+ is_special_handshake_on = true;
+ } else if (!strncasecmp(clean, "J1=", 3) && j > 4) {
+ is_special_handshake_on = true;
+ } else if (!strncasecmp(clean, "J2=", 3) && j > 4) {
+ is_special_handshake_on = true;
+ } else if (!strncasecmp(clean, "J3=", 3) && j > 4) {
+ is_special_handshake_on = true;
+ } else if (!strncasecmp(clean, "Itime=", 6) && j > 4) {
+ is_special_handshake_on = true;
}
}
*config = concat_and_free(*config, "", line);
@@ -1322,4 +1341,4 @@ int main(int argc, char *argv[])
return 1;
}
return 0;
-}
\ No newline at end of file
+}
diff --git a/src/wg.c b/src/wg.c
index 6480970..0431fce 100644
--- a/src/wg.c
+++ b/src/wg.c
@@ -42,7 +42,7 @@ int main(int argc, const char *argv[])
PROG_NAME = argv[0];
if (argc == 2 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version") || !strcmp(argv[1], "version"))) {
- printf("wireguard-tools v%s - https://git.zx2c4.com/wireguard-tools/\n", WIREGUARD_TOOLS_VERSION);
+ printf("amneziawg-tools v%s - https://amnezia.org\n", WIREGUARD_TOOLS_VERSION);
return 0;
}
if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") || !strcmp(argv[1], "help"))) {