Documentation
¶
Overview ¶
Package wgtypes provides shared types for the wgctrl family of packages.
Index ¶
Constants ¶
const KeyLen = 32 // wgh.KeyLen
KeyLen is the expected key length for a WireGuard key.
Variables ¶
var ErrUpdateOnlyNotSupported = errors.New("the UpdateOnly flag is not supported by this platform")
ErrUpdateOnlyNotSupported is returned due to missing kernel support of the PeerConfig UpdateOnly flag.
Functions ¶
This section is empty.
Types ¶
type AmneziaVersion ¶ added in v1.3.0
type AmneziaVersion int
An AmneziaVersion identifies the AmneziaWG protocol generation of a device.
const ( AWGNone AmneziaVersion = iota // plain WireGuard AWG15 // 1.5: static magic headers AWG20 // 2.0: ranged headers, I1-I5, S3/S4 AWG30 // 3.0: header protection, padding/timing ranges AWG31 // 3.1: random trailers, cookie control )
Possible AmneziaVersion values.
func (AmneziaVersion) String ¶ added in v1.3.0
func (v AmneziaVersion) String() string
String returns a short name such as "1.5" or "3.1".
type Config ¶
type Config struct {
// PrivateKey specifies a private key configuration, if not nil.
//
// A non-nil, zero-value Key will clear the private key.
PrivateKey *Key
// ListenPort specifies a device's listening port, if not nil.
ListenPort *int
// FirewallMark specifies a device's firewall mark, if not nil.
//
// If non-nil and set to 0, the firewall mark will be cleared.
FirewallMark *int
// ReplacePeers specifies if the Peers in this configuration should replace
// the existing peer list, instead of appending them to the existing list.
ReplacePeers bool
// Peers specifies a list of peer configurations to apply to a device.
Peers []PeerConfig
// Junk Packet parameters
Jc *int // Count
Jmin *int // Min size
Jmax *int // Max size
// Message Padding parameters (bytes)
S1 *int // Init
S2 *int // Response
S3 *int // Cookie
S4 *int // Transport
// Message Magic Headers
// In AmneziaWG 2.0 these should be ranges (e.g., "123456-123999")
H1 *string // Init
H2 *string // Response
H3 *string // Cookie
H4 *string // Transport
// Init Packet Magic / Custom Signature (obfuscation)
// For client-side explicit setups only.
I1 *string
I2 *string
I3 *string
I4 *string
I5 *string
// HeaderProtectionKey encrypts the magic headers with ChaCha20, if not
// nil. Requires S1-S4 to be at least 12 bytes (the embedded nonce size).
HeaderProtectionKey *[32]byte
// ContentPaddingAddition, if not nil, appends a random number of bytes
// picked from the range to every transport packet.
ContentPaddingAddition *UintRange
// Protocol timings, if not nil. Unlike WireGuard's fixed constants these
// are picked at random from the given ranges.
RekeyAfterTime *UintRange
RekeyTimeout *UintRange
RejectAfterTime *UintRange
KeepaliveTimeout *UintRange
MaxHandshakeAttempts *UintRange
// RandomTrailers, if not nil, pads packets with random trailing bytes
// bounded by the UDP window size. This breaks simple packet-size
// fingerprinting, but both endpoints must enable it.
RandomTrailers *bool
// DisableCookies, if not nil, disables cookie replies and the whole
// "under load" code path, removing a recognisable response pattern.
DisableCookies *bool
}
A Config is a WireGuard device configuration.
Because the zero value of some Go types may be significant to WireGuard for Config fields, pointer types are used for some of these fields. Only pointer fields which are not nil will be applied when configuring a device.
func (*Config) GenerateAmneziaParams ¶
func (cfg *Config) GenerateAmneziaParams(ver AmneziaVersion)
GenerateAmneziaParams populates the config with obfuscation values for the given AmneziaWG generation. Generations below 3.0 receive the classic 2.0 profile; 3.0 and 3.1 additionally get header protection, content padding and timing ranges (3.1 also enables random trailers and cookie control).
type Device ¶
type Device struct {
// Name is the name of the device.
Name string
// Type specifies the underlying implementation of the device.
Type DeviceType
// PrivateKey is the device's private key.
PrivateKey Key
// PublicKey is the device's public key, computed from its PrivateKey.
PublicKey Key
// ListenPort is the device's network listening port.
ListenPort int
// FirewallMark is the device's current firewall mark.
//
// The firewall mark can be used in conjunction with firewall software to
// take action on outgoing WireGuard packets.
FirewallMark int
IsAmnezia bool
// AmneziaVersion is the detected AmneziaWG generation of this device, or
// AWGNone for a plain WireGuard device.
AmneziaVersion AmneziaVersion
// AmneziaWG obfuscation parameters, zero when the device is plain
// WireGuard or the attribute is absent.
Jc int
Jmin int
Jmax int
S1, S2, S3, S4 int
H1, H2, H3, H4 UintRange
I1, I2, I3, I4, I5 string
ContentPaddingAddition *UintRange
RekeyAfterTime *UintRange
RekeyTimeout *UintRange
RejectAfterTime *UintRange
KeepaliveTimeout *UintRange
MaxHandshakeAttempts *UintRange
RandomTrailers bool
DisableCookies bool
// SawRandomTrailers reports that the peer implementation advertised the
// AmneziaWG 3.1 random trailers capability, even when it is disabled.
SawRandomTrailers bool
// HeaderProtectionKey is the ChaCha20 key encrypting the magic headers.
// A nil value means no header protection is configured.
HeaderProtectionKey *[32]byte
// Peers is the list of network peers associated with this device.
Peers []Peer
}
A Device is a WireGuard device.
type DeviceType ¶
type DeviceType int
A DeviceType specifies the underlying implementation of a WireGuard device.
const ( Unknown DeviceType = iota LinuxKernel OpenBSDKernel FreeBSDKernel WindowsKernel Userspace )
Possible DeviceType values.
func (DeviceType) String ¶
func (dt DeviceType) String() string
String returns the string representation of a DeviceType.
type Key ¶
A Key is a public, private, or pre-shared secret key. The Key constructor functions in this package can be used to create Keys suitable for each of these applications.
func GenerateKey ¶
GenerateKey generates a Key suitable for use as a pre-shared secret key from a cryptographically safe source.
The output Key should not be used as a private key; use GeneratePrivateKey instead.
func GeneratePrivateKey ¶
GeneratePrivateKey generates a Key suitable for use as a private key from a cryptographically safe source.
func NewKey ¶
NewKey creates a Key from an existing byte slice. The byte slice must be exactly 32 bytes in length.
func ParseKey ¶
ParseKey parses a Key from a base64-encoded string, as produced by the Key.String method.
type Peer ¶
type Peer struct {
// PublicKey is the public key of a peer, computed from its private key.
//
// PublicKey is always present in a Peer.
PublicKey Key
// additional layer of security for peer communications.
//
// A zero-value Key means no preshared key is configured.
PresharedKey Key
// Endpoint is the most recent source address used for communication by
// this Peer.
Endpoint *net.UDPAddr
// PersistentKeepaliveInterval specifies how often an "empty" packet is sent
// to a peer to keep a connection alive.
//
// A value of 0 indicates that persistent keepalives are disabled.
PersistentKeepaliveInterval time.Duration
// LastHandshakeTime indicates the most recent time a handshake was performed
// with this peer.
//
// A zero-value time.Time indicates that no handshake has taken place with
// this peer.
LastHandshakeTime time.Time
// ReceiveBytes indicates the number of bytes received from this peer.
ReceiveBytes int64
// TransmitBytes indicates the number of bytes transmitted to this peer.
TransmitBytes int64
// AllowedIPs specifies which IPv4 and IPv6 addresses this peer is allowed
// to communicate on.
//
// 0.0.0.0/0 indicates that all IPv4 addresses are allowed, and ::/0
// indicates that all IPv6 addresses are allowed.
AllowedIPs []net.IPNet
// ProtocolVersion specifies which version of the WireGuard protocol is used
// for this Peer.
//
// A value of 0 indicates that the most recent protocol version will be used.
ProtocolVersion int
}
A Peer is a WireGuard peer to a Device.
type PeerConfig ¶
type PeerConfig struct {
// PublicKey specifies the public key of this peer. PublicKey is a
// mandatory field for all PeerConfigs.
PublicKey Key
// Remove specifies if the peer with this public key should be removed
// from a device's peer list.
Remove bool
// UpdateOnly specifies that an operation will only occur on this peer
// if the peer already exists as part of the interface.
UpdateOnly bool
//
// A non-nil, zero-value Key will clear the preshared key.
PresharedKey *Key
// Endpoint specifies the endpoint of this peer entry, if not nil.
Endpoint *net.UDPAddr
// PersistentKeepaliveInterval specifies the persistent keepalive interval
// for this peer, if not nil.
//
// A non-nil value of 0 will clear the persistent keepalive interval.
PersistentKeepaliveInterval *time.Duration
// ReplaceAllowedIPs specifies if the allowed IPs specified in this peer
// configuration should replace any existing ones, instead of appending them
// to the allowed IPs list.
ReplaceAllowedIPs bool
// AllowedIPs specifies a list of allowed IP addresses in CIDR notation
// for this peer.
AllowedIPs []net.IPNet
}
A PeerConfig is a WireGuard device peer configuration.
Because the zero value of some Go types may be significant to WireGuard for PeerConfig fields, pointer types are used for some of these fields. Only pointer fields which are not nil will be applied when configuring a peer.
type UintRange ¶ added in v1.3.0
type UintRange struct {
Lo, Hi uint32
}
A UintRange is an inclusive [Lo, Hi] range of unsigned values. AmneziaWG uses ranges for magic headers and, since 3.0, for content padding and protocol timing parameters.
func ParseUintRange ¶ added in v1.3.0
ParseUintRange parses an AmneziaWG range in "lo" or "lo-hi" form.