Documentation
¶
Overview ¶
Package awgcfg is the pure data model of an AmneziaWG interface shared by the node engine, the wire clients (awgnl, awguapi) and the panel plugin: settings JSON, the strict validator and the peer types. It has no dependencies and no OS-specific code, so the panel can import it too.
Index ¶
Constants ¶
const ( Version20 = "2.0" Version31 = "3.1" )
Versions of the protocol a profile can speak.
Variables ¶
This section is empty.
Functions ¶
func CheckCPS ¶
CheckCPS validates one custom packet (an I1..I5 value) and returns its size in bytes. The grammar is the intersection of what amneziawg-go, the kernel module and the clients accept: a chain of <b 0xHEX> <r N> <rc N> <rd N> <t> with nothing between the tags, N in 1..1000, hex non-empty and even, at most one <t>. <c> is refused (only the module knows it, clients reject the config) and so is '#' (the comment character of .conf files).
Types ¶
type Issue ¶
type Issue struct {
Pointer string
Code string // stable snake_case id
Message string // short English fact
}
Issue is one finding of Validate. Pointer is a JSON pointer into the profile ("/obfuscation/s1").
type Obfuscation ¶
type Obfuscation struct {
Preset string `json:"preset,omitempty"` // panel only: input of the generator, label in the UI
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 Range `json:"h1"`
H2 Range `json:"h2"`
H3 Range `json:"h3"`
H4 Range `json:"h4"`
I1 string `json:"i1,omitempty"` // client side only
I2 string `json:"i2,omitempty"`
I3 string `json:"i3,omitempty"`
I4 string `json:"i4,omitempty"`
I5 string `json:"i5,omitempty"`
HeaderProtectionKey string `json:"header_protection_key,omitempty"` // base64, 32 bytes; 3.1 only; a secret
RandomTrailers bool `json:"random_trailers,omitempty"` // 3.1 only
DisableCookies bool `json:"disable_cookies,omitempty"` // 3.1 only, server side only
ContentPaddingAddition Range `json:"content_padding_addition,omitzero"` // 3.1
RekeyAfterTime Range `json:"rekey_after_time,omitzero"` // 3.1
RekeyTimeout Range `json:"rekey_timeout,omitzero"` // 3.1
RejectAfterTime Range `json:"reject_after_time,omitzero"` // 3.1
KeepaliveTimeout Range `json:"keepalive_timeout,omitzero"` // 3.1
MaxHandshakeAttempts Range `json:"max_handshake_attempts,omitzero"` // 3.1
PersistentKeepalive Range `json:"persistent_keepalive,omitzero"` // client [Peer] only
}
Obfuscation is the "obfuscation" object of a profile. Field order is the order the node JSON is serialized in (it is hashed). Client-only fields (i1..i5, preset, persistent_keepalive) are part of the type because the panel uses it too; the node ignores what it does not need.
func (Obfuscation) HPK ¶
func (o Obfuscation) HPK() (key *[32]byte, ok bool)
HPK decodes the header protection key: nil when unset, ok=false when malformed.
func (Obfuscation) Timers ¶
func (o Obfuscation) Timers() [6]Range
Timers returns the six 3.1 range fields in the order: content_padding_addition, rekey_after_time, rekey_timeout, reject_after_time, keepalive_timeout, max_handshake_attempts.
type Options ¶
type Options struct {
MTU int // tunnel MTU: enables the jmax >= mtu and mtu > 1280 warnings
}
Options are the facts outside Settings that some rules need. Zero values skip the rule.
type Peer ¶
type Peer struct {
PublicKey [32]byte
PSK *[32]byte
AllowedIPs []netip.Prefix
Endpoint string // "host:port", client side only
Keepalive Range // client side only
Remove bool // the session dies at once; re-adding costs the client up to ~15 s
UpdateOnly bool // never creates a peer: the safe way to change a live one
ReplaceIPs bool // replace the allowed ips instead of adding
}
Peer is one peer operation for a backend or a wire client. Endpoint and Keepalive are for the client side (tests; the engine never sets them on a server: a server that sets keepalive starts initiating handshakes).
type PeerStat ¶
type PeerStat struct {
PublicKey [32]byte
RxBytes uint64 // client -> node (plugin.UserTraffic.Up)
TxBytes uint64 // node -> client (plugin.UserTraffic.Down)
LastHS time.Time // zero = never
Endpoint netip.AddrPort
AllowedIPs []netip.Prefix
}
PeerStat is one peer as a device reports it.
type Range ¶
type Range struct {
Lo, Hi uint32
// contains filtered or unexported fields
}
Range is an "n" or "lo-hi" value. The zero value means "unset". In JSON it is a string; a bare number and "" are accepted on input.
func ParseRange ¶
ParseRange parses "n" or "lo-hi" (both ends uint32); "" is the zero Range.
func (Range) MarshalJSON ¶
func (Range) String ¶
String renders "n" or "lo-hi" (what UAPI and .conf files take); callers skip zero ranges.
func (*Range) UnmarshalJSON ¶
type Result ¶
Result is what Validate found. Errors make the profile unusable; Warnings do not.
type Settings ¶
type Settings struct {
Version string `json:"version"`
PrivateKey string `json:"private_key,omitempty"` // base64; the inbound's server key, a secret; node JSON only
Obfuscation Obfuscation `json:"obfuscation"`
}
Settings is the settings_json of an awg inbound (and, with the client-only fields, of the profile). Port, mtu, egress and the subnets are first-class InboundSpec fields (listen, tunnel, egress), not settings.
func ParseSettings ¶
ParseSettings reads a settings document. Unknown keys are ignored (the panel may add fields without a lock-step node upgrade); values are not validated here, see Validate.