Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
scratch.txt
.DS_Store
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,23 @@ ENV VPN_SERVICE_PROVIDER=pia \
WIREGUARD_ADDRESSES_SECRETFILE=/run/secrets/wireguard_addresses \
WIREGUARD_MTU= \
WIREGUARD_IMPLEMENTATION=auto \
# Wireguard AmneziaWG userspace obfuscation (requires WIREGUARD_IMPLEMENTATION=amneziawg)
WIREGUARD_JC= \
WIREGUARD_JMIN= \
WIREGUARD_JMAX= \
WIREGUARD_S1= \
WIREGUARD_S2= \
WIREGUARD_S3= \
WIREGUARD_S4= \
WIREGUARD_H1= \
WIREGUARD_H2= \
WIREGUARD_H3= \
WIREGUARD_H4= \
WIREGUARD_I1= \
WIREGUARD_I2= \
WIREGUARD_I3= \
WIREGUARD_I4= \
WIREGUARD_I5= \
Comment on lines +115 to +131
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to re-iterate on that, re-reading the code I think it's fine to have these changed to AMENZIAWG_XYZ as long as internal/configuration/sources/files/reader.go string cases are changed, please update to use AMNEZIAWG_ prefixes for the options 🙏 Thanks!

# PMTUD
PMTUD_ICMP_ADDRESSES=1.1.1.1,8.8.8.8 \
PMTUD_TCP_ADDRESSES=1.1.1.1:443,8.8.8.8:443,1.1.1.1:53,8.8.8.8:53,[2606:4700:4700::1111]:53,[2001:4860:4860::8888]:53,[2606:4700:4700::1111]:443,[2001:4860:4860::8888]:443 \
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.25.0

