stuntmaster

    Production-grade RFC 8489 STUN for MoonBit — RFC 5769 proven

    stun
    networking
    rfc8489
    Download zip
    Author
    Version
    0.2.4
    License
    Apache-2.0
    Last updated
    18 days ago
    Downloads
    24

    Dependencies

    #Camilotk/stuntmaster

    stuntmaster is the production-grade RFC 8489 STUN stack for MoonBit — proven against every RFC 5769 vector.

    #Scope

    Version 0.2.4 provides a pure RFC 8489 protocol package, a protocol-independent STUN transaction engine, RFC 7983 packet demultiplexing, and the native infrastructure the upcoming UDP/TCP/TLS transports build on.

    protocol:

    • fixed-header, message-type, attribute-frame, and generic message codecs;
    • IPv4 and IPv6 MAPPED-ADDRESS, XOR-MAPPED-ADDRESS, and ALTERNATE-SERVER values;
    • USERNAME, REALM, NONCE, SOFTWARE, ERROR-CODE, and UNKNOWN-ATTRIBUTES values;
    • short-term credentials and legacy MD5 long-term key derivation;
    • MESSAGE-INTEGRITY and full-length MESSAGE-INTEGRITY-SHA256 signing and verification;
    • FINGERPRINT generation and verification;
    • security-attribute order validation; and
    • complete RFC 5769 request and IPv4/IPv6 response vectors.

    engine:

    • an I/O-free, clock-free event/effect transaction state machine (Engine::handle);
    • transaction tracking, response correlation, and RFC 8489 §6.2.1 retransmission timing;
    • a generation-based guard against stale retransmission timers;
    • an injectable transaction-ID source, with a deterministic generator for tests; and
    • unauthenticated and short-/long-term-authenticated Binding transaction flows, including inbound MESSAGE-INTEGRITY verification on responses.

    mux:

    • RFC 7983 §7 first-byte demultiplexing into STUN, DTLS, TURN ChannelData, RTP, or RTCP, with an Unknown fallback for short or unrecognized input;
    • STUN classification confirmed by the RFC 8489 magic cookie; RTP/RTCP disambiguated by the RFC 5761 §4 RTCP packet-type range.

    cmd/main (native target only):

    • moonbitlang/async@0.21.0, the async runtime the UDP/TCP/TLS transports will run on, scoped so it cannot leak into protocol/engine; and
    • the production TransactionId generator for engine's injectable id source, sourcing OS-grade secure randomness from /dev/urandom and failing loudly rather than degrading if that source is ever exhausted.

    Real sockets/DNS, PRECIS processing, password-algorithm negotiation, and SHA-256 long-term key derivation are outside this release.

    #Installation

    moon add Camilotk/stuntmaster@0.2.4

    Import the protocol package from Camilotk/stuntmaster/protocol.

    #Security Boundaries

    Use verify_preferred_message_integrity when either integrity algorithm may be present. It verifies SHA-256 whenever that attribute exists, never downgrades an invalid SHA-256 value to SHA-1, and returns the count of attributes preceding the verified integrity attribute. Attributes at or after that boundary are not authenticated and must not be treated as authenticated application input.

    The algorithm-specific verification methods are low-level operations. A FINGERPRINT detects accidental corruption and protocol multiplexing mistakes; it does not authenticate a message.

    LongTermCredentialKey::from_credentials implements legacy MD5 derivation over the exact UTF-8 bytes of username:realm:password. Callers must apply the required OpaqueString or legacy SASLprep processing before calling it. The MESSAGE-INTEGRITY-SHA256 API emits and accepts the RFC default full 32-byte value; usage-specific truncation is not supported.

    Generic decoding retains attribute values as views into the input and ignores bytes beyond the length declared in the STUN header. Generic encoding emits zero padding and does not recompute existing integrity or fingerprint attributes, so signed messages must be regenerated through the security APIs after mutation.

    #Development

    moon fmt moon fmt --check moon check --deny-warn moon test --deny-warn

    See DEVELOPMENT.md for the audited MoonBit workflow and DEPENDENCIES.md for dependency decisions. RFC 5769 vector attribution is in THIRD_PARTY_NOTICES.md.