Documentation
¶
Overview ¶
Package agentlink contains the versioned signed-link handshake shared by the panel and node agent.
Index ¶
- Constants
- Variables
- func AgentDigest(nodeID, audience string, panelNonce []byte) []byte
- func AgentDigestV2(nodeID, audience string, panelNonce, agentNonce []byte) []byte
- func BridgeDigest(entryNodeID string, exporter []byte) []byte
- func EnrollKey(token string) ed25519.PrivateKey
- func OpenFrame(keys []byte, fromAgent bool, seq uint64, sealed []byte) ([]byte, error)
- func PanelBridgeDigest(hostNodeID string, exporter []byte) []byte
- func PanelDigest(nodeID, audience string, panelNonce, agentNonce []byte) []byte
- func ProvesEnrollToken(token string) bool
- func ReadFrame(ctx context.Context, ws *websocket.Conn) (websocket.MessageType, []byte, error)
- func SealFrame(keys []byte, fromAgent bool, seq uint64, plain []byte) ([]byte, error)
- func SealKeys(priv *ecdsa.PrivateKey, peer *ecdsa.PublicKey, nodeID, audience string, ...) ([]byte, error)
- func SealNonce() ([]byte, error)
- func SealedPanelDigest(nodeID, audience string, panelNonce, agentNonce []byte) []byte
- func Sign(key *ecdsa.PrivateKey, digest []byte) ([]byte, error)
- func SignEnroll(token string, csrDER []byte) (pub, signature []byte)
- func TunnelHost(ctx context.Context) string
- func Verify(key *ecdsa.PublicKey, digest, signature []byte) bool
- func VerifyEnroll(pub, csrDER, signature []byte) bool
- func WantsSeal(agentNonce []byte) bool
- func WithTunnelHost(ctx context.Context, host string) context.Context
- func WriteFrame(ctx context.Context, ws *websocket.Conn, message proto.Message) error
- type Link
Constants ¶
const EnrollTokenPrefix = "mg2_"
EnrollTokenPrefix marks a token the agent proves instead of sending.
const MaxFrameSize = 4 << 20
MaxFrameSize is the maximum encoded link frame size in bytes (4 MiB).
const (
// SealOverhead is what sealing adds to a frame (the GCM tag).
SealOverhead = 16
)
Variables ¶
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.
var ErrFrameTooLarge = errors.New("link frame too large")
ErrFrameTooLarge reports a link frame whose encoded payload exceeds MaxFrameSize.
Functions ¶
func AgentDigest ¶
AgentDigest hashes the mistgate-agent-link/1 domain, NUL-separated node ID and audience, and panel nonce with SHA-256.
func AgentDigestV2 ¶
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 ¶
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
OpenFrame decrypts frame number seq of the agent's (fromAgent) or the panel's direction.
func PanelBridgeDigest ¶
PanelBridgeDigest is BridgeDigest in the panel's own domain (mistgate-sub-host/1): the panel, as the exit of a subscription host's bridge, signs it with its short fleet certificate (design/adr/0018-panel-behind-nat.md). A bridge proof never verifies as a panel proof, nor the other way round.
func PanelDigest ¶
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
ProvesEnrollToken reports whether token is proven rather than sent.
func SealFrame ¶ added in v0.1.66
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
SealNonce is a new agent's LinkAuth nonce: 32 bytes, the seal marker then random.
func SealedPanelDigest ¶ added in v0.1.66
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
SignEnroll signs the CSR with the token's key; it returns the public key and the signature.
func TunnelHost ¶
TunnelHost returns the subscription domain that carried the agent request, or empty for a direct connection.
func VerifyEnroll ¶ added in v0.1.66
VerifyEnroll checks a signature of SignEnroll.
func WantsSeal ¶ added in v0.1.66
WantsSeal reports whether the agent that sent this nonce seals its link.
func WithTunnelHost ¶
WithTunnelHost records the subscription domain that carried a verified agent request.
Types ¶
type Link ¶ added in v0.1.66
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 ¶ added in v0.1.66
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
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.