Documentation
ΒΆ
Overview ΒΆ
Package atxp implements the ATXP (Atendi9 Transmission Exchange Protocol) wire protocol framing and transport layer.
- Copyright (c) 2026 Atendi9
Package atxp implements the ATXP (Atendi9 Transmission Exchange Protocol) wire protocol framing and transport layer.
- Copyright (c) 2026 Atendi9
Package atxp implements the ATXP (Atendi9 Transmission Exchange Protocol) wire protocol framing and transport layer.
- Copyright (c) 2026 Atendi9
Package atxp implements the ATXP (Atendi9 Transmission Exchange Protocol) wire protocol framing and transport layer.
- Copyright (c) 2026 Atendi9
Package atxp implements the ATXP (Atendi9 Transmission Exchange Protocol) wire protocol framing and transport layer.
- Copyright (c) 2026 Atendi9
Package atxp implements the ATXP (Atendi9 Transmission Exchange Protocol) wire protocol framing and transport layer.
- Copyright (c) 2026 Atendi9
Package atxp implements the ATXP (Atendi9 Transmission Exchange Protocol) wire protocol framing and transport layer.
- Copyright (c) 2026 Atendi9
Package atxp implements the ATXP (Atendi9 Transmission Exchange Protocol) wire protocol framing and transport layer.
- Copyright (c) 2026 Atendi9
Package atxp implements the ATXP (Atendi9 Transmission Exchange Protocol) wire protocol framing and transport layer.
- Copyright (c) 2026 Atendi9
ATXP V2 secure layer ΒΆ
V2 is an additive, backward-incompatible-on-the-wire successor to V1 that fixes V1's security and robustness flaws:
- The whole frame is encrypted with AES-256-GCM under a key derived from a shared password via PBKDF2-HMAC-SHA256. The password is never transmitted; possession is proven implicitly by the GCM authentication tag.
- Frames use a length-prefixed binary envelope, so arbitrary binary payloads (PDFs, images, anything) are carried losslessly and no payload byte can collide with a delimiter.
- Reads are bounded by MaxFrameSizeV2 and every I/O operation has a deadline, preventing unbounded-memory and hung-connection denial of service.
- A monotonic per-connection sequence number defends against replay and reordering.
Index ΒΆ
- Constants
- Variables
- func CloseClient(conn io.Closer) error
- func ConnectClient(host string, port int) (net.Conn, error)
- func ConnectTLSClient(host string, port int, config *tls.Config) (net.Conn, error)
- func CreateServer(port int) (net.Listener, error)
- func CreateTLSServer(port int, config *tls.Config) (net.Listener, error)
- func Deserialize(buffer string, msg *Message) error
- func DeserializeV2(plaintext []byte, msg *Message) (uint64, error)
- func NewMT(mt MT_V2) bool
- func Receive(conn NetworkIO) (string, error)
- func Send(conn NetworkIO, msg *Message) (int, error)
- func SendResponseV2(conn SecureConn, c Cipher, code ResponseCode, seq uint64) error
- func SendV2(conn SecureConn, c Cipher, msg *Message, seq uint64) (int, error)
- func Serialize(msg *Message) ([]byte, error)
- func SerializeV2(msg *Message, seq uint64) ([]byte, error)
- func TypeToString(messageType MT) string
- func TypeToStringV2(code MT) string
- type Auth
- type AuthData
- type AuthHandler
- type AuthHandlerV2
- type Cipher
- type Client
- type ClientV2
- func (c *ClientV2) Close() error
- func (c *ClientV2) Send(messageType MT, data []byte, filename string) (ResponseCode, error)
- func (c *ClientV2) SendDocument(document []byte, filename string) (ResponseCode, error)
- func (c *ClientV2) SendNotification(message string) (ResponseCode, error)
- func (c *ClientV2) SendURL(url string) (ResponseCode, error)
- type Handler
- type MT
- type MT_V2
- type Message
- type NetworkIO
- type OptionV2
- type ResponseCode
- type SecureConn
- type Server
- type ServerV2
- type V2
Constants ΒΆ
const ( // SaltSize is the length in bytes of the per-connection PBKDF2 salt. SaltSize = 16 // NonceSize is the AES-GCM standard nonce length in bytes. NonceSize = 12 // KeySize is the AES-256 key length in bytes. KeySize = 32 // GCMTagSize is the AES-GCM authentication tag length in bytes. GCMTagSize = 16 // DefaultKDFIterations is the default PBKDF2 iteration count. It follows the // OWASP recommendation for PBKDF2-HMAC-SHA256 and is applied once per // connection (not per frame) so the cost is bounded. DefaultKDFIterations = 600_000 )
Cryptographic sizing constants for the ATXP V2 secure layer. None of these are magic numbers: they are fixed by the chosen primitives (AES-256-GCM, PBKDF2-HMAC-SHA256).
const ( // ProtocolVersionV2 is the version byte sent in the handshake header. ProtocolVersionV2 = 2 // HandshakeMagic prefixes the handshake header so peers can detect a // non-ATXP-V2 stream early. HandshakeMagic = "ATXP2" // LengthPrefixSize is the size in bytes of the big-endian frame length. LengthPrefixSize = 4 // MaxFrameSizeV2 is the default ceiling on a single encrypted frame // (16 MiB). It can be raised or lowered per endpoint with // [WithMaxFrameSize] β useful for beefier servers that must accept larger // documents. MaxFrameSizeV2 = 1 << 24 // MinFrameSizeV2 is the smallest a valid encrypted frame can be: a 12-byte // nonce plus a 16-byte GCM tag. A configured cap below this is rejected. MinFrameSizeV2 = NonceSize + GCMTagSize // DefaultIOTimeout bounds every frame read/write and handshake step. DefaultIOTimeout = 30 * time.Second )
Protocol-level constants for ATXP V2. None are magic numbers.
Variables ΒΆ
var ( // ErrFrameTooLarge is returned when an incoming frame announces a length // above MaxFrameSizeV2, or a frame to be sent exceeds that ceiling. ErrFrameTooLarge = errors.New("atxp: frame exceeds MaxFrameSizeV2") // ErrFrameTooSmall is returned when a frame is shorter than the minimum // envelope (nonce + GCM tag) and therefore cannot be authentic. ErrFrameTooSmall = errors.New("atxp: frame smaller than minimum secure envelope") // ErrInvalidChecksum is returned when AES-GCM authentication fails while // opening a frame. It means the password is wrong or the ciphertext was // tampered with. The two cases are intentionally indistinguishable. ErrInvalidChecksum = errors.New("atxp: decryption or authentication failed") // ErrHandshake is returned when the V2 handshake cannot be completed // (bad magic, unsupported version, short read). ErrHandshake = errors.New("atxp: handshake failed") // ErrWeakPassword is returned by NewV2 when the supplied password is empty. ErrWeakPassword = errors.New("atxp: password must be non-empty") // ErrReplay is returned when a received frame carries a sequence number // that is not strictly greater than the last accepted one, indicating a // replayed or reordered frame. ErrReplay = errors.New("atxp: out-of-order or replayed frame") // ErrInvalidEnvelope is returned when the decrypted plaintext does not // conform to the ATXP V2 internal envelope layout. ErrInvalidEnvelope = errors.New("atxp: malformed v2 envelope") // ErrInvalidKey is returned when a derived or supplied key has an // unexpected length for AES-256. ErrInvalidKey = errors.New("atxp: key must be 32 bytes for AES-256") )
Sentinel errors for the ATXP V2 secure protocol. Inspect them with errors.Is; never compare error strings directly.
var ( // ErrInvalidFormat occurs when an ATXP packet does not comply with the protocol syntax. ErrInvalidFormat = errors.New("malformed atxp packet protocol") )
Functions ΒΆ
func CloseClient ΒΆ
CloseClient terminates the provided connection safely.
func ConnectClient ΒΆ
ConnectClient dials an outbound virtual raw network channel interface targeting a remote ATXP host destination.
func ConnectTLSClient ΒΆ
ConnectTLSClient dials an outbound secure network channel interface targeting a remote ATXP host destination over TLS.
func CreateServer ΒΆ
CreateServer establishes a TCP network listener for incoming ATXP connections at the specified local port binding.
func CreateTLSServer ΒΆ
CreateTLSServer establishes a secure TLS network listener for incoming ATXP connections using the provided server certificate configuration.
func Deserialize ΒΆ
Deserialize decodes a raw string packet back into the provided Message structure reference based on ATXP syntax.
func DeserializeV2 ΒΆ added in v1.3.0
DeserializeV2 decodes a V2 message envelope into msg and returns the carried sequence number. It returns ErrInvalidEnvelope for any structural fault.
func NewMT ΒΆ added in v1.3.0
NewMT registers a new ATXP V2 message type. It returns false (and registers nothing) when the Code is already in use, preventing accidental override of the built-in or previously registered types. It is safe for concurrent use.
func Receive ΒΆ
Receive continuously pulls incoming bytes out of a custom NetworkIO reference stream container until a trailing ATXP sequence header is hit.
func Send ΒΆ
Send serializes a Message and transmits it through the provided NetworkIO implementation using ATXP framing.
func SendResponseV2 ΒΆ added in v1.3.0
func SendResponseV2(conn SecureConn, c Cipher, code ResponseCode, seq uint64) error
SendResponseV2 seals and writes a response frame using the default frame cap.
func SendV2 ΒΆ added in v1.3.0
SendV2 serializes, seals and writes a message frame using the default frame cap MaxFrameSizeV2, returning the number of bytes written on the wire. To use a custom cap, build a ClientV2/ServerV2 with WithMaxFrameSize.
func Serialize ΒΆ
Serialize encodes a Message into a raw byte slice payload according to the ATXP wire protocol.
func SerializeV2 ΒΆ added in v1.3.0
SerializeV2 encodes msg and its sequence number into the V2 inner plaintext envelope. Every variable-length field is length-prefixed, so the payload may contain any bytes. The result is the plaintext to be sealed, not the wire frame.
func TypeToString ΒΆ
TypeToString converts a numeric ATXP type to its equivalent string representation.
func TypeToStringV2 ΒΆ added in v1.3.0
TypeToStringV2 converts a registered message type code to its Name, or "UNKNOWN" when the code is not registered. It is safe for concurrent use.
Types ΒΆ
type AuthData ΒΆ added in v1.1.0
AuthData encapsulates optional authentication metadata that may be associated with incoming ATXP messages, allowing handlers to access user credentials or session information when necessary.
type AuthHandler ΒΆ added in v1.1.0
AuthHandler defines a function signature for authentication logic, allowing the server to verify credentials and optionally return additional authentication data for use in message handling.
type AuthHandlerV2 ΒΆ added in v1.3.0
AuthHandlerV2 authorizes a connection by username only. Unlike the V1 AuthHandler, it receives no password: in V2 the password is the encryption key and is never transmitted, so the fact that the client's frames decrypt successfully already proves it holds the shared secret. The username is used for identity and to attach per-user AuthData.
type Cipher ΒΆ added in v1.3.0
type Cipher interface {
Seal(plaintext []byte) ([]byte, error)
Open(nonceAndCiphertext []byte) ([]byte, error)
}
Cipher seals and opens ATXP V2 frame payloads using an authenticated encryption scheme. Implementations are safe for concurrent use.
Seal returns the concatenation nonce || ciphertext || tag. Open expects that same layout and returns the recovered plaintext, or ErrInvalidChecksum when authentication fails (wrong key or tampering).
type Client ΒΆ
type Client struct {
// contains filtered or unexported fields
}
Client represents an ATXP protocol client session wrapping an active network connection.
func NewClient ΒΆ
NewClient instantiates a new Client reference associated with a specific connection and credentials.
func (*Client) SendDocument ΒΆ
func (c *Client) SendDocument(document []byte, filename string) (ResponseCode, error)
SendDocument transmits a dedicated document byte slice frame payload with an optional filename using the internal Client connection state.
func (*Client) SendNotification ΒΆ
func (c *Client) SendNotification(message string) (ResponseCode, error)
SendNotification transmits a dedicated alert or notification payload frame using the internal Client connection state.
type ClientV2 ΒΆ added in v1.3.0
type ClientV2 struct {
// contains filtered or unexported fields
}
ClientV2 is a secure ATXP V2 client bound to a single connection. It performs the handshake on construction and thereafter encrypts every frame and tracks sequence numbers for replay protection.
ClientV2 is NOT safe for concurrent use by multiple goroutines; serialize calls or use one client per goroutine.
func NewClientV2 ΒΆ added in v1.3.0
func NewClientV2(conn SecureConn, password, username string, opts ...OptionV2) (*ClientV2, error)
NewClientV2 derives the session key via the V2 client handshake over conn and returns a ready client. The password is used only to derive the encryption key and is never transmitted. username identifies the caller to the server's AuthHandlerV2.
func (*ClientV2) Send ΒΆ added in v1.3.0
Send transmits a frame of an arbitrary (possibly custom, see NewMT) message type. filename is only meaningful for document-like types and may be empty.
func (*ClientV2) SendDocument ΒΆ added in v1.3.0
func (c *ClientV2) SendDocument(document []byte, filename string) (ResponseCode, error)
SendDocument transmits a binary document with an optional filename. The payload may contain arbitrary bytes (e.g. a PDF); the length-prefixed envelope carries it losslessly.
func (*ClientV2) SendNotification ΒΆ added in v1.3.0
func (c *ClientV2) SendNotification(message string) (ResponseCode, error)
SendNotification transmits a notification message frame.
type Handler ΒΆ
type Handler func(msg *Message, authData AuthData) ResponseCode
Handler defines a function signature capable of routing and processing incoming decrypted ATXP message payloads.
func ValidateDocumentHandler ΒΆ
ValidateDocumentHandler provides a basic validation ensuring payload sizes match requirements.
func ValidateURLHandler ΒΆ
func ValidateURLHandler() Handler
ValidateURLHandler provides a standard fallback business logic example validation for standard URL structures.
type MT ΒΆ
type MT int
MT represents the numeric type identifier for ATXP message frames.
Message Types constants representing supported ATXP frames.
func StringToType ΒΆ
StringToType converts an ATXP string type representation back to its numeric value.
func StringToTypeV2 ΒΆ added in v1.3.0
StringToTypeV2 resolves a registered message type Name back to its code. The boolean result is false when no registered type carries that name. It is safe for concurrent use.
type MT_V2 ΒΆ added in v1.3.0
type MT_V2 struct {
// Name is the human-readable identifier transmitted on the wire is NOT
// used for routing; routing is done by Code. Name is metadata for tooling
// and diagnostics.
Name string
// Code is the numeric routing identifier. It must be unique and, because it
// is serialized as a big-endian uint32, must be in the range [0, 2^32).
Code MT
// Description documents the intended use of the message type.
Description string
}
MT_V2 describes a registered ATXP V2 message type. Unlike the V1 fixed enum, V2 message types are registrable at runtime so that callers outside this package can define their own framing categories (for example a webhook registration URL, a storage document, or an event-driven notification).
type Message ΒΆ
Message represents an internal ATXP protocol message frame. It wraps the type, an optional byte payload data structure, and credentials.
func ReceiveV2 ΒΆ added in v1.3.0
func ReceiveV2(conn SecureConn, c Cipher) (*Message, uint64, error)
ReceiveV2 reads, opens and decodes a single message frame using the default frame cap MaxFrameSizeV2, returning the message and its sequence number.
type NetworkIO ΒΆ
type NetworkIO interface {
io.ReadWriter
Close() error
}
NetworkIO abstracts the net.Conn interface for easy testing and dependency injection.
type OptionV2 ΒΆ added in v1.3.0
type OptionV2 func(*V2)
OptionV2 configures a V2 instance.
func WithHandshakeTimeout ΒΆ added in v1.3.0
WithHandshakeTimeout overrides the deadline applied to handshake I/O.
func WithIterations ΒΆ added in v1.3.0
WithIterations overrides the PBKDF2 iteration count. Values <= 0 are ignored. Both peers must use the same value to derive matching keys.
func WithMaxFrameSize ΒΆ added in v1.3.0
WithMaxFrameSize overrides the maximum encrypted frame size accepted and emitted by ClientV2 and ServerV2 built from this endpoint. Raise it for servers that must transfer large documents, or lower it to tighten the denial-of-service surface. Values below MinFrameSizeV2 are ignored, keeping the default MaxFrameSizeV2. Peers should agree on a compatible cap: a sender's cap must not exceed the receiver's, or large frames are rejected.
type ResponseCode ΒΆ
type ResponseCode int
ResponseCode represents the status of an ATXP protocol handshake or message processing result.
const ( OK ResponseCode = iota ERROR UNAUTHORIZED )
Response Codes constants representing ATXP protocol handshake results.
func ReceiveResponse ΒΆ
func ReceiveResponse(conn NetworkIO) (ResponseCode, error)
ReceiveResponse parses an incoming ATXP acknowledgment envelope to retrieve status responses from a NetworkIO stream.
func ReceiveResponseV2 ΒΆ added in v1.3.0
func ReceiveResponseV2(conn SecureConn, c Cipher) (ResponseCode, uint64, error)
ReceiveResponseV2 reads, opens and decodes a single response frame using the default frame cap.
func SendResponse ΒΆ
func SendResponse(conn NetworkIO, responseCode ResponseCode) (ResponseCode, error)
SendResponse flushes an ATXP status acknowledgment payload segment back to the underlying socket connection.
type SecureConn ΒΆ added in v1.3.0
type SecureConn interface {
io.ReadWriteCloser
SetReadDeadline(t time.Time) error
SetWriteDeadline(t time.Time) error
}
SecureConn is the transport contract required by the V2 layer. The standard library net.Conn satisfies it. Declaring deadline methods in the interface keeps every I/O operation bounded and keeps the layer testable with mocks.
type Server ΒΆ
type Server struct {
// contains filtered or unexported fields
}
Server manages inbound connection routing rules, payload verification, and session authentication lifecycles.
func NewServer ΒΆ
func NewServer(authFn AuthHandler) *Server
NewServer configures a brand new Server context setup with no default active route bindings.
func (*Server) HandleConnection ΒΆ
HandleConnection processes single network stream frames incoming through standard NetworkIO implementations.
func (*Server) RegisterHandler ΒΆ
RegisterHandler registers a specific Handler callback mapping execution logic against an ATXP framing type.
type ServerV2 ΒΆ added in v1.3.0
type ServerV2 struct {
// contains filtered or unexported fields
}
ServerV2 is a secure ATXP V2 server. It performs the handshake per connection, decrypts and routes frames to registered handlers, and enforces replay protection via per-connection sequence numbers.
ServerV2 is safe for concurrent use: handler registration and lookup are guarded by a mutex, and each connection is handled in its own goroutine.
func NewServerV2 ΒΆ added in v1.3.0
func NewServerV2(password string, authFn AuthHandlerV2, opts ...OptionV2) (*ServerV2, error)
NewServerV2 creates a secure server using the shared password to derive per-connection session keys. authFn may be nil to accept any client that holds the password.
func (*ServerV2) HandleConnection ΒΆ added in v1.3.0
func (s *ServerV2) HandleConnection(conn SecureConn)
HandleConnection runs the handshake and then the per-connection frame loop: receive, verify sequence ordering, authorize, route, respond. Each response also carries a monotonic sequence number for the client's replay checks.
func (*ServerV2) RegisterHandler ΒΆ added in v1.3.0
RegisterHandler binds a Handler to a message type. It is safe for concurrent use.
type V2 ΒΆ added in v1.3.0
type V2 struct {
// contains filtered or unexported fields
}
V2 holds the shared secret and key-derivation parameters for an ATXP V2 endpoint. It is safe for concurrent use; the derived per-connection Cipher is what carries connection state.
func NewV2 ΒΆ added in v1.3.0
NewV2 creates a V2 endpoint from a shared password. It returns ErrWeakPassword when the password is empty.
func (*V2) ClientHandshake ΒΆ added in v1.3.0
func (v *V2) ClientHandshake(conn SecureConn) (Cipher, error)
ClientHandshake performs the client side of the V2 handshake: it reads and validates the handshake header and returns the session Cipher.
func (*V2) ServerHandshake ΒΆ added in v1.3.0
func (v *V2) ServerHandshake(conn SecureConn) (Cipher, error)
ServerHandshake performs the server side of the V2 handshake: it generates a random salt, transmits the handshake header, and returns the session Cipher. The salt is not secret.