Documentation
¶
Overview ¶
Package tunnel defines the TunnelBackend abstraction: the seam between domain services and the AmneziaWG implementation (ADR-0001 — AWG is driven through its pinned CLI as a subprocess; nothing AWG-specific leaks above this interface). internal/tunnel/amneziawg implements it against the real CLI in Phase 2; tunnel/fake is the in-memory implementation for tests and dev without root.
Index ¶
- Variables
- func GeneratePresharedKey() (string, error)
- func PublicKeyFromPrivate(b64 string) (string, error)
- func ValidateEncodedKey(value string) error
- func ValidateKeyPair(private, public string) error
- func ValidatePrivateKey(b64 string) error
- func ValidatePublicKey(b64 string) error
- type Backend
- type InterfaceConfig
- type InterfaceSpec
- type InterfaceState
- type KeyPair
- type Obfuscation
- type PeerConfig
- type PeerState
Constants ¶
This section is empty.
Variables ¶
var ErrInterfaceNotFound = errors.New("tunnel: interface not found")
ErrInterfaceNotFound is returned when the named interface does not exist in the backend (distinct from DB-not-found domain errors).
Functions ¶
func GeneratePresharedKey ¶
GeneratePresharedKey returns 32 random bytes, base64 — exactly what `awg genpsk` produces.
func PublicKeyFromPrivate ¶
PublicKeyFromPrivate derives the public key for a base64 private key.
func ValidateEncodedKey ¶ added in v0.1.9
ValidateEncodedKey accepts the canonical 32-byte base64 form used for keys/PSKs.
func ValidateKeyPair ¶ added in v0.1.9
ValidateKeyPair checks canonical storage and that the public identity belongs to this private key. Errors never contain either key.
func ValidatePrivateKey ¶
ValidatePrivateKey checks base64 form and 32-byte length.
func ValidatePublicKey ¶
ValidatePublicKey checks base64 form and 32-byte length.
Types ¶
type Backend ¶
type Backend interface {
// ListInterfaces returns the names of interfaces visible to the backend.
ListInterfaces(ctx context.Context) ([]string, error)
// CreateInterface brings up a new interface with the given spec (link
// + config, no peers).
CreateInterface(ctx context.Context, spec InterfaceSpec) error
// RemoveInterface tears down and removes the interface.
RemoveInterface(ctx context.Context, name string) error
// ApplyInterfaceConfig fully replaces the interface configuration
// (setconf semantics; active handshakes may reset).
ApplyInterfaceConfig(ctx context.Context, name string, cfg InterfaceConfig) error
// SyncPeers diff-applies the peer list without disturbing the interface
// (syncconf semantics; active sessions survive).
SyncPeers(ctx context.Context, name string, peers []PeerConfig) error
// Dump returns the observed state (stats + handshakes + config snapshot).
Dump(ctx context.Context, name string) (InterfaceState, error)
}
Backend is the control-plane surface WG-Guard needs from the tunnel engine. Implementations must be safe for concurrent use.
type InterfaceConfig ¶
type InterfaceConfig struct {
PrivateKey string
ListenPort int
Fwmark string
Obfuscation Obfuscation
Peers []PeerConfig
}
InterfaceConfig is a full interface configuration: setconf semantics (complete replace).
type InterfaceSpec ¶
type InterfaceSpec struct {
Name string
BackendMode string // kernel (default) or userspace
PrivateKey string // base64
ListenPort int
Fwmark string // "" = off
MTU int
Address string // interface gateway CIDR, e.g. "10.8.0.1/24"
Addresses []string // all managed gateway CIDRs; Address is the primary
Obfuscation Obfuscation
}
InterfaceSpec is the identity-level configuration of a backend interface. Address was added in Phase 2: a backend that creates the link (kernel path) must assign the interface gateway address at bring-up, and the spec is the only state the backend receives — the phase-1 draft omitted it.
type InterfaceState ¶
type InterfaceState struct {
Name string
BackendMode string // observed mode when the real backend can identify it
PublicKey string
ListenPort int
Obfuscation Obfuscation
Peers []PeerState
}
InterfaceState is the observed state of one interface (dump semantics).
type KeyPair ¶
KeyPair is a Curve25519 keypair in WireGuard's base64 encoding. Generation uses the standard library (crypto/ecdh): WireGuard/AWG keys *are* X25519 keys — this is standard cryptography, not a reinvented scheme. The `awg genkey` CLI remains the pinned engine's own generator for parity checks in Phase 2; services only need correct key material.
func GenerateKeyPair ¶
GenerateKeyPair creates a fresh Curve25519 keypair.
type Obfuscation ¶
type Obfuscation struct {
Enabled bool
Jc int
Jmin, Jmax int
S1, S2 int
H1, H2, H3, H4 awgparam.U32Range
I1, I2, I3, I4, I5 string // hex blobs, "" = unset (client-side only params)
S3, S4 int // plain u16 when set
HeaderProtectionKey string // base64 32-byte key, "" = disabled
ContentPaddingAddition awgparam.U16Range // zero = disabled
RekeyAfterTime awgparam.U16Range // zero = upstream default
RekeyTimeout awgparam.U16Range
RejectAfterTime awgparam.U16Range
KeepaliveTimeout awgparam.U16Range
MaxHandshakeAttempts awgparam.U16Range
RandomTrailers bool // rendered as "on" (upstream panic history — default off)
DisableCookies bool // rendered as "on" (security implications — default off)
}
Obfuscation carries the AWG obfuscation parameters for one interface (one profile per interface — ADR-0002). Enabled=false means a plain WireGuard configuration: every parameter is omitted upstream. Field semantics and constraints are pinned in docs/integrations/amneziawg.md; validation of the kernel-README constraint set happens in the interface service before anything reaches a backend.
The 2.0/3.x-generation fields below are explicit advanced options: the pinned tools, kernel, and userspace runtimes apply and dump them, while client compatibility still varies by option. They render only when set, and a runtime that silently ignores them surfaces through verify-after-apply.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package amneziawg implements tunnel.Backend against the pinned awg CLI (docs/integrations/amneziawg.md — nothing here may assume upstream behavior that document does not verify).
|
Package amneziawg implements tunnel.Backend against the pinned awg CLI (docs/integrations/amneziawg.md — nothing here may assume upstream behavior that document does not verify). |
|
Package fake is an in-memory TunnelBackend for tests and development without root or the pinned AWG tooling.
|
Package fake is an in-memory TunnelBackend for tests and development without root or the pinned AWG tooling. |