require (
github.com/ProtonMail/go-srp v0.0.7
github.com/amnezia-vpn/amneziawg-go v0.2.16
github.com/breml/rootcerts v0.3.4
github.com/fatih/color v1.18.0
github.com/golang/mock v1.6.0
Expand Down Expand Up @@ -59,7 +60,6 @@ require (
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/mod v0.31.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.40.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
google.golang.org/protobuf v1.35.1 // indirect
Expand Down
16 changes: 10 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/ProtonMail/go-crypto v1.3.0-proton h1:tAQKQRZX/73VmzK6yHSCaRUOvS/3OYS
github.com/ProtonMail/go-crypto v1.3.0-proton/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
github.com/ProtonMail/go-srp v0.0.7 h1:Sos3Qk+th4tQR64vsxGIxYpN3rdnG9Wf9K4ZloC1JrI=
github.com/ProtonMail/go-srp v0.0.7/go.mod h1:giCp+7qRnMIcCvI6V6U3S1lDDXDQYx2ewJ6F/9wdlJk=
github.com/amnezia-vpn/amneziawg-go v0.2.16 h1:XY6HOq/xtqH8ZXMncRWkjFs85EKdN10NLNnw23kTpE0=
github.com/amnezia-vpn/amneziawg-go v0.2.16/go.mod h1:nRkPpIzjCxMW8pZKXTRkpqAQVlmFJdVOGkeQSC7wbms=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/breml/rootcerts v0.3.4 h1:9i7WNl/ctd9OEAOaTfLy//Wrlfxq/tRQ7v4okYFN9Ys=
Expand All @@ -26,8 +28,8 @@ github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
Expand Down Expand Up @@ -103,6 +105,8 @@ github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqTosly
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
Expand Down Expand Up @@ -157,8 +161,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
Expand All @@ -184,8 +188,8 @@ gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 h1:TbRPT0HtzFP3Cno1zZo7yPzEEnfu8EjLfl6IU9VfqkQ=
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259/go.mod h1:AVgIgHMwK63XvmAzWG9vLQ41YnVHN0du0tEC46fI7yY=
gvisor.dev/gvisor v0.0.0-20231202080848-1f7806d17489 h1:ze1vwAdliUAr68RQ5NtufWaXaOg8WUO2OACzEV+TNdE=
gvisor.dev/gvisor v0.0.0-20231202080848-1f7806d17489/go.mod h1:10sU+Uh5KKNv1+2x2A0Gvzt8FjD3ASIhorV3YsauXhk=
kernel.org/pub/linux/libs/security/libcap/cap v1.2.70 h1:QnLPkuDWWbD5C+3DUA2IUXai5TK6w2zff+MAGccqdsw=
kernel.org/pub/linux/libs/security/libcap/cap v1.2.70/go.mod h1:/iBwcj9nbLejQitYvUm9caurITQ6WyNHibJk6Q9fiS4=
kernel.org/pub/linux/libs/security/libcap/psx v1.2.70 h1:HsB2G/rEQiYyo1bGoQqHZ/Bvd6x1rERQTNdPr1FyWjI=
Expand Down
133 changes: 133 additions & 0 deletions internal/configuration/settings/amneziawg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package settings

import (
"errors"
"fmt"

"github.com/qdm12/gosettings"
"github.com/qdm12/gotree"
)

type AmneziaWg struct {
JunkPacketCount uint16 `json:"junk_packet_count"`
JunkPacketMin uint16 `json:"junk_packet_min"`
JunkPacketMax uint16 `json:"junk_packet_max"`
PaddingS1 uint16 `json:"padding_s1"`
PaddingS2 uint16 `json:"padding_s2"`
PaddingS3 uint16 `json:"padding_s3"`
PaddingS4 uint16 `json:"padding_s4"`
HeaderH1 string `json:"header_h1"`
HeaderH2 string `json:"header_h2"`
HeaderH3 string `json:"header_h3"`
HeaderH4 string `json:"header_h4"`
InitPacketI1 string `json:"init_packet_i1"`
InitPacketI2 string `json:"init_packet_i2"`
InitPacketI3 string `json:"init_packet_i3"`
InitPacketI4 string `json:"init_packet_i4"`
InitPacketI5 string `json:"init_packet_i5"`
}

func (s AmneziaWg) copy() (copied AmneziaWg) {
copied.JunkPacketCount = s.JunkPacketCount
copied.JunkPacketMin = s.JunkPacketMin
copied.JunkPacketMax = s.JunkPacketMax
copied.PaddingS1 = s.PaddingS1
copied.PaddingS2 = s.PaddingS2
copied.PaddingS3 = s.PaddingS3
copied.PaddingS4 = s.PaddingS4
copied.HeaderH1 = s.HeaderH1
copied.HeaderH2 = s.HeaderH2
copied.HeaderH3 = s.HeaderH3
copied.HeaderH4 = s.HeaderH4
copied.InitPacketI1 = s.InitPacketI1
copied.InitPacketI2 = s.InitPacketI2
copied.InitPacketI3 = s.InitPacketI3
copied.InitPacketI4 = s.InitPacketI4
copied.InitPacketI5 = s.InitPacketI5
return copied
}

//nolint:dupl
func (s *AmneziaWg) overrideWith(other AmneziaWg) {
s.JunkPacketCount = gosettings.OverrideWithComparable(s.JunkPacketCount, other.JunkPacketCount)
s.JunkPacketMin = gosettings.OverrideWithComparable(s.JunkPacketMin, other.JunkPacketMin)
s.JunkPacketMax = gosettings.OverrideWithComparable(s.JunkPacketMax, other.JunkPacketMax)
s.PaddingS1 = gosettings.OverrideWithComparable(s.PaddingS1, other.PaddingS1)
s.PaddingS2 = gosettings.OverrideWithComparable(s.PaddingS2, other.PaddingS2)
s.PaddingS3 = gosettings.OverrideWithComparable(s.PaddingS3, other.PaddingS3)
s.PaddingS4 = gosettings.OverrideWithComparable(s.PaddingS4, other.PaddingS4)
s.HeaderH1 = gosettings.OverrideWithComparable(s.HeaderH1, other.HeaderH1)
s.HeaderH2 = gosettings.OverrideWithComparable(s.HeaderH2, other.HeaderH2)
s.HeaderH3 = gosettings.OverrideWithComparable(s.HeaderH3, other.HeaderH3)
s.HeaderH4 = gosettings.OverrideWithComparable(s.HeaderH4, other.HeaderH4)
s.InitPacketI1 = gosettings.OverrideWithComparable(s.InitPacketI1, other.InitPacketI1)
s.InitPacketI2 = gosettings.OverrideWithComparable(s.InitPacketI2, other.InitPacketI2)
s.InitPacketI3 = gosettings.OverrideWithComparable(s.InitPacketI3, other.InitPacketI3)
s.InitPacketI4 = gosettings.OverrideWithComparable(s.InitPacketI4, other.InitPacketI4)
s.InitPacketI5 = gosettings.OverrideWithComparable(s.InitPacketI5, other.InitPacketI5)
}

func (s AmneziaWg) toLinesNode() (node *gotree.Node) {
node = gotree.New("Amneziawg parameters:")

uintFields := []struct {
key string
val uint16
}{
{"jc", s.JunkPacketCount},
{"jmin", s.JunkPacketMin},
{"jmax", s.JunkPacketMax},
{"s1", s.PaddingS1},
{"s2", s.PaddingS2},
{"s3", s.PaddingS3},
{"s4", s.PaddingS4},
}
for _, f := range uintFields {
if f.val != 0 {
node.Appendf("%s: %d", f.key, f.val)
}
}
stringFields := []struct {
key string
val string
}{
{"h1", s.HeaderH1},
{"h2", s.HeaderH2},
{"h3", s.HeaderH3},
{"h4", s.HeaderH4},
{"i1", s.InitPacketI1},
{"i2", s.InitPacketI2},
{"i3", s.InitPacketI3},
{"i4", s.InitPacketI4},
{"i5", s.InitPacketI5},
}
for _, f := range stringFields {
if f.val != "" {
node.Appendf("%s: %s", f.key, f.val)
}
}

return node
}

var (
ErrJunkPacketBounds = errors.New("junk packet minimum must be lower than or equal to maximum")
ErrJunkPacketMinMaxNotSet = errors.New("junk packet min and max must be set when junk packet count is set")
ErrJunkPacketCountNotSet = errors.New("junk packet count must be set when junk packet min or max is set")
)

func (s AmneziaWg) validate() error {
switch {
case s.JunkPacketMax != 0 && s.JunkPacketMin > s.JunkPacketMax:
return fmt.Errorf("%w: jmin=%d and jmax=%d",
ErrJunkPacketBounds, s.JunkPacketMin, s.JunkPacketMax)
case s.JunkPacketCount == 0 && (s.JunkPacketMin != 0 || s.JunkPacketMax != 0):
return fmt.Errorf("%w: jc=%d and jmin=%d and jmax=%d",
ErrJunkPacketCountNotSet, s.JunkPacketCount, s.JunkPacketMin, s.JunkPacketMax)
case s.JunkPacketCount != 0 && (s.JunkPacketMin == 0 || s.JunkPacketMax == 0):
return fmt.Errorf("%w: jc=%d and jmin=%d and jmax=%d",
ErrJunkPacketMinMaxNotSet, s.JunkPacketCount, s.JunkPacketMin, s.JunkPacketMax)
}

return nil
}
2 changes: 2 additions & 0 deletions internal/configuration/settings/openvpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ func (o *OpenVPN) copy() (copied OpenVPN) {
// overrideWith overrides fields of the receiver
// settings object with any field set in the other
// settings.
//
//nolint:dupl
func (o *OpenVPN) overrideWith(other OpenVPN) {
o.Version = gosettings.OverrideWithComparable(o.Version, other.Version)
o.User = gosettings.OverrideWithPointer(o.User, other.User)
Expand Down
64 changes: 61 additions & 3 deletions internal/configuration/settings/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ type Wireguard struct {
// 0 indicating to use PMTUD.
MTU *uint32 `json:"mtu"`
// Implementation is the Wireguard implementation to use.
// It can be "auto", "userspace" or "kernelspace".
// It can be "auto", "userspace", "kernelspace" or "amneziawg".
// It defaults to "auto" and cannot be the empty string
// in the internal state.
Implementation string `json:"implementation"`
// AmneziaWG contains obfuscation parameters
AmneziaWG AmneziaWg `json:"amneziawg"`
}

var regexpInterfaceName = regexp.MustCompile(`^[a-zA-Z0-9_]+$`)
Expand Down Expand Up @@ -136,11 +138,16 @@ func (w Wireguard) validate(vpnProvider string, ipv6Supported bool) (err error)
ErrWireguardInterfaceNotValid, w.Interface, regexpInterfaceName)
}

validImplementations := []string{"auto", "userspace", "kernelspace"}
validImplementations := []string{"auto", "userspace", "kernelspace", "amneziawg"}
if err := validate.IsOneOf(w.Implementation, validImplementations...); err != nil {
return fmt.Errorf("%w: %w", ErrWireguardImplementationNotValid, err)
}

err = w.AmneziaWG.validate()
if err != nil {
return fmt.Errorf("amneziawg settings: %w", err)
}

return nil
}

Expand All @@ -154,6 +161,7 @@ func (w *Wireguard) copy() (copied Wireguard) {
Interface: w.Interface,
MTU: w.MTU,
Implementation: w.Implementation,
AmneziaWG: w.AmneziaWG.copy(),
}
}

