wgcfg

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: BSD-3-Clause Imports: 18 Imported by: 20

Documentation

Overview

Package wgcfg has types and a parser for representing WireGuard config.

Index

Constants

View Source
const EndpointDiscoSuffix = ".disco.tailscale:12345"

EndpointDiscoSuffix is appended to the hex representation of a peer's discovery key and is then the sole wireguard endpoint for peers with a non-zero discovery key. This form is then recognize by magicsock's CreateEndpoint.

View Source
const KeySize = 32

Variables

This section is empty.

Functions

func ReconfigDevice

func ReconfigDevice(d *device.Device, cfg *Config, logf logger.Logf) (err error)

ReconfigDevice replaces the existing device configuration with cfg.

Types

type Config

type Config struct {
	Name       string
	PrivateKey PrivateKey
	Addresses  []netaddr.IPPrefix
	ListenPort uint16
	MTU        uint16
	DNS        []netaddr.IP
	Peers      []Peer
}

Config is a WireGuard configuration. It only supports the set of things Tailscale uses.

func DeviceConfig

func DeviceConfig(d *device.Device) (*Config, error)

func FromUAPI

func FromUAPI(r io.Reader) (*Config, error)

FromUAPI generates a Config from r. r should be generated by calling device.IpcGetOperation; it is not compatible with other uapi streams.

func (Config) Copy

func (cfg Config) Copy() Config

Copy makes a deep copy of Config. The result aliases no memory with the original.

func (Config) PeerWithKey

func (config Config) PeerWithKey(k Key) (Peer, bool)

PeerWithKey returns the Peer with key k and reports whether it was found.

func (*Config) ToUAPI

func (cfg *Config) ToUAPI(w io.Writer, prev *Config) error

ToUAPI writes cfg in UAPI format to w. Prev is the previous device Config. Prev is required so that we can remove now-defunct peers without having to remove and re-add all peers.

type Key

type Key [KeySize]byte

Key is curve25519 key. It is used by WireGuard to represent public and preshared keys.

func NewPresharedKey

func NewPresharedKey() (*Key, error)

NewPresharedKey generates a new random key.

func ParseHexKey

func ParseHexKey(s string) (Key, error)

func ParseKey

func ParseKey(b64 string) (*Key, error)

func (Key) Base64

func (k Key) Base64() string

func (Key) Equal

func (k Key) Equal(k2 Key) bool

func (Key) HexString

func (k Key) HexString() string

func (*Key) IsZero

func (k *Key) IsZero() bool

func (*Key) LessThan

func (a *Key) LessThan(b *Key) bool

func (*Key) MarshalJSON

func (k *Key) MarshalJSON() ([]byte, error)

func (*Key) ShortString

func (k *Key) ShortString() string

func (Key) String

func (k Key) String() string

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(b []byte) error

type ParseError

type ParseError struct {
	// contains filtered or unexported fields
}

func (*ParseError) Error

func (e *ParseError) Error() string

type Peer

type Peer struct {
	PublicKey           Key
	AllowedIPs          []netaddr.IPPrefix
	Endpoints           string // comma-separated host/port pairs: "1.2.3.4:56,[::]:80"
	PersistentKeepalive uint16
}

func (Peer) Copy

func (peer Peer) Copy() Peer

Copy makes a deep copy of Peer. The result aliases no memory with the original.

type PrivateKey

type PrivateKey [KeySize]byte

PrivateKey is curve25519 key. It is used by WireGuard to represent private keys.

func NewPrivateKey

func NewPrivateKey() (PrivateKey, error)

NewPrivateKey generates a new curve25519 secret key. It conforms to the format described on https://cr.yp.to/ecdh.html.

func ParsePrivateHexKey

func ParsePrivateHexKey(v string) (PrivateKey, error)

func ParsePrivateKey

func ParsePrivateKey(b64 string) (*PrivateKey, error)

func (*PrivateKey) Equal

func (k *PrivateKey) Equal(k2 PrivateKey) bool

func (*PrivateKey) HexString

func (k *PrivateKey) HexString() string

func (*PrivateKey) IsZero

func (k *PrivateKey) IsZero() bool

func (PrivateKey) MarshalText

func (k PrivateKey) MarshalText() ([]byte, error)

func (*PrivateKey) Public

func (k *PrivateKey) Public() Key

Public computes the public key matching this curve25519 secret key.

func (PrivateKey) SharedSecret

func (k PrivateKey) SharedSecret(pub Key) (ss [KeySize]byte)

func (*PrivateKey) String

func (k *PrivateKey) String() string

func (*PrivateKey) UnmarshalText

func (k *PrivateKey) UnmarshalText(b []byte) error

type SymmetricKey

type SymmetricKey [chacha20poly1305.KeySize]byte

SymmetricKey is a chacha20poly1305 key. It is used by WireGuard to represent pre-shared symmetric keys.

func ParseSymmetricHexKey

func ParseSymmetricHexKey(s string) (SymmetricKey, error)

func ParseSymmetricKey

func ParseSymmetricKey(b64 string) (SymmetricKey, error)

func (SymmetricKey) Base64

func (k SymmetricKey) Base64() string

func (SymmetricKey) Equal

func (k SymmetricKey) Equal(k2 SymmetricKey) bool

func (SymmetricKey) HexString

func (k SymmetricKey) HexString() string

func (SymmetricKey) IsZero

func (k SymmetricKey) IsZero() bool

func (SymmetricKey) String

func (k SymmetricKey) String() string

Directories

Path Synopsis
Package nmcfg converts a controlclient.NetMap into a wgcfg config.
Package nmcfg converts a controlclient.NetMap into a wgcfg config.

Jump to

Keyboard shortcuts

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