CORE | C. Bormann |
Internet-Draft | Universitaet Bremen TZI |
Intended status: Standards Track | S. Lemay |
Expires: February 25, 2017 | Zebra Technologies |
H. Tschofenig | |
ARM Ltd. | |
K. Hartke | |
Universitaet Bremen TZI | |
B. Silverajan | |
Tampere University of Technology | |
B. Raymor, Ed. | |
Microsoft | |
August 24, 2016 |
CoAP (Constrained Application Protocol) over TCP, TLS, and WebSockets
draft-ietf-core-coap-tcp-tls-04
The Constrained Application Protocol (CoAP), although inspired by HTTP, was designed to use UDP instead of TCP. The message layer of the CoAP over UDP protocol 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 TLS. This document outlines the changes required to use CoAP over TCP, TLS, and WebSockets transports.
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."
This Internet-Draft will expire on February 25, 2017.
Copyright (c) 2016 IETF Trust and the persons identified as the document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.
The Constrained Application Protocol (CoAP) [RFC7252] was designed for Internet of Things (IoT) deployments, assuming that UDP [RFC0768] or DTLS [RFC6347] over UDP can be used unimpeded. UDP is a good choice for transferring small amounts of data across networks that follow the IP architecture.
Some CoAP deployments need to integrate well with existing enterprise infrastructures, where UDP-based protocols may not be well-received or may even be blocked by firewalls. Middleboxes that are unaware of CoAP usage for IoT can make the use of UDP brittle, resulting in lost or malformed packets.
Emerging standards such as Lightweight Machine to Machine [LWM2M] currently use CoAP over UDP as a transport and require support for CoAP over TCP to address the issues above and to protect investments in existing CoAP implementations and deployments. Although HTTP/2 could also potentially address these requirements, there would be additional costs and delays introduced by such a transition. Currently, there are also fewer HTTP/2 implementations available for constrained devices in comparison to CoAP.
To address these requirements, this document defines how to transport CoAP over TCP, CoAP over TLS, and CoAP over WebSockets. Figure 1 illustrates the layering:
+--------------------------------+ | Application | +--------------------------------+ +--------------------------------+ | Requests/Responses/Signaling | CoAP (RFC 7252) / This Document |--------------------------------| | Message Framing | This Document +--------------------------------+ | Reliable Transport | +--------------------------------+
Figure 1: Layering of CoAP over Reliable Transports
Where NATs are present, CoAP over TCP can help with their traversal. NATs often calculate expiration timers based on the transport layer protocol being used by application protocols. Many NATs maintain TCP-based NAT bindings for longer periods based on the assumption that a transport layer protocol, such as TCP, offers additional information about the session life cycle. UDP, on the other hand, does not provide such information to a NAT and timeouts tend to be much shorter [HomeGateway].
Some environments may also benefit from the ability of TCP to exchange larger payloads, such as firmware images, without application layer segmentation and to utilize the more sophisticated congestion control capabilities provided by many TCP implementations.
CoAP may be integrated into a Web environment where the front-end uses CoAP over UDP from IoT devices to a cloud infrastructure and then CoAP over TCP between the back-end services. A TCP-to-UDP gateway can be used at the cloud boundary to communicate with the UDP-based IoT device.
To allow IoT devices to better communicate in these demanding environments, CoAP needs to support different transport protocols, namely TCP [RFC0793], in some situations secured by TLS [RFC5246].
In addition, some corporate networks only allow Internet access via a HTTP proxy. In this case, the best transport for CoAP would be the WebSocket Protocol [RFC6455]. The WebSocket protocol provides two-way communication between a client and a server after upgrading an HTTP/1.1 [RFC7230] connection and may be available in an environment that blocks CoAP over UDP. Another scenario for CoAP over WebSockets is a CoAP application running inside a web browser without access to connectivity other than HTTP and WebSockets.
This document specifies how to access resources using CoAP requests and responses over the TCP/TLS and WebSocket protocols. This allows connectivity-limited applications to obtain end-to-end CoAP connectivity either by communicating CoAP directly with a CoAP server accessible over a TCP/TLS or WebSocket connection or via a CoAP intermediary that proxies CoAP requests and responses between different transports, such as between WebSockets and UDP.
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in [RFC2119].
This document assumes that readers are familiar with the terms and concepts that are used in [RFC6455] and [RFC7252].
The term “reliable transport” only refers to stream-based transport protocols such as TCP.
The request/response interaction model of CoAP over TCP is the same as CoAP over UDP. The primary differences are in the message layer. CoAP over UDP supports optional reliability by defining four types of messages: Confirmable, Non-confirmable, Acknowledgement, and Reset. TCP eliminates the need for the message layer to support reliability. As a result, message types are not defined in CoAP over TCP.
Conceptually, CoAP over TCP replaces most of the CoAP over UDP message layer with a framing mechanism on top of the byte stream provided by TCP/TLS, conveying the length information for each message that on datagram transports is provided by the UDP/DTLS datagram layer.
TCP ensures reliable message transmission, so the CoAP over TCP messaging layer is not required to support acknowledgements or detection of duplicate messages. As a result, both the Type and Message ID fields are no longer required and are removed from the CoAP over TCP message format. All messages are also untyped.
Figure 2 illustrates the difference between CoAP over UDP and CoAP over reliable transport. The removed Type and Message ID fields are indicated by dashes.
Client Server Client Server | | | | | CON [0xbc90] | | (-------) [------] | | GET /temperature | | GET /temperature | | (Token 0x71) | | (Token 0x71) | +------------------->| +------------------->| | | | | | ACK [0xbc90] | | (-------) [------] | | 2.05 Content | | 2.05 Content | | (Token 0x71) | | (Token 0x71) | | "22.5 C" | | "22.5 C" | |<-------------------+ |<-------------------+ | | | | CoAP over UDP CoAP over reliable transport
Figure 2: Comparison between CoAP over unreliable and reliable transport.
A UDP-to-TCP gateway MUST discard all Empty messages (Code 0.00) after processing at the message layer. For Confirmable (CON), Non-Confirmable (NOM), and Acknowledgement (ACK) messages that are not Empty, their contents are repackaged into untyped messages.
Both the client and the server MUST send a Capability and Settings message (CSM see Section 4.3) as its first message on the connection. This message establishes the initial settings and capabilities for the endpoint such as maximum message size or support for block-wise transfers. The absence of options in the CSM indicates that base values are assumed.
Clients and servers MUST treat a missing or invalid CSM as a connection error and abort the connection (see Section 4.6).
The CoAP message format defined in [RFC7252], as shown in Figure 3, relies on the datagram transport (UDP, or DTLS over UDP) for keeping the individual messages separate and for providing length information.
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Ver| T | TKL | Code | Message ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Token (if any, TKL bytes) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 1 1 1 1 1 1 1| Payload (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 3: RFC 7252 defined CoAP Message Format.
The CoAP over TCP message format is very similar to the format specified for CoAP over UDP. The differences are as follows:
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Len=13 | TKL |Extended Length| Code | TKL bytes ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 1 1 1 1 1 1 1| Payload (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 4: CoAP frame with 8-bit Extended Length field.
The encoding of the Length field is modeled on CoAP Options (see section 3.1 of [RFC7252]).
The following figures show the message format for the 0-bit, 16-bit, and the 32-bit variable length cases.
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Len | TKL | Code | Token (if any, TKL bytes) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 1 1 1 1 1 1 1| Payload (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 5: CoAP message format without an Extended Length field.
For example: A CoAP message just containing a 2.03 code with the token 7f and no options or payload would be encoded as shown in Figure 6.
0 1 2 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 0x01 | 0x43 | 0x7f | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Len = 0 ------> 0x01 TKL = 1 ___/ Code = 2.03 --> 0x43 Token = 0x7f
Figure 6: CoAP message with no options or payload.
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Len=14 | TKL | Extended Length (16 bits) | Code | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Token (if any, TKL bytes) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 1 1 1 1 1 1 1| Payload (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 7: CoAP message format with 16-bit Extended Length field.
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Len=15 | TKL | Extended Length (32 bits) +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | Code | Token (if any, TKL bytes) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 1 1 1 1 1 1 1| Payload (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 8: CoAP message format with 32-bit Extended Length field.
The semantics of the other CoAP header fields are left unchanged.
CoAP requests and responses are exchanged asynchronously over the TCP/TLS connection. A CoAP client can send multiple requests without waiting for a response and the CoAP server can return responses in any order. Responses MUST be returned over the same connection as the originating request. Concurrent requests are differentiated by their Token, which is scoped locally to the connection.
The connection is bi-directional, so requests can be sent both by the entity that established the connection and the remote host.
Retransmission and deduplication of messages is provided by the TCP/TLS protocol.
Since the TCP protocol provides ordered delivery of messages, the mechanism for reordering detection when observing resources [RFC7641] is not needed. The value of the Observe Option in notifications MAY be empty on transmission and MUST be ignored on reception.
CoAP over WebSockets can be used in a number of configurations. The most basic configuration is a CoAP client retrieving or updating a CoAP resource located at a CoAP server that exposes a WebSocket endpoint (Figure 9). The CoAP client acts as the WebSocket client, establishes a WebSocket connection, and sends a CoAP request, to which the CoAP server returns a CoAP response. The WebSocket connection can be used for any number of requests.
___________ ___________ | | | | | _|___ requests ___|_ | | CoAP / \ \ -------------> / / \ CoAP | | Client \__/__/ <------------- \__\__/ Server | | | responses | | |___________| |___________| WebSocket =============> WebSocket Client Connection Server
Figure 9: CoAP Client (WebSocket client) accesses CoAP Server (WebSocket server)
The challenge with this configuration is how to identify a resource in the namespace of the CoAP server. When the WebSocket protocol is used by a dedicated client directly (i.e., not from a web page through a web browser), the client can connect to any WebSocket endpoint. This means it is necessary for the client to identify both the WebSocket endpoint (identified by a “ws” or “wss” URI) and the path and query of the CoAP resource within that endpoint from the same URI. When the WebSocket protocol is used from a web page, the choices are more limited [RFC6454], but the challenge persists.
Section 6.2 defines a new “coap+ws” URI scheme that identifies both a WebSocket endpoint and a resource within that endpoint as follows:
coap+ws://example.org/sensors/temperature?u=Cel \______ ______/\___________ ___________/ \/ \/ Uri-Path: "sensors" ws://example.org/.well-known/coap Uri-Path: "temperature" Uri-Query: "u=Cel"
Figure 10: The "coap+ws" URI Scheme
Another possible configuration is to set up a CoAP forward proxy at the WebSocket endpoint. Depending on what transports are available to the proxy, it could forward the request to a CoAP server with a CoAP UDP endpoint (Figure 11), an SMS endpoint (a.k.a. mobile phone), or even another WebSocket endpoint. The client specifies the resource to be updated or retrieved in the Proxy-URI Option.
___________ ___________ ___________ | | | | | | | _|___ ___|_ _|___ ___|_ | | CoAP / \ \ ---> / / \ CoAP / \ \ ---> / / \ CoAP | | Client \__/__/ <--- \__\__/ Proxy \__/__/ <--- \__\__/ Server | | | | | | | |___________| |___________| |___________| WebSocket ===> WebSocket UDP UDP Client Server Client Server
Figure 11: CoAP Client (WebSocket client) accesses CoAP Server (UDP server) via a CoAP proxy (WebSocket server/UDP client)
A third possible configuration is a CoAP server running inside a web browser (Figure 12). The web browser initially connects to a WebSocket endpoint and is then reachable through the WebSocket server. When no connection exists, the CoAP server is unreachable. Because the WebSocket server is the only way to reach the CoAP server, the CoAP proxy should be a Reverse Proxy.
___________ ___________ ___________ | | | | | | | _|___ ___|_ _|___ ___|_ | | CoAP / \ \ ---> / / \ CoAP / / \ ---> / \ \ CoAP | | Client \__/__/ <--- \__\__/ Proxy \__\__/ <--- \__/__/ Server | | | | | | | |___________| |___________| |___________| UDP UDP WebSocket <=== WebSocket Client Server Server Client
Figure 12: CoAP Client (UDP client) accesses sleepy CoAP Server (WebSocket client) via a CoAP proxy (UDP server/WebSocket server)
Further configurations are possible, including those where a WebSocket connection is established through an HTTP proxy.
CoAP over WebSockets is intentionally very similar to CoAP over UDP. Therefore, instead of presenting CoAP over WebSockets as a new protocol, this document specifies it as a series of deltas from [RFC7252].
Before CoAP requests and responses are exchanged, a WebSocket connection is established as defined in Section 4 of [RFC6455]. Figure 13 shows an example.
The WebSocket client MUST include the subprotocol name “coap” in the list of protocols, which indicates support for the protocol defined in this document. Any later, incompatible versions of CoAP or CoAP over WebSockets will use a different subprotocol name.
The WebSocket client includes the hostname of the WebSocket server in the Host header field of its handshake as per [RFC6455]. The Host header field also indicates the default value of the Uri-Host Option in requests from the WebSocket client to the WebSocket server.
GET /.well-known/coap HTTP/1.1 Host: example.org Upgrade: websocket Connection: Upgrade Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Protocol: coap Sec-WebSocket-Version: 13 HTTP/1.1 101 Switching Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= Sec-WebSocket-Protocol: coap
Figure 13: Example of an Opening Handshake
Once a WebSocket connection is established, CoAP requests and responses can be exchanged as WebSocket messages. Since CoAP uses a binary message format, the messages are transmitted in binary data frames as specified in Sections 5 and 6 of [RFC6455].
The message format shown in Figure 14 is the same as the CoAP over TCP message format (see Section 2.4) with one restriction. The Length (Len) field MUST be set to zero because the WebSockets frame contains the length.
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Len | TKL | Code | Token (TKL bytes) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 1 1 1 1 1 1 1| Payload (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Figure 14: CoAP Message Format over WebSockets
The CoAP over TCP message format eliminates the Version field defined in CoAP over UDP. If CoAP version negotiation is required in the future, CoAP over WebSockets can address the requirement by the definition of a new subprotocol identifier that is negotiated during the opening handshake.
Requests and response messages can be fragmented as specified in Section 5.4 of [RFC6455], though typically they are sent unfragmented as they tend to be small and fully buffered before transmission. The WebSocket protocol does not provide means for multiplexing. If it is not desirable for a large message to monopolize the connection, requests and responses can be transferred in a block-wise fashion as defined in [I-D.ietf-core-block].
Empty messages (Code 0.00) MUST be ignored by the recipient (see also Section 4.4).
CoAP requests and responses are exchanged asynchronously over the WebSocket connection. A CoAP client can send multiple requests without waiting for a response and the CoAP server can return responses in any order. Responses MUST be returned over the same connection as the originating request. Concurrent requests are differentiated by their Token, which is scoped locally to the connection.
The connection is bi-directional, so requests can be sent both by the entity that established the connection and the remote host.
Retransmission and deduplication of messages is provided by the WebSocket protocol. CoAP over WebSockets therefore does not make a distinction between Confirmable or Non-Confirmable messages, and does not provide Acknowledgement or Reset messages.
Since the WebSocket protocol provides ordered delivery of messages, the mechanism for reordering detection when observing resources [RFC7641] is not needed. The value of the Observe Option in notifications MAY be empty on transmission and MUST be ignored on reception.
When a client does not receive any response for some time after sending a CoAP request (or, similarly, when a client observes a resource and it does not receive any notification for some time), the connection between the WebSocket client and the WebSocket server may be lost or temporarily disrupted without the client being aware of it.
To check the health of the WebSocket connection (and thereby of all active requests, if any), a client can send a CoAP Ping Signaling message (Section 4.4). WebSocket Ping and unsolicited Pong frames as specified in Section 5.5 of [RFC6455] SHOULD NOT be used to ensure that redundant maintenance traffic is not transmitted.
There is no way to retransmit a request without creating a new one. Re-registering interest in a resource is permitted, but entirely unnecessary.
The WebSocket connection is closed as specified in Section 7 of [RFC6455].
All requests for which the CoAP client has not received a response yet are cancelled when the connection is closed. If the client observes one or more resources over the WebSocket connection, then the CoAP server (or intermediary in the role of the CoAP server) MUST remove all entries associated with the client from the lists of observers when the connection is closed.
Signaling messages are introduced to allow peers to:
Signaling is a third basic kind of message in CoAP, after requests and responses. Signaling messages share a common structure with the existing CoAP messages. There is a code, a token, options, and an optional payload.
(See Section 3 of [RFC7252] for the overall structure, as adapted to the specific transport.)
A code in the 7.01-7.31 range indicates a Signaling message. Values in this range are assigned by the “CoAP Signaling Codes” sub-registry (see Section 8.1).
For each message, there is a sender and a peer receiving the message.
Payloads in Signaling messages are diagnostic payloads (see Section 5.5.2 of [RFC7252]), unless otherwise defined by a Signaling message option.
Option numbers for Signaling messages are specific to the message code. They do not share the number space with CoAP options for request/response messages or with Signaling messages using other codes.
Option numbers are assigned by the “CoAP Signaling Option Numbers” sub-registry (see Section 8.2).
Signaling options are elective or critical as defined in Section 5.4.1 of [RFC7252]). If a Signaling option is critical and not understood by the receiver, it MUST abort the connection (see Section 4.6). If the option is understood but cannot be processed, the option documents the behavior.
Capability and Settings messages (CSM) are used for two purposes:
A Capability and Settings message MUST be sent by both endpoints at the start of the connection and MAY be sent at any other time by either endpoint over the lifetime of the connection.
Both capability and settings options are cumulative. A Capability and Settings message does not invalidate a previously sent capability indication or setting even if it is not repeated. A capability message without any option is a no-operation (and can be used as such). An option that is sent might override a previous value for the same option. The option defines how to handle this case if needed.
Base values are listed below for CSM Options. These are the values for the Capability and Setting before any Capability and Settings messages send a modified value.
These are not default values for the option as defined in Section 5.4.4 in [RFC7252]. A default value would mean that an empty Capability and Settings message would result in the option being set to its default value.
Capability and Settings messages are indicated by the 7.01 code (CSM).
Number | Applies to | Name | Format | Length | Base Value |
---|---|---|---|---|---|
1 | CSM | Server-Name | string | 1-255 | (see below) |
A client can use the Server-Name critical option to indicate the default value for the Uri-Host Options in the messages that it sends to the server. It has the same restrictions as the Uri-Host Option (Section 5.10 of [RFC7252].
For TLS, the initial value for the Server-Name Option is given by the SNI value.
For Websockets, the initial value for the Server-Name Option is given by the HTTP Host header field.
The sender can use the Max-Message-Size elective option to indicate the maximum message size in bytes that it can receive.
Number | Applies to | Name | Format | Length | Base Value |
---|---|---|---|---|---|
2 | CSM | Max-Message-Size | uint | 0-4 | 1152 |
As per Section 4.6 of [RFC7252], the base value (and the value used when this option is not implemented) is 1152. A peer that relies on this option being indicated with a certain minimum value will enjoy limited interoperability.
Number | Applies to | Name | Format | Length | Base Value |
---|---|---|---|---|---|
4 | CSM | Block-wise Transfer | empty | 0 | (none) |
A sender can use the Block-wise Transfer elective Option to indicate that it supports the block-wise transfer protocol [I-D.ietf-core-block].
If the option is not given, the peer has no information about whether block-wise transfers are supported by the sender or not. An implementation that supports block-wise transfers SHOULD indicate the Block-wise Transfer Option. If a Max-Message-Size Option is indicated with a value that is greater than 1152 (in the same or a different CSM message), the Block-wise Transfer Option also indicates support for BERT (see Section 5).
In CoAP over TCP, Empty messages (Code 0.00) can always be sent and MUST be ignored by the recipient. This provides a basic keep-alive function that can refresh NAT bindings. In contrast, Ping and Pong messages are a bidirectional exchange.
Upon receipt of a Ping message, a single Pong message is returned with the identical token. As with all Signaling messages, the recipient of a Ping or Pong message MUST ignore elective options it does not understand.
Ping and Pong messages are indicated by the 7.02 code (Ping) and the 7.03 code (Pong).
Number | Applies to | Name | Format | Length | Base Value |
---|---|---|---|---|---|
2 | Ping, Pong | Custody | empty | 0 | (none) |
A peer replying to a Ping message can add a Custody elective option to the Pong message it returns. This option indicates that the application has processed all request/response messages that it has received in the present connection ahead of the Ping message that prompted the Pong message. (Note that there is no definition of specific application semantics of “processed”, but there is an expectation that the sender of the Ping leading to the Pong with a Custody Option should be able to free buffers based on this indication.)
A Custody elective option can also be sent in a Ping message to explicitly request the return of a Custody Option in the Pong message. A peer is always free to indicate that it has finished processing all previous request/response messages by sending a Custody Option in a Pong message. A peer is also free NOT to send a Custody Option in case it is still processing previous request/response messages; however, it SHOULD delay its response to a Ping with a Custody Option until it can also return one.
A release message indicates that the sender does not want to continue maintaining the connection and opts for an orderly shutdown; the details are in the options. A diagnostic payload MAY be included. A release message will normally be replied to by the peer by closing the TCP/TLS connection. Messages may be in flight when the sender decides to send a Release message. The general expectation is that these will still be processed.
Release messages are indicated by the 7.04 code (Release).
Release messages can indicate one or more reasons using elective options. The following options are defined:
Number | Applies to | Name | Format | Length | Base Value |
---|---|---|---|---|---|
2 | Release | Bad-Server-Name | empty | 0 | (none) |
The Bad-Server-Name elective option indicates that the default indicated by the CSM Server-Name Option is unlikely to be useful for this server.
Number | Applies to | Name | Format | Length | Base Value |
---|---|---|---|---|---|
4 | Release | Alternate-Address | string | 1-255 | (none) |
The Alternative-Address elective option requests the peer to instead open a connection of the same kind as the present connection to the alternative transport address given. Its value is in the form “authority” as defined in Section 3.2 of [RFC3986].
Number | Applies to | Name | Format | Length | Base Value |
---|---|---|---|---|---|
6 | Release | Hold-Off | uint | 0-3 | (none) |
The Hold-Off elective option indicates that the server is requesting that the peer not reconnect to it for the number of seconds given in the value.
An abort message indicates that the sender is unable to continue maintaining the connection and cannot even wait for an orderly release. The sender shuts down the connection immediately after the abort (and may or may not wait for a release or abort message or connection shutdown in the inverse direction). A diagnostic payload SHOULD be included in the Abort message. Messages may be in flight when the sender decides to send an abort message. The general expectation is that these will NOT be processed.
Abort messages are indicated by the 7.05 code (Abort).
Abort messages can indicate one or more reasons using elective options. The following option is defined:
Number | Applies to | Name | Format | Length | Base Value |
---|---|---|---|---|---|
2 | Abort | Bad-CSM-Option | uint | 0-2 | (none) |
The Bad-CSM-Option Option indicates that the sender is unable to process the CSM option identified by its option number, e.g. when it is critical and the option number is unknown by the sender, or when there is parameter problem with the value of an elective option. More detailed information SHOULD be included as a diagnostic payload.
One reason for an sender to generate an abort message is a general syntax error in the byte stream received. No specific option has been defined for this, as the details of that syntax error are best left to a diagnostic payload.
An encoded example of a Ping message with a non-empty token is shown in Figure 15.
0 1 2 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 0x01 | 0xe2 | 0x42 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Len = 0 -------> 0x01 TKL = 1 ___/ Code = 7.02 Ping --> 0xe2 Token = 0x42
Figure 15: Ping Message Example
An encoded example of the corresponding Pong message is shown in Figure 16.
0 1 2 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 0x01 | 0xe3 | 0x42 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Len = 0 -------> 0x01 TKL = 1 ___/ Code = 7.03 Pong --> 0xe3 Token = 0x42
Figure 16: Pong Message Example
The message size restrictions defined in Section 4.6 of CoAP [RFC7252] to avoid IP fragmentation are not necessary when CoAP is used over a reliable byte stream transport. While this suggests that the Block-wise transfer protocol [I-D.ietf-core-block] is also no longer needed, it remains applicable for a number of cases:
The ‘Block-wise Extension for Reliable Transport (BERT)’ extends the Block protocol to enable the use of larger messages over a reliable transport.
The use of this new extension is signaled by sending Block1 or Block2 Options with SZX == 7 (a “BERT option”). SZX == 7 is a reserved value in [I-D.ietf-core-block].
In control usage, a BERT option is interpreted in the same way as the equivalent Option with SZX == 6, except that it also indicates the capability to process BERT blocks. As with the basic Block protocol, the recipient of a CoAP request with a BERT option in control usage is allowed to respond with a different SZX value, e.g. to send a non-BERT block instead.
In descriptive usage, a BERT Option is interpreted in the same way as the equivalent Option with SZX == 6, except that the payload is allowed to contain a multiple of 1024 bytes (non-final BERT block) or more than 1024 bytes (final BERT block).
The recipient of a non-final BERT block (M=1) conceptually partitions the payload into a sequence of 1024-byte blocks and acts exactly as if it had received this sequence in conjunction with block numbers starting at, and sequentially increasing from, the block number given in the Block Option. In other words, the entire BERT block is positioned at the byte position that results from multiplying the block number with 1024. The position of further blocks to be transferred is indicated by incrementing the block number by the number of elements in this sequence (i.e., the size of the payload divided by 1024 bytes).
As with SZX == 6, the recipient of a final BERT block (M=0) simply appends the payload at the byte position that is indicated by the block number multiplied with 1024.
The following examples illustrate BERT options. A value of SZX == 7 is labeled as “BERT” or as “BERT(nnn)” to indicate a payload of size nnn.
In all these examples, a Block Option is decomposed to indicate the kind of Block Option (1 or 2) followed by a colon, the block number (NUM), more bit (M), and block size exponent (2**(SZX+4)) separated by slashes. E.g., a Block2 Option value of 33 would be shown as 2:2/0/32), or a Block1 Option value of 59 would be shown as 1:3/1/128.
Figure 17 shows a GET request with a response that is split into three BERT blocks. The first response contains 3072 bytes of payload; the second, 5120; and the third, 4711. Note how the block number increments to move the position inside the response body forward.
CLIENT SERVER | | | GET, /status ------> | | | | <------ 2.05 Content, 2:0/1/BERT(3072) | | | | GET, /status, 2:3/0/BERT ------> | | | | <------ 2.05 Content, 2:3/1/BERT(5120) | | | | GET, /status, 2:8/0/BERT ------> | | | | <------ 2.05 Content, 2:8/0/BERT(4711) |
Figure 17: GET with BERT blocks.
Figure 18 demonstrates a PUT exchange with BERT blocks.
CLIENT SERVER | | | PUT, /options, 1:0/1/BERT(8192) ------> | | | | <------ 2.31 Continue, 1:0/1/BERT | | | | PUT, /options, 1:8/1/BERT(16384) ------> | | | | <------ 2.31 Continue, 1:8/1/BERT | | | | PUT, /options, 1:24/0/BERT(5683) ------> | | | | <------ 2.04 Changed, 1:24/0/BERT | | |
Figure 18: PUT with BERT blocks.
CoAP over UDP [RFC7252] defines the “coap” and “coaps” URI schemes for identifying CoAP resources and providing a means of locating the resource.
CoAP over TCP uses the “coap+tcp” URI scheme. CoAP over TLS uses the “coaps+tcp” scheme. The rules from Section 6 of [RFC7252] apply to both of these URI schemes.
[RFC7252], Section 8 (Multicast CoAP) is not applicable to these schemes.
Resources made available via one of the “coap+tcp” or “coaps+tcp” schemes have no shared identity with the other scheme or with the “coap” or “coaps” scheme, even if their resource identifiers indicate the same authority (the same host listening to the same port). The schemes constitute distinct namespaces and, in combination with the authority, are considered to be distinct origin servers.
coap-tcp-URI = "coap+tcp:" "//" host [ ":" port ] path-abempty [ "?" query ]
The semantics defined in [RFC7252], Section 6.1, apply to this URI scheme, with the following changes:
coaps-tcp-URI = "coaps+tcp:" "//" host [ ":" port ] path-abempty [ "?" query ]
The semantics defined in [RFC7252], Section 6.2, apply to this URI scheme, with the following changes:
For the first configuration discussed in Section 3, this document defines two new URIs schemes that can be used for identifying CoAP resources and providing a means of locating these resources: “coap+ws” and “coap+wss”.
Similar to the “coap” and “coaps” schemes, the “coap+ws” and “coap+wss” schemes organize resources hierarchically under a CoAP origin server. The key difference is that the server is potentially reachable on a WebSocket endpoint instead of a UDP endpoint.
The WebSocket endpoint is identified by a “ws” or “wss” URI that is composed of the authority part of the “coap+ws” or “coap+wss” URI, respectively, and the well-known path “/.well-known/coap” [RFC5785]. The path and query parts of a “coap+ws” or “coap+wss” URI identify a resource within the specified endpoint which can be operated on by the methods defined by CoAP.
The syntax of the “coap+ws” and “coap+wss” URI schemes is specified below in Augmented Backus-Naur Form (ABNF) [RFC5234]. The definitions of “host”, “port”, “path-abempty” and “query” are the same as in [RFC3986].
coap-ws-URI = "coap+ws:" "//" host [ ":" port ] path-abempty [ "?" query ] coap-wss-URI = "coap+wss:" "//" host [ ":" port ] path-abempty [ "?" query ]
The port component is OPTIONAL; the default for “coap+ws” is port 80, while the default for “coap+wss” is port 443.
Fragment identifiers are not part of the request URI and thus MUST NOT be transmitted in a WebSocket handshake or in the URI options of a CoAP request.
The steps for decomposing a “coap+ws” or “coap+wss” URI into CoAP options are the same as specified in Section 6.4 of [RFC7252] with the following changes:
The steps to construct a URI from a request’s options are changed accordingly.
The security considerations of [RFC7252] apply.
TLS version 1.2 or higher is mandatory-to-implement and MUST be enabled by default. An endpoint MAY immediately abort a CoAP over TLS connection that does not meet this requirement (see Section 4.6) and SHOULD include a diagnostic payload.
The TLS usage guidance in [RFC7925] SHOULD be followed.
TLS does not protect the TCP header. This may, for example, allow an on-path adversary to terminate a TCP connection prematurely by spoofing a TCP reset message.
CoAP over WebSockets and CoAP over TLS-secured WebSockets do not introduce additional security issues beyond CoAP and DTLS-secured CoAP respectively [RFC7252]. The security considerations of [RFC6455] apply.
IANA is requested to create a third sub-registry for values of the Code field in the CoAP header (Section 12.1 of [RFC7252]). The name of this sub-registry is “CoAP Signaling Codes”.
Each entry in the sub-registry must include the Signaling Code in the range 7.01-7.31, its name, and a reference to its documentation.
Initial entries in this sub-registry are as follows:
Code | Name | Reference |
---|---|---|
7.01 | CSM | [RFCthis] |
7.02 | Ping | [RFCthis] |
7.03 | Pong | [RFCthis] |
7.04 | Release | [RFCthis] |
7.05 | Abort | [RFCthis] |
All other Signaling Codes are Unassigned.
The IANA policy for future additions to this sub-registry is “IETF Review or IESG Approval” as described in [RFC5226].
IANA is requested to create a sub-registry for signaling options similar to the CoAP Option Numbers Registry (Section 12.2 of [RFC7252]), with the single change that a fourth column is added to the sub-registry that is one of the codes in the Signaling Codes subregistry (Section 8.1).
The name of this sub-registry is “CoAP Signaling Option Numbers”.
Initial entries in this sub-registry are as follows:
Number | Applies to | Name | Reference |
---|---|---|---|
1 | CSM | Server-Name | [RFCthis] |
2 | CSM | Max-Message-Size | [RFCthis] |
4 | CSM | Block-wise-Transfer | [RFCthis] |
2 | Ping, Pong | Custody | [RFCthis] |
2 | Release | Bad-Server-Name | [RFCthis] |
4 | Release | Alternative-Address | [RFCthis] |
6 | Release | Hold-Off | [RFCthis] |
2 | Abort | Bad-CSM-Option | [RFCthis] |
The IANA policy for future additions to this sub-registry is based on number ranges for the option numbers, analogous to the policy defined in Section 12.2 of [RFC7252].
IANA is requested to assign the port number 5683 and the service name “coap+tcp”, in accordance with [RFC6335].
IANA is requested to assign the port number 5684 and the service name “coaps+tcp”, in accordance with [RFC6335]. The port number is requested to address the exceptional case of TLS implementations that do not support the “Application-Layer Protocol Negotiation Extension” [RFC7301].
This document registers two new URI schemes, namely “coap+tcp” and “coaps+tcp”, for the use of CoAP over TCP and for CoAP over TLS over TCP, respectively. The “coap+tcp” and “coaps+tcp” URI schemes can thus be compared to the “http” and “https” URI schemes.
The syntax of the “coap” and “coaps” URI schemes is specified in Section 6 of [RFC7252] and the present document re-uses their semantics for “coap+tcp” and “coaps+tcp”, respectively, with the exception that TCP, or TLS over TCP is used as a transport protocol.
IANA is requested to add these new URI schemes to the registry established with [RFC7595].
This document requests the registration of the Uniform Resource Identifier (URI) scheme “coap+ws”. The registration request complies with [RFC4395].
This document requests the registration of the Uniform Resource Identifier (URI) scheme “coap+wss”. The registration request complies with [RFC4395].
IANA is requested to register the ‘coap’ well-known URI in the “Well-Known URIs” registry. This registration request complies with [RFC5785]:
IANA is requested to assign the following value in the registry “Application Layer Protocol Negotiation (ALPN) Protocol IDs” created by [RFC7301]. The “coap” string identifies CoAP when used over TLS.
IANA is requested to register the WebSocket CoAP subprotocol under the “WebSocket Subprotocol Name Registry”:
CoAP is defined in [RFC7252] with a version number of 1. At this time, there is no known reason to support version numbers different from 1.
In contrast to the message layer for UDP and DTLS, the CoAP over TCP message format does not include a version number. If version negotiation needs to be addressed in the future, then Capability and Settings have been specifically designed to enable such a potential feature.
This section gives examples for the first two configurations discussed in Section 3.
An example of the process followed by a CoAP client to retrieve the representation of a resource identified by a “coap+ws” URI might be as follows. Figure 19 below illustrates the WebSocket and CoAP messages exchanged in detail.
CoAP CoAP Client Server (WebSocket (WebSocket Client) Server) | | | | +=========>| GET /.well-known/coap HTTP/1.1 | | Host: example.org | | Upgrade: websocket | | Connection: Upgrade | | Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== | | Sec-WebSocket-Protocol: coap | | Sec-WebSocket-Version: 13 | | |<=========+ HTTP/1.1 101 Switching Protocols | | Upgrade: websocket | | Connection: Upgrade | | Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= | | Sec-WebSocket-Protocol: coap | | | | +--------->| Binary frame (opcode=%x2, FIN=1, MASK=1) | | +-------------------------+ | | | GET | | | | Token: 0x53 | | | | Uri-Path: "sensors" | | | | Uri-Path: "temperature" | | | | Uri-Query: "u=Cel" | | | +-------------------------+ | | |<---------+ Binary frame (opcode=%x2, FIN=1, MASK=0) | | +-------------------------+ | | | 2.05 Content | | | | Token: 0x53 | | | | Payload: "22.3 Cel" | | | +-------------------------+ : : : : | | +--------->| Close frame (opcode=%x8, FIN=1, MASK=1) | | |<---------+ Close frame (opcode=%x8, FIN=1, MASK=0) | |
Figure 19: A CoAP client retrieves the representation of a resource identified by a "coap+ws" URI
Figure 20 shows how a CoAP client uses a CoAP forward proxy with a WebSocket endpoint to retrieve the representation of the resource “coap://[2001:DB8::1]/”. The use of the forward proxy and the address of the WebSocket endpoint are determined by the client from local configuration rules. The request URI is specified in the Proxy-Uri Option. Since the request URI uses the “coap” URI scheme, the proxy fulfills the request by issuing a Confirmable GET request over UDP to the CoAP server and returning the response over the WebSocket connection to the client.
CoAP CoAP CoAP Client Proxy Server (WebSocket (WebSocket (UDP Client) Server) Endpoint) | | | +--------->| | Binary frame (opcode=%x2, FIN=1, MASK=1) | | | +------------------------------------+ | | | | GET | | | | | Token: 0x7d | | | | | Proxy-Uri: "coap://[2001:DB8::1]/" | | | | +------------------------------------+ | | | | +--------->| CoAP message (Ver=1, T=Con, MID=0x8f54) | | | +------------------------------------+ | | | | GET | | | | | Token: 0x0a15 | | | | +------------------------------------+ | | | | |<---------+ CoAP message (Ver=1, T=Ack, MID=0x8f54) | | | +------------------------------------+ | | | | 2.05 Content | | | | | Token: 0x0a15 | | | | | Payload: "ready" | | | | +------------------------------------+ | | | |<---------+ | Binary frame (opcode=%x2, FIN=1, MASK=0) | | | +------------------------------------+ | | | | 2.05 Content | | | | | Token: 0x7d | | | | | Payload: "ready" | | | | +------------------------------------+ | | |
Figure 20: A CoAP client retrieves the representation of a resource identified by a "coap" URI via a WebSockets-enabled CoAP proxy
The RFC Editor is requested to remove this section at publication.
Merged draft-savolainen-core-coap-websockets-07 Merged draft-bormann-core-block-bert-01 Merged draft-bormann-core-coap-sig-02
Editorial updates
Added mandatory exchange of Capabilities and Settings messages after connecting
Added support for coaps+tcp port 5684 and more details on Application-Layer Protocol Negotiation (ALPN)
Added guidance on CoAP Signaling Ping-Pong versus WebSocket Ping-Pong
Updated references and requirements for TLS security considerations
We would like to thank Stephen Berard, Geoffrey Cristallo, Olivier Delaby, Christian Groves, Nadir Javed, Michael Koster, Matthias Kovatsch, Achim Kraus, David Navarro, Szymon Sasin, Zach Shelby, Andrew Summers, Julien Vermillard, and Gengyu Wei for their feedback.
Valik Solorzano Barboza Zebra Technologies 820 W. Jackson Blvd. Suite 700 Chicago 60607 United States of America Phone: +1-847-634-6700 Email: vsolorzanobarboza@zebra.com Teemu Savolainen Nokia Technologies Hatanpaan valtatie 30 Tampere FI-33100 Finland Email: teemu.savolainen@nokia.com