Expand All @@ -167,6 +175,7 @@ func (w *Wireguard) overrideWith(other Wireguard) {
w.Interface = gosettings.OverrideWithComparable(w.Interface, other.Interface)
w.MTU = gosettings.OverrideWithComparable(w.MTU, other.MTU)
w.Implementation = gosettings.OverrideWithComparable(w.Implementation, other.Implementation)
w.AmneziaWG.overrideWith(other.AmneziaWG)
}

func (w *Wireguard) setDefaults(vpnProvider string) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should set defaults to the amnesiawg config (maybe 0?). The invalid value (0 or nil for uint16 fields) cannot stay "invalid" after the setDefaults call

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll set them as zero

Copy link
Owner

@qdm12 qdm12 Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sorry to reconsider this again) there is a use case for the zero value 0/"": for example someone may want to set J1=1 but leave J2=0.


if the default is 0 and is a valid value, we need these fields as pointers to uint16 so their "Go default" is nil, to distinguish between the default value (0) and the unset value (nil).
Same for the string values, if their default is "", then we want them as string pointers too.

Then you need to:

  • explicitely set these fields to their default (0, "") in a new function func (s *AmneziaWg) setDefaults() that call from func (w *Wireguard) setDefaults(vpnProvider string) - you can use gosettings.DefaultPointer
  • copy these fields using in the func (s AmneziaWg) copy() (copied AmneziaWg) using gosettings.CopyPointer(x)
  • override these fields in the func (s *AmneziaWg) overrideWith(other AmneziaWg) using gosettings.OverrideWithPointer(a, b)
  • in func (s *AmneziaWg) toLinesNode and func (s *AmneziaWg) validate, you don't need to add nil checks, you can assume all fields are set (to their defaults or user specified values) when calling these functions, so directly dereference them i.e. *s.JunckPacketCount
  • in func (s *AmneziaWg) toLinesNode(), remove the f.val != 0 and f.val != "" checks; both are valid default values and should be logged out.

