wg

package
v0.0.0-...-692cc24 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package wg implements wormhole integration with WireGuard

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertFromString

func ConvertFromString(private, public string) ([32]byte, [32]byte, error)

ConvertFromString decodes base64 encoded private and public keys.

func Decrypt

func Decrypt(ciphertext []byte, private, public string) ([]byte, error)

Decrypt decrypts the ciphertext using the provided private and public keys.

func DeriveKeys

func DeriveKeys(sharedSecret [32]byte) ([32]byte, [32]byte, error)

DeriveKeys derives encryption and authentication keys using HKDF.

func Encrypt

func Encrypt(payload []byte, private, public string) ([]byte, error)

Encrypt encrypts the payload using the provided private and public keys.

func GetOrGenerateKeyPair

func GetOrGenerateKeyPair(storage KeyStorage) (string, string, error)

GetOrGenerateKeyPair returns the stored key pair or generates a new one

func PerformKeyExchange

func PerformKeyExchange(privateKey, peerPublicKey [32]byte) ([32]byte, error)

PerformKeyExchange computes a shared secret using peer's public key and our private key.

func RenderTemplate

func RenderTemplate(settings Config) (string, error)

RenderTemplate renders the WireGuard configuration template with the given settings

Types

type Config

type Config struct {
	Address    string
	Subnet     string
	ListenPort int
	PrivateKey string

	EnableKeepAlive bool

	Peers []Peer
}

Config represents the WireGuard configuration

func (*Config) DeleteByPublicKey

func (c *Config) DeleteByPublicKey(publicKey string)

DeleteByPublicKey removes a peer from the configuration by its public key

func (*Config) Upsert

func (c *Config) Upsert(p Peer)

Upsert adds or replaces a peer in the configuration

type KeyStorage

type KeyStorage interface {
	Store(private, public string) error
	Load() (private, public string, err error)
}

KeyStorage is responsible for storing and loading WireGuard key pair

func NewBoltKeyStorage

func NewBoltKeyStorage(path string) KeyStorage

NewBoltKeyStorage creates a new KeyStorage that stores keys in a BoltDB database

func NewInMemoryKeyStorage

func NewInMemoryKeyStorage() KeyStorage

NewInMemoryKeyStorage creates a new KeyStorage that stores keys in memory

func NewNoStorage

func NewNoStorage() KeyStorage

NewNoStorage creates a new KeyStorage that does not store keys

type Peer

type Peer struct {
	Name       string
	PublicKey  string
	AllowedIPs string
	Endpoint   string

	PersistentKeepalive int
}

Peer represents a single WireGuard peer in the configuration

type Watcher

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

Watcher watches for changes in the WireGuard configuration and updates it

func NewWatcher

func NewWatcher(cfgPath string) *Watcher

NewWatcher creates a new Watcher instance

func (*Watcher) Update

func (w *Watcher) Update(settings Config) error

Update updates the WireGuard configuration with the given settings

type WireguardConfigReloader

type WireguardConfigReloader interface {
	Update(Config) error
}

WireguardConfigReloader is an interface for updating Wireguard configuration

Jump to

Keyboard shortcuts

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