rtciv0.5.0

rtci-stun

STUN messages, attributes and a sans-I/O client (RFC 8489), for WebRTC. 22 public modules, 196 items at 0.5.0.

README

STUN messages and attributes, message integrity (HMAC-SHA1 and HMAC-SHA256), fingerprints, long-term credentials with the password algorithms and USERHASH, a validator that exposes only the attributes the integrity check covers, and a client transaction layer with the RFC 8489 retransmission timer.

Specifications

  • RFC 8489, Session Traversal Utilities for NAT (STUN)
  • RFC 5780, NAT behaviour discovery attributes
  • RFC 8656 and RFC 6062, the attributes TURN adds
  • RFC 7983, multiplexing STUN with DTLS, RTP and others

Clause-by-clause status, with the test that proves each clause: rfc8489, rfc5780, rfc7983.

Use

message::Message builds, marshals and parses messages; validated::Validator checks integrity and fingerprint before an attribute is read; client::Client runs transactions. rtci-ice and rtci-turn are built on it.

Sans-I/O

The client is a state machine driven by the caller's datagrams and Instants. The crate does no I/O and reads no clock: every call that depends on time takes an Instant from the caller. Integrity uses rtci-crypto's provider.

Licence

Licensed under either of the MIT licence or the Apache License, Version 2.0, at your option.

This crate is part of the rtci workspace, which descends from webrtc-rs/rtc and is developed independently; FORK.md lists what it carries over upstream. Upstream's licence and copyright notices are retained.

rtci_stun

STUN for the Sans-I/O WebRTC stack.

  • modaddrSocket-address helpers shared by the address attributes.
  • modagentTransaction tracking: which requests are outstanding and when they time out.
  • modalternateThe client side of 300 (Try Alternate): ALTERNATE-SERVER and the redirection-loop rule.
  • modattributesSTUN attribute types.
  • modchecksValidation helpers for received messages and attributes.
  • modclientA Sans-I/O STUN client for talking to a STUN server.
  • moderror_codeThe ERROR-CODE attribute and the codes defined by STUN, TURN and ICE.
  • modfingerprintThe FINGERPRINT attribute, a CRC-32 over the message.
  • modintegrityThe MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256 attributes, HMACs over the message.
  • modlong_termThe client side of the long-term credential mechanism.
  • modmessageThe STUN message itself: header, attributes, and encoding.
  • modnonce_cookieThe nonce cookie and its STUN Security Feature bits.
  • modopaqueThe OpaqueString profile (RFC 8265) for user names, realms and passwords.
  • modpassword_algorithmThe PASSWORD-ALGORITHM and PASSWORD-ALGORITHMS attributes.
  • modtextattrsText-valued attributes such as USERNAME, REALM and SOFTWARE.
  • modtimerThe retransmission timer of RFC 8489 section 6.2, shared by every transaction layer.
  • moduattrsThe UNKNOWN-ATTRIBUTES attribute, listing attributes a server could not process.
  • moduriParsing stun: and stuns: URIs.
  • moduserhashThe USERHASH attribute.
  • modvalidatedChecking a received message and reading only what its integrity covers.
  • modxoraddrThe XOR-MAPPED-ADDRESS attribute, whose value is masked with the magic cookie.
  • constDEFAULT_PORTIANA assigned ports for "stun" protocol.
  • constDEFAULT_TLS_PORTThe default port for stuns: (STUN over TLS/DTLS).
  • usecrypto

rtci_stun::addr

Socket-address helpers shared by the address attributes.

  • structMappedAddressMappedAddress represents MAPPED-ADDRESS attribute.

rtci_stun::agent

Transaction tracking: which requests are outstanding and when they time out.

  • structAgentAgent is low-level abstraction over transaction list that handles concurrency and time outs (via Collect call).
  • structEventEvent is passed to Handler describing the transaction event. Do not reuse outside Handler.
  • enumClientAgentClientAgent is Agent implementation that is used by Client to process transactions.
  • enumStunEventWhat became of a STUN transaction.
  • enumTransactionFailureWhy a transaction failed although the server answered.