Expand Down Expand Up @@ -232,7 +241,11 @@ func (w Wireguard) toLinesNode() (node *gotree.Node) {
}

if w.Implementation != "auto" {
node.Appendf("Implementation: %s", w.Implementation)
implNode := node.Appendf("Implementation: %s", w.Implementation)

if w.Implementation == "amneziawg" {
implNode.AppendNode(w.AmneziaWG.toLinesNode())
}
}

return node
Expand All @@ -245,6 +258,51 @@ func (w *Wireguard) read(r *reader.Reader) (err error) {
reader.RetroKeys("WIREGUARD_INTERFACE"), reader.ForceLowercase(false))
w.Implementation = r.String("WIREGUARD_IMPLEMENTATION")

w.AmneziaWG.JunkPacketCount, err = r.Uint16("WIREGUARD_JC")
if err != nil {
return err
}

w.AmneziaWG.JunkPacketMin, err = r.Uint16("WIREGUARD_JMIN")
if err != nil {
return err
}

w.AmneziaWG.JunkPacketMax, err = r.Uint16("WIREGUARD_JMAX")
if err != nil {
return err
}

w.AmneziaWG.PaddingS1, err = r.Uint16("WIREGUARD_S1")
if err != nil {
return err
}

w.AmneziaWG.PaddingS2, err = r.Uint16("WIREGUARD_S2")
if err != nil {
return err
}

