peerauth

package
v0.84.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: BSD-3-Clause Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package peerauth authenticates peers to Signal and Relay: Management issues a token bound to the peer's keys, and the peer proves possession of its signing key on every connection.

Index

Constants

View Source
const (
	MetadataToken     = "x-netbird-auth-token-bin" //nolint:gosec // G101: metadata key name, not a credential
	MetadataTimestamp = "x-netbird-auth-ts"
	MetadataHostname  = "x-netbird-auth-host"
	MetadataSignature = "x-netbird-auth-sig-bin"
)

gRPC metadata keys carrying the credentials to Signal. Keys ending in -bin are binary.

View Source
const DefaultSkew = 10 * time.Minute

DefaultSkew is how far a proof timestamp may be from the verifier clock when the timestamp check is enabled.

Variables

View Source
var (
	ErrBadProofSig   = errors.New("invalid proof signature")
	ErrStaleProof    = errors.New("proof timestamp outside the allowed skew")
	ErrHostMismatch  = errors.New("proof hostname is not one of the verifier hostnames")
	ErrMalformedHost = errors.New("malformed hostname")
)
View Source
var (
	ErrMalformedToken  = errors.New("malformed token")
	ErrAlgoNotAccepted = errors.New("token algorithm not accepted by this verifier")
	ErrUnknownKeyID    = errors.New("unknown token key id")
	ErrBadTokenSig     = errors.New("invalid token signature")
	ErrTokenExpired    = errors.New("token expired")
	ErrKeyConfig       = errors.New("token verifier needs Management public keys of valid size, each under its derived key ID")
)
View Source
var (
	ErrMissingCredentials   = errors.New("missing peer auth credentials")
	ErrMalformedCredentials = errors.New("malformed peer auth credentials")
)
View Source
var (
	ErrNoProof            = errors.New("no proof in the auth extension")
	ErrMalformedExtension = errors.New("malformed auth extension")
)

Functions

func IssueEd25519Token

func IssueEd25519Token(priv ed25519.PrivateKey, t Token) ([]byte, error)

IssueEd25519Token signs the token with Management's private key.

func LoadSigningKeyFile

func LoadSigningKeyFile(path string) (ed25519.PrivateKey, error)

LoadSigningKeyFile reads Management's Ed25519 signing key from a PEM PKCS#8 file.

func MarshalRelayExtension

func MarshalRelayExtension(p Proof) ([]byte, error)

MarshalRelayExtension encodes the proof for the extension area of the Relay auth envelope as type-length-value entries, so later fields can be added without breaking older parsers.

func MarshalSigningKeyPEM

func MarshalSigningKeyPEM(key ed25519.PrivateKey) ([]byte, error)

MarshalSigningKeyPEM encodes Management's Ed25519 signing key as a PEM PKCS#8 block, the format ParseSigningKeyPEM reads.

func MetadataPairs

func MetadataPairs(token []byte, p Proof) []string

MetadataPairs returns the gRPC metadata key-value pairs carrying the token and the proof.

func NormalizeHostname

func NormalizeHostname(host string) (string, error)

NormalizeHostname reduces a dialed host, as url.URL.Hostname returns it, to the form both sides sign: lower case punycode, no trailing dot. Lowercasing comes first because punycode encodes case, and the A-label is what fits a gRPC header. An IP address takes its canonical form, so every spelling of one address matches.

func ParseSigningKeyPEM

func ParseSigningKeyPEM(data []byte) (ed25519.PrivateKey, error)

ParseSigningKeyPEM parses Management's Ed25519 signing key from a PEM PKCS#8 block, the format `openssl genpkey -algorithm ed25519` writes.

func ValidateHostnames

func ValidateHostnames(hostnames []string) error

ValidateHostnames checks a configured list of accepted hostnames. Proofs carry the bare hostname the peer dialed, so an entry with a port would never match and refuse every peer.

func VerifyProof

func VerifyProof(authPub ed25519.PublicKey, svc Service, token []byte, p Proof, hostnames []string, now time.Time, skew time.Duration) error

