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
- Variables
- func IssueEd25519Token(priv ed25519.PrivateKey, t Token) ([]byte, error)
- func LoadSigningKeyFile(path string) (ed25519.PrivateKey, error)
- func MarshalRelayExtension(p Proof) ([]byte, error)
- func MarshalSigningKeyPEM(key ed25519.PrivateKey) ([]byte, error)
- func MetadataPairs(token []byte, p Proof) []string
- func NormalizeHostname(host string) (string, error)
- func ParseSigningKeyPEM(data []byte) (ed25519.PrivateKey, error)
- func ValidateHostnames(hostnames []string) error
- func VerifyProof(authPub ed25519.PublicKey, svc Service, token []byte, p Proof, ...) error
- type Algo
- type KeyID
- type Proof
- type Service
- type Token
- type TokenKeys
- type Verifier
Constants ¶
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.
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 ¶
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") )
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") )
var ( ErrMissingCredentials = errors.New("missing peer auth credentials") ErrMalformedCredentials = errors.New("malformed peer auth credentials") )
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 ¶
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 ¶
MetadataPairs returns the gRPC metadata key-value pairs carrying the token and the proof.
func NormalizeHostname ¶
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 ¶
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 ¶
Ed25519KeyID derives the key ID of a Management public key from its SHA-256 digest.
type Proof ¶
Proof is the peer's signature over the token, the time and the hostname it dialed.
func FromMetadata ¶
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 ¶
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.
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.
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 ¶
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 ¶
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.