w.AmneziaWG.PaddingS3, err = r.Uint16("WIREGUARD_S3")
if err != nil {
return err
}

w.AmneziaWG.PaddingS4, err = r.Uint16("WIREGUARD_S4")
if err != nil {
return err
}

w.AmneziaWG.HeaderH1 = r.String("WIREGUARD_H1", reader.ForceLowercase(false))
w.AmneziaWG.HeaderH2 = r.String("WIREGUARD_H2", reader.ForceLowercase(false))
w.AmneziaWG.HeaderH3 = r.String("WIREGUARD_H3", reader.ForceLowercase(false))
w.AmneziaWG.HeaderH4 = r.String("WIREGUARD_H4", reader.ForceLowercase(false))
w.AmneziaWG.InitPacketI1 = r.String("WIREGUARD_I1", reader.ForceLowercase(false))
w.AmneziaWG.InitPacketI2 = r.String("WIREGUARD_I2", reader.ForceLowercase(false))
w.AmneziaWG.InitPacketI3 = r.String("WIREGUARD_I3", reader.ForceLowercase(false))
w.AmneziaWG.InitPacketI4 = r.String("WIREGUARD_I4", reader.ForceLowercase(false))
w.AmneziaWG.InitPacketI5 = r.String("WIREGUARD_I5", reader.ForceLowercase(false))
Comment on lines +261 to +304
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move these to amneziawg.go as its own func (s *AmneziaWg) read(r *reader.Reader) (err error) which would then be called from func (w *Wireguard) read(r *reader.Reader) (err error). You can also for loop these with a map[string]*string and map[string]*uint16 I think


addressStrings := r.CSV("WIREGUARD_ADDRESSES", reader.RetroKeys("WIREGUARD_ADDRESS"))
// WARNING: do not initialize w.Addresses to an empty slice
// or the defaults for nordvpn will not work.
Expand Down
32 changes: 32 additions & 0 deletions internal/configuration/sources/files/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,38 @@ func (s *Source) Get(key string) (value string, isSet bool) {
return strPtrToStringIsSet(s.lazyLoadWireguardConf().EndpointIP)
case "wireguard_endpoint_port":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().EndpointPort)
case "wireguard_jc":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.Jc)
case "wireguard_jmin":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.Jmin)
case "wireguard_jmax":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.Jmax)
case "wireguard_s1":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.S1)
case "wireguard_s2":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.S2)
case "wireguard_s3":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.S3)
case "wireguard_s4":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.S4)
case "wireguard_h1":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.H1)
case "wireguard_h2":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.H2)
case "wireguard_h3":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.H3)
case "wireguard_h4":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.H4)
case "wireguard_i1":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.I1)
case "wireguard_i2":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.I2)
case "wireguard_i3":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.I3)
case "wireguard_i4":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.I4)
case "wireguard_i5":
return strPtrToStringIsSet(s.lazyLoadWireguardConf().AmneziaParams.I5)
}

value, isSet, err := ReadFromFile(path)
Expand Down
Loading