MatterEx.SecureChannel (matter_ex v0.4.0)

Copy Markdown View Source

Secure message framing for established Matter sessions.

Pure functional module — caller threads session state through. Wraps the message codec, AES-CCM encryption, counter management, and replay protection into two operations:

  • seal/2 — encrypt and frame an outgoing message
  • open/2 — decrypt and verify an incoming frame

Summary

Functions

Decrypt and verify an incoming encrypted frame.

Encrypt and frame an outgoing message.

Encrypt and frame an outgoing message, returning the assigned message counter.

Functions

open(session, frame)

Decrypt and verify an incoming encrypted frame.

Parses the plaintext header, verifies the session ID matches, decrypts the payload, and checks the message counter for replay.

Returns {:ok, message, updated_session} or {:error, reason}.

seal(session, proto)

Encrypt and frame an outgoing message.

Builds a message header with the session's local session ID, increments the message counter, constructs the nonce, and encrypts the protocol header + payload with AES-128-CCM.

Returns {frame_binary, updated_session}.

seal_with_counter(session, proto)

Encrypt and frame an outgoing message, returning the assigned message counter.