Documentation
¶
Overview ¶
Package awg is the panel half of the AmneziaWG protocol plugin: the settings schema, a validator stricter than both implementations, the obfuscation generator with its mimicry presets, the translation of a profile into a node-side inbound, the per-device X25519 credentials and the three client formats (.conf, vpn://, Mihomo proxy).
One profile is one interface on one UDP port with one protocol version. A device is a peer bound to ONE profile and valid on every inbound of that profile; the server key is per inbound (InitInbound).
Index ¶
- Constants
- func MaxPeerIndex(raw json.RawMessage) (int, error)
- func PeerAddrs(raw json.RawMessage, idx int) (v4 netip.Addr, v6 netip.Addr, err error)
- func PickDNS(servers []string) (pair [2]string, fallback bool)
- func PresetVaries(preset string) bool
- func RUDirectAllowedIPs() []string
- func RandomPort() (int, error)
- func SubnetsFor(n int) (v4, v6 string, err error)
- type ClientTunnel
- type NodeData
- type NodeObfuscation
- type NodeSettings
- type Obfuscation
- type Protocol
- func (*Protocol) BuildInbound(in protocols.InboundInput) (plugin.InboundSpec, error)
- func (*Protocol) Clients() []plugin.ClientSupport
- func (*Protocol) DefaultSettings() (json.RawMessage, error)
- func (*Protocol) DisplayName() string
- func (*Protocol) Doctor() []protocols.Check
- func (*Protocol) ID() string
- func (*Protocol) InitInbound(protocols.InboundInitInput) (protocols.InboundInit, error)
- func (*Protocol) IssueCredential(in protocols.IssueInput) (protocols.Issued, error)
- func (*Protocol) MinClients(raw json.RawMessage) []protocols.ClientReq
- func (*Protocol) NormalizeSettings(in protocols.NormalizeInput) (json.RawMessage, error)
- func (*Protocol) PerDevice() bool
- func (*Protocol) Render(in protocols.RenderInput) (plugin.Fragment, bool)
- func (*Protocol) SettingsSchema() []byte
- func (*Protocol) Summary(raw json.RawMessage) string
- func (*Protocol) Validate(raw json.RawMessage) []protocols.FieldError
- type Score
- type ScoreItem
- type Settings
- type Warning
Constants ¶
const ( TierHeaderProtection = "header_protection" // 3.1 with a header protection key: the headers are encrypted TierRanges = "ranges" // no key, H ranges: AmneziaWG 2.0 TierCPS = "cps" // no key, H singles, a signature packet: AmneziaWG 1.5 TierHeaders = "headers" // no key, junk and padding only: AmneziaWG 1.0 TierWireGuard = "wireguard" // nothing hidden )
Tiers, from the strongest.
const ( Version31 = "3.1" Version20 = "2.0" )
Protocol versions of a profile. 3.0 is 3.1 without RandomTrailers and is not offered: Amnezia itself calls everything 3.x "3.1".
const ID = "awg"
ID is the plugin id.
const RUDirectVersion = "2026-11-24"
The "Russian services direct" key: the .conf and the vpn:// key of such a device carry AllowedIPs = the whole IPv4 world minus the networks below, so the traffic to those services leaves around the tunnel and they never see the node's address. AmneziaVPN overwrites its own split-tunnelling fields from the app's settings before every connect, so AllowedIPs is the one thing a key can carry. A key holds about 1 400 entries; phones start failing near 2 400 (amnezia-client #2976, #3207), which is why the list is networks of companies, not "all of Russia" (13 000 networks, 32 000 entries).
RUDirectVersion is the date of the list. Change it with the list: the keys of the devices that hold another version are then called "needs a new key" (access.markDNSStale), the ordinary keys are not touched.
How to rebuild the list (the sources are public routing data):
- ranges of the big services' own sites: resolve their domains, take the range of the routing table that holds each answer (the first study: 94 networks);
- add every IPv4 prefix the RIPEstat call announced-prefixes returns for AS13238 (Yandex), AS47541 (VK), AS47764 (Mail.ru);
- the checking host of Yandex, ipv4-internet.yandex.net (5.45.196.64), must be inside the result: with the first study alone it was not, and the node's address showed on yandex.ru/internet.
The networks are merged and complemented below (complement4); the property test pins what the result must and must not cover.
const RouteRUDirect = "ru-direct"
RouteRUDirect is the value of a device's route (store: device.awg_route) for this key; "" is the ordinary key.
Variables ¶
This section is empty.
Functions ¶
func MaxPeerIndex ¶
func MaxPeerIndex(raw json.RawMessage) (int, error)
MaxPeerIndex is the largest peer index the client network of the settings holds: the network and broadcast addresses and the node's .1 are not peers, so indexes run 2..size-2. A /22 holds 1021 peers.
func PeerAddrs ¶
PeerAddrs returns the client addresses of peer index idx in the profile's networks (IPv4 always, IPv6 when the profile has a network for it); the node is .1 of each.
func PickDNS ¶
PickDNS returns the two plain IPv4 servers an AWG client carries (AmneziaVPN reads exactly two IPv4 addresses): the first two usable entries of servers, a single one repeated, the built-in pair when none is usable. fallback reports the last case so the caller can warn (dns_fallback).
func PresetVaries ¶
PresetVaries: the chain of the preset depends on the rng, so per-device signatures give every device another one. The other presets are the same I1..I5 whatever the seed (all their randomness is in tags): per-device signatures do nothing for them, and the score does not count them. awg_test.go checks this list against the generator.
func RUDirectAllowedIPs ¶
func RUDirectAllowedIPs() []string
RUDirectAllowedIPs is the AllowedIPs of a "Russian services direct" key: every IPv4 address but those of the services, as the fewest networks (the list is the same for every key; the caller must not change it).
func RandomPort ¶
RandomPort is the "random" button next to the port field: 10000-60000 without knownPorts.
func SubnetsFor ¶
SubnetsFor returns the client networks of the n-th profile slot (0-63): 10.66.(4n).0/22 and fd66:66:0:n::/64. 10.66.0.0/16 holds 64 of them. access picks the first n no other profile uses.
Types ¶
type ClientTunnel ¶
type ClientTunnel struct {
IPC string // device.IpcSet text of amneziawg-go: key, obfuscation and the one peer with its endpoint
Addrs []netip.Addr // the device's tunnel addresses, IPv4 first
DNS []netip.Addr // the pair a real config of this profile carries (PickDNS)
MTU int
Server [32]byte // the node's public key: how the peer is found in IpcGet
}
ClientTunnel is what an in-process AmneziaWG client (the health module's synthetic checker) needs to join one inbound as the device that RenderInput describes. It is written from the same clientConfig as the .conf, the vpn:// key and the Mihomo proxy, so the checker cannot be configured differently from a real device: the same obfuscation, the same per-device signature, the same keys, the same keepalive.
func ClientDevice ¶
func ClientDevice(in protocols.RenderInput) (ClientTunnel, error)
ClientDevice turns a RenderInput into a ClientTunnel. in.NodeAddr must be an IP literal here: the UAPI endpoint takes no host name, so the caller resolves it. A masked (preview) input has no secrets and is refused.
type NodeData ¶
type NodeData struct {
PublicKey string `json:"public_key"`
AllowedIPs []string `json:"allowed_ips"`
PSK string `json:"psk"`
}
NodeData is Issued.NodeData, the verifier shipped to nodes (UserCred.Data). No private key.
type NodeObfuscation ¶
type NodeObfuscation struct {
Jc int `json:"jc"`
Jmin int `json:"jmin"`
Jmax int `json:"jmax"`
S1 int `json:"s1"`
S2 int `json:"s2"`
S3 int `json:"s3"`
S4 int `json:"s4"`
H1 string `json:"h1"`
H2 string `json:"h2"`
H3 string `json:"h3"`
H4 string `json:"h4"`
HeaderProtectionKey string `json:"header_protection_key,omitempty"`
RandomTrailers bool `json:"random_trailers,omitempty"`
DisableCookies bool `json:"disable_cookies,omitempty"`
ContentPaddingAddition string `json:"content_padding_addition,omitempty"`
RekeyAfterTime string `json:"rekey_after_time,omitempty"`
RekeyTimeout string `json:"rekey_timeout,omitempty"`
RejectAfterTime string `json:"reject_after_time,omitempty"`
KeepaliveTimeout string `json:"keepalive_timeout,omitempty"`
MaxHandshakeAttempts string `json:"max_handshake_attempts,omitempty"`
}
NodeObfuscation is the "obfuscation" object of NodeSettings. The node reads the document as awgcfg.Settings, which keeps these fields under "obfuscation": a flat document makes every inbound fail with /obfuscation/h1: required.
type NodeSettings ¶
type NodeSettings struct {
Version string `json:"version"`
PrivateKey string `json:"private_key"`
Obfuscation NodeObfuscation `json:"obfuscation"`
}
NodeSettings is the JSON the node engine receives in InboundSpec.Settings: the profile settings without what became first-class fields (port, mtu, egress, subnets), without the client-only I1..I5, preset and persistent keepalive, plus the server key of this inbound. Field order and omitempty are part of the contract: the bytes feed the state hash.
type Obfuscation ¶
type Obfuscation struct {
Preset string `json:"preset"` // quic|dns|stun|...|custom: the generator's input and a label in the UI
Jc int `json:"jc"` // client
Jmin int `json:"jmin"` // client
Jmax int `json:"jmax"` // client
S1 int `json:"s1"`
S2 int `json:"s2"`
S3 int `json:"s3"`
S4 int `json:"s4"`
H1 string `json:"h1"`
H2 string `json:"h2"`
H3 string `json:"h3"`
H4 string `json:"h4"`
I1 string `json:"i1"` // client
I2 string `json:"i2"` // client
I3 string `json:"i3"` // client
I4 string `json:"i4"` // client
I5 string `json:"i5"` // client
HeaderProtectionKey string `json:"header_protection_key"` // 3.1, secret
RandomTrailers bool `json:"random_trailers"` // 3.1
DisableCookies bool `json:"disable_cookies"` // 3.1, node side only
ContentPaddingAddition string `json:"content_padding_addition"` // 3.1, ranges
RekeyAfterTime string `json:"rekey_after_time"` // 3.1
RekeyTimeout string `json:"rekey_timeout"` // 3.1
RejectAfterTime string `json:"reject_after_time"` // 3.1
KeepaliveTimeout string `json:"keepalive_timeout"` // 3.1
MaxHandshakeAttempts string `json:"max_handshake_attempts"` // 3.1
PersistentKeepalive string `json:"persistent_keepalive"` // client [Peer]; 2.0: a single number
// Where I1..I5 come from. All three are client only and never reach the node. A profile stored before they
// existed has them zero: per-device signatures off, the profile's I1..I5 for everyone.
Domain string `json:"domain"` // host name in the packets (UsesDomain presets); "" = one from the pool
PerDeviceSignature bool `json:"per_device_signature"` // every device gets its own I1..I5, drawn from SignatureSeed and its id
SignatureSeed string `json:"signature_seed"` // random, not a secret: it only makes the per-device chains reproducible
}
Obfuscation is the `obfuscation` object of the settings. The fields marked client are only written into client configs (the node never initiates a handshake); the rest the node needs as well.
func GenerateObfuscation ¶
func GenerateObfuscation(version, preset string, mtu int, domain string) (Obfuscation, error)
GenerateObfuscation returns a complete, valid `obfuscation` object for a version and a mimicry preset: what the editor's "Generate" button fills in. mtu bounds Jmax (the junk must stay below the MTU) and S4 (the data packet must fit 1500 with its headers, see maxS4). domain is the host name of the UsesDomain presets, "" draws one from the pool. The header protection key and the signature seed always come from crypto/rand.
func GenerateObfuscationSeeded ¶
func GenerateObfuscationSeeded(version, preset string, mtu int, seed uint64, domain string) (Obfuscation, error)
GenerateObfuscationSeeded is GenerateObfuscation with a fixed seed, for tests and goldens. NEVER for a real profile: its header protection key comes from the seed, not from crypto/rand.
func GenerateSignature ¶
func GenerateSignature(preset, domain string) (Obfuscation, error)
GenerateSignature is the "pick a mimicry card" call: a fresh Preset, Domain and I1..I5 and nothing else, so nothing the peers must agree on changes and no issued config goes stale. The preset must have a generator.
type Protocol ¶
type Protocol struct{}
Protocol implements protocols.Protocol and the optional InboundInitializer, PerDevice and ClientRequirements.
func (*Protocol) BuildInbound ¶
func (*Protocol) BuildInbound(in protocols.InboundInput) (plugin.InboundSpec, error)
BuildInbound lifts port, egress and the tunnel (node address and MTU) out of the settings; the rest goes to the node as NodeSettings together with the server private key of this inbound. The caller sets InboundSpec.ID.
func (*Protocol) Clients ¶
func (*Protocol) Clients() []plugin.ClientSupport
Clients: the Amnezia apps take vpn:// and .conf, Mihomo-based apps the YAML proxy. Happ cannot carry AWG and is deliberately absent; the minimum versions depend on the profile (MinClients).
func (*Protocol) DefaultSettings ¶
func (*Protocol) DefaultSettings() (json.RawMessage, error)
DefaultSettings implements protocols.Protocol: a fresh 3.1 profile with everything random and the secret generated. Port: random in 10000-60000 without knownPorts (the WireGuard and Amnezia defaults, the first ports a scanner tries). Networks: the first slot (SubnetsFor(1)). access keeps networks a create request names; for one it leaves out it picks the first slot no other profile uses, so the editor drops them from a new profile. Per-device signatures are on: a new profile has no devices to surprise.
func (*Protocol) DisplayName ¶
func (*Protocol) InitInbound ¶
func (*Protocol) InitInbound(protocols.InboundInitInput) (protocols.InboundInit, error)
InitInbound makes the server key pair of one inbound (a hacked node must not give away the others). State is the private key in base64, Public is {"public_key": ...}.
func (*Protocol) IssueCredential ¶
IssueCredential makes the keys and the addresses of one device on one profile: X25519 key pair and a pre-shared key, addresses from the profile's networks by peer index. Secret (vault-sealed by the caller) keeps the private key, the PSK and the addresses; NodeData is what the nodes get and has no private key.
func (*Protocol) MinClients ¶
func (*Protocol) MinClients(raw json.RawMessage) []protocols.ClientReq
MinClients implements protocols.ClientRequirements. Unparsable settings give the 3.1 list, the stricter one.
func (*Protocol) NormalizeSettings ¶
func (*Protocol) NormalizeSettings(in protocols.NormalizeInput) (json.RawMessage, error)
NormalizeSettings makes sure the schema defaults never become a live config. The form shows the schema's fixed values (H1-H4 = 1..4, S = 24); the values worth storing are the generated ones, which differ for every profile. So, when the result is stored:
- a profile created, or moved to another version, WITHOUT an obfuscation block gets a generated one for its version (a create without a block and without a version is DefaultSettings already);
- a block that is there is the owner's choice, whatever its values: an import of an existing client's S1-S4 and H1-H4 must reach the server as written, even when the headers are the plain WireGuard 1, 2, 3, 4. The validator only warns (h_default_v20).
The owner's own choices survive the new block: preset, domain, per-device signatures and seed, and the chain of a custom preset. Always, stored or previewed: a seed is made when per-device signatures are on without one, and a domain is brought to its normal form. Anything it cannot fix (an invalid domain, a bad MTU) is left for the validator to report.
func (*Protocol) PerDevice ¶
PerDevice: a credential belongs to one profile and is issued on request, not for every device.
func (*Protocol) SettingsSchema ¶
func (*Protocol) Summary ¶
func (*Protocol) Summary(raw json.RawMessage) string
Summary: "UDP 51842 · AWG 3.1 · QUIC".
func (*Protocol) Validate ¶
func (*Protocol) Validate(raw json.RawMessage) []protocols.FieldError
Validate implements protocols.Protocol.
type Score ¶
Score is the result. Value = clamp(Base + the Items' Deltas, 0, 100).
func ScoreSettings ¶
func ScoreSettings(raw json.RawMessage) (Score, bool)
ScoreSettings scores a settings document; false when it does not parse or is not valid (nothing to rate).
type Settings ¶
type Settings struct {
Version string `json:"version"`
Port int `json:"port"`
MTU int `json:"mtu"`
Egress string `json:"egress"` // direct | warp
Subnet4 string `json:"subnet4"`
Subnet6 string `json:"subnet6"` // "" = no IPv6 inside the tunnel
Obfuscation Obfuscation `json:"obfuscation"`
}
Settings is the merged profile settings document (the secret, header_protection_key, in place). JSON names are the schema property names; the schema test keeps the two in step.
type Warning ¶
Warning is a legal setting that deserves a remark in the editor; Code is stable, the UI owns the text. Params carry the numbers the text needs (mtu_headroom: suggested_mtu).
func Warnings ¶
func Warnings(raw json.RawMessage) []Warning
Warnings lists the remarks for valid settings. Invalid settings give none.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mimicry builds and checks the I1..I5 "custom protocol signature" packets of AmneziaWG 2.0/3.x.
|
Package mimicry builds and checks the I1..I5 "custom protocol signature" packets of AmneziaWG 2.0/3.x. |
|
Package vpnkey encodes and decodes the vpn:// connection key of AmneziaVPN.
|
Package vpnkey encodes and decodes the vpn:// connection key of AmneziaVPN. |