Skip to content

Commit

Permalink
feat: introduce the wireguard experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
ainghazal committed Jun 23, 2024
1 parent f10bad6 commit 2252500
Show file tree
Hide file tree
Showing 7 changed files with 524 additions and 1 deletion.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Psiphon-Labs/psiphon-tunnel-core v1.0.11-0.20240424194431-3612a5a6fb4c
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/amnezia-vpn/amneziawg-go v0.2.8
github.com/apex/log v1.9.0
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5
github.com/cloudflare/circl v1.3.8
Expand Down Expand Up @@ -81,15 +82,17 @@ require (
github.com/segmentio/fasthash v1.0.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tevino/abool/v2 v2.1.0 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
gitlab.com/yawning/edwards25519-extra v0.0.0-20231005122941-2149dcafc266 // indirect
go.uber.org/mock v0.4.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/exp/typeparams v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gvisor.dev/gvisor v0.0.0-20230922204349-b3f36d574a7f // indirect
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 // indirect
)

require (
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjH
github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 h1:ez/4by2iGztzR4L0zgAOR8lTQK9VlyBVVd7G4omaOQs=
github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/amnezia-vpn/amneziawg-go v0.2.8 h1:J8PPx+hylx5nNZ5U1+ECFj9noGkcm2ThmSV9rBNDgy8=
github.com/amnezia-vpn/amneziawg-go v0.2.8/go.mod h1:12g0XRbFeGbpXvuCmBOV21YxLWSFnUFJnwgrzyHBUyk=
github.com/andybalholm/brotli v1.0.6 h1:Yf9fFpf49Zrxb9NlQaluyE92/+X7UVHlhMNJN2sxfOI=
github.com/andybalholm/brotli v1.0.6/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/apex/log v1.9.0 h1:FHtw/xuaM8AgmvDDTI9fiwoAL25Sq2cxojnZICUU8l0=
Expand Down Expand Up @@ -531,6 +533,8 @@ github.com/templexxx/cpu v0.1.0/go.mod h1:w7Tb+7qgcAlIyX4NhLuDKt78AHA5SzPmq0Wj6H
github.com/templexxx/xorsimd v0.4.1/go.mod h1:W+ffZz8jJMH2SXwuKu9WhygqBMbFnp14G2fqEr8qaNo=
github.com/templexxx/xorsimd v0.4.2 h1:ocZZ+Nvu65LGHmCLZ7OoCtg8Fx8jnHKK37SjvngUoVI=
github.com/templexxx/xorsimd v0.4.2/go.mod h1:HgwaPoDREdi6OnULpSfxhzaiiSUY4Fi3JPn1wpt28NI=
github.com/tevino/abool/v2 v2.1.0 h1:7w+Vf9f/5gmKT4m4qkayb33/92M+Um45F2BkHOR+L/c=
github.com/tevino/abool/v2 v2.1.0/go.mod h1:+Lmlqk6bHDWHqN1cbxqhwEAwMPXgc8I1SDEamtseuXY=
github.com/tj/assert v0.0.0-20171129193455-018094318fb0/go.mod h1:mZ9/Rh9oLWpLLDRpvE+3b7gP/C2YyLFYxNmcLnPTMe0=
github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk=
github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk=
Expand Down Expand Up @@ -757,6 +761,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 h1:B82qJJgjvYKsXS9jeunTOisW56dUokqW/FOteYJJ/yg=
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
Expand Down Expand Up @@ -800,6 +806,8 @@ 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-20230922204349-b3f36d574a7f h1:w4K7S8+VKrhX67mFdUymQUsGVbEElPCN0v7U0DoLpUw=
gvisor.dev/gvisor v0.0.0-20230922204349-b3f36d574a7f/go.mod h1:AVgIgHMwK63XvmAzWG9vLQ41YnVHN0du0tEC46fI7yY=
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 h1:TbRPT0HtzFP3Cno1zZo7yPzEEnfu8EjLfl6IU9VfqkQ=
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259/go.mod h1:AVgIgHMwK63XvmAzWG9vLQ41YnVHN0du0tEC46fI7yY=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
Expand Down
94 changes: 94 additions & 0 deletions internal/experiment/wireguard/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package wireguard

import (
"encoding/base64"
"encoding/hex"
)

// Config contains the experiment config.
//
// This contains all the settings that user can set to modify the behaviour
// of this experiment. By tagging these variables with `ooni:"..."`, we allow
// miniooni's -O flag to find them and set them.
type Config struct {
ConfigFile string `ooni:"Configuration file for the WireGuard experiment"`

// TODO(ainghzal): honor it
PublicTarget bool `ooni:"Treat the target endpoint as public data (if true, it will be included in the report)`

Verbose bool `ooni:"Use extra-verbose mode in wireguard logs"`

// Safe_XXX options are not sent to the backend for archival.
SafeRemote string `ooni:"Remote to connect to using WireGuard"`
SafePrivateKey string `ooni:"Private key to connect to remote"`
SafePublicKey string `ooni:"Public key of the remote"`
SafePresharedKey string `ooni:"Pre-shared key for authentication"`
SafeIP string `ooni:"Allocated IP for this peer"`

// Optional obfuscation parameters for AmneziaWG
Jc string `ooni:"jc"`
Jmin string `ooni:"jmin"`
Jmax string `ooni:"jmax"`
S1 string `ooni:"s1"`
S2 string `ooni:"s2"`
H1 string `ooni:"h1"`
H2 string `ooni:"h2"`
H3 string `ooni:"h3"`
H4 string `ooni:"h4"`
}

type options struct {
// common wireguard parameters
endpoint string
ip string
pubKey string
privKey string
presharedKey string
ns string

// parameters from AmneziaWG
// TODO(ainghazal: make these optional)
jc string
jmin string
jmax string
s1 string
s2 string
h1 string
h2 string
h3 string
h4 string
}

func getOptionsFromConfig(c Config) (options, error) {
o := options{}

pub, _ := base64.StdEncoding.DecodeString(c.SafePublicKey)
pubHex := hex.EncodeToString(pub)
o.pubKey = pubHex

priv, _ := base64.StdEncoding.DecodeString(c.SafePrivateKey)
privHex := hex.EncodeToString(priv)
o.privKey = privHex

psk, _ := base64.StdEncoding.DecodeString(c.SafePresharedKey)
pskHex := hex.EncodeToString(psk)
o.presharedKey = pskHex

o.ip = c.SafeIP

// TODO: reconcile this with Input if c.PublicTarget=true
o.endpoint = c.SafeRemote

o.jc = c.Jc
o.jmin = c.Jmin
o.jmax = c.Jmax
o.s1 = c.S1
o.s2 = c.S2
o.h1 = c.H1
o.h2 = c.H2
o.h3 = c.H3
o.h4 = c.H4

o.ns = defaultNameserver
return o, nil
}
27 changes: 27 additions & 0 deletions internal/experiment/wireguard/testkeys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package wireguard

// TestKeys contains the experiment's result.
//
// This is what will end up into the Measurement.TestKeys field
// when you run this experiment.
//
// In other words, the variables in this struct will be
// the specific results of this experiment.
type TestKeys struct {
Success bool `json:"success"`
Failure *string `json:"failure"`
NetworkEvents []*Event `json:"network_events"`
URLGet []*URLGetResult `json:"urlget"`
}

// URLGetResult is the result of fetching a URL via the wireguard tunnel,
// using the standard library.
type URLGetResult struct {
ByteCount int `json:"bytes,omitempty"`
Error string `json:"error,omitempty"`
Failure *string `json:"failure"`
StatusCode int `json:"status_code"`
T0 float64 `json:"t0"`
T float64 `json:"t"`
URL string `json:"url"`
}
Loading

0 comments on commit 2252500

Please sign in to comment.