rtci_stun::alternate

The client side of 300 (Try Alternate): ALTERNATE-SERVER and the redirection-loop rule.

  • structRedirectGuardRemembers which servers a request went to, so that a redirection back to one of them within five minutes is refused (RFC 8489 section 10: the client "MUST ignore the redirection and consider the transaction to have failed").
  • structTryAlternateWhat a 300 (Try Alternate) error response says.
  • fnis_usable_alternateWhether server, read from an ALTERNATE-SERVER, can name "a different STUN server that the STUN client should try" (RFC 8489 section 14.15) for a client that reached the redirecting server at original.
  • constREDIRECT_LOOP_WINDOWHow long a server counts as already tried (RFC 8489 section 10: "within the last five minutes").

rtci_stun::attributes

STUN attribute types.

rtci_stun::checks

Validation helpers for received messages and attributes.

  • fncheck_overflowCheck_overflow returns ErrAttributeSizeOverflow if got is bigger that max.
  • fncheck_sizeCheck_size returns ErrAttrSizeInvalid if got is not equal to expected.
  • fnis_attr_size_invalidIs_attr_size_invalid returns true if error means that attribute size is invalid.
  • fnis_attr_size_overflowIs_attr_size_overflow returns true if error means that attribute size is too big.

rtci_stun::client

A Sans-I/O STUN client for talking to a STUN server.

  • structClientClient simulates "connection" to STUN server.
  • structClientBuilderBuilds a Client with a chosen transaction timeout, retransmission schedule and handler.
  • structClientTransactionClientTransaction represents transaction in progress. If transaction is succeed or failed, f will be called provided by event. Concurrent access is invalid.
  • structTaggedMessageA Message together with the instant the caller is sending it at.

rtci_stun::error_code

The ERROR-CODE attribute and the codes defined by STUN, TURN and ICE.

rtci_stun::fingerprint

The FINGERPRINT attribute, a CRC-32 over the message.

rtci_stun::integrity

The MESSAGE-INTEGRITY and MESSAGE-INTEGRITY-SHA256 attributes, HMACs over the message.

  • structMessageIntegrityThe MESSAGE-INTEGRITY key: an HMAC-SHA1 is computed over the message with it.
  • structMessageIntegritySha256The MESSAGE-INTEGRITY-SHA256 key: an HMAC-SHA256 is computed over the message with it (RFC 8489 section 14.6).
  • enumIntegrityAlgorithmWhich of the two integrity attributes protects a message.
  • fnlong_term_keyThe key of the long-term credential mechanism for a password algorithm of the STUN Password Algorithms registry (RFC 8489 sections 9.2.2 and 18.5.1):
  • constMESSAGE_INTEGRITY_SHA256_MIN_SIZEThe shortest MESSAGE-INTEGRITY-SHA256 value RFC 8489 section 14.6 allows, in bytes.
  • constMESSAGE_INTEGRITY_SHA256_SIZEThe length of an untruncated MESSAGE-INTEGRITY-SHA256 value in bytes.
  • constMESSAGE_INTEGRITY_SIZEThe length of a MESSAGE-INTEGRITY value in bytes.

rtci_stun::long_term

The client side of the long-term credential mechanism.

  • structLongTermAuthenticationThe authentication attributes of a request, as a Setter: see LongTermCredentials::setter.
  • structLongTermCredentialsA client's long-term credentials for one server, and what the server's challenges added to them. See the module documentation.
  • enumChallengeErrorWhy a 401 or 438 error response does not lead to a retry.
  • enumLongTermResponseWhat a response to a request of this client is, once checked.

rtci_stun::message