VerifyProof checks the proof against the signing key from a verified token. An empty hostnames list skips the hostname check, which still leaves the signature bound to the name. A zero skew skips the timestamp check, so the proof is valid as long as its token.

Types

type Algo

type Algo byte

Algo is the algorithm Management signs the token with.

const AlgoEd25519 Algo = 2

AlgoEd25519 is the only token algorithm. It is numbered as the Relay token algorithms, where 1 is the legacy HMAC token, so a legacy token is never taken for a bound one; the algorithm byte leaves room for a post-quantum signature later.

type KeyID

type KeyID uint32

KeyID identifies the Management key that signed a token. It is derived from the Ed25519 public key, so verifiers pick the key without configuring IDs and rotated keys never share one.

func Ed25519KeyID

func Ed25519KeyID(pub ed25519.PublicKey) KeyID

Ed25519KeyID derives the key ID of a Management public key from its SHA-256 digest.

type Proof

type Proof struct {
	Timestamp time.Time
	Hostname  string
	Signature []byte
}

Proof is the peer's signature over the token, the time and the hostname it dialed.

func FromMetadata

func FromMetadata(md metadata.MD) ([]byte, Proof, error)

FromMetadata extracts the token and the proof sent to Signal. ErrMissingCredentials means none was sent; partial or unparseable credentials are ErrMalformedCredentials and must be refused.

func SignProof

func SignProof(priv ed25519.PrivateKey, svc Service, token []byte, hostname string, now time.Time) (Proof, error)

SignProof signs the token for one connection to the named verifier.

func UnmarshalRelayExtension

func UnmarshalRelayExtension(ext []byte) (Proof, error)

UnmarshalRelayExtension returns the proof from the extension area, skipping unknown entries. ErrNoProof means a legacy client; any other error means credentials that must be refused.

type Service

type Service byte

Service separates Relay proofs from Signal proofs, so one cannot be replayed as the other.

const (
	ServiceRelay  Service = 1
	ServiceSignal Service = 2
)

type Token

type Token struct {
	Algo    Algo
	KeyID   KeyID
	Expiry  time.Time
	WGPub   wgtypes.Key
	AuthPub ed25519.PublicKey
}

Token is the content Management vouches for: the peer's WireGuard key and its signing key.

func VerifyToken

func VerifyToken(raw []byte, keys TokenKeys, now time.Time) (*Token, error)

VerifyToken checks the token against the verifier keys and its expiry.

type TokenKeys

type TokenKeys struct {
	// Ed25519 maps each accepted Management public key by its Ed25519KeyID; build it with
	// NewEd25519Keys.
	Ed25519 map[KeyID]ed25519.PublicKey
}

TokenKeys holds the Management public keys a verifier checks tokens with. Verifiers hold no secret, so no Relay or Signal can mint a token.

func NewEd25519Keys

func NewEd25519Keys(pubs []ed25519.PublicKey) (TokenKeys, error)

NewEd25519Keys returns verifier keys accepting tokens signed by any of the given Management public keys, refusing keys of the wrong size and keys whose IDs collide.

func ParsePublicKeys

func ParsePublicKeys(b64Keys []string) (TokenKeys, error)

ParsePublicKeys builds verifier keys from base64 Management public keys, as Management logs them. Several keys let a verifier accept tokens of the old and the new key during a rotation.

func (TokenKeys) KeyIDs

func (k TokenKeys) KeyIDs() []KeyID

KeyIDs returns the IDs of the accepted keys in ascending order, for logging.

func (TokenKeys) Validate

func (k TokenKeys) Validate() error

Validate refuses key material that would make verification panic or never match a token.

type Verifier

type Verifier struct {
	Service   Service
	Keys      TokenKeys
	Hostnames []string
	// Skew bounds the proof timestamp against the verifier clock; zero skips the check.
	Skew time.Duration
}

Verifier checks a peer's token and proof.

func (*Verifier) Verify

func (v *Verifier) Verify(token []byte, p Proof, now time.Time) (*Token, error)

Verify returns the token content once both the token and the proof are valid. The caller still has to match the peer identity it was handed against Token.WGPub.

Jump to

Keyboard shortcuts

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