agentlink

package
v0.2.0-dev.5 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0 modules, 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 agentlink contains the versioned signed-link handshake shared by the panel and node agent.

Index

Constants

View Source
const EnrollTokenPrefix = "mg2_"

EnrollTokenPrefix marks a token the agent proves instead of sending.

View Source
const MaxFrameSize = 4 << 20

MaxFrameSize is the maximum encoded link frame size in bytes (4 MiB).

View Source
const (

	// SealOverhead is what sealing adds to a frame (the GCM tag).
	SealOverhead = 16
)

Variables

View Source
var ErrFrameAuth = errors.New("link frame failed authentication")

ErrFrameAuth reports a sealed frame that did not open: changed, replayed, reordered or sealed with another key.

View Source
var ErrFrameTooLarge = errors.New("link frame too large")

ErrFrameTooLarge reports a link frame whose encoded payload exceeds MaxFrameSize.

Functions

func AgentDigest

func AgentDigest(nodeID, audience string, panelNonce []byte) []byte

AgentDigest hashes the mistgate-agent-link/1 domain, NUL-separated node ID and audience, and panel nonce with SHA-256.

func AgentDigestV2

func AgentDigestV2(nodeID, audience string, panelNonce, agentNonce []byte) []byte

AgentDigestV2 is AgentDigest in the mistgate-agent-link/2 domain with the agent's own nonce appended: the signature covers what the agent asks for (the seal marker in its nonce), so nobody can change that request on the way. A new agent signs only this; a v2 signature never verifies as a v1 one and the other way round.

func BridgeDigest

func BridgeDigest(entryNodeID string, exporter []byte) []byte

BridgeDigest hashes the bridge domain, TLS exporter and accepting entry id. The exporter is unique to that connection, so a captured proof cannot be replayed over another TLS session or protocol.

func EnrollKey added in v0.1.66

func EnrollKey(token string) ed25519.PrivateKey

EnrollKey is the key a proven token stands for.

func OpenFrame added in v0.1.66

func OpenFrame(keys []byte, fromAgent bool, seq uint64, sealed []byte) ([]byte, error)

OpenFrame decrypts frame number seq of the agent's (fromAgent) or the panel's direction.

func PanelDigest

func PanelDigest(nodeID, audience string, panelNonce, agentNonce []byte) []byte

PanelDigest hashes the mistgate-panel-link/1 domain, NUL-separated node ID and audience, and concatenated nonces with SHA-256.

func ProvesEnrollToken added in v0.1.66

func ProvesEnrollToken(token string) bool

ProvesEnrollToken reports whether token is proven rather than sent.

func ReadFrame

func ReadFrame(ctx context.Context, ws *websocket.Conn) (websocket.MessageType, []byte, error)

ReadFrame reads one WebSocket frame and rejects payloads larger than MaxFrameSize.

func SealFrame added in v0.1.66

func SealFrame(keys []byte, fromAgent bool, seq uint64, plain []byte) ([]byte, error)

SealFrame encrypts frame number seq of the agent's (fromAgent) or the panel's direction.

func SealKeys added in v0.1.66

func SealKeys(priv *ecdsa.PrivateKey, peer *ecdsa.PublicKey, nodeID, audience string, panelNonce, agentNonce []byte) ([]byte, error)

SealKeys derives a session's keys from one side's private key and the other's public key: the node key and the CA certificate's key on the agent, the CA key and the node certificate's key on the panel. The 64 bytes are the key of the agent's frames, then the key of the panel's.

func SealNonce added in v0.1.66

func SealNonce() ([]byte, error)

SealNonce is a new agent's LinkAuth nonce: 32 bytes, the seal marker then random.

func SealedPanelDigest added in v0.1.66

func SealedPanelDigest(nodeID, audience string, panelNonce, agentNonce []byte) []byte

SealedPanelDigest is PanelDigest for a sealed session, in a domain of its own: an older agent never accepts it, and a new agent that gets the plain one knows the panel does not seal.

func Sign

func Sign(key *ecdsa.PrivateKey, digest []byte) ([]byte, error)

Sign signs digest and encodes the ECDSA signature as fixed-width r||s: two 32-byte big-endian scalars.

func SignEnroll added in v0.1.66

func SignEnroll(token string, csrDER []byte) (pub, signature []byte)

SignEnroll signs the CSR with the token's key; it returns the public key and the signature.

func Verify

func Verify(key *ecdsa.PublicKey, digest, signature []byte) bool

Verify reports whether digest matches the fixed-width 64-byte r||s ECDSA signature.

func VerifyEnroll added in v0.1.66

func VerifyEnroll(pub, csrDER, signature []byte) bool

VerifyEnroll checks a signature of SignEnroll.

func WantsSeal added in v0.1.66

func WantsSeal(agentNonce []byte) bool

WantsSeal reports whether the agent that sent this nonce seals its link.

func WriteFrame

func WriteFrame(ctx context.Context, ws *websocket.Conn, message proto.Message) error

WriteFrame protobuf-encodes message as a binary WebSocket frame capped at MaxFrameSize.

Types

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

Link is one end of a link session after the handshake: protobuf frames, sealed when both ends can. One goroutine reads.

func NewLink(ws *websocket.Conn, keys []byte, agent bool) *Link

NewLink wraps ws for the agent's end (agent) or the panel's; keys are SealKeys', nil for a plain session.

func (*Link) Read added in v0.1.66

func (l *Link) Read(ctx context.Context) (websocket.MessageType, []byte, error)

Read returns the next frame, opened when the session is sealed. A non-binary frame comes back as it is, for the caller to refuse.

func (*Link) Sealed added in v0.1.66

func (l *Link) Sealed() bool

Sealed reports whether the session's frames are sealed.

func (*Link) Write added in v0.1.66

func (l *Link) Write(ctx context.Context, message proto.Message) error

Write sends one message. Sealed writes are serialised so their sequence numbers go out in order.

Jump to

Keyboard shortcuts

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