The STUN message itself: header, attributes, and encoding.

  • structMessageA STUN message: type, transaction id, and attributes, plus the encoded bytes.
  • structMessageClassA STUN message class: request, indication, success response or error response.
  • structMessageTypeA message's class and method together, as encoded in the first two header bytes.
  • structMethodA STUN method, such as Binding or one of TURN's.
  • structTransactionIdA 96-bit transaction id, which pairs a response with its request.
  • traitCheckerChecker checks *Message attribute.
  • traitGetterGetter parses attribute from *Message.
  • traitSetterInterfaces that are implemented by message attributes, shorthands for them, or helpers for message fields as type or transaction id.
  • fnis_stun_messageIs_stun_message returns true if b looks like STUN message: at least a header, the first two bits zero and the magic cookie in place (RFC 8489 section 6.3). Useful for multiplexing. is_stun_message does not guarantee that decoding will be successful.
  • constATTRIBUTE_HEADER_SIZEBytes of type and length preceding each attribute value.
  • constBINDING_ERRORBinding error response message type.
  • constBINDING_REQUESTCommon STUN message types. Binding request message type.
  • constBINDING_SUCCESSBinding success response message type.
  • constCLASS_ERROR_RESPONSE0b11.
  • constCLASS_INDICATION0b01.
  • constCLASS_REQUESTPossible values for message class in STUN Message Type. 0b00.
  • constCLASS_SUCCESS_RESPONSE0b10.
  • constMAGIC_COOKIEFixed value that aids in distinguishing STUN packets from packets of other protocols when STUN is multiplexed with those other protocols on the same Port.
  • constMESSAGE_HEADER_SIZEBytes in the STUN message header.
  • constMETHOD_ALLOCATETURN Allocate: asks a relay for a public address.
  • constMETHOD_BINDINGPossible methods for STUN Message.
  • constMETHOD_CHANNEL_BINDTURN ChannelBind: binds a channel number to a peer for compact framing.
  • constMETHOD_CONNECTMethods from RFC 6062.
  • constMETHOD_CONNECTION_ATTEMPTTURN-TCP ConnectionAttempt: notifies the client of an inbound TCP connection.
  • constMETHOD_CONNECTION_BINDTURN-TCP ConnectionBind: associates a new TCP connection with an allocation.
  • constMETHOD_CREATE_PERMISSIONTURN CreatePermission: authorizes traffic to and from a peer address.
  • constMETHOD_DATATURN Data: an indication carrying data from a peer through the relay.
  • constMETHOD_REFRESHTURN Refresh: extends or releases an allocation.
  • constMETHOD_SENDTURN Send: an indication carrying data to a peer through the relay.
  • constTRANSACTION_ID_SIZELength of transaction id array (in bytes). 96 bit.

The nonce cookie and its STUN Security Feature bits.

rtci_stun::opaque

The OpaqueString profile (RFC 8265) for user names, realms and passwords.

rtci_stun::password_algorithm

The PASSWORD-ALGORITHM and PASSWORD-ALGORITHMS attributes.

  • structPasswordAlgorithmOne entry of the STUN Password Algorithms registry with its parameters: the value of PASSWORD-ALGORITHM, and an element of PASSWORD-ALGORITHMS.
  • structPasswordAlgorithmsThe PASSWORD-ALGORITHMS attribute: the algorithms a server can derive the long-term key with, in its order of preference.
  • constPASSWORD_ALGORITHM_MD5MD5, the key of RFC 5389 (RFC 8489 section 18.5.1.1): for legacy systems only.
  • constPASSWORD_ALGORITHM_SHA256SHA-256 (RFC 8489 section 18.5.1.2).

rtci_stun::textattrs

Text-valued attributes such as USERNAME, REALM and SOFTWARE.

  • structTextAttributeA text-valued attribute: USERNAME, REALM, NONCE, SOFTWARE or ALTERNATE-DOMAIN.
  • typeAlternateDomainALTERNATE-DOMAIN attribute.
  • typeNonceNONCE attribute.
  • typeRealmREALM attribute.
  • typeSoftwareSOFTWARE attribute.
  • typeUsernameUSERNAME attribute.
  • constMAX_ALTERNATE_DOMAIN_BThe longest ALTERNATE-DOMAIN, in bytes (RFC 8489 section 14.16).
  • constMAX_TEXT_BThe longest REALM, NONCE, SOFTWARE or reason phrase that is sent, in bytes (RFC 8489 sections 14.8 to 14.10 and 14.14).
  • constMAX_TEXT_CHARSREALM, NONCE, SOFTWARE and the reason phrase are fewer than this many characters.
  • constMAX_USERNAME_BThe longest USERNAME that is sent: "fewer than 509 bytes" (RFC 8489 section 14.3).

