lib

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2020 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyPSK = [32]byte{
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
	0, 0, 0, 0, 0, 0, 0, 0,
}

EmptyPSK is the byte representation used when no preshared key is set on a peer

Functions

func AnyError

func AnyError(errs ...error) bool

AnyError returns whether any of the given error is not nil

func FirstError

func FirstError(errs ...error) error

FirstError returns the first non-nil error in the given arguments, and otherwise retuens nil

func GetConfigPath

func GetConfigPath() string

GetConfigPath returns the directory where the configuration files should be looked for This path can be overridden by setting the WGCTL_CONFIG_PATH environment variable

func GetInstanceFromArg

func GetInstanceFromArg(path string) string

GetInstanceFromArg returns the normalized name of a WireGuard tunnel instance (and interface)

func GetKey

func GetKey(t *testing.T) []byte

GetKey returns a []byte key to be used in test functions

Types

type Config

type Config struct {
	Interface Interface `yaml:"interface"`
	Peers     []*Peer   `yaml:"peers"`
}

Config represents a YAML-encodable configuration for a WireGuard tunnel

func ParseConfig

func ParseConfig(instance string) (*Config, error)

ParseConfig unmarshals a Config from a YAML string

func ParseConfigReader

func ParseConfigReader(config io.Reader) (*Config, error)

ParseConfigReader unmarshals a Config from an io.Reader mapped to a YAML file

func (*Config) Check

func (c *Config) Check() error

Check verifies that all mandatory config directive have been given for a Config It also sets default values for some fields

func (*Config) GetPeer

func (c *Config) GetPeer(publicKey string) *Peer

GetPeer finds a peer in a Config from its public key string representation

type IPMask

type IPMask struct {
	IP   net.IP
	Mask int
}

IPMask represents an IP address and its subnet mask, to be assigned to an interface

func (*IPMask) MarshalYAML

func (ip *IPMask) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML string representation of an IPMask

func (IPMask) String

func (ip IPMask) String() string

String returns the classic CIDR representation of an IPMask (e.g. 192.168.0.1/24)

func (*IPMask) UnmarshalYAML

func (ip *IPMask) UnmarshalYAML(f func(interface{}) error) error

UnmarshalYAML returns an IPMask from a YAML string

type IPNet

type IPNet net.IPNet

IPNet is an unmarshalable version of net.IPNet

func GetSubnet

func GetSubnet(t *testing.T) IPNet

GetSubnet returns a random IPv4 IPNet to be used in test functions

func (IPNet) MarshalYAML

func (ip IPNet) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML string representation of an IPNet

func (*IPNet) UnmarshalYAML

func (ip *IPNet) UnmarshalYAML(f func(interface{}) error) error

UnmarshalYAML returns an IPNet from a YAML string

type Interface

type Interface struct {
	Description string     `yaml:"description"`
	Address     *IPMask    `yaml:"address"`
	ListenPort  int        `yaml:"listen_port"`
	PrivateKey  PrivateKey `yaml:"private_key"`
	FWMark      int        `yaml:"fwmark,omitempty"`
	PostUp      [][]string `yaml:"post_up,omitempty"`
	PreDown     [][]string `yaml:"pre_down,omitempty"`
	SetUpRoutes *bool      `yaml:"routes,omitempty"`
}

Interface represents a YAML-encodable configuration for a WireGuard interface

type Key

type Key []byte

Key is an unmarshalable ED25519 key

func ComputePublicKey

func ComputePublicKey(b []byte) Key

ComputePublicKey computes the matching Curve25519 public key from a private key

func (*Key) Bytes

func (k *Key) Bytes() [wgtypes.KeyLen]byte

Bytes returns the byte representation of a public key

func (Key) MarshalYAML

func (k Key) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML string representation of a Key

func (*Key) String

func (k *Key) String() string

String returns the string representation of a public key

func (*Key) UnmarshalYAML

func (k *Key) UnmarshalYAML(f func(interface{}) error) error

UnmarshalYAML returns a Key from a YAML string

type Peer

type Peer struct {
	Description       string        `yaml:"description"`
	PublicKey         Key           `yaml:"public_key"`
	PresharedKey      *PresharedKey `yaml:"preshared_key,omitempty"`
	Endpoint          *UDPAddr      `yaml:"endpoint,omitempty"`
	AllowedIPS        []IPNet       `yaml:"allowed_ips,omitempty"`
	KeepaliveInterval time.Duration `yaml:"keepalive_interval,omitempty"`
}

Peer represents a YAML-encodable configuration for a WireGuard peer

type PresharedKey

type PresharedKey []byte

PresharedKey is un unmarshable preshared key

func GeneratePSK

func GeneratePSK() (PresharedKey, error)

GeneratePSK generates a random preshared key to be used with a WireGuard peer

func GetPSK

func GetPSK(t *testing.T) *PresharedKey

GetPSK returns a []byte PSK to be used in test functions

func (*PresharedKey) Bytes

func (k *PresharedKey) Bytes() [wgtypes.KeyLen]byte

Bytes returns the byte representation of a preshared key

func (PresharedKey) MarshalYAML

func (k PresharedKey) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML string representation of a PresharedKey

func (*PresharedKey) String

func (k *PresharedKey) String() string

String returns the hex string representation of a preshared key

func (*PresharedKey) UnmarshalYAML

func (k *PresharedKey) UnmarshalYAML(f func(interface{}) error) error

UnmarshalYAML returns a PresharedKey from a YAML string

type PrivateKey

type PrivateKey struct {
	Path string
	Data [wgtypes.KeyLen]byte
}

PrivateKey is an unmarshalable file path

func GeneratePrivateKey

func GeneratePrivateKey() (*PrivateKey, error)

GeneratePrivateKey generates a new Curve25519 private key from crypto/rand

func NewPrivateKey

func NewPrivateKey(bk []byte) PrivateKey

NewPrivateKey retirns a PrivateKey from a []byte

func (*PrivateKey) Bytes

func (k *PrivateKey) Bytes() [wgtypes.KeyLen]byte

Bytes returns the byte representation of a private key

func (PrivateKey) MarshalYAML

func (k PrivateKey) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML string representation of a PrivateKeyFile

func (*PrivateKey) String

func (k *PrivateKey) String() string

String returns the string repsentation of a private key

func (*PrivateKey) UnmarshalYAML

func (k *PrivateKey) UnmarshalYAML(f func(interface{}) error) error

UnmarshalYAML returns an private key from a YAML file path

type UDPAddr

type UDPAddr net.UDPAddr

UDPAddr is an unmarshalable version of net.UDPAddr

func GetEndpoint

func GetEndpoint(t *testing.T) *UDPAddr

GetEndpoint returns a random IPv4 UDPAddr to be used in test functions

func (UDPAddr) MarshalYAML

func (ip UDPAddr) MarshalYAML() (interface{}, error)

MarshalYAML returns the YAML string representation of an UDPAddr

func (*UDPAddr) UnmarshalYAML

func (ip *UDPAddr) UnmarshalYAML(f func(interface{}) error) error

UnmarshalYAML returns an UDPAddr from a YAML string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL