rfc-8323

CoAP (Constrained Application Protocol) over TCP, TLS, and WebSockets

C. Bormann, S. Lemay, H. Tschofenig, K. Hartke, B. Silverajan, B. Raymor (Editor)
date2018-02 streamIETF areawit wgcore statusPROPOSED STANDARD pages54 canonicalhttps://www.rfc-editor.org/rfc/rfc8323 doi10.17487/RFC8323
The Constrained Application Protocol (CoAP), although inspired by HTTP, was designed to use UDP instead of TCP. The message layer of CoAP over UDP includes support for reliable delivery, simple congestion control, and flow control. Some environments benefit from the availability of CoAP carried over reliable transports such as TCP or Transport Layer Security (TLS). This document outlines the changes required to use CoAP over TCP, TLS, and WebSockets transports. It also formally updates RFC 7641 for use with these transports and RFC 7959 to enable the use of larger messages over a reliable transport.

updated by

updates

Extracted elements (30)

design-rationale §6

Although block-wise transfer is no longer required for IP-fragmentation avoidance over TCP, it remains applicable for large messages (to avoid head-of-line blocking) and for UDP-to-TCP gateways that cannot reconstruct a complete body without block context.

tcp

design-rationale §1

CoAP over TCP was introduced primarily because UDP is completely blocked in approximately 2–4% of terrestrial access networks, with higher rates in enterprise environments. TCP also provides longer NAT binding lifetimes (mean 386 minutes vs. 160 seconds for UDP) and more sophisticated congestion/flow control for large payloads.

tcp, nat, congestion

design-rationale §3.1

The Type (T) and Message ID fields from CoAP over UDP are elided in the TCP message format because TCP provides reliable delivery and deduplication, making those fields redundant. The Version field is also elided; if version negotiation is needed in the future, the CSM mechanism was specifically designed to enable that.

tcp

normative-requirement §7.4 MUST

A CoAP client observing resources over a reliable transport MUST explicitly deregister by issuing a GET request with the Observe Option set to 1 (deregister), rather than relying on a Reset message as with CoAP over UDP.

tcp

normative-requirement §9 MUST

A security solution MUST be implemented to protect CoAP over reliable transports and MUST be enabled by default. TLS is the defined binding, but alternative solutions at other protocol layers MAY be used when appropriate.

tls, security

normative-requirement §3.3 MUST

CoAP responses MUST be returned over the same connection as the originating request. Each concurrent request is differentiated by its Token, which is scoped locally to the connection.

tcp

normative-requirement §3.4 MUST

Empty messages (Code 0.00) can always be sent and MUST be ignored by the recipient, providing a basic keepalive function that can refresh NAT bindings.

tcp, nat

normative-requirement §3.3 MUST

Endpoints MUST treat a missing or invalid CSM as a connection error and abort the connection.

tcp

normative-requirement §7.1 MUST

For CoAP over reliable transports, the Observe Option value in 2.xx notifications MAY be empty on transmission and MUST be ignored on reception, since TCP guarantees ordered delivery and reordering detection is unnecessary.

tcp

normative-requirement §8.2 MUST

For coaps+tcp on TCP ports other than 5684, the TLS client MUST use the ALPN extension to advertise the "coap" protocol identifier. If the server does not negotiate ALPN or returns no_application_protocol, the client MUST close the connection.

tls, tcp

normative-requirement §5.2 MUST

If a critical Signaling Option is not understood by the receiver, it MUST abort the connection. Elective options that are not understood MUST be ignored.

tcp

normative-requirement §3.3 MUST

Once a Transport Connection is established, each endpoint MUST send a CSM as its first message on the connection to establish initial capabilities and settings.

tcp

normative-requirement §7.4 MUST

The CoAP server MUST remove all observer list entries associated with a client endpoint when the reliable transport connection either times out or is closed.

tcp

normative-requirement §4.1 MUST

The WebSocket client MUST include the subprotocol name "coap" in the list of protocols during the WebSocket opening handshake.

websocket

normative-requirement §3.3 MUST NOT

To avoid deadlock, the Connection Initiator MUST NOT wait for the Connection Acceptor to send its initial CSM before sending its own initial CSM.

tcp

normative-requirement §5.4 MUST

Upon receipt of a Ping message (code 7.02), the receiver MUST return a Pong message (code 7.03) with an identical Token in response, and SHOULD respond as soon as practical unless the Ping carries the Custody Option.

tcp

protocol-element §6

Block-wise Extension for Reliable Transport (BERT) extends RFC 7959 by using SZX=7 (a reserved BERT Option value). In descriptive usage, a non-final BERT block payload MUST be a multiple of 1024 bytes; a final BERT block is a multiple of 1024 bytes plus a partial block of less than 1024 bytes.

tcp

protocol-element §5.3

Capabilities and Settings Messages (CSMs, code 7.01) carry capability options (what the sender can receive) and setting options (what the sender will apply). One CSM MUST be sent at connection start; additional CSMs MAY be sent later. Options are cumulative and not reset by subsequent CSMs.

tcp

protocol-element §8

Four new URI schemes are defined: coap+tcp (default port 5683), coaps+tcp (default port 5684), coap+ws (default port 80), and coaps+ws (default port 443). Resources under different schemes have distinct origins even if they share the same authority.

tcp, websocket

protocol-element §5.6

The Abort message (code 7.05) signals an immediate unrecoverable connection error. The sender shuts down immediately after sending. A diagnostic payload SHOULD be included. The Bad-CSM-Option (uint, 0–2 bytes) identifies the offending CSM option number.

tcp

protocol-element §5.3.2

The Block-Wise-Transfer Option (CSM option number 4) signals that the sender supports block-wise transfer per RFC 7959. When combined with a Max-Message-Size greater than 1152, it also indicates BERT support.

tcp

protocol-element §5.3.1

The Max-Message-Size Option (CSM option number 2) indicates the maximum message size in bytes the sender can receive. Its base value is 1152. Values greater than 1152 in combination with Block-Wise-Transfer Option also signal BERT support.

tcp

protocol-element §5.5

The Release message (code 7.04) signals an orderly shutdown request, leaving the peer to close the connection. It may carry the Alternative-Address Option (string, 1–255 bytes, repeatable) and Hold-Off Option (uint, 0–3 bytes) to redirect or throttle reconnections.

tcp

registry §11.1

IANA created the "CoAP Signaling Codes" subregistry (codes 7.00–7.31) with initial entries: 7.01 CSM, 7.02 Ping, 7.03 Pong, 7.04 Release, 7.05 Abort. Future additions require IETF Review or IESG Approval.

registry, tcp

registry §11.2

IANA created the "CoAP Signaling Option Numbers" subregistry with initial entries: Max-Message-Size (7.01, #2), Block-Wise-Transfer (7.01, #4), Custody (7.02/7.03, #2), Alternative-Address (7.04, #2), Hold-Off (7.04, #4), Bad-CSM-Option (7.05, #2).

registry, tcp

registry §11.5

IANA registered four permanent URI schemes: coap+tcp, coaps+tcp, coap+ws, and coaps+ws. A note in each registration acknowledges that assigning distinct URI schemes per transport runs counter to the W3C principle of avoiding URI aliases for the same resource.

registry, tcp, websocket

registry §11.3

IANA registered port 5683 (service name "coap", TCP) and port 5684 (service name "coaps", TCP). Port 5684 addresses the exceptional case of TLS implementations that do not support the ALPN extension.

registry, tcp, tls

security-consideration §10.1 MUST NOT

A peer MUST NOT assume that a successful connection to an Alternative-Address (received in a Release message) inherits all the security properties of the current connection. The guidance from an Alternative-Address Option cannot be followed blindly.

security, tls

wire-format §4.2 MUST

For CoAP over WebSockets, the message format is identical to CoAP over TCP except the Length (Len) field MUST be set to zero, because message length is provided by the WebSocket frame itself.

websocket

wire-format §3.2

The CoAP over TCP frame replaces the fixed 4-byte UDP header with a variable-length framing header. A 4-bit Len field encodes message length (0–12 = literal bytes; 13 = 8-bit Extended Length minus 13; 14 = 16-bit Extended Length minus 269; 15 = 32-bit Extended Length minus 65805). The Version, Type, and Message ID fields are absent.

tcp