rtci_stun::timer

The retransmission timer of RFC 8489 section 6.2, shared by every transaction layer.

  • structRtoEstimatorThe retransmission timeout of RFC 6298, as RFC 8489 section 6.2.1 uses it: kept per server, to 1 ms, never below the configured initial value, and forgotten after ten minutes without a transaction.
  • structScheduleThe parameters of the retransmission schedule (RFC 8489 sections 6.2.1 and 6.2.2). The default is the RFC's: Rc 7, Rm 16, Ti 39.5 s.
  • fnafternow + d, without the panic Instant reserves for an overflow.
  • fnis_server_errorWhether code is one of the server errors (500 through 599) after which RFC 8489 section 6.3.4 lets a client resend its request.
  • fnserver_error_resend_delayHow long a client waits, after the server-error response, before the resend-th resend of a request (1 for the first): the interval its retransmission of the same number would wait (RFC 8489 section 6.2.1: RTO, then twice that, and so on), so that four resends are spread over RTO, 2 RTO, 4 RTO and 8 RTO (7.5 s at 500 ms) and a failing server is not asked again at the rate it answers. Each …
  • constDEFAULT_MAX_OUTSTANDINGRFC 8489 section 6.2: outstanding transactions to one server.
  • constDEFAULT_RCRFC 8489 section 6.2.1: Rc, the number of times a request is sent.
  • constDEFAULT_RMRFC 8489 section 6.2.1: Rm, the last wait in units of RTO.
  • constDEFAULT_RTORFC 8489 section 6.2.1: the initial RTO "SHOULD be greater than or equal to 500 ms".
  • constDEFAULT_SERVER_ERROR_RESENDSRFC 8489 section 6.3.4: after an error response of 500 through 599 "the client MAY resend the request; clients that do so MUST limit the number of times they do this. Unless a specific error code specifies a different value, the number of retransmissions SHOULD be limited to 4." The engine's clients resend that many times by default.
  • constDEFAULT_TIRFC 8489 section 6.2.2: Ti, how long a request over a reliable transport waits.
  • constRTO_CACHE_LIFETIMERFC 8489 section 6.2.1: a cached RTO is stale after ten minutes without a transaction.

rtci_stun::uattrs

The UNKNOWN-ATTRIBUTES attribute, listing attributes a server could not process.

rtci_stun::uri

Parsing stun: and stuns: URIs.

  • structUriA parsed stun: or stuns: URI.
  • constSCHEMEThe stun: URI scheme.
  • constSCHEME_SECUREThe stuns: URI scheme, for STUN over TLS or DTLS.

rtci_stun::userhash

The USERHASH attribute.

  • structUserhashThe USERHASH attribute: SHA-256(OpaqueString(username) ":" OpaqueString(realm)).
  • constUSERHASH_SIZEThe length of a USERHASH value in bytes.

rtci_stun::validated

Checking a received message and reading only what its integrity covers.

  • structValidatedMessageA received message that passed a Validator, reduced to what its checks cover.
  • structValidatorThe checks a usage applies to every message it receives.
  • enumRejectionWhy a received message was not accepted.
  • fnunknown_attributes_responseBuilds the answer to a request that failed with Rejection::UnknownAttributes: an error response of the request's method and transaction id with ERROR-CODE 420 (Unknown Attribute) and the attributes in UNKNOWN-ATTRIBUTES (RFC 8489 sections 6.3.1 and 14.8).

rtci_stun::xoraddr

The XOR-MAPPED-ADDRESS attribute, whose value is masked with the magic cookie.

  • structXorMappedAddressXORMappedAddress implements XOR-MAPPED-ADDRESS attribute.
  • fnxor_bytesxor_bytes xors the bytes in a and b. The destination is assumed to have enough space. Returns the number of bytes xor'd.

Generated from the sources of rtci-stun 0.5.0 at its release tag. Items made by macros and methods are on docs.rs.