idnits 2.17.1 draft-ietf-core-coap-04.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (January 24, 2011) is 4834 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: '0x7d34' is mentioned on line 2986, but not defined == Missing Reference: '0x01a0' is mentioned on line 3109, but not defined == Missing Reference: '0xbc90' is mentioned on line 395, but not defined == Missing Reference: '0xbc91' is mentioned on line 395, but not defined == Missing Reference: '0x7a10' is mentioned on line 420, but not defined == Missing Reference: '0x23bb' is mentioned on line 431, but not defined == Missing Reference: '0x20' is mentioned on line 2986, but not defined == Missing Reference: '0x7d35' is mentioned on line 3021, but not defined == Missing Reference: '0x31' is mentioned on line 3021, but not defined == Missing Reference: '0x7d36' is mentioned on line 3055, but not defined == Missing Reference: '0x42' is mentioned on line 3040, but not defined == Missing Reference: '0x53' is mentioned on line 3057, but not defined == Missing Reference: '0xad7b' is mentioned on line 3059, but not defined == Missing Reference: '0x7d37' is mentioned on line 3074, but not defined == Missing Reference: '0x64' is mentioned on line 3076, but not defined == Missing Reference: '0xad7c' is mentioned on line 3078, but not defined == Missing Reference: '0x7d38' is mentioned on line 3088, but not defined == Missing Reference: '0x75' is mentioned on line 3090, but not defined == Missing Reference: '0xad7d' is mentioned on line 3090, but not defined == Missing Reference: '0x7d39' is mentioned on line 3105, but not defined == Missing Reference: '0x86' is mentioned on line 3111, but not defined == Missing Reference: '0x60b1' is mentioned on line 3107, but not defined == Missing Reference: '0x952a' is mentioned on line 3111, but not defined ** Obsolete normative reference: RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) ** Obsolete normative reference: RFC 2818 (Obsoleted by RFC 9110) ** Obsolete normative reference: RFC 4347 (Obsoleted by RFC 6347) ** Obsolete normative reference: RFC 4395 (Obsoleted by RFC 7595) ** Obsolete normative reference: RFC 4835 (Obsoleted by RFC 7321) ** Obsolete normative reference: RFC 5226 (Obsoleted by RFC 8126) ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) ** Obsolete normative reference: RFC 5389 (Obsoleted by RFC 8489) ** Obsolete normative reference: RFC 5996 (Obsoleted by RFC 7296) == Outdated reference: A later version (-01) exists of draft-eggert-core-congestion-control-00 == Outdated reference: A later version (-21) exists of draft-ietf-core-block-00 == Outdated reference: A later version (-14) exists of draft-ietf-core-link-format-02 == Outdated reference: A later version (-06) exists of draft-ietf-tls-rfc4347-bis-04 == Outdated reference: A later version (-10) exists of draft-ietf-tsvwg-iana-ports-09 == Outdated reference: A later version (-04) exists of draft-mcgrew-tls-aes-ccm-00 == Outdated reference: A later version (-08) exists of draft-mcgrew-tls-aes-ccm-ecc-01 == Outdated reference: A later version (-03) exists of draft-oflynn-core-bootstrapping-02 -- Obsolete informational reference (is this intentional?): RFC 3920 (Obsoleted by RFC 6120) Summary: 9 errors (**), 0 flaws (~~), 32 warnings (==), 2 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 CoRE Working Group Z. Shelby 3 Internet-Draft Sensinode 4 Intended status: Standards Track K. Hartke 5 Expires: July 28, 2011 C. Bormann 6 Universitaet Bremen TZI 7 B. Frank 8 SkyFoundry 9 January 24, 2011 11 Constrained Application Protocol (CoAP) 12 draft-ietf-core-coap-04 14 Abstract 16 This document specifies the Constrained Application Protocol (CoAP), 17 a specialized web transfer protocol for use with constrained networks 18 and nodes for machine-to-machine applications such as smart energy 19 and building automation. These constrained nodes often have 8-bit 20 microcontrollers with small amounts of ROM and RAM, while networks 21 such as 6LoWPAN often have high packet error rates and a typical 22 throughput of 10s of kbit/s. CoAP provides a method/response 23 interaction model between application end-points, supports built-in 24 resource discovery, and includes key web concepts such as URIs and 25 content-types. CoAP easily translates to HTTP for integration with 26 the web while meeting specialized requirements such as multicast 27 support, very low overhead and simplicity for constrained 28 environments. 30 Status of this Memo 32 This Internet-Draft is submitted in full conformance with the 33 provisions of BCP 78 and BCP 79. 35 Internet-Drafts are working documents of the Internet Engineering 36 Task Force (IETF). Note that other groups may also distribute 37 working documents as Internet-Drafts. The list of current Internet- 38 Drafts is at http://datatracker.ietf.org/drafts/current/. 40 Internet-Drafts are draft documents valid for a maximum of six months 41 and may be updated, replaced, or obsoleted by other documents at any 42 time. It is inappropriate to use Internet-Drafts as reference 43 material or to cite them other than as "work in progress." 45 This Internet-Draft will expire on July 28, 2011. 47 Copyright Notice 48 Copyright (c) 2011 IETF Trust and the persons identified as the 49 document authors. All rights reserved. 51 This document is subject to BCP 78 and the IETF Trust's Legal 52 Provisions Relating to IETF Documents 53 (http://trustee.ietf.org/license-info) in effect on the date of 54 publication of this document. Please review these documents 55 carefully, as they describe your rights and restrictions with respect 56 to this document. Code Components extracted from this document must 57 include Simplified BSD License text as described in Section 4.e of 58 the Trust Legal Provisions and are provided without warranty as 59 described in the Simplified BSD License. 61 Table of Contents 63 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 5 64 1.1. Features . . . . . . . . . . . . . . . . . . . . . . . . . 5 65 1.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 6 66 2. Constrained Application Protocol . . . . . . . . . . . . . . . 7 67 2.1. Messaging Model . . . . . . . . . . . . . . . . . . . . . 8 68 2.2. Request/Response Model . . . . . . . . . . . . . . . . . . 9 69 2.3. Intermediaries and Caching . . . . . . . . . . . . . . . . 11 70 2.4. Resource Discovery . . . . . . . . . . . . . . . . . . . . 11 71 3. Message Syntax . . . . . . . . . . . . . . . . . . . . . . . . 11 72 3.1. Message Format . . . . . . . . . . . . . . . . . . . . . . 12 73 3.2. Option Format . . . . . . . . . . . . . . . . . . . . . . 13 74 4. Message Semantics . . . . . . . . . . . . . . . . . . . . . . 14 75 4.1. Reliable Messages . . . . . . . . . . . . . . . . . . . . 15 76 4.2. Unreliable Messages . . . . . . . . . . . . . . . . . . . 16 77 4.3. Message Types . . . . . . . . . . . . . . . . . . . . . . 16 78 4.3.1. Confirmable (CON) . . . . . . . . . . . . . . . . . . 16 79 4.3.2. Non-Confirmable (NON) . . . . . . . . . . . . . . . . 17 80 4.3.3. Acknowledgement (ACK) . . . . . . . . . . . . . . . . 17 81 4.3.4. Reset (RST) . . . . . . . . . . . . . . . . . . . . . 17 82 4.4. Multicast . . . . . . . . . . . . . . . . . . . . . . . . 17 83 4.5. Congestion Control . . . . . . . . . . . . . . . . . . . . 17 84 5. Request/Response Semantics . . . . . . . . . . . . . . . . . . 18 85 5.1. Requests . . . . . . . . . . . . . . . . . . . . . . . . . 18 86 5.2. Responses . . . . . . . . . . . . . . . . . . . . . . . . 18 87 5.2.1. Immediate . . . . . . . . . . . . . . . . . . . . . . 19 88 5.2.2. Deferred . . . . . . . . . . . . . . . . . . . . . . . 20 89 5.2.3. Non-Confirmable . . . . . . . . . . . . . . . . . . . 20 90 5.3. Request/Response Matching . . . . . . . . . . . . . . . . 20 91 5.4. Options . . . . . . . . . . . . . . . . . . . . . . . . . 21 92 5.4.1. Critical/Elective . . . . . . . . . . . . . . . . . . 22 93 5.4.2. Length . . . . . . . . . . . . . . . . . . . . . . . . 23 94 5.4.3. Default Values . . . . . . . . . . . . . . . . . . . . 23 95 5.4.4. Repeating Options . . . . . . . . . . . . . . . . . . 23 96 5.4.5. Option Numbers . . . . . . . . . . . . . . . . . . . . 23 97 5.5. Payload . . . . . . . . . . . . . . . . . . . . . . . . . 23 98 5.6. Caching . . . . . . . . . . . . . . . . . . . . . . . . . 24 99 5.6.1. Freshness Model . . . . . . . . . . . . . . . . . . . 24 100 5.6.2. Validation Model . . . . . . . . . . . . . . . . . . . 25 101 5.7. Proxying . . . . . . . . . . . . . . . . . . . . . . . . . 25 102 5.8. Method Definitions . . . . . . . . . . . . . . . . . . . . 27 103 5.8.1. GET . . . . . . . . . . . . . . . . . . . . . . . . . 27 104 5.8.2. POST . . . . . . . . . . . . . . . . . . . . . . . . . 27 105 5.8.3. PUT . . . . . . . . . . . . . . . . . . . . . . . . . 28 106 5.8.4. DELETE . . . . . . . . . . . . . . . . . . . . . . . . 28 107 5.9. Response Code Definitions . . . . . . . . . . . . . . . . 28 108 5.9.1. Success 2.xx . . . . . . . . . . . . . . . . . . . . . 28 109 5.9.2. Client Error 4.xx . . . . . . . . . . . . . . . . . . 30 110 5.9.3. Server Error 5.xx . . . . . . . . . . . . . . . . . . 31 111 5.10. Option Definitions . . . . . . . . . . . . . . . . . . . . 31 112 5.10.1. Token . . . . . . . . . . . . . . . . . . . . . . . . 32 113 5.10.2. Uri-Host, Uri-Port, Uri-Path and Uri-Query . . . . . . 32 114 5.10.3. Proxy-Uri . . . . . . . . . . . . . . . . . . . . . . 33 115 5.10.4. Content-Type . . . . . . . . . . . . . . . . . . . . . 34 116 5.10.5. Max-Age . . . . . . . . . . . . . . . . . . . . . . . 34 117 5.10.6. Etag . . . . . . . . . . . . . . . . . . . . . . . . . 34 118 5.10.7. Location-Path . . . . . . . . . . . . . . . . . . . . 35 119 6. CoAP URIs . . . . . . . . . . . . . . . . . . . . . . . . . . 35 120 6.1. URI Scheme Syntax . . . . . . . . . . . . . . . . . . . . 35 121 6.2. Normalization and Comparison Rules . . . . . . . . . . . . 36 122 6.3. Parsing URIs . . . . . . . . . . . . . . . . . . . . . . . 36 123 6.4. Constructing URIs . . . . . . . . . . . . . . . . . . . . 38 124 7. Finding and Addressing CoAP End-Points . . . . . . . . . . . . 39 125 7.1. Resource Discovery . . . . . . . . . . . . . . . . . . . . 39 126 7.2. Default Port . . . . . . . . . . . . . . . . . . . . . . . 39 127 7.3. Multiplexing DTLS and CoAP . . . . . . . . . . . . . . . . 39 128 7.3.1. Future-Proofing the Multiplexing . . . . . . . . . . . 40 129 8. HTTP Mapping . . . . . . . . . . . . . . . . . . . . . . . . . 41 130 8.1. CoAP-HTTP Mapping . . . . . . . . . . . . . . . . . . . . 41 131 8.2. HTTP-CoAP Mapping . . . . . . . . . . . . . . . . . . . . 45 132 9. Protocol Constants . . . . . . . . . . . . . . . . . . . . . . 47 133 10. Security Considerations . . . . . . . . . . . . . . . . . . . 47 134 10.1. Securing CoAP with IPsec . . . . . . . . . . . . . . . . . 48 135 10.2. Securing CoAP with DTLS . . . . . . . . . . . . . . . . . 49 136 10.2.1. SharedKey & MultiKey Modes . . . . . . . . . . . . . . 50 137 10.2.2. Certificate Mode . . . . . . . . . . . . . . . . . . . 50 138 10.3. Threat analysis and protocol limitations . . . . . . . . . 51 139 10.3.1. Protocol Parsing, Processing URIs . . . . . . . . . . 51 140 10.3.2. Proxying and Caching . . . . . . . . . . . . . . . . . 51 141 10.3.3. Risk of amplification . . . . . . . . . . . . . . . . 52 142 10.3.4. Cross-Protocol Attacks . . . . . . . . . . . . . . . . 53 144 11. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 54 145 11.1. CoAP Code Registry . . . . . . . . . . . . . . . . . . . . 55 146 11.1.1. Method Codes . . . . . . . . . . . . . . . . . . . . . 55 147 11.1.2. Response Codes . . . . . . . . . . . . . . . . . . . . 55 148 11.2. Option Number Registry . . . . . . . . . . . . . . . . . . 56 149 11.3. Media Type Registry . . . . . . . . . . . . . . . . . . . 57 150 11.4. URI Scheme Registration . . . . . . . . . . . . . . . . . 58 151 11.5. Service Name and Port Number Registration . . . . . . . . 59 152 12. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 60 153 13. References . . . . . . . . . . . . . . . . . . . . . . . . . . 60 154 13.1. Normative References . . . . . . . . . . . . . . . . . . . 60 155 13.2. Informative References . . . . . . . . . . . . . . . . . . 62 156 Appendix A. Integer Option Value Format . . . . . . . . . . . . . 64 157 Appendix B. Examples . . . . . . . . . . . . . . . . . . . . . . 64 158 Appendix C. URI Examples . . . . . . . . . . . . . . . . . . . . 69 159 Appendix D. Changelog . . . . . . . . . . . . . . . . . . . . . . 70 160 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 74 162 1. Introduction 164 The use of web services on the Internet has become ubiquitous in most 165 applications, and depends on the fundamental Representational State 166 Transfer (REST) architecture of the web. 168 The Constrained RESTful Environments (CoRE) working group aims at 169 realizing the REST architecture in a suitable form for the most 170 constrained nodes (e.g. 8-bit microcontrollers with limited RAM and 171 ROM) and networks (e.g. 6LoWPAN). Constrained networks like 6LoWPAN 172 support the expensive fragmentation of IPv6 packets into small link- 173 layer frames. One design goal of CoRE has been to keep message 174 overhead small, thus limiting the use of fragmentation. 176 One of the main goals of CoRE is to design a generic web protocol for 177 the special requirements of this constrained environment, especially 178 considering energy, building automation and other M2M applications. 179 The goal of CoAP is not to blindly compress HTTP [RFC2616], but 180 rather to realize a subset of REST common with HTTP but optimized for 181 M2M applications. Although CoRE could be used for compressing simple 182 HTTP interfaces, it more importantly also offers features for M2M 183 such as built-in discovery, multicast support and asynchronous 184 message exchanges. 186 This document specifies the Constrained Application Protocol (CoAP), 187 which easily translates to HTTP for integration with the existing web 188 while meeting specialized requirements such as multicast support, 189 very low overhead and simplicity for constrained environments and M2M 190 applications. 192 1.1. Features 194 CoAP has the following main features: 196 o Constrained web protocol fulfilling M2M requirements. 198 o A stateless HTTP mapping, allowing proxies to be built providing 199 access to CoAP resources via HTTP in a uniform way or for HTTP 200 simple interfaces to be realized alternatively over CoAP. 202 o UDP binding with reliable unicast and best-effort multicast 203 support. 205 o Asynchronous message exchanges. 207 o Low header overhead and parsing complexity. 209 o URI and Content-type support. 211 o Simple proxy and caching capabilities. 213 o Optional resource discovery. 215 1.2. Terminology 217 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 218 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 219 document are to be interpreted as described in [RFC2119]. 221 This specification requires readers to be familiar with all the terms 222 and concepts that are discussed in [RFC2616]. In addition, this 223 specification defines the following terminology: 225 Immediate Response 226 An Immediate Response is included right in a CoAP Acknowledgement 227 (ACK) message that is sent to acknowledge receipt of the Request 228 for this Response (Section 5.2.1). 230 Deferred Response 231 When a Confirmable message carrying a Request is acknowledged with 232 an empty message (e.g., because the server doesn't have the answer 233 right away), a Deferred Response is sent later in a separate 234 message exchange (Section 5.2.2). 236 Critical 237 An option that would need to be understood by the end-point 238 receiving the message in order to properly process the message 239 (Section 5.4.1). Note that the implementation of critical options 240 is, as the name "Option" implies, generally optional: unsupported 241 critical options lead to rejection of the message. 243 Elective 244 An option that is intended be ignored by an end-point that does 245 not understand it, which nonetheless still can correctly process 246 the message (Section 5.4.1). 248 Resource Discovery 249 The process where a CoAP client queries a server for its list of 250 hosted resources (i.e., links, Section 7.1). 252 Intermediary 253 There are two common forms of intermediary: proxy and reverse 254 proxy. In some cases, a single intermediary might act as an 255 origin server, proxy, or reverse proxy, switching behavior based 256 on the nature of each request. 258 Proxy 259 A "proxy" is an end-point selected by a client, usually via local 260 configuration rules, to perform requests on behalf of the client, 261 doing any necessary translations. Some translations are minimal, 262 such as for proxy requests for "coap" URIs, whereas other requests 263 might require translation to and from entirely different 264 application-layer protocols. 266 Reverse Proxy 267 A "reverse proxy" is an end-point that acts as a layer above some 268 other server(s) and satisfies requests on behalf of these, doing 269 any necessary translations. Unlike a proxy, a reverse proxy 270 receives requests as if it was the origin server for the target 271 resource; the requesting client will not be aware that it is 272 communicating with a reverse proxy. 274 In this specification, the term "byte" is used in its now customary 275 sense as a synonym for "octet". 277 In this specification, the operator "^" stands for exponentiation. 279 2. Constrained Application Protocol 281 The interaction model of CoAP is similar to the client/server model 282 of HTTP. However, machine-to-machine interactions typically result 283 in a CoAP implementation acting in both client and server roles 284 (called an end-point). A CoAP request is equivalent to that of HTTP, 285 and is sent by a client to request an action (using a method code) on 286 a resource (identified by a URI) on a server. The server then sends 287 a response with a response code; this response may include a resource 288 representation. 290 Unlike HTTP, CoAP deals with these interchanges asynchronously over a 291 datagram-oriented transport such as UDP. This is done using a layer 292 of messages that supports optional reliability (with exponential 293 back-off). CoAP defines four types of messages: Confirmable, Non- 294 Confirmable, Acknowledgement, Reset; method codes and response codes 295 included in some of these messages make them carry requests or 296 responses. The basic exchanges of the four types of messages are 297 transparent to the request/response interactions. 299 One could think of CoAP as using a two-layer approach, a CoAP 300 messaging layer used to deal with UDP and the asynchronous nature of 301 the interactions, and the request/response interactions using Method 302 and Response codes (see Figure 1). 304 +----------------------+ 305 | Application | 306 +----------------------+ 307 +----------------------+ 308 | Requests/Responses | 309 |----------------------| CoAP 310 | Messages | 311 +----------------------+ 312 +----------------------+ 313 | UDP | 314 +----------------------+ 316 Figure 1: Abstract layering of CoAP 318 2.1. Messaging Model 320 The CoAP messaging model is based on the exchange of messages over 321 UDP between end-points. 323 CoAP uses a short fixed-length binary header (4 bytes) that may be 324 followed by compact binary options and a payload. This message 325 format is shared by requests and responses. The CoAP message format 326 is specified in Section 3. Each message contains a Message ID used 327 to detect duplicates and for optional reliability. 329 Reliability is provided by marking a message as Confirmable (CON). A 330 Confirmable message is retransmitted using a default timeout and 331 exponential back-off between retransmissions, until the recipient 332 sends an Acknowledgement message (ACK) with the same Message ID (for 333 example, 0x7d34); see Figure 2. When a recipient is not able to 334 process a Confirmable message, it replies with a Reset message (RST) 335 instead of an Acknowledgement (ACK). 337 Client Server 338 | | 339 | CON [0x7d34] | 340 +----------------->| 341 | | 342 | ACK [0x7d34] | 343 |<-----------------+ 344 | | 346 Figure 2: Reliable message delivery 348 A message that does not require reliable delivery, for example each 349 single measurement out of a stream of sensor data, can be sent as a 350 Non-confirmable message (NON). These are not acknowledged, but still 351 have a Message ID for duplicate detection (Figure 3). 353 Client Server 354 | | 355 | NON [0x01a0] | 356 +----------------->| 357 | | 359 Figure 3: Unreliable message delivery 361 See Section 4 for details of CoAP messages. 363 As CoAP is based on UDP, it also supports the use of multicast IP 364 destination addresses, enabling multicast CoAP requests. Section 4.4 365 discusses the proper use of CoAP messages with multicast addresses 366 and precautions for avoiding response congestion. 368 Several security modes are defined for CoAP in Section 10 ranging 369 from no security to certificate based security. The use of IPsec 370 along with a binding to DTLS are specified for securing the protocol. 372 2.2. Request/Response Model 374 CoAP request and response semantics are carried in CoAP messages, 375 which include either a method or response code, respectively. 376 Optional (or default) request and response information, such as the 377 URI and payload content-type are carried as CoAP options. A Token 378 Option is used to match responses to requests independently from the 379 underlying messages (Section 5.3). 381 A request is carried in a Confirmable (CON) or Non-confirmable (NON) 382 message, and if immediately available, the response to a request 383 carried in a Confirmable message is carried in the resulting 384 Acknowledgement (ACK) message. This is called an immediate CoAP 385 response, detailed in Section 5.2.1. Two examples for a basic GET 386 request with immediate response are shown in Figure 4. 388 Client Server Client Server 389 | | | | 390 | CON [0xbc90] | | CON [0xbc91] | 391 | GET /temperature | | GET /temperature | 392 | (Token 0x71) | | (Token 0x72) | 393 +----------------->| +----------------->| 394 | | | | 395 | ACK [0xbc90] | | ACK [0xbc91] | 396 | 2.00 OK | | 4.04 Not Found | 397 | (Token 0x71) | | (Token 0x72) | 398 | "22.5 C" | | "Not found" | 399 |<-----------------+ |<-----------------+ 400 | | | | 402 Figure 4: Two GET requests with immediate responses, one successful, 403 one not found 405 If the server is not able to respond immediately to a request carried 406 in a Confirmable message, it simply responds with an empty 407 Acknowledgement message so that the client can stop retransmitting 408 the request. When the response is ready, the server sends it in a 409 new Confirmable message (which then in turn needs to be acknowledged 410 by the client). This is called a deferred response, as illustrated 411 in Figure 5 and described in more detail in Section 5.2.2. 413 Client Server 414 | | 415 | CON [0x7a10] | 416 | GET /temperature | 417 | (Token 0x73) | 418 +----------------->| 419 | | 420 | ACK [0x7a10] | 421 |<-----------------+ 422 | | 423 ... Time Passes ... 424 | | 425 | CON [0x23bb] | 426 | 2.00 OK | 427 | (Token 0x73) | 428 | "22.5 C" | 429 |<-----------------+ 430 | | 431 | ACK [0x23bb] | 432 +----------------->| 433 | | 435 Figure 5: A GET request with a deferred response 437 CoAP makes use of HTTP GET, PUT, POST and DELETE methods, with the 438 semantics specified in Section 5.8. URI support in a server is 439 simplified as the client already parses the URI and splits it into 440 host, port, path and query components, making use of default values 441 for efficiency. Response codes correspond to a small subset of HTTP 442 response codes with a few CoAP specific codes added, as defined in 443 Section 5.9. 445 2.3. Intermediaries and Caching 447 The protocol supports the caching of responses in order to 448 efficiently fulfill requests. Simple caching is enabled using 449 freshness and validity information carried with CoAP responses. A 450 cache could be located in an end-point or an intermediary. Caching 451 functionality is specified in Section 5.6. 453 Proxying is useful in constrained networks for several reasons, 454 including network traffic limiting, to improve performance, to access 455 resource of sleeping devices or for security reasons. The proxying 456 of requests on behalf of another CoAP end-point is supported in the 457 protocol. The URI of the resource to request is included in the 458 request, while the destination IP address is set to the proxy. See 459 Section 5.7 for more information on proxy functionality. 461 As CoAP was designed according to the REST architecture and thus 462 exhibits functionality similar to that of the HTTP protocol, it is 463 quite straightforward to map between HTTP-CoAP or CoAP-HTTP. Such a 464 mapping may be used to realize an HTTP REST interface using CoAP, or 465 for converting between HTTP and CoAP. This conversion can be carried 466 out by a proxy, which converts the method or response code, content- 467 type and options to the corresponding HTTP feature. Section 8 468 provides more detail about HTTP mapping. 470 2.4. Resource Discovery 472 Resource discovery is important for machine-to-machine interactions, 473 and is supported using the CoRE Link Format 474 [I-D.ietf-core-link-format] as discussed in Section 7.1. 476 3. Message Syntax 478 CoAP is based on the exchange of short messages which, by default, 479 are transported over UDP (i.e. each CoAP message occupies the data 480 section of one UDP datagram). CoAP may be used with Datagram 481 Transport Layer Security (DTLS) (see Section 10.2). It could also be 482 used over other transports such as TCP or SCTP, the specification of 483 which is out of this document's scope. 485 3.1. Message Format 487 CoAP messages are encoded in a simple binary format. A message 488 consists of a fixed-sized CoAP Header followed by options in Type- 489 Length-Value (TLV) format and a payload. The number of options is 490 determined by the header. The payload is made up of the bytes after 491 the options, if any; its length is calculated from the datagram 492 length. 494 0 1 2 3 495 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 496 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 497 |Ver| T | OC | Code | Message ID | 498 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 499 | Options (if any) ... 500 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 501 | Payload (if any) ... 502 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 504 Figure 6: Message Format 506 The fields in the header are defined as follows: 508 Version (Ver): 2-bit unsigned integer. Indicates the CoAP version 509 number. Implementations of this specification MUST set this field 510 to 1. Other values are reserved for future versions. 512 Type (T): 2-bit unsigned integer. Indicates if this message is of 513 type Confirmable (0), Non-Confirmable (1), Acknowledgement (2) or 514 Reset (3). See Section 4 for the semantics of these message 515 types. 517 Option Count (OC): 4-bit unsigned integer. Indicates the number of 518 options after the header. If set to 0, there are no options and 519 the payload (if any) immediately follows the header. The format 520 of options is defined below. 522 Code: 8-bit unsigned integer. Indicates if the message carries a 523 request (1-31) or a response (64-191), or is empty (0). (All 524 other code values are reserved.) In case of a request, the Code 525 field indicates the Request Method; in case of a response a 526 Response Code. Possible values are maintained in the CoAP Code 527 Registry (Section 11.1). See Section 5 for the semantics of 528 requests and responses. 530 Message ID: 16-bit unsigned integer. Used for the detection of 531 message duplication, and to match messages of type 532 Acknowledgement/Reset and messages of type Confirmable. See 533 Section 4 for Message ID generation rules and how messages are 534 matched. 536 While specific link layers make it beneficial to keep CoAP messages 537 small enough to fit into their link layer packets (see Section 1), 538 this is a matter of implementation quality. The CoAP specification 539 itself provides only an upper bound to the message size. A CoAP 540 message, appropriately encapsulated, SHOULD fit within a single IP 541 packet (i.e., avoid IP fragmentation) and MUST fit within a single IP 542 datagram. If the Path MTU is not known for a destination, an MTU of 543 1280 bytes SHOULD be assumed; if nothing is known about the size of 544 the headers, good upper bounds are 1152 bytes for the message size 545 and 1024 bytes for the payload size. 547 3.2. Option Format 549 Options MUST appear in order of their Option Number (see 550 Section 5.4.5). A delta encoding is used between options, with the 551 Option Number for each Option calculated as the sum of its Option 552 Delta field and the Option Number of the preceding Option in the 553 message, if any, or zero otherwise. Multiple options with the same 554 Option Number can be included by using an Option Delta of zero. 555 Following the Option Delta, each option has a Length field which 556 specifies the length of the Option Value. The Length field can be 557 extended by one byte for options with values longer than 14 bytes. 558 The Option Value immediately follows the Length field. 560 0 1 2 3 4 5 6 7 561 +---+---+---+---+---+---+---+---+ 562 | Option Delta | Length | for 0..14 563 +---+---+---+---+---+---+---+---+ 564 | Option Value ... 565 +---+---+---+---+---+---+---+---+ 566 for 15..270: 567 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 568 | Option Delta | 1 1 1 1 | Length - 15 | 569 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 570 | Option Value ... 571 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 573 Figure 7: Option Format 575 The fields in an option are defined as follows: 577 Option Delta: 4-bit unsigned integer. Indicates the difference 578 between the Option Number of this option and the previous option 579 (or zero for the first option). In other words, the Option Number 580 is calculated by simply summing the Option Delta fields of this 581 and previous options before it. The Option Numbers 14, 28, 42, 582 ... are reserved for no-op options when they are sent with an 583 empty value (they are ignored) and can be used as "fenceposts" if 584 deltas larger than 15 would otherwise be required. 586 Length: Indicates the length of the Option Value. Normally Length 587 is a 4-bit unsigned integer allowing value lengths of 0-14 bytes. 588 When the Length field is set to 15, another byte is added as an 589 8-bit unsigned integer whose value is added to the 15, allowing 590 option value lengths of 15-270 bytes. 592 The length and format of the Option Value depends on the respective 593 option, which MAY define variable length values. Options defined in 594 this document make use of the following formats for option values: 596 uint: A non-negative integer which is represented in network byte 597 order using a variable number of bytes (see Appendix A). 599 string: A Unicode string which is encoded using UTF-8 [RFC3629] in 600 Net-Unicode form [RFC5198]. 602 opaque: An opaque sequence of bytes. 604 Option Numbers are maintained in the CoAP Option Number Registry 605 (Section 11.2). See Section 5.10 for the semantics of the options 606 defined in this document. 608 4. Message Semantics 610 CoAP messages are exchanged asynchronously between CoAP end-points. 611 They are used to transport CoAP requests and responses, the semantics 612 of which are defined in Section 5. 614 As CoAP is bound to non-reliable transports such as UDP, CoAP 615 messages may arrive out of order, appear duplicated, or go missing 616 without notice. For this reason, CoAP implements a lightweight 617 reliability mechanism, without trying to re-create the full feature 618 set of a transport like TCP. It has the following features: 620 o Simple stop-and-wait retransmission reliability with exponential 621 back-off for "confirmable" messages. 623 o Duplicate detection for both "confirmable" and "non-confirmable" 624 messages. 626 o Multicast support. 628 4.1. Reliable Messages 630 The reliable transmission of a message is initiated by marking the 631 message as "confirmable" in the CoAP header. A recipient MUST 632 acknowledge such a message with an acknowledgement message (or, if it 633 lacks context to process the message properly, MUST reject it with a 634 reset message). The sender retransmits the confirmable message at 635 exponentially increasing intervals, until it receives an 636 acknowledgement (or reset message), or runs out of attempts. 638 Retransmission is controlled by two things that a CoAP end-point MUST 639 keep track of for each confirmable message it sends while waiting for 640 an acknowledgement (or reset): a timeout and a retransmission 641 counter. For a new confirmable message, the initial timeout is set 642 to RESPONSE_TIMEOUT and the retransmission counter is set to 0. When 643 the timeout is triggered and the retransmission counter is less than 644 MAX_RETRANSMIT, the message is retransmitted, the retransmission 645 counter is incremented, and the timeout is doubled. If the 646 retransmission counter reaches MAX_RETRANSMIT on a timeout, or if the 647 end-point receives a reset message, then the attempt to transmit the 648 message is cancelled and the application process informed of failure. 649 On the other hand, if the end-point receives an acknowledgement 650 message in time, transmission is considered successful. 652 An acknowledgement or reset message is related to a confirmable 653 message by means of a Message ID. The Message ID is a 16-bit 654 unsigned integer that is generated by the sender of a confirmable 655 message and included in the CoAP header. The Message ID MUST be 656 echoed in the acknowledgement or reset message by the recipient. A 657 CoAP end-point generates Message IDs by keeping a single Message ID 658 variable, which is changed each time a new confirmable message is 659 sent regardless of the destination address or port. The initial 660 variable value SHOULD be randomized. The same Message ID MUST NOT be 661 re-used within the potential retransmission window, calculated as 662 RESPONSE_TIMEOUT * (2 ^ MAX_RETRANSMIT - 1) plus the expected maximum 663 round trip time. 665 A recipient MUST be prepared to receive the same confirmable message 666 (as indicated by the Message ID) multiple times, for example, when 667 its acknowledgement went missing or didn't reach the original sender 668 before the first timeout. As a general rule that may be relaxed 669 based on the specific semantics of a message, the recipient SHOULD 670 acknowledge each duplicate copy of a confirmable message using the 671 same acknowledgement or reset message, but SHOULD process any request 672 or response in the message only once. 674 4.2. Unreliable Messages 676 As a more lightweight alternative, a message can be transmitted less 677 reliably by marking the message as "non-confirmable". A non- 678 confirmable message MUST NOT be acknowledged or be rejected by the 679 recipient. If a recipient lacks context to process the message 680 properly, the message MUST be silently ignored. 682 There is no way to detect if a non-confirmable message was received 683 or not at the CoAP-level. A sender MAY choose to transmit a non- 684 confirmable message multiple times which, for this purpose, specifies 685 a Message ID as well. The same rules for generating the Message ID 686 apply. 688 A recipient MUST be prepared to receive the same non-confirmable 689 message (as indicated by the Message ID) multiple times. As a 690 general rule that may be relaxed based on the specific semantics of a 691 message, the recipient SHOULD silently ignore any duplicated non- 692 confirmable message, and SHOULD process any request or response in 693 the message only once. 695 4.3. Message Types 697 The different types of messages are summarized below. The type of a 698 message is specified by the T field of the CoAP header. 700 Separate from the message type, a message may carry a request, a 701 response, or be empty. This is signalled by the Code field in the 702 CoAP header and is relevant to the request/response model. Possible 703 values for the Code field are maintained by the CoAP Code Registry 704 (Section 11.1). 706 An empty message has the Code field set to 0. The OC field SHOULD be 707 set to 0 and no bytes SHOULD be present after the Message ID field. 708 The OC field and any those bytes MUST be ignored by any recipient. 710 4.3.1. Confirmable (CON) 712 Some messages require an acknowledgement. These messages are called 713 "Confirmable". When no packets are lost, each confirmable message 714 elicits exactly one return message of type Acknowledgement or type 715 Reset. 717 A confirmable message always carries either a request or response and 718 MUST NOT be empty. 720 4.3.2. Non-Confirmable (NON) 722 Some other messages do not require an acknowledgement. This is 723 particularly true for messages that are repeated regularly for 724 application requirements, such as repeated readings from a sensor 725 where eventual arrival is sufficient. 727 A non-confirmable message always carries either a request or 728 response, as well, and MUST NOT be empty. 730 4.3.3. Acknowledgement (ACK) 732 An Acknowledgement message acknowledges that a specific confirmable 733 message (identified by its Message ID) arrived. It does not indicate 734 success or failure of any encapsulated request. 736 The acknowledgement message MUST echo the Message ID of the 737 confirmable message, and MUST carry a response or be empty (see 738 Section 5.2.1 and Section 5.2.2). 740 4.3.4. Reset (RST) 742 A Reset message indicates that a specific confirmable message was 743 received, but some context is missing to properly process it. This 744 condition is usually caused when the receiving node has rebooted and 745 has forgotten some state that would be required to interpret the 746 message. 748 A reset message MUST echo the Message ID of the confirmable message, 749 and MUST be empty. 751 4.4. Multicast 753 CoAP supports sending messages to multicast destination addresses. 754 Such multicast messages MUST be Non-Confirmable. Mechanisms for 755 avoiding congestion from multicast requests are being considered in 756 [I-D.eggert-core-congestion-control]. 758 4.5. Congestion Control 760 Basic congestion control for CoAP is provided by the exponential 761 back-off mechanism in Section 4.1. Further congestion control 762 optimizations are being considered and tested for CoAP 763 [I-D.eggert-core-congestion-control]. 765 5. Request/Response Semantics 767 CoAP operates under a similar request/response model as HTTP: a CoAP 768 end-point in the role of a "client" sends one or more CoAP requests 769 to a "server", which services the requests by sending CoAP responses. 770 Unlike HTTP, requests and responses are not sent over a previously 771 established connection, but exchanged asynchronously over CoAP 772 messages. 774 5.1. Requests 776 A CoAP request consists of the method to be applied to the resource, 777 the identifier of the resource, a payload and Internet media type (if 778 any), and optional meta-data about the request. 780 CoAP supports the basic methods of GET, POST, PUT, DELETE, which are 781 easily mapped to HTTP. They have the same properties of safe (only 782 retrieval) and idempotent (you can invoke it multiple times with the 783 same effects) as HTTP (see Section 9.1 of [RFC2616]). The GET method 784 is safe, therefore it MUST NOT take any other action on a resource 785 other than retrieval. The GET, PUT and DELETE methods MUST be 786 performed in such a way that they are idempotent. POST is not 787 idempotent, because its effect is determined by the origin server and 788 dependent on the target resource; it usually results in a new 789 resource being created or the target resource being updated. 791 A request is initiated by setting the Code field in the CoAP header 792 of a confirmable or a non-confirmable message to a Method Code and 793 including request information. 795 5.2. Responses 797 After receiving and interpreting a request, a server responds with a 798 CoAP response, which can be matched to the request by means of a 799 client-generated token. 801 A response is identified by the Code field in the CoAP header being 802 set to a Response Code. Similar to the HTTP Status Code, the CoAP 803 Response Code indicates the result of the attempt to understand and 804 satisfy the request. These codes are fully defined in Section 5.9. 805 The Response Code numbers to be set in the Code field of the CoAP 806 header are maintained in the CoAP Response Code Registry 807 (Section 11.1.2). 809 0 810 0 1 2 3 4 5 6 7 811 +-+-+-+-+-+-+-+-+ 812 |class| detail | 813 +-+-+-+-+-+-+-+-+ 815 Figure 8: Structure of a Response Code 817 The upper three bits of the 8-bit Response Code number define the 818 class of response. The lower five bits do not have any 819 categorization role; they give additional detail to the overall class 820 (Figure 8). There are 3 classes: 822 2 - Success: The request was successfully received, understood, and 823 accepted. 825 4 - Client Error: The request contains bad syntax or cannot be 826 fulfilled. 828 5 - Server Error: The server failed to fulfill an apparently valid 829 request. 831 The response codes are designed to be extensible: Response Codes in 832 the Client Error and Server Error class that are unrecognized by an 833 end-point MUST be treated as being equivalent to the generic Response 834 Code of that class. However, there is no generic Response Code 835 indicating success, so a Response Code in the Success class that is 836 unrecognized by an end-point can only be used to determine that the 837 request was successful without any further details. 839 As a human readable notation for specifications and protocol 840 diagnostics, the numeric value of a response code is indicated by 841 giving the upper three bits in decimal, followed by a dot and then 842 the lower five bits in a two-digit decimal. E.g., "Not Found" is 843 written as 4.04 -- indicating a value of hexadecimal 0x84 or decimal 844 132. In other words, the dot "." functions as a short-cut for 845 "*32+". 847 Responses can be sent in multiple ways, which are defined below. 849 5.2.1. Immediate 851 In the most basic case, the response is carried directly in the 852 acknowledgement message that acknowledges the request (which requires 853 that the request was carried in a confirmable message). This is 854 called an "immediate" response. 856 The response is returned in the acknowledgement message independent 857 of whether the response indicates success or failure. In effect, the 858 response is piggy-backed on the acknowledgement message, so no 859 separate message is required to both acknowledge that the request was 860 received and return the response. 862 5.2.2. Deferred 864 It may not be possible to return an immediate response in all cases. 865 For example, a server might need longer to obtain the representation 866 of the resource requested than it can wait sending back the 867 acknowledgement message, without risking the client to repeatedly 868 retransmit the request message. 870 The server maybe initiates the attempt to obtain the resource 871 representation and times out an acknowledgement timer, or it 872 immediately sends an acknowledgement knowing in advance that there 873 will be no immediate response. The acknowledgement effectively is a 874 promise that the request will be acted upon. 876 When the server finally has obtained the resource representation, it 877 sends the response. To ensure that this message is not lost, it is 878 again sent as a confirmable message and answered by the client with 879 an acknowledgement, echoing the new Message ID chosen by the server. 881 (Note that, as the underlying datagram transport may not be sequence- 882 preserving, the confirmable message carrying the response may 883 actually arrive before or after the acknowledgement message for the 884 request.) 886 For a deferred exchange, both the acknowledgement to the confirmable 887 request and the acknowledgement to the confirmable response MUST be 888 an empty message, i.e. one that carries neither a request nor a 889 response. 891 5.2.3. Non-Confirmable 893 If the request message is non-confirmable, then the response SHOULD 894 be returned in a non-confirmable message as well. However, an end- 895 point MUST be prepared to receive a non-confirmable response 896 (preceded or followed an empty acknowledgement message) in reply to a 897 confirmable request, or a confirmable response in reply to a non- 898 confirmable request. 900 5.3. Request/Response Matching 902 Regardless of how a response is sent, it is matched to the request by 903 means of a token that is included by the client in the request. The 904 token MUST be echoed by the server in any resulting response without 905 modification. 907 The exact rules for matching a response to a request are as follows: 909 1. For requests sent in a unicast message, the source of the 910 response MUST match the destination of the original request. How 911 this is determined depends on the security mode used (see 912 Section 10): With NoSec, the IP address and port number of the 913 request destination and response source must match. With other 914 security modes, in addition to the IP address and UDP port 915 matching, the request and response MUST have the same security 916 context. 918 2. In an immediate response, both the Message ID of the confirmable 919 request and the acknowledgement, and the token of the response 920 and original request MUST match. In a deferred response, just 921 the token of the response and original request MUST match. 923 The client SHOULD generate tokens in a way that tokens currently in 924 use are unique. An end-point receiving a token MUST treat it as 925 opaque and make no assumptions about its format. (Note that there is 926 a default value for the Token Option, so every message carries a 927 token, even if it is not explicitly expressed in a CoAP option.) 929 In case a confirmable message carrying a response is unexpected (i.e. 930 the client is not waiting for a response with the specified address 931 and/or token), the confirmable response SHOULD be rejected with a 932 reset message and MUST NOT be acknowledged. 934 5.4. Options 936 Both requests and responses may include a list of one or more 937 options. For example, the URI in a request is transported in several 938 options, and meta-data that would be carried in an HTTP header in 939 HTTP is supplied as options as well. 941 CoAP defines a single set of options that are used in both requests 942 and responses: 944 o Content-Type 946 o Etag 948 o Location-Path 950 o Max-Age 951 o Token 953 o Uri-Host 955 o Uri-Path 957 o Uri-Port 959 o Proxy-Uri 961 o Uri-Query 963 The semantics of these options along with their properties are 964 defined in Section 5.10. 966 Not all options have meaning with all methods and response codes. 967 The possible options for methods and response codes are defined in 968 Section 5.8 and Section 5.9 respectively. In case an option has no 969 meaning, it SHOULD NOT be included by the sender and MUST be ignored 970 by the recipient. 972 5.4.1. Critical/Elective 974 Options fall into one of two classes: "critical" or "elective". The 975 difference between these is how an option unrecognized by an end- 976 point is handled: 978 o Upon reception, unrecognized options of class "elective" MUST be 979 silently ignored. 981 o Unrecognized options of class "critical" that occur in a 982 confirmable request MUST cause the return of a 4.02 (Bad Option) 983 response. This response SHOULD include a human-readable error 984 message describing the unrecognized option(s) (see Section 5.5). 986 o Unrecognized options of class "critical" that occur in a 987 confirmable response SHOULD cause the response to be rejected with 988 a reset message. 990 o Unrecognized options of class "critical" that occur in a non- 991 confirmable message MUST cause the message be silently ignored. 993 Note that, whether critical or elective, an option is never 994 "mandatory" (it is always optional): These rules are defined in order 995 to enable implementations to reject options they do not understand or 996 implement. 998 5.4.2. Length 1000 Option values are defined to have a specific length, often in the 1001 form of an upper and lower bound. If the length of an option value 1002 in a request is outside the defined range, that option MUST be 1003 treated like an unrecognized option (see Section 5.4.1). 1005 5.4.3. Default Values 1007 Options may be defined to have a default value. If the value of 1008 option is intended to be this default value, the option SHOULD NOT be 1009 included in the message. If the option is not present, the default 1010 value MUST be assumed. 1012 5.4.4. Repeating Options 1014 Each definition of an option specifies whether it is defined to occur 1015 only at most once or whether it can occur multiple times. If a 1016 message includes an option with more instances than the option is 1017 defined for, the additional option instances MUST be treated like an 1018 unrecognized option (see Section 5.4.1). 1020 5.4.5. Option Numbers 1022 Options are identified by an option number. Odd numbers indicate a 1023 critical option, while even numbers indicate an elective option. 1025 The numbers 14, 28, 42, ... are reserved for "fenceposting", as 1026 described in Section 3.2. As these option numbers are even, they 1027 stand for elective options, and unless assigned a meaning, these MUST 1028 be silently ignored. 1030 The option numbers for the options defined in this document are 1031 listed in the CoAP Option Number Registry (Section 11.2). 1033 5.5. Payload 1035 Both requests and responses may include payload, depending on the 1036 method or response code respectively. Methods with payload are PUT 1037 and POST, and the response codes with payload are 2.00 (OK) and the 1038 error codes. 1040 The payload of PUT, POST and 2.00 (OK) is typically a resource 1041 representation. Its format is specified by the Internet media type 1042 given by the Content-Type Option. A default value of "text/plain; 1043 charset=utf-8" is assumed in the absence of this option. 1045 A response with a code indicating a Client or Server Error SHOULD 1046 include a brief human-readable diagnostic message as payload, 1047 explaining the error situation. This diagnostic message MUST be 1048 encoded using UTF-8 [RFC3629], more specifically using Net-Unicode 1049 form [RFC5198]. The Content-Type Option has no meaning and SHOULD 1050 NOT be included. 1052 If a method or response code is not defined to have a payload, then 1053 the sender SHOULD NOT include one, and the recipient MUST ignore it. 1055 5.6. Caching 1057 CoAP nodes MAY cache responses in order to reduce the response time 1058 and network bandwidth consumption on future, equivalent requests. 1060 The goal of caching in CoAP is to reuse a prior response message to 1061 satisfy a current request. In some cases, a stored response can be 1062 reused without the need for a network request, reducing latency and 1063 network round-trips; a "freshness" mechanism is used for this purpose 1064 (see Section 5.6.1). Even when a new request is required, it is 1065 often possible to reuse the payload of a prior response to satisfy 1066 the request, thereby reducing network bandwidth usage; a "validation" 1067 mechanism is used for this purpose (see Section 5.6.2). 1069 Unlike HTTP, the cacheability of CoAP responses does not depend on 1070 the request method, but the Response Code. The cacheability of each 1071 Response Code is defined along the Response Code definitions in 1072 Section 5.9. Response Codes that indicate success and are 1073 unrecognized by an end-point MUST NOT be cached. 1075 For a presented request, a CoAP node MUST NOT use a stored response, 1076 unless: 1078 o the presented request method and that used to obtain the stored 1079 response match, 1081 o all options match between those in the presented request and those 1082 of the request used to obtain the stored response (which includes 1083 the request URI), except that there is no need for a match of the 1084 Token, Max-Age, or Etag request option(s), and 1086 o the stored response is either fresh or successfully validated as 1087 defined below. 1089 5.6.1. Freshness Model 1091 When a response is "fresh" in the cache, it can be used to satisfy 1092 subsequent requests without contacting the origin server, thereby 1093 improving efficiency. 1095 The mechanism for determining freshness is for an origin server to 1096 provide an explicit expiration time in the future, using the Max-Age 1097 Option (see Section 5.10.5). The Max-Age Option indicates that the 1098 response is to be considered not fresh after its age is greater than 1099 the specified number of seconds. 1101 As the Max-Age Option defaults to a value of 60, if it is not present 1102 in a cacheable response, then the response is considered not fresh 1103 after its age is greater than 60 seconds. If an origin server wishes 1104 to prevent caching, it MUST explicitly include a Max-Age Option with 1105 a value of zero seconds. 1107 In general, the origin server end-point is responsible for 1108 determining the Max-Age value. However, in some cases a client might 1109 need to influence freshness calculation. It can do this by including 1110 the Max-Age Option in a request. While this option value does not 1111 take part in the request matching, this indicates that the client is 1112 requesting a response whose remaining lifetime is no less than the 1113 specified time in seconds. 1115 5.6.2. Validation Model 1117 When an end-point has one or more stored responses for a GET request, 1118 but cannot use any of them (e.g., because they are not fresh), it can 1119 use the Etag Option in the GET request to give the origin server an 1120 opportunity to both select a stored response to be used, and to 1121 update its freshness. This process is known as "validating" or 1122 "revalidating" the stored response. 1124 When sending such a request, the client SHOULD add an Etag Option 1125 specifying the entity-tag for each stored response that is 1126 applicable. 1128 A 2.03 (Valid) response indicates the stored response identified by 1129 the entity-tag given in the response's Etag Option can be reused, 1130 after updating its freshness with the value of the Max-Age Option 1131 that is included with the response (see Section 5.9.1.4). 1133 Any other response code indicates that none of the stored responses 1134 nominated in the request is suitable. Instead, the response SHOULD 1135 be used to satisfy the request and MAY replace the stored response. 1137 5.7. Proxying 1139 CoAP distinguishes between requests to an origin server and a request 1140 made through a proxy. A proxy is a CoAP end-point that can be tasked 1141 by CoAP clients to perform requests on their behalf. This may be 1142 useful, for example, when the request could otherwise not be made, or 1143 to service the response from a cache in order to reduce response time 1144 and network bandwidth or energy consumption. 1146 CoAP requests to a proxy are made as normal confirmable or non- 1147 confirmable requests to the proxy end-point, but specify the request 1148 URI in a different way: The request URI in a proxy request is 1149 specified as a string in the Proxy-Uri Option (see Section 5.10.3), 1150 while the request URI in a request to an origin server is split into 1151 the Uri-Host, Uri-Port, Uri-Path and Uri-Query Options (see 1152 Section 5.10.2). 1154 When a proxy request is made to an end-point and the end-point is 1155 unwilling or unable to act as proxy for the request URI, it MUST 1156 return a 5.05 (Proxying Not Supported) response. If the authority 1157 (host and port) is recognized as identifying the proxy end-point, 1158 then the request MUST be treated as a local request. 1160 Unless a proxy is configured to forward the proxy request to another 1161 proxy, it MUST translate the request as follows: The origin server's 1162 IP address and port are determined by the authority component of the 1163 request URI, and the request URI is decoded and split into the Uri- 1164 Host, Uri-Port, Uri-Path and Uri-Query Options. 1166 All options present in a proxy request MUST be processed at the 1167 proxy. Critical options in a request that are not recognized by the 1168 proxy MUST lead to a 4.02 (Bad Option) response being returned by the 1169 proxy. Elective options not recognized by the proxy MUST NOT be 1170 forwarded to the origin server. Similarly, critical options in a 1171 response that are not recognized by the proxy server MUST lead to a 1172 5.02 (Bad Gateway) response. Again, elective options that are not 1173 recognized MUST NOT be forwarded. 1175 If the proxy does not employ a cache, then it simply forwards the 1176 translated request to the determined destination. Otherwise, if it 1177 does not have a stored response that matches the translated request 1178 and is considered fresh, then it needs to refresh its cache according 1179 to Section 5.6. 1181 If the request to the destination times out, then a 5.04 (Gateway 1182 Timeout) response MUST be returned. If the request to the 1183 destination returns an response that cannot be processed by the 1184 proxy, then a 5.02 (Bad Gateway) response MUST be returned. 1185 Otherwise, the proxy returns the response to the client. 1187 If a response is generated out of a cache, it MUST be generated with 1188 a max-age option that does not extend the max-age originally set by 1189 the server, considering the time the resource representation spent in 1190 the cache. E.g., the Max-Age option could be adjusted by the proxy 1191 for each response using the formula: proxy-max-age = original-max-age 1192 - cache-age. For example if a request is made to a proxied resource 1193 that was refreshed 20 seconds ago and had an original Max-Age of 60 1194 seconds, then that resource's proxied Max-Age is now 40 seconds. 1196 5.8. Method Definitions 1198 In this section each method is defined along with its behavior. A 1199 request with an unrecognized or unsupported Method Code MUST generate 1200 a 4.05 (Method Not Allowed) response. 1202 5.8.1. GET 1204 The GET method retrieves a representation for the information that 1205 currently corresponds to the resource identified by the request URI. 1206 If the request includes an Etag Option, the GET method requests that 1207 Etag be validated and that the representation be transferred only if 1208 validation failed. Upon success a 2.00 (OK) or 2.03 (Valid) response 1209 SHOULD be sent. 1211 The GET method is safe and idempotent. An implementation MAY relax 1212 the requirement to answer all retransmissions of a request with the 1213 same response (Section 4.1), obviating the need to maintain state for 1214 Message IDs. 1216 5.8.2. POST 1218 The POST method requests that the representation enclosed in the 1219 request be processed. The actual function performed by the POST 1220 method is determined by the origin server and dependent on the target 1221 resource. It usually results in a new resource being created or the 1222 target resource being updated. 1224 If a resource has been created on the server, a 2.01 (Created) 1225 response that includes the URI of the new resource in a sequence of 1226 one or more Location-Path Options SHOULD be returned. If the POST 1227 succeeds but does not result in a new resource being created on the 1228 server, a 2.04 (Changed) response SHOULD be returned. 1230 If the request passes through a cache that has one or more stored 1231 responses for the request URI, those stored responses SHOULD be 1232 marked as stale. 1234 POST is neither safe nor idempotent and generally requires the full 1235 deduplication support from the message layer. 1237 5.8.3. PUT 1239 The PUT method requests that the resource identified by the request 1240 URI be updated or created with the enclosed representation. The 1241 representation format is specified by the media type given in the 1242 Content-Type Option. 1244 If a resource exists at the request URI the enclosed representation 1245 SHOULD be considered a modified version of that resource, and a 2.04 1246 (Changed) response SHOULD be returned. If no resource exists then 1247 the server MAY create a new resource with that URI, resulting in a 1248 2.01 (Created) response. If the resource could not be created or 1249 modified, then an appropriate error response code SHOULD be sent. 1251 If the request passes through a cache that has one or more stored 1252 responses for the request URI, those stored responses SHOULD be 1253 marked as stale. 1255 PUT is not safe, but idempotent. An implementation MAY relax the 1256 message layer deduplication support and process duplicate 1257 transmissions of the request as separate requests. 1259 5.8.4. DELETE 1261 The DELETE method requests that the resource identified by the 1262 request URI be deleted. A 2.02 (Deleted) response SHOULD be sent on 1263 success or in case the resource did not exist before the request. 1265 If the request passes through a cache and the request URI identifies 1266 one or more currently stored responses, those entries SHOULD be 1267 treated as stale. 1269 DELETE is not safe, but idempotent. An implementation MAY relax the 1270 message layer deduplication support and process duplicate 1271 transmissions of the request as separate requests. 1273 5.9. Response Code Definitions 1275 Each response code is described below, including any options required 1276 in the response. Where appropriate, some of the codes will be 1277 specified in regards to related response codes in HTTP [RFC2616]; 1278 this does not mean that any such relationship modifies the HTTP 1279 mapping specified in Section 8. 1281 5.9.1. Success 2.xx 1283 This class of status code indicates that the clients request was 1284 successfully received, understood, and accepted. 1286 5.9.1.1. 2.00 OK 1288 Like HTTP 200 "OK", but only used in response to GET requests. 1290 The payload returned with the response is a representation of the 1291 target resource. The representation format is specified by the media 1292 type given in the Content-Type Option. 1294 This response is cacheable: Caches can use the Max-Age Option to 1295 determine freshness (see Section 5.6.1) and (if present) the Etag 1296 Option for validation (see Section 5.6.2). 1298 5.9.1.2. 2.01 Created 1300 Like HTTP 201 "Created", but only used in response to POST and PUT 1301 requests. 1303 If the response includes the Location-Path Option, the value of the 1304 option specifies the location at which the resource was created. 1305 Otherwise, the resource was created at the request URI. A cache 1306 SHOULD mark any stored response for the location as not fresh. 1308 This response is not cacheable. 1310 5.9.1.3. 2.02 Deleted 1312 Like HTTP 204 "No Content", but only used in response to DELETE 1313 requests. 1315 This response is not cacheable. 1317 5.9.1.4. 2.03 Valid 1319 Related to HTTP 304 "Not Modified", but only used to indicate that 1320 the response identified by the entity-tag identified by the included 1321 Etag Option is valid. Accordingly, the response MUST include an Etag 1322 Option. 1324 When a cache receives a 2.03 (Valid) response, it needs to update the 1325 stored response with the value of the Max-Age Option included in the 1326 response (see Section 5.6.2). 1328 5.9.1.5. 2.04 Changed 1330 Like HTTP 204 "No Content", but only used in response to POST and PUT 1331 requests. 1333 This response is not cacheable. 1335 5.9.2. Client Error 4.xx 1337 This class of response code is intended for cases in which the client 1338 seems to have erred. These response codes are applicable to any 1339 request method. 1341 The server SHOULD include a brief human-readable message as payload, 1342 as detailed in Section 5.5. 1344 Responses of this class are cacheable: Caches can use the Max-Age 1345 Option to determine freshness (see Section 5.6.1). They cannot be 1346 validated. 1348 5.9.2.1. 4.00 Bad Request 1350 Like HTTP 400 "Bad Request". 1352 5.9.2.2. 4.01 Unauthorized 1354 The client is not authorized to perform the requested action. The 1355 client SHOULD NOT repeat the request without previously improving its 1356 authentication status to the server. Which specific mechanism can be 1357 used for this is outside this document's scope; see also Section 10. 1359 5.9.2.3. 4.02 Bad Option 1361 The request could not be understood by the server due to one or more 1362 unrecognized or malformed critical options. The client SHOULD NOT 1363 repeat the request without modification. 1365 5.9.2.4. 4.03 Forbidden 1367 Like HTTP 403 "Forbidden". 1369 5.9.2.5. 4.04 Not Found 1371 Like HTTP 404 "Not Found". 1373 5.9.2.6. 4.05 Method Not Allowed 1375 Like HTTP 405 "Method Not Allowed", but with no parallel to the 1376 "Accept" header field. 1378 5.9.2.7. 4.13 Request Entity Too Large 1380 Like HTTP 413 "Request Entity Too Large". 1382 5.9.2.8. 4.15 Unsupported Media Type 1384 Like HTTP 415 "Unsupported Media Type". 1386 5.9.3. Server Error 5.xx 1388 This class of response code indicates cases in which the server is 1389 aware that it has erred or is incapable of performing the request. 1390 These response codes are applicable to any request method. 1392 The server SHOULD include a human-readable message as payload, as 1393 detailed in Section 5.5. 1395 Responses of this class are cacheable: Caches can use the Max-Age 1396 Option to determine freshness (see Section 5.6.1). They cannot be 1397 validated. 1399 5.9.3.1. 5.00 Internal Server Error 1401 Like HTTP 500 "Internal Server Error". 1403 5.9.3.2. 5.01 Not Implemented 1405 Like HTTP 501 "Not Implemented". 1407 5.9.3.3. 5.02 Bad Gateway 1409 Like HTTP 502 "Bad Gateway". 1411 5.9.3.4. 5.03 Service Unavailable 1413 Like HTTP 503 "Service Unavailable", but using the Max-Age Option in 1414 place of the "Retry-After" header field. 1416 5.9.3.5. 5.04 Gateway Timeout 1418 Like HTTP 504 "Gateway Timeout". 1420 5.9.3.6. 5.05 Proxying Not Supported 1422 The server is unable or unwilling to act as a proxy for the URI 1423 specified in the Proxy-Uri Option (see Section 5.10.3). 1425 5.10. Option Definitions 1427 The individual CoAP options are summarized in Table 1 and explained 1428 below. 1430 +-----+-----+---------------+--------+---------+-------------+ 1431 | No. | C/E | Name | Format | Length | Default | 1432 +-----+-----+---------------+--------+---------+-------------+ 1433 | 1 | C | Content-Type | uint | 1-2 B | 0 | 1434 | 2 | E | Max-Age | uint | 0-4 B | 60 | 1435 | 3 | C | Proxy-Uri | string | 1-270 B | (none) | 1436 | 4 | E | Etag | opaque | 1-4 B | (none) | 1437 | 5 | C | Uri-Host | string | 1-270 B | (see below) | 1438 | 6 | E | Location-Path | string | 1-270 B | (none) | 1439 | 7 | C | Uri-Port | uint | 0-2 B | (see below) | 1440 | 9 | C | Uri-Path | string | 1-270 B | (none) | 1441 | 11 | C | Token | opaque | 1-8 B | (empty) | 1442 | 15 | C | Uri-Query | string | 1-270 B | (none) | 1443 +-----+-----+---------------+--------+---------+-------------+ 1445 Table 1: Options 1447 5.10.1. Token 1449 The Token Option is used to match a response with a request. Every 1450 request has a client-generated token which the server MUST echo in 1451 any response. 1453 A token is intended for use as a client-local identifier for 1454 differentiating between concurrent requests. A client SHOULD 1455 generate tokens in a way that tokens currently in use are unique. An 1456 end-point receiving a token MUST treat it as opaque and make no 1457 assumptions about its format. 1459 A default value of a zero-length token is assumed in the absence of 1460 the option. 1462 This option is "critical". It MUST NOT occur more than once. 1464 5.10.2. Uri-Host, Uri-Port, Uri-Path and Uri-Query 1466 The Uri-Host, Uri-Port, Uri-Path and Uri-Query Options are used to 1467 specify the target resource of a request to a CoAP origin server. 1468 The options encode the different components of the request URI in a 1469 way that no percent-encoding is visible in the option values (except 1470 for Uri-Query) and that the full URI can be reconstructed at any 1471 involved end-point. The syntax of CoAP URIs is defined in Section 6. 1473 The steps for parsing URIs into options is defined in Section 6.3. 1474 These steps result in zero or more Uri-Host, Uri-Port, Uri-Path and 1475 Uri-Query Options being included in a request, where each option 1476 holds the following values: 1478 o the Uri-Host Option specifies the Internet host of the resource 1479 being requested, 1481 o the Uri-Port Option specifies the port number of the resource, 1483 o each Uri-Path Option specifies one segment of the absolute path to 1484 the resource, and 1486 o the Uri-Query Option specifies the query. 1488 Note: Fragments ([RFC3986], Section 3.5) are not part of the request 1489 URI and thus will not be transmitted in a CoAP request. 1491 The default value of the Uri-Host Option is the IP literal 1492 representing the destination IP address of the request message. 1493 Likewise, the default value of the Uri-Port Option is the destination 1494 UDP port. 1496 The Uri-Path Option can contain any character sequence. No percent- 1497 encoding is performed. The value MUST NOT be "." or ".." (as the 1498 request URI must be resolved before parsing it into options). 1500 The steps for constructing the request URI from the options are 1501 defined in Section 6.4. Note that an implementation does not 1502 necessarily have to construct the URI; it can simply look up the 1503 target resource by looking at the individual options. 1505 Examples can be found in Appendix C. 1507 All of the options are "critical". Uri-Host, Uri-Port and Uri-Query 1508 MUST NOT occur more than once; Uri-Path MAY occur one or more times. 1510 5.10.3. Proxy-Uri 1512 The Proxy-Uri Option is used to make a request to a proxy (see 1513 Section 5.7). The proxy is requested to forward the request or 1514 service it from a valid cache, and return the response. 1516 The option value is an absolute-URI ([RFC3986], Section 4.3). In 1517 case the absolute-URI doesn't fit within a single option, the Proxy- 1518 Uri Option MAY be included multiple times in a request such that the 1519 concatenation of the values results in the single absolute-URI. 1521 All but the last instance of the Proxy-Uri Option MUST have a value 1522 with a length of 270 bytes, and the last instance MUST NOT be empty. 1524 Note that the proxy MAY forward the request on to another proxy or 1525 directly to the server specified by the absolute-URI. In order to 1526 avoid request loops, a proxy MUST be able to recognize all of its 1527 server names, including any aliases, local variations, and the 1528 numeric IP addresses. 1530 An end-point receiving a request with a Proxy-Uri Option that is 1531 unable or unwilling to act as a proxy for the request MUST cause the 1532 return of a 5.05 (Proxying Not Supported) response. 1534 This option is "critical". It MAY occur one or more times and MUST 1535 take precedence over any of the Uri-Host, Uri-Port, Uri-Path or Uri- 1536 Query options (which MUST NOT be included at the same time). 1538 5.10.4. Content-Type 1540 The Content-Type Option indicates the representation format of the 1541 message payload. The representation format is given as a numeric 1542 media type identifier that is defined in the CoAP Media Type registry 1543 (Section 11.3). A default value of 0 (meaning "text/plain; 1544 charset=utf-8") is assumed in the absence of the option. 1546 This option is "critical". It MUST NOT occur more than once. 1548 5.10.5. Max-Age 1550 The Max-Age Option indicates the maximum time a response may be 1551 cached before it MUST be considered not fresh (see Section 5.6.1). 1553 When included in a request, the Max-Age Option indicates the minimum 1554 value for the maximum age of a cached response the client will 1555 accept. Note that the default value of 60 seconds for the Max-Age 1556 Option does not apply in a request. 1558 The option value is an integer number of seconds between 0 and 2^32-1 1559 inclusive (about 136.1 years). A default value of 60 seconds is 1560 assumed in the absence of the option in a response. 1562 This option is "elective". It MUST NOT occur more than once. 1564 5.10.6. Etag 1566 The Etag Option in a response provides the current value of the 1567 entity-tag for the enclosed representation of the target resource. 1569 An entity-tag is intended for use as a resource-local identifier for 1570 differentiating between representations of the same resource that 1571 vary over time. It may be generated in any number of ways including 1572 a version, checksum, hash or time. An end-point receiving an entity- 1573 tag MUST treat it as opaque and make no assumptions about its format. 1575 A node that has one or more representations previously obtained from 1576 the resource can specify the Etag Option in a request for each stored 1577 response to determine if any of those representations is current (see 1578 Section 5.6.2). 1580 This option is "elective". It MUST NOT occur more than once in a 1581 response, and MAY occur one or more times in a request. 1583 5.10.7. Location-Path 1585 The collection of Location-Path Options indicates the location of a 1586 resource as an absolute path URI; each Location-Path Option is 1587 similar to a Uri-Path Option. The Location-Path Option MAY be 1588 included in a response to indicate the location of a new resource 1589 created with POST. 1591 If a response with a Location-Path Option passes through a cache and 1592 the implied URI identifies one or more currently stored responses, 1593 those entries SHOULD be treated as stale. 1595 This option is "elective". It MAY occur one or more times. 1597 6. CoAP URIs 1599 CoAP uses the "coap" URI scheme for identifying CoAP resources and 1600 providing a means of locating the resource. Resources are organized 1601 hierarchically and governed by a potential CoAP origin server 1602 listening for CoAP requests on a given UDP port. The CoAP server is 1603 identified via the generic syntax's authority component, which 1604 includes a host identifier and optional UDP port number, and the 1605 remainder of the URI is considered to be identifying a resource which 1606 can be operated on by the methods available through the CoAP 1607 protocol. CoAP URIs can thus be compared to the "http" URI scheme. 1609 6.1. URI Scheme Syntax 1611 The syntax of the "coap" URI scheme is specified below in Augmented 1612 Backus-Naur Form (ABNF) [RFC5234]. The definitions of "host", 1613 "port", "path-abempty", and "query" are adopted from [RFC3986], as 1614 well as "segment", "IP-literal", "IPv4address" and "reg-name" for the 1615 following sections. 1617 coap-URI = "coap:" "//" host [ ":" port ] path-abempty [ "?" query ] 1619 If host is provided as an IP literal or IPv4 address, then the CoAP 1620 server is located at that IP address. If host is a registered name, 1621 then that name is considered an indirect identifier and the end-point 1622 might use a name resolution service, such as DNS, to find the address 1623 of that host. The host MUST NOT be empty. The port subcomponent 1624 indicates the UDP port at which the CoAP server is located. If it is 1625 empty or not given, then the default port 5683 is assumed. 1627 The path identifies a resource within the scope of the host and port. 1628 It consists of a sequence of path segments separated by a slash ("/") 1629 character. The query serves to further parametrize the resource, 1630 often in the form of "key=value" pairs. 1632 Application designers are encouraged to make use of short, but 1633 descriptive URIs. As the environments that CoAP is used in are 1634 usually constrained for bandwidth and energy, the trade-off between 1635 these two qualities should lean towards the shortness, without 1636 ignoring descriptiveness. 1638 6.2. Normalization and Comparison Rules 1640 Since the "coap" scheme conforms to the URI generic syntax, URIs of 1641 this scheme are normalized and compared according to the algorithm 1642 defined in [RFC3986], Section 6. 1644 If the port is equal to the default port 5683, the normal form is to 1645 elide the port component. Likewise, an empty path component is 1646 equivalent to an absolute path of "/", so the normal form is to 1647 provide a path of "/" instead. The scheme and host are case- 1648 insensitive and normally provided in lowercase; IP-literals are in 1649 recommended form [RFC5952]; all other components are compared in a 1650 case-sensitive manner. Characters other than those in the "reserved" 1651 set are equivalent to their percent-encoded octets (see [RFC3986], 1652 Section 2.1): the normal form is to not encode them. 1654 For example, the following three URIs are equivalent, and cause the 1655 same options and option values to appear in the CoAP messages: 1657 coap://example.com:5683/~sensors/temp.xml 1659 coap://EXAMPLE.com/%7Esensors/temp.xml 1661 coap://EXAMPLE.com:/%7esensors/temp.xml 1663 6.3. Parsing URIs 1665 The steps to parse a request's options from a string /url/ are as 1666 follows. These steps either result in zero or more of the Uri-Host, 1667 Uri-Port, Uri-Path and Uri-Query Options being included in the 1668 request, or they fail. 1670 1. If the /url/ string is not an absolute URI ([RFC3986]), then fail 1671 this algorithm. 1673 2. Resolve the /url/ string using the process of reference 1674 resolution defined by [RFC3986], with the URL character encoding 1675 set to UTF-8 [RFC3629]. 1677 NOTE: It doesn't matter what it is resolved relative to, since we 1678 already know it is an absolute URL at this point. 1680 3. If /url/ does not have a component whose value, when 1681 converted to ASCII lowercase, is "coap", then fail this 1682 algorithm. 1684 4. If /url/ has a component, then fail this algorithm. 1686 5. If the component of /url/ does not represent the request's 1687 destination IP address as an IP-literal or IPv4 address, include 1688 a Uri-Host Option and let that option's value be the value of the 1689 component of /url/, converted to ASCII lowercase, and then 1690 converting each percent-encoding ("%" followed by two hexadecimal 1691 digits) to the corresponding byte. . 1693 NOTE: In the usual case where the request's destination IP 1694 address is derived from the host part, this ensures that Uri-Host 1695 Options are only used for host parts of the form reg-name. 1697 6. If /url/ has a component, then let /port/ be that 1698 component's value interpreted as a decimal integer; otherwise, 1699 let /port/ be the default port 5683. 1701 7. If /port/ does not equal the request's destination UDP port, 1702 include a Uri-Port Option and let that option's value be /port/. 1704 8. If the value of the component of /url/ is empty or 1705 consists of a single slash character (U+002F SOLIDUS "/"), then 1706 move to the next step. 1708 Otherwise, for each segment in the component, include a 1709 Uri-Path Option and let that option's value be the segment (not 1710 including the delimiting slash characters) after converting each 1711 percent-encoding ("%" followed by two hexadecimal digits) to the 1712 corresponding byte. 1714 9. If /url/ has a component, then include a Uri-Query Option 1715 and let that option's value be the value of the component 1716 (not including the delimiting question mark). (Note that, in 1717 contrast to the other components, percent-encodings stay intact 1718 in the Uri-Query option.) 1720 Note that these rules completely resolve any percent-encoding except 1721 in a reg-name and in a query. 1723 6.4. Constructing URIs 1725 The steps to construct a URI from a request's options are as follows. 1726 These steps either result in a URI, or they fail. In these steps, 1727 percent-encoding a character means replacing each of its (UTF-8 1728 encoded) bytes by a "%" character followed by two hexadecimal digits 1729 representing the byte, where the digits A-F are in upper case (as 1730 defined in [RFC3986] Section 2.1; to reduce variability, the 1731 hexadecimal notation in CoAP URIs MUST use uppercase letters). 1733 1. Let /url/ be the string "coap://". 1735 2. If the request includes a Uri-Host Option, let /host/ be that 1736 option's value, where any non-ASCII characters are replaced by 1737 their corresponding percent-encoding. If /host/ is not a valid 1738 reg-name or IP-literal or IPv4address, fail the algorithm. 1739 Otherwise, let /host/ be the IP-literal (making use of the 1740 conventions of [RFC5952]) or IPv4address representing the 1741 request's destination IP address. 1743 3. Append /host/ to /url/. 1745 4. If the request includes a Uri-Port Option, let /port/ be that 1746 option's value. Otherwise, let /port/ be the request's 1747 destination UDP port. 1749 5. If /port/ is not the default port 5683, then append a single 1750 U+003A COLON character (:) followed by the decimal 1751 representation of /port/ to /url/. 1753 6. Let /resource name/ be the empty string. For each Uri-Path 1754 Option in the request, append a single character U+002F SOLIDUS 1755 (/) followed by the option's value to /resource name/, after 1756 converting any character that is not either in the "unreserved" 1757 set, "sub-delims" set, a U+003A COLON character (:) or U+0040 1758 COMMERCIAL AT (@), to its percent-encoded form. 1760 7. If /resource name/ is the empty string, set it to a single 1761 character U+002F SOLIDUS (/). 1763 8. Append /resource name/ to /url/. 1765 9. If the request includes a Uri-Query Option, append a single 1766 U+003F QUESTION MARK character (?) to /url/, followed by the 1767 option's value. 1769 10. Return /url/. 1771 Note that these steps have been designed to lead to a URI in normal 1772 form (see Section 6.2). 1774 7. Finding and Addressing CoAP End-Points 1776 7.1. Resource Discovery 1778 The discovery of resources offered by a CoAP end-point is extremely 1779 important in machine-to-machine applications where there are no 1780 humans in the loop and static interfaces result in fragility. A CoAP 1781 end-point SHOULD support the CoRE Link Format of discoverable 1782 resources as described in [I-D.ietf-core-link-format]. 1784 7.2. Default Port 1786 The CoAP default port number 5683 MUST be supported by a server for 1787 resource discovery and SHOULD be supported for providing access to 1788 other resources. In addition other end-points may be hosted in the 1789 dynamic port space. 1791 When a CoAP server is hosted by a 6LoWPAN node, it SHOULD also 1792 support a port in the 61616-61631 compressed UDP port space defined 1793 in [RFC4944]. 1795 7.3. Multiplexing DTLS and CoAP 1797 The CoAP encoding has been chosen to enable demultiplexing of two 1798 kinds of packets that arrive on a single UDP port: 1800 o CoAP messages directly sent within UDP 1802 o DTLS 1.1 or 1.2 messages (which might contain CoAP messages) on 1803 UDP 1805 Possibly less importantly, a distinction can also be made between 1806 these two and: 1808 o STUN messages on UDP 1810 This demultiplexing is possible because DTLS 1.1 or 1.2 UDP payloads 1811 begin with a byte out of: 1813 enum { 1814 change_cipher_spec(20), alert(21), handshake(22), 1815 application_data(23), (255) 1816 } ContentType; 1818 Figure 9: TLS ContentType 1820 i.e. 0x14 to 0x17 hex [RFC4347]. In a CoAP message, such an initial 1821 byte would be decoded as a CoAP version 0, which is not in use. 1823 7.3.1. Future-Proofing the Multiplexing 1825 To maintain this property, future versions of CoAP will not use 1826 version number 0. Note that future versions of DTLS might 1827 theoretically start to use "ContentType" values that fall into the 1828 range of 64 to 127; CoAP implementations would then not be able to 1829 reliably multiplex these new kinds of DTLS datagrams with CoAP 1830 datagrams on the same UDP port. To maintain transparency for this 1831 case, an initial byte of 0x11 (17 decimal) is inserted on 1832 transmission and discarded upon reception; the rest of the datagram 1833 is interpreted as the DTLS message. 0x11 MUST NOT be followed by 0x14 1834 to 0x17 hex, i.e. the DTLS messages defined by DTLS 1.1 and 1.2 are 1835 always sent unescaped. Datagrams starting with 0x11 and then 0x14 to 1836 0x17 MUST be discarded. 1838 Similarly, STUN messages begin with 00mmmmmc binary (MSBs) [RFC5389] 1839 and so far happen to use an encoding for mmmmmc that also enables 1840 this initial byte to be distinguished from valid DTLS messages. 1841 Again, future versions of CoAP will need to avoid using version 1842 number 0. STUN messages are most likely to begin with 0x00 and 0x01. 1843 All other STUN messages MUST be escaped with a an initial 0x10 byte 1844 (16 decimal). 0x10 MUST NOT be followed by 0x00 or 0x01 hex, i.e. the 1845 more likely STUN messages are always sent unescaped. 1847 Note that the escaping rules defined in this section are insurance 1848 for the future; they need no additional code in implementations that 1849 do not implement STUN or DTLS or implement only the versions current 1850 at the time of writing. For easy reference, Table 2 summarizes the 1851 rules upon reception. 1853 +--------------+-------------+----------------+ 1854 | initial byte | disposition | interpretation | 1855 +--------------+-------------+----------------+ 1856 | 0x00 or 0x01 | keep | STUN | 1857 | 0x10 | remove | STUN | 1858 | 0x11 | remove | DTLS | 1859 | 0x14 to 0x17 | keep | DTLS | 1860 | 0x40 to 0x7F | keep | CoAP | 1861 | all others | | (invalid) | 1862 +--------------+-------------+----------------+ 1864 Table 2: Interpretation of initial byte when multiplexing 1866 8. HTTP Mapping 1868 CoAP supports a limited subset of HTTP functionality, and thus a 1869 mapping to HTTP is straightforward. There might be several reasons 1870 for mapping between CoAP and HTTP, for example when designing a web 1871 interface for use over either protocol or when realizing a CoAP-HTTP 1872 proxy. Likewise, CoAP could equally be mapped to other protocols 1873 such as XMPP [RFC3920] or SIP [RFC3264], the definition of these 1874 mappings is out of scope of this specification. 1876 This section discusses two ways of mapping: 1878 CoAP-HTTP Mapping: Enables CoAP clients to access resources on HTTP 1879 servers through an intermediary. This is initiated by including 1880 the Proxy-Uri Option with an "http" URI in a CoAP request to a 1881 CoAP-HTTP proxy, or by sending a CoAP request to a reverse proxy 1882 that maps CoAP to HTTP. 1884 HTTP-CoAP Mapping: Enables HTTP clients to access resources on CoAP 1885 servers through an intermediary. This is initiated by specifying 1886 a "coap" URI in the Request-Line of an HTTP request to an HTTP- 1887 CoAP proxy, or by sending an HTTP request to a reverse proxy that 1888 maps HTTP to CoAP. 1890 Either way, only the Request/Response model of CoAP is mapped to 1891 HTTP. The underlying model of confirmable or non-confirmable 1892 messages, etc., is invisible and MUST have no effect on a proxy 1893 function. 1895 8.1. CoAP-HTTP Mapping 1897 The mapping of CoAP to HTTP is a relatively straightforward 1898 conversion of the CoAP method or response code, content-type and 1899 options to the corresponding HTTP feature. The payload is carried in 1900 an equivalent way by both protocols. 1902 In a similar manner to CoAP-CoAP proxying, the CoAP-HTTP proxy MAY 1903 perform caching of HTTP responses. If no caching is performed, a 1904 CoAP GET request that specifies an entity-tag in an Etag Option 1905 SHOULD be mapped to a conditional HTTP request that includes the 1906 entity-tag in the "If-None-Match" request-header field. If the 1907 entity-tag matches the entity-tag of the representation, the HTTP 1908 server responds with an HTTP 304 (Not Modified) response which SHOULD 1909 be mapped to a CoAP 2.03 (Valid) response with the Etag Option 1910 reflecting the response's "Etag" response-header field. The mapping 1911 of max-age is straightforward. 1913 HTTP entity-tags consist of characters in a subset of the US-ASCII 1914 character set, which can be carried directly in a CoAP Etag Option. 1915 Weak entity-tags are not supported by this mapping. However, an 1916 entity-tag may not fit within the CoAP Etag Option. In this case, 1917 the proxy MAY map the entity-tag to a shorter unique byte sequence 1918 and keep state, or MAY silently ignore the "Etag" response-header 1919 when mapping an HTTP response to CoAP (so the CoAP client will never 1920 send a CoAP GET request with an Etag Option). 1922 Provisional responses (HTTP Status Codes 1xx), and responses 1923 indicating that further action needs to be taken (HTTP Status Codes 1924 3xx), SHOULD cause the proxy to complete the request, e.g., by 1925 following the redirects. If the proxy is unable to complete the 1926 request, it SHOULD respond with a CoAP 5.02 (Bad Gateway) error. 1928 HTTP responses are mapped to CoAP responses as follows: 1930 +-------------------------------+---------------------------+-------+ 1931 | HTTP Status Code | CoAP Response Code | Notes | 1932 +-------------------------------+---------------------------+-------+ 1933 | 100 Continue | | 2 | 1934 | 101 Switching Protocols | | 2 | 1935 | 200 OK | | 3 | 1936 | 201 Created | 2.01 Created | | 1937 | 202 Accepted | | 4 | 1938 | 203 Non-Authoritative | | 4 | 1939 | Information | | | 1940 | 204 No Content | | 6 | 1941 | 205 Reset Content | | 4 | 1942 | 206 Partial Content | | 2 | 1943 | 300 Multiple Choices | | 2 | 1944 | 301 Moved Permanently | | 2 | 1945 | 302 Found | | 2 | 1946 | 303 See Other | | 2 | 1947 | 304 Not Modified | 2.03 Valid | 7 | 1948 | 305 Use Proxy | | 2 | 1949 | 306 (Unused) | 5.02 Bad Gateway | 1 | 1950 | 307 Temporary Redirect | | 2 | 1951 | 400 Bad Request | 4.00 Bad Request | | 1952 | 401 Unauthorized | 4.01 Unauthorized | 5 | 1953 | 402 Payment Required | 4.00 Bad Request | 1 | 1954 | 403 Forbidden | 4.03 Forbidden | | 1955 | 404 Not Found | 4.04 Not Found | | 1956 | 405 Method Not Allowed | 4.05 Method Not Allowed | 8 | 1957 | 406 Not Acceptable | 4.00 Bad Request | 1 | 1958 | 407 Proxy Authentication | 4.00 Bad Request | 1 | 1959 | Required | | | 1960 | 408 Request Timeout | 4.00 Bad Request | 1 | 1961 | 409 Conflict | 4.00 Bad Request | 1 | 1962 | 410 Gone | 4.00 Bad Request | 1 | 1963 | 411 Length Required | 4.00 Bad Request | 1 | 1964 | 412 Precondition Failed | 4.00 Bad Request | 1 | 1965 | 413 Request Entity Too Large | 4.13 Request Entity Too | | 1966 | | Large | | 1967 | 414 URI Too Long | 4.00 Bad Request | 1 | 1968 | 415 Unsupported Media Type | 4.15 Unsupported Media | | 1969 | | Type | | 1970 | 416 Requested Range Not | 4.00 Bad Request | 1 | 1971 | Satisfiable | | | 1972 | 417 Expectation Failed | 4.00 Bad Request | 1 | 1973 | 500 Internal Server Error | 5.00 Internal Server | | 1974 | | Error | | 1975 | 501 Not Implemented | 5.01 Not Implemented | | 1976 | 502 Bad Gateway | 5.02 Bad Gateway | | 1977 | 503 Service Unavailable | 5.03 Service Unavailable | 9 | 1978 | 504 Gateway Timeout | 5.04 Gateway Timeout | | 1979 | 505 HTTP Version Not | | 2 | 1980 | Supported | | | 1981 +-------------------------------+---------------------------+-------+ 1983 Table 3: CoAP-HTTP Mapping 1985 Notes: 1987 1. There is no equivalent CoAP response. 1989 2. The proxy should perform the action implied by the response code 1990 (e.g., by following redirects); i.e. this response is never 1991 forwarded to the CoAP client. If the proxy is unable or 1992 unwilling to perform this function, the CoAP response code 5.02 1993 (Bad Gateway) can be returned. 1995 3. The CoAP response code depends on the request method. For a GET 1996 request, the response code SHOULD be 2.00 (OK). For a POST, PUT 1997 or DELETE request, the mapping is only partial: response entities 1998 are ignored, and the response code depends on the method as 1999 defined in Section 5.8. 2001 4. (The mapping for these rarely-used status codes is not defined in 2002 this specification.) 2004 5. The HTTP "WWW-Authenticate" response-header field has no 2005 equivalent option in CoAP and is either processed by the proxy by 2006 performing an additional request or silently dropped. 2008 6. The CoAP response code depends on the request method. For a POST 2009 or PUT request, the response code SHOULD be 2.04 (Changed); for a 2010 DELETE request, 2.02 (Deleted). 2012 7. Since a CoAP request with Etag Option is mapped to a conditional 2013 HTTP GET request with a "If-None-Match" request-header field, any 2014 HTTP 304 (Not Modified) response will confirm that the Etag is 2015 valid. Except for the max-age directive of the Cache-Control 2016 header field, any additional headers in the HTTP Not Modified 2017 response are not carried through to the CoAP client, though. 2019 8. The HTTP "Accept" response-header field has no equivalent option 2020 in CoAP and is silently dropped. 2022 9. The HTTP "Retry-After" response-header field has no equivalent 2023 option in CoAP, although it may be used to find a value for the 2024 Max-Age Option. 2026 8.2. HTTP-CoAP Mapping 2028 The mapping of HTTP to CoAP requires checking for methods, response 2029 codes and options that are not supported by CoAP. A proxy SHOULD 2030 attempt to map options, response codes and content-types to a 2031 suitable alternative if possible. Otherwise the unsupported feature 2032 SHOULD be silently dropped if possible, or an appropriate error code 2033 generated otherwise. 2035 Mapping MAY include performing payload conversion (e.g., from EXI to 2036 XML), the definition of which is out of this document's scope. 2038 Only those Conditional HTTP requests can be mapped to CoAP requests 2039 that have method GET and include a "If-None-Match" request-header 2040 field. The "If-Match", "If-Modified-Since" and "If-Unmodified-Since" 2041 request-header fields are not supported on the CoAP side, but could 2042 be implemented locally by a caching proxy. A HTTP-CoAP proxy SHOULD 2043 map Etags generated by a CoAP server to HTTP-friendly Etags by using 2044 Base64 [RFC4648]. 2046 A proxy SHOULD respond with a HTTP 502 (Bad Gateway) error to HTTP 2047 requests which can not be successfully mapped to CoAP. 2049 A proxy SHOULD employ a cache to limit traffic on the constrained 2050 network. 2052 CoAP responses are mapped to HTTP responses as follows: 2054 +-----------------------------+-----------------------------+-------+ 2055 | CoAP Response Code | HTTP Status Code | Notes | 2056 +-----------------------------+-----------------------------+-------+ 2057 | 2.00 OK | 200 OK | | 2058 | 2.01 Created | 201 Created | | 2059 | 2.02 Deleted | 204 No Content | | 2060 | 2.03 Valid | 304 Not Modified | 1 | 2061 | 2.04 Changed | 204 No Content | | 2062 | 4.00 Bad Request | 400 Bad Request | | 2063 | 4.01 Unauthorized | 400 Bad Request | 2 | 2064 | 4.02 Bad Option | 400 Bad Request | | 2065 | 4.03 Forbidden | 403 Forbidden | | 2066 | 4.04 Not Found | 404 Not Found | | 2067 | 4.05 Method Not Allowed | 405 Method Not Allowed | 3 | 2068 | 4.13 Request Entity Too | 413 Request Entity Too | | 2069 | Large | Large | | 2070 | 4.15 Unsupported Media Type | 415 Unsupported Media Type | | 2071 | 5.00 Internal Server Error | 500 Internal Server Error | | 2072 | 5.01 Not Implemented | 501 Not Implemented | | 2073 | 5.02 Bad Gateway | 502 Bad Gateway | | 2074 | 5.03 Service Unavailable | 503 Service Unavailable | 4 | 2075 | 5.04 Gateway Timeout | 504 Gateway Timeout | | 2076 | 5.05 Proxying Not Supported | 502 Bad Gateway | | 2077 +-----------------------------+-----------------------------+-------+ 2079 Table 4: HTTP-CoAP Mapping 2081 Notes: 2083 1. A CoAP 2.03 (Valid) response only (1) confirms that the request 2084 Etag is valid and (2) provides a new Max-Age value. HTTP 304 2085 (Not Modified) also updates some header fields of a stored 2086 response. A non-caching proxy may not have enough information to 2087 fill in the required values in the HTTP 304 (Not Modified) 2088 response, so it may not be advisable to provoke the 2.03 (Valid) 2089 response by forwarding an Etag. A caching proxy will fill the 2090 information out of the cache. 2092 2. There is no equivalent HTTP status code. 2094 3. CoAP does not provide enough information to compute a value for 2095 the required "Allow" response-header field. If this violation of 2096 [RFC2616] cannot be tolerated, the proxy should instead send a 2097 4.00 (Bad Request) response. 2099 4. The value of the "Retry-After" response-header field is the value 2100 of the Max-Age Option. 2102 9. Protocol Constants 2104 This section defines the relevant protocol constants defined in this 2105 document: 2107 RESPONSE_TIMEOUT 2 seconds 2109 MAX_RETRANSMIT 4 2111 10. Security Considerations 2113 This section describes mechanisms that can be used to secure CoAP and 2114 analyzes the possible threats to the protocol and its limitations. 2115 Security bootstrapping (authenticating nodes and setting up keys) in 2116 constrained environments is considered in 2117 [I-D.oflynn-core-bootstrapping]. 2119 During the bootstrap and enrollment phases, a CoAP device is provided 2120 with the security information that it needs, including keying 2121 materials. How this is done is out of scope for this specification 2122 but a couple of ways of doing this are described in 2123 [I-D.oflynn-core-bootstrapping]. At the end of the enrollment and 2124 bootstrap, the device will be in one of four security modes with the 2125 following information for the given mode: 2127 NoSec: There is no protocol level security. 2129 SharedKey: There is one shared key between all the nodes that this 2130 CoAP nodes needs to communicate with. 2132 MultiKey: There is a list of shared keys and each key includes a 2133 list of which nodes it can be used to communicate with. At the 2134 extreme there may be one key for each node this CoAP node needs to 2135 communicate with. 2137 Certificate: The device has an asymmetric key pair with a X.509 2138 [RFC5280] certificate that binds it to its Authority Name and is 2139 signed by a some common trust root. The device also has a list or 2140 root trust anchors that can be used for validating a certificate. 2141 There may be an optional shared key that all the nodes that 2142 communicate have access too. 2144 The Authority Name in the certificate is the name that would be used 2145 in the Authority part of a CoAP URI. It is worth noting that this 2146 would typically not be either an IP address or DNS name but would 2147 instead be a long term unique identifier for the device such as the 2148 EUI-64 [EUI64]. The discovery process used in the system would build 2149 up the mapping between IP addresses of the given devices and the 2150 Authority Name for each device. Some devices could have more than 2151 one Authority and would need more than a single certificate. 2153 In the "NoSec" mode, the system simply sends the packets over normal 2154 UDP over IP. The system is secured only by keeping attackers from 2155 being able to send or receive packets from the network with the CoAP 2156 nodes; see Section 10.3.4 for an additional complication with this 2157 approach. The other three security modes can be achieved with IPsec 2158 or DTLS. The result is a security association that can be used to 2159 authenticate (within the limits of the security model) and, based on 2160 this authentication, authorize the communication partner. CoAP 2161 itself does not provide protocol primitives for authentication or 2162 authorization; where this is required, it can either be provided by 2163 communication security (i.e., IPsec or DTLS) or by object security 2164 (within the payload). Devices that require authorization for certain 2165 operations are expected to require one of these two forms of 2166 security. Necessarily, where an intermediary is involved, 2167 communication security only works when that intermediary is part of 2168 the trust relationships; CoAP does not provide a way to forward 2169 different levels of authorization that clients may have with an 2170 intermediary to further intermediaries or origin servers -- it 2171 therefore may be required to perform all authorization at the first 2172 intermediary. 2174 10.1. Securing CoAP with IPsec 2176 One mechanism to secure CoAP in constrained environments is the IPsec 2177 Encapsulating Security Payload (ESP) [RFC4303]. Using IPsec ESP with 2178 the appropriate configuration, it is possible for many constrained 2179 devices to support encryption with built-in link-layer encryption 2180 hardware. For example, some IEEE 802.15.4 radio chips are compatible 2181 with AES-CBC (with 128-bit keys) [RFC3602] as defined for use with 2182 IPsec in [RFC4835]. Alternatively, particularly on more common IEEE 2183 802.15.4 hardware that supports AES encryption but not decryption, 2184 and to avoid the need for padding, nodes could directly use the more 2185 widely supported AES-CCM as defined for use with IPsec in [RFC4309], 2186 if the security considerations in section 9 of that specification can 2187 be fulfilled. Necessarily for AES-CCM, but much preferably also for 2188 AES-CBC, static keying should be avoided and the initial keying 2189 material be derived into transient session keys, e.g. using a low- 2190 overhead mode of IKEv2 [RFC5996]; such a protocol for managing keys 2191 and sequence numbers is also the only way to achieve anti-replay 2192 capabilities. However, no recommendation can be made at this point 2193 on how to manage group keys (i.e., for multicast) in a constrained 2194 environment. Once any initial setup is completed, IPsec ESP adds a 2195 limited per-packet overhead of approximately 10 bytes, not including 2196 initialization vectors, integrity check values and padding required 2197 by the cipher suite. 2199 When using IPsec to secure CoAP, both authentication and 2200 confidentiality SHOULD be applied as recommended in [RFC4303]. The 2201 use of IPsec between CoAP end-points is transparent to the 2202 application layer and does not require special consideration for a 2203 CoAP implementation. 2205 IPsec may not be appropriate for all environments. For example, 2206 IPsec support is not available for many embedded IP stacks and even 2207 in full PC operating systems or on back-end web servers, application 2208 developers may not have sufficient access to configure or enable 2209 IPsec or to add a security gateway to the infrastructure. Problems 2210 with firewalls and NATs may furthermore limit the use of IPsec. 2212 10.2. Securing CoAP with DTLS 2214 Just as HTTP may be secured using Transport Layer Security (TLS) over 2215 TCP, CoAP may be secured using Datagram TLS (DTLS) [RFC4347] over 2216 UDP. This section gives a quick overview of how to secure CoAP with 2217 DTLS, along with the minimal configurations appropriate for 2218 constrained environments. DTLS is in practice TLS with added 2219 features to deal with the unreliable nature of the UDP transport. 2221 In some constrained nodes (limited flash and/or RAM) and networks 2222 (limited bandwidth or high scalability requirements), and depending 2223 on the specific cipher suites in use, DTLS may not be applicable. 2224 Some of DTLS' cipher suites can add significant implementation 2225 complexity as well as some initial handshake overhead needed when 2226 setting up the security association. Once the initial handshake is 2227 completed, DTLS adds a limited per-datagram overhead of approximately 2228 13 bytes, not including any initialization vectors (which are 2229 generally implicitly derived with DTLS), integrity check values 2230 (e.g., 8 bytes with the proposed TLS_PSK_WITH_AES_128_CCM_8 2231 [I-D.mcgrew-tls-aes-ccm]) and padding required by the cipher suite. 2232 Whether and which mode of using DTLS is applicable for a CoAP-based 2233 application should be carefully weighed considering the specific 2234 cipher suites that may be applicable, and whether the session 2235 maintenance makes it compatible with application flows and sufficient 2236 resources are available on the constrained nodes and for the added 2237 network overhead. DTLS is not applicable to group keying (multicast 2238 communication); however, it may be a component in a future group key 2239 management protocol. 2241 Devices SHOULD support the Server Name Indication (SNI) to indicate 2242 their Authority Name in the SNI HostName field as defined in Section 2243 3 of [RFC6066]. This is needed so that when a host that acts as a 2244 virtual server for multiple Authorities receives a new DTLS 2245 connection, it knows which keys to use for the DTLS session. 2247 DTLS connections with certificates are set up using mutual 2248 authentication so they can remain up and be reused for future message 2249 exchanges in either direction. Devices can close a DTLS connection 2250 when they need to recover resources but in general they should keep 2251 the connection up for as long as possible. Closing the DTLS 2252 connection after every CoAP message exchange is very inefficient. 2254 10.2.1. SharedKey & MultiKey Modes 2256 When forming a connection to a new node, the system selects an 2257 appropriate key based on which nodes it is trying to reach then forms 2258 a DTLS session using a PSK (Pre-Shared Key) mode of DTLS. 2259 Implementations SHOULD support the mandatory to implement cipher 2260 suite TLS_PSK_WITH_AES_128_CBC_SHA as specified in [RFC4279]; once 2261 TLS_PSK_WITH_AES_128_CCM_8 as specified in [I-D.mcgrew-tls-aes-ccm] 2262 (or related cipher suites specified in [I-D.mcgrew-tls-aes-ccm-ecc]) 2263 in conjunction with [I-D.ietf-tls-rfc4347-bis] becomes available, 2264 this may be easier to implement on certain contemporary chipsets. 2266 The security considerations of [RFC4279] (Section 7) apply. In 2267 particular, applications should carefully weigh whether they need 2268 Perfect Forward Secrecy (PFS) or not and select an appropriate cipher 2269 suite (7.1). The entropy of the PSK must be sufficient to mitigate 2270 against brute-force and (where the PSK is not chosen randomly but by 2271 a human) dictionary attacks (7.2). The cleartext communication of 2272 client identities may leak data or compromise privacy (7.3). 2274 10.2.2. Certificate Mode 2276 As with IPsec, DTLS should be configured with a cipher suite 2277 compatible with any possible hardware engine on the node, for example 2278 AES-CBC in the case of IEEE 802.15.4. Implementations SHOULD support 2279 the mandatory to implement cipher suite TLS_RSA_WITH_AES_128_CBC_SHA 2280 as specified in [RFC5246]. 2282 When a new connection is formed, the certificate from the remote 2283 device needs to be verified. If the CoAP node has a source of 2284 absolute time, then the node SHOULD check the validity dates are of 2285 the certificate are within range. The certificate MUST also be 2286 signed by an appropriate chain of trust. If the certificate contains 2287 a SubjectAltName, then the Authority Name MUST match at least one of 2288 the authority names of any CoAP URI found in a URI type fields in the 2289 SubjectAltName set. If there is no SubjectAltName in the 2290 certificate, then the Authoritative Name must match the CN found in 2291 the certificate using the matching rules defined in [RFC2818] with 2292 the exception that certificates with wildcards are not allowed. 2294 If the system has a shared key in addition to the certificate, then a 2295 cipher suite that includes the shared key such as 2296 TLS_RSA_PSK_WITH_AES_128_CBC_SHA SHOULD be used. 2298 10.3. Threat analysis and protocol limitations 2300 This section is meant to inform protocol and application developers 2301 about the security limitations of CoAP as described in this document. 2302 As CoAP realizes a subset of the features in HTTP/1.1, the security 2303 considerations in Section 15 of [RFC2616] are also pertinent to CoAP. 2304 This section concentrates on describing limitations specific to CoAP 2305 and CoRE. 2307 10.3.1. Protocol Parsing, Processing URIs 2309 A network-facing application can exhibit vulnerabilities in its 2310 processing logic for incoming packets. Complex parsers are well- 2311 known as a likely source of such vulnerabilities, such as the ability 2312 to remotely crash a node, or even remotely execute arbitrary code on 2313 it. CoAP attempts to narrow the opportunities for introducing such 2314 vulnerabilities by reducing parser complexity, by giving the entire 2315 range of encodable values a meaning where possible, and by 2316 aggressively reducing complexity that is often caused by unnecessary 2317 choice between multiple representations that mean the same. Much of 2318 the URI processing has been moved to the clients, further reducing 2319 the opportunities for introducing vulnerabilities into the servers. 2320 Even so, the URI processing code in CoAP implementations is likely to 2321 be a large source of remaining vulnerabilities and should be 2322 implemented with special care. The most complex parser remaining 2323 could be the one for the link-format, although this also has been 2324 designed with a goal of reduced implementation complexity 2325 [I-D.ietf-core-link-format]. (See also section 15.2 of [RFC2616].) 2327 10.3.2. Proxying and Caching 2329 As mentioned in 15.2 of [RFC2616], which see, proxies are by their 2330 very nature men-in-the-middle, breaking any IPsec or DTLS protection 2331 that a direct CoAP message exchange might have. They are therefore 2332 interesting targets for breaking confidentiality or integrity of CoAP 2333 message exchanges. As noted in [RFC2616], they are also interesting 2334 targets for breaking availability. 2336 The threat to confidentiality and integrity of request/response data 2337 is amplified where proxies also cache. Note that CoAP does not 2338 define any of the cache-suppressing Cache-Control options that 2339 HTTP/1.1 provides to better protect sensitive data. 2341 Finally, a proxy that fans out deferred responses to multiple 2342 original requesters may provide additional amplification (see below). 2344 10.3.3. Risk of amplification 2346 CoAP servers generally reply to a request packet with a response 2347 packet. This response packet may be significantly larger than the 2348 request packet. An attacker might use CoAP nodes to turn a small 2349 attack packet into a larger attack packet, an approach known as 2350 amplification. There is therefore a danger that CoAP nodes could 2351 become implicated in denial of service (DoS) attacks by using the 2352 amplifying properties of the protocol: An attacker that is attempting 2353 to overload a victim but is limited in the amount of traffic it can 2354 generate, can use amplification to generate a larger amount of 2355 traffic. 2357 This is particularly a problem in nodes that enable NoSec access and 2358 that are accessible from an attacker and can access potential victims 2359 (e.g. on the general Internet), as the UDP protocol provides no way 2360 to verify the source address given in the request packet. An 2361 attacker need only place the IP address of the victim in the source 2362 address of a suitable request packet to generate a larger packet 2363 directed at the victim. 2365 As a mitigating factor, many constrained network will only be able to 2366 generate a small amount of traffic, which may make CoAP nodes less 2367 attractive for this attack. However, the limited capacity of the 2368 constrained network makes the network itself a likely victim of an 2369 amplification attack. 2371 A CoAP server can reduce the amount of amplification it provides to 2372 an attacker by using slicing/blocking modes of CoAP 2373 [I-D.ietf-core-block] and offering large resource representations 2374 only in relatively small slices. E.g., for a 1000 byte resource, a 2375 10-byte request might result in an 80-byte response (with a 64-byte 2376 block) instead of a 1016-byte response, considerably reducing the 2377 amplification provided. 2379 CoAP also supports the use of multicast IP addresses in requests, an 2380 important requirement for M2M. Multicast CoAP requests may be the 2381 source of accidental or deliberate denial of service attacks, 2382 especially over constrained networks. This specification attempts to 2383 reduce the amplification effects of multicast requests by limiting 2384 when a response is returned. To limit the possibility of malicious 2385 use, CoAP servers SHOULD NOT accept multicast requests that can not 2386 be authenticated. If possible a CoAP server SHOULD limit the support 2387 for multicast requests to specific resources where the feature is 2388 required. 2390 On some general purpose operating systems providing a Posix-style 2391 API, it is not straightforward to find out whether a packet received 2392 was addressed to a multicast address. While many implementations 2393 will know whether they have joined a multicast group, this creates a 2394 problem for packets addressed to multicast addresses of the form 2395 FF0x::1, which are received by every IPv6 node. Implementations 2396 SHOULD make use of modern APIs such as IPV6_RECVPKTINFO [RFC3542], if 2397 available, to make this determination. 2399 10.3.4. Cross-Protocol Attacks 2401 The ability to incite a CoAP end-point to send packets to a fake 2402 source address can be used not only for amplification, but also for 2403 cross-protocol attacks: 2405 o the attacker sends a message to a CoAP end point with a fake 2406 source address, 2408 o the CoAP end point replies with a message to the given source 2409 address, 2411 o the victim at the given source address receives a UDP packet that 2412 it interprets according to the rules of a different protocol. 2414 This may be used to circumvent firewall rules that prevent direct 2415 communication from the attacker to the victim, but happen to allow 2416 communication from the CoAP end-point (which may also host a valid 2417 role in the other protocol) to the victim. 2419 Also, CoAP end-points may be the victim of a cross-protocol attack 2420 generated through an endpoint of another UDP-based protocol such as 2421 DNS. In both cases, attacks are possible if the security properties 2422 of the end-points rely on checking IP addresses (and firewalling off 2423 direct attacks sent from outside using fake IP addresses). In 2424 general, because of their lack of context, UDP-based protocols are 2425 relatively easy targets for cross-protocol attacks. 2427 Finally, CoAP URIs transported by other means could be used to incite 2428 clients to send messages to end-points of other protocols. 2430 One mitigation against cross-protocol attacks is strict checking of 2431 the syntax of packets received, combined with sufficient difference 2432 in syntax. As an example, it might help if it were difficult to 2433 incite a DNS server to send a DNS response that would pass the checks 2434 of a CoAP endpoint. Unfortunately, the first two bytes of a DNS 2435 reply are an ID that can be chosen by the attacker, which map into 2436 the interesting part of the CoAP header, and the next two bytes are 2437 then interpreted as CoAP's Message ID (i.e., any value is 2438 acceptable). The DNS count words may be interpreted as multiple 2439 instances of a (non-existent, but elective) CoAP option 0. The 2440 echoed query finally may be manufactured by the attacker to achieve a 2441 desired effect on the CoAP endpoint; the response added by the server 2442 (if any) might then just be interpreted as added payload. 2444 1 1 1 1 1 1 2445 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 2446 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 2447 | ID | T, OC, code 2448 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 2449 |QR| Opcode |AA|TC|RD|RA| Z | RCODE | message id 2450 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 2451 | QDCOUNT | (options 0) 2452 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 2453 | ANCOUNT | (options 0) 2454 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 2455 | NSCOUNT | (options 0) 2456 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 2457 | ARCOUNT | (options 0) 2458 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 2460 Figure 10: DNS Header vs. CoAP Message 2462 In general, for any pair of protocols, one of the protocols can very 2463 well have been designed in a way that enables an attacker to cause 2464 the generation of replies that look like messages of the other 2465 protocol. It is often much harder to ensure or prove the absence of 2466 viable attacks than to generate examples that may not yet completely 2467 enable an attack but might be further developed by more creative 2468 minds. Cross-protocol attacks can therefore only be completely 2469 mitigated if end-points don't authorize actions desired by an 2470 attacker just based on trusting the source IP address of a packet. 2471 Conversely, a NoSec environment that completely relies on a firewall 2472 for CoAP security not only needs to firewall off the CoAP end-points 2473 but also all other end-points that might be incited to send UDP 2474 messages to CoAP end-points using some other UDP-based protocol. 2476 In addition to the considerations above, the security considerations 2477 for DTLS with respect to cross-protocol attacks apply. E.g., if the 2478 same DTLS security association ("connection") is used to carry data 2479 of multiple protocols, DTLS no longer provides protection against 2480 cross-protocol attacks between these protocols. 2482 11. IANA Considerations 2483 11.1. CoAP Code Registry 2485 This document defines a registry for the values of the Code field in 2486 the CoAP header. The name of the registry is "CoAP Codes". 2488 Values are as follows: 2490 0 Indicates an empty message (see Section 4.3) 2492 1-31 Assigned by the "Method Codes" sub-registry (see below) 2494 32-63 Reserved 2496 64-191 Assigned by the "Response Codes" sub-registry (see below) 2498 192-255 Reserved 2500 11.1.1. Method Codes 2502 The name of the sub-registry is "CoAP Method Codes". 2504 Each entry in the sub-registry must include the Method Code in the 2505 range 1-31, the name of the method, and a reference to the method's 2506 documentation. 2508 Initial entries in this sub-registry are as follows: 2510 +------+--------+---------------+ 2511 | Code | Name | Reference | 2512 +------+--------+---------------+ 2513 | 1 | GET | Section 5.8.1 | 2514 | 2 | POST | Section 5.8.2 | 2515 | 3 | PUT | Section 5.8.3 | 2516 | 4 | DELETE | Section 5.8.4 | 2517 +------+--------+---------------+ 2519 Table 5: CoAP Method Codes 2521 All other Method Codes are Unassigned. 2523 The IANA policy for future additions to this registry is "IETF 2524 Review" as described by [RFC5226]. 2526 11.1.2. Response Codes 2528 The name of the sub-registry is "CoAP Response Codes". 2530 Each entry in the sub-registry must include the Response Code in the 2531 range 64-191, a description of the Response Code, and a reference to 2532 the Response Code's documentation. 2534 Initial entries in this sub-registry are as follows: 2536 +------+-------------------------------+-----------------+ 2537 | Code | Description | Reference | 2538 +------+-------------------------------+-----------------+ 2539 | 64 | 2.00 OK | Section 5.9.1.1 | 2540 | 65 | 2.01 Created | Section 5.9.1.2 | 2541 | 66 | 2.02 Deleted | Section 5.9.1.3 | 2542 | 67 | 2.03 Valid | Section 5.9.1.4 | 2543 | 68 | 2.04 Changed | Section 5.9.1.5 | 2544 | 128 | 4.00 Bad Request | Section 5.9.2.1 | 2545 | 129 | 4.01 Unauthorized | Section 5.9.2.2 | 2546 | 130 | 4.02 Bad Option | Section 5.9.2.3 | 2547 | 131 | 4.03 Forbidden | Section 5.9.2.4 | 2548 | 132 | 4.04 Not Found | Section 5.9.2.5 | 2549 | 133 | 4.05 Method Not Allowed | Section 5.9.2.6 | 2550 | 141 | 4.13 Request Entity Too Large | Section 5.9.2.7 | 2551 | 143 | 4.15 Unsupported Media Type | Section 5.9.2.8 | 2552 | 160 | 5.00 Internal Server Error | Section 5.9.3.1 | 2553 | 161 | 5.01 Not Implemented | Section 5.9.3.2 | 2554 | 162 | 5.02 Bad Gateway | Section 5.9.3.3 | 2555 | 163 | 5.03 Service Unavailable | Section 5.9.3.4 | 2556 | 164 | 5.04 Gateway Timeout | Section 5.9.3.5 | 2557 | 165 | 5.05 Proxying Not Supported | Section 5.9.3.6 | 2558 +------+-------------------------------+-----------------+ 2560 Table 6: CoAP Response Codes 2562 The Response Codes 96-127 are Reserved for future use. All other 2563 Response Codes are Unassigned. 2565 The IANA policy for future additions to this registry is "IETF 2566 Review" as described by [RFC5226]. 2568 11.2. Option Number Registry 2570 This document defines a registry for the option numbers used in CoAP 2571 options. The name of the registry is "CoAP Option Numbers". 2573 Each entry in the registry must include the Option Number, the name 2574 of the option and a a reference to the option's documentation. 2576 Initial entries in this registry are as follows: 2578 +--------+---------------+----------------+ 2579 | Number | Name | Reference | 2580 +--------+---------------+----------------+ 2581 | 1 | Content-Type | Section 5.10.4 | 2582 | 2 | Max-Age | Section 5.10.5 | 2583 | 3 | Proxy-Uri | Section 5.10.3 | 2584 | 4 | Etag | Section 5.10.6 | 2585 | 5 | Uri-Host | Section 5.10.2 | 2586 | 6 | Location-Path | Section 5.10.7 | 2587 | 7 | Uri-Port | Section 5.10.2 | 2588 | 9 | Uri-Path | Section 5.10.2 | 2589 | 11 | Token | Section 5.10.1 | 2590 | 15 | Uri-Query | Section 5.10.2 | 2591 +--------+---------------+----------------+ 2593 Table 7: CoAP Option Numbers 2595 The Option Numbers 0 and 8 are Reserved for future use. The Option 2596 Numbers 14, 28, 42, ... are Reserved for "fenceposting" (see 2597 Section 3.2). All other Option Numbers are Unassigned. 2599 The IANA policy for future additions to this registry is "IETF 2600 Review" as described by [RFC5226]. 2602 11.3. Media Type Registry 2604 Media types are identified by a string, such as "application/xml" 2605 [RFC2046]. In order to minimize the overhead of using these media 2606 types to indicate the format of payloads, this document defines a 2607 registry for a subset of Internet media types to be used in CoAP and 2608 assigns each a numeric identifier. The name of the registry is "CoAP 2609 Media Types". 2611 Each entry in the registry must include the media type registered 2612 with IANA, the numeric identifier in the range 0-65535 to be used for 2613 that media type in CoAP, and a reference to a document describing 2614 what payload with that media types means semantically. 2616 Initial entries in this registry are as follows: 2618 +------------------------------+-----+-----------------------------+ 2619 | Media type | Id. | Reference | 2620 +------------------------------+-----+-----------------------------+ 2621 | text/plain; charset=utf-8 | 0 | | 2622 | text/xml; charset=utf-8 | 1 | | 2623 | text/csv; charset=utf-8 | 2 | | 2624 | text/html; charset=utf-8 | 3 | | 2625 | application/link-format | 40 | [I-D.ietf-core-link-format] | 2626 | application/xml | 41 | | 2627 | application/octet-stream | 42 | | 2628 | application/rdf+xml | 43 | | 2629 | application/soap+xml | 44 | | 2630 | application/atom+xml | 45 | | 2631 | application/xmpp+xml | 46 | | 2632 | application/exi | 47 | [EXIMIME] | 2633 | application/fastinfoset | 48 | | 2634 | application/soap+fastinfoset | 49 | | 2635 | application/json | 50 | | 2636 | application/x-obix-binary | 51 | [OBIX1.1] | 2637 +------------------------------+-----+-----------------------------+ 2639 Table 8: CoAP Media Types 2641 The identifiers between 201 and 255 inclusive are reserved for 2642 Private Use. The identifiers between 256 and 65535 inclusive are 2643 Reserved for future use. All other identifiers are Unassigned. 2645 Because the name space is so small, the IANA policy for future 2646 additions to this registry is "Expert Review" as described by 2647 [RFC5226]. 2649 In machine to machine applications, it is not expected that generic 2650 Internet media types such as text/plain, application/xml or 2651 application/octet-stream are useful for real applications. It is 2652 recommended that M2M applications making use of CoAP will request new 2653 Internet media types from IANA indicating semantic information about 2654 how to create or parse a payload. Correct examples from Table 8 2655 include application/link-format, application/atom+xml and 2656 application/x-obix-binary. For example, a Smart Energy application 2657 payload carried as XML would request a more specific type like 2658 application/se+xml or application/se+exi. 2660 11.4. URI Scheme Registration 2662 This document requests the registration of the Uniform Resource 2663 Identifier (URI) scheme "coap". The registration request complies 2664 with [RFC4395]. 2666 URI scheme name. 2667 coap 2669 Status. 2670 Provisional. 2672 URI scheme syntax. 2673 Defined in Section 6.1. 2675 URI scheme semantics. 2676 The "coap" URI scheme provides a way to identify resources that 2677 are potentially accessible over the Constrained Application 2678 Protocol (CoAP). This scheme can thus be compared to the "http" 2679 URI scheme [RFC2616]. See Section 6 for the details of operation. 2681 Encoding considerations. 2682 The scheme encoding conforms to the encoding rules established for 2683 URIs in [RFC3986]. 2685 Applications/protocols that use this URI scheme name. 2686 The scheme is used by CoAP end-points to access CoAP resources. 2688 Interoperability considerations. 2689 None. 2691 Security considerations. 2692 See "Security considerations" section above. 2694 Contact. 2695 Zach Shelby 2697 Author/Change controller. 2698 Zach Shelby 2700 References. 2701 This document. 2703 11.5. Service Name and Port Number Registration 2705 One of the functions of CoAP is resource discovery: A CoAP client can 2706 ask a CoAP server about the resources offered by it (see 2707 Section 7.1). To enable resource discovery just based on the 2708 knowledge of an IP address, the CoAP port for resource discovery 2709 needs to be standardized. 2711 This document requests the assignment of the port number 5683 and the 2712 service name "coap", in accordance with [I-D.ietf-tsvwg-iana-ports]. 2714 Besides unicast, CoAP can be used with both multicast and anycast. 2716 Service Name. 2717 coap 2719 Transport Protocol. 2720 UDP 2722 Assignee. 2723 IETF 2725 Contact. 2726 IESG 2728 Description. 2729 Constrained Application Protocol (CoAP) 2731 Reference. 2732 This document. 2734 Port Number. 2735 5683 2737 12. Acknowledgements 2739 Special thanks to Peter Bigot and Cullen Jennings for substantial 2740 contributions to the ideas and text in the document, along with 2741 countless detailed reviews and discussions. 2743 Thanks to Michael Stuber, Richard Kelsey, Guido Moritz, Peter Van Der 2744 Stok, Adriano Pezzuto, Lisa Dussealt, Alexey Melnikov, Gilbert Clark, 2745 Salvatore Loreto, Petri Mutka, Szymon Sasin, Robert Quattlebaum, 2746 Robert Cragie, Angelo Castellani, Tom Herbst, Ed Beroset, Gilman 2747 Tolle, Robby Simpson, Colin O'Flynn, Eric Rescorla, Matthieu Vial, 2748 Linyi Tian, Kerry Lynn, Dale Seed, Akbar Rahman and David Ryan for 2749 helpful comments and discussions that have shaped the document. 2751 Some of the text has been lifted from the working documents of the 2752 IETF httpbis working group. 2754 13. References 2756 13.1. Normative References 2758 [RFC2046] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 2759 Extensions (MIME) Part Two: Media Types", RFC 2046, 2760 November 1996. 2762 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 2763 Requirement Levels", BCP 14, RFC 2119, March 1997. 2765 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 2766 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 2767 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 2769 [RFC2818] Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000. 2771 [RFC3602] Frankel, S., Glenn, R., and S. Kelly, "The AES-CBC Cipher 2772 Algorithm and Its Use with IPsec", RFC 3602, 2773 September 2003. 2775 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 2776 10646", STD 63, RFC 3629, November 2003. 2778 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 2779 Resource Identifier (URI): Generic Syntax", STD 66, 2780 RFC 3986, January 2005. 2782 [RFC4279] Eronen, P. and H. Tschofenig, "Pre-Shared Key Ciphersuites 2783 for Transport Layer Security (TLS)", RFC 4279, 2784 December 2005. 2786 [RFC4303] Kent, S., "IP Encapsulating Security Payload (ESP)", 2787 RFC 4303, December 2005. 2789 [RFC4309] Housley, R., "Using Advanced Encryption Standard (AES) CCM 2790 Mode with IPsec Encapsulating Security Payload (ESP)", 2791 RFC 4309, December 2005. 2793 [RFC4347] Rescorla, E. and N. Modadugu, "Datagram Transport Layer 2794 Security", RFC 4347, April 2006. 2796 [RFC4395] Hansen, T., Hardie, T., and L. Masinter, "Guidelines and 2797 Registration Procedures for New URI Schemes", BCP 35, 2798 RFC 4395, February 2006. 2800 [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data 2801 Encodings", RFC 4648, October 2006. 2803 [RFC4835] Manral, V., "Cryptographic Algorithm Implementation 2804 Requirements for Encapsulating Security Payload (ESP) and 2805 Authentication Header (AH)", RFC 4835, April 2007. 2807 [RFC5198] Klensin, J. and M. Padlipsky, "Unicode Format for Network 2808 Interchange", RFC 5198, March 2008. 2810 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 2811 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 2812 May 2008. 2814 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax 2815 Specifications: ABNF", STD 68, RFC 5234, January 2008. 2817 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 2818 (TLS) Protocol Version 1.2", RFC 5246, August 2008. 2820 [RFC5280] Cooper, D., Santesson, S., Farrell, S., Boeyen, S., 2821 Housley, R., and W. Polk, "Internet X.509 Public Key 2822 Infrastructure Certificate and Certificate Revocation List 2823 (CRL) Profile", RFC 5280, May 2008. 2825 [RFC5389] Rosenberg, J., Mahy, R., Matthews, P., and D. Wing, 2826 "Session Traversal Utilities for NAT (STUN)", RFC 5389, 2827 October 2008. 2829 [RFC5952] Kawamura, S. and M. Kawashima, "A Recommendation for IPv6 2830 Address Text Representation", RFC 5952, August 2010. 2832 [RFC5996] Kaufman, C., Hoffman, P., Nir, Y., and P. Eronen, 2833 "Internet Key Exchange Protocol Version 2 (IKEv2)", 2834 RFC 5996, September 2010. 2836 [RFC6066] Eastlake, D., "Transport Layer Security (TLS) Extensions: 2837 Extension Definitions", RFC 6066, January 2011. 2839 13.2. Informative References 2841 [EUI64] "GUIDELINES FOR 64-BIT GLOBAL IDENTIFIER (EUI-64) 2842 REGISTRATION AUTHORITY", April 2010, . 2845 [EXIMIME] "Efficient XML Interchange (EXI) Format 1.0", 2846 December 2009, . 2849 [I-D.eggert-core-congestion-control] 2850 Eggert, L., "Congestion Control for the Constrained 2851 Application Protocol (CoAP)", 2852 draft-eggert-core-congestion-control-00 (work in 2853 progress), June 2010. 2855 [I-D.ietf-core-block] 2856 Shelby, Z. and C. Bormann, "Blockwise transfers in CoAP", 2857 draft-ietf-core-block-00 (work in progress), October 2010. 2859 [I-D.ietf-core-link-format] 2860 Shelby, Z., "CoRE Link Format", 2861 draft-ietf-core-link-format-02 (work in progress), 2862 December 2010. 2864 [I-D.ietf-tls-rfc4347-bis] 2865 Rescorla, E. and N. Modadugu, "Datagram Transport Layer 2866 Security version 1.2", draft-ietf-tls-rfc4347-bis-04 (work 2867 in progress), July 2010. 2869 [I-D.ietf-tsvwg-iana-ports] 2870 Cotton, M., Eggert, L., Touch, J., Westerlund, M., and S. 2871 Cheshire, "Internet Assigned Numbers Authority (IANA) 2872 Procedures for the Management of the Service Name and 2873 Transport Protocol Port Number Registry", 2874 draft-ietf-tsvwg-iana-ports-09 (work in progress), 2875 December 2010. 2877 [I-D.mcgrew-tls-aes-ccm] 2878 McGrew, D. and D. Bailey, "AES-CCM Cipher Suites for TLS", 2879 draft-mcgrew-tls-aes-ccm-00 (work in progress), June 2010. 2881 [I-D.mcgrew-tls-aes-ccm-ecc] 2882 McGrew, D., Bailey, D., Campagna, M., and R. Dugal, "AES- 2883 CCM ECC Cipher Suites for TLS", 2884 draft-mcgrew-tls-aes-ccm-ecc-01 (work in progress), 2885 January 2011. 2887 [I-D.oflynn-core-bootstrapping] 2888 Sarikaya, B., Ohba, Y., Cao, Z., and R. Cragie, "Security 2889 Bootstrapping of Resource-Constrained Devices", 2890 draft-oflynn-core-bootstrapping-02 (work in progress), 2891 October 2010. 2893 [OBIX1.1] "OBIX Version 1.1", June 2010, . 2896 [RFC3264] Rosenberg, J. and H. Schulzrinne, "An Offer/Answer Model 2897 with Session Description Protocol (SDP)", RFC 3264, 2898 June 2002. 2900 [RFC3542] Stevens, W., Thomas, M., Nordmark, E., and T. Jinmei, 2901 "Advanced Sockets Application Program Interface (API) for 2902 IPv6", RFC 3542, May 2003. 2904 [RFC3920] Saint-Andre, P., Ed., "Extensible Messaging and Presence 2905 Protocol (XMPP): Core", RFC 3920, October 2004. 2907 [RFC4944] Montenegro, G., Kushalnagar, N., Hui, J., and D. Culler, 2908 "Transmission of IPv6 Packets over IEEE 802.15.4 2909 Networks", RFC 4944, September 2007. 2911 Appendix A. Integer Option Value Format 2913 Options of type uint contain a non-negative integer that is 2914 represented in network byte order using a variable number of bytes, 2915 as shown in Figure 11. 2917 Length = 0 (implies value of 0) 2919 0 2920 0 1 2 3 4 5 6 7 2921 +-+-+-+-+-+-+-+-+ 2922 Length = 1 | 0-255 | 2923 +-+-+-+-+-+-+-+-+ 2925 0 1 2926 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 2927 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2928 Length = 2 | 0-65535 | 2929 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2931 Length = 3 is 24 bits, Length = 4 is 32 bits etc. 2933 Figure 11: Variable-length unsigned integer format 2935 Appendix B. Examples 2937 This section gives a number of short examples with message flows for 2938 GET requests. These examples demonstrate the basic operation, the 2939 operation in the presence of retransmissions, and multicast. 2941 Figure 12 shows a basic GET request causing an immediate response: 2942 The client sends a Confirmable GET request for the resource 2943 coap://server/temperature to the server with a Message ID of 0x7d34. 2944 The request includes one Uri-Path Option (Delta 0 + 9 = 9, Length 11, 2945 Value "temperature"); the Token is left at its default value (empty). 2946 This request is a total of 16 bytes long. A 2.00 (OK) response is 2947 returned in the Acknowledgement message that acknowledges the 2948 Confirmable request, echoing both the Message ID 0x7d34 and the 2949 (implicitly empty) Token value. The response includes a Payload of 2950 "22.3 C" and is 10 bytes long. 2952 CLIENT SERVER 2953 | | 2954 +--- CON [0x7d34] GET /temperature [] -------------------->| 2955 | | 2956 |<-------------------- ACK [0x7d34] 2.00 OK [] "22.3 C" ---+ 2957 | | 2959 0 1 2 3 2960 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 2961 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2962 | 1 | 0 | 2 | GET=1 | MID=0x7d34 | 2963 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2964 | 9 | 11 | "temperature" (11 B) ... 2965 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2967 0 1 2 3 2968 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 2969 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2970 | 1 | 2 | 1 | 2.00=64 | MID=0x7d34 | 2971 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2972 | "22.3 C" (6 B) ... 2973 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2975 Figure 12: Confirmable request; Immediate response 2977 Figure 13 shows a similar example, but with the inclusion of an 2978 explicit Token option (Delta 9 + 2 = 11, Length 1, Value 0x20) in the 2979 request and (Delta 11 + 0 = 11) in the response, increasing the sizes 2980 to 18 and 12 bytes, respectively. 2982 CLIENT SERVER 2983 | | 2984 +--- CON [0x7d34] GET /temperature [0x20] ---------------->| 2985 | | 2986 |<---------------- ACK [0x7d34] 2.00 OK [0x20] "22.3 C" ---+ 2987 | | 2989 0 1 2 3 2990 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 2991 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2992 | 1 | 0 | 2 | GET=1 | MID=0x7d34 | 2993 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2994 | 9 | 11 | "temperature" (11 B) ... 2995 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2996 | 2 | 1 | 0x20 | 2997 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 2999 0 1 2 3 3000 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 3001 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 3002 | 1 | 2 | 1 | 2.00=64 | MID=0x7d34 | 3003 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 3004 | 11 | 1 | 0x20 | "22.3 C" (6 B) ... 3005 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 3007 Figure 13: Confirmable request; Immediate response 3009 In Figure 14, the Confirmable GET request is lost. After 3010 RESPONSE_TIMEOUT seconds, the client retransmits the request, 3011 resulting in an immediate response as in the previous example. 3013 CLIENT SERVER 3014 | | 3015 +--- CON [0x7d35] GET /temperature [0x31] -----X | 3016 | | 3017 : TIMEOUT : 3018 | | 3019 +--- CON [0x7d35] GET /temperature [0x31] ---------------->| 3020 | | 3021 |<---------------- ACK [0x7d35] 2.00 OK [0x31] "22.3 C" ---+ 3022 | | 3024 Figure 14: Confirmable request (retransmitted); Immediate response 3026 In Figure 15, the first Acknowledgement message from the server to 3027 the client is lost. After RESPONSE_TIMEOUT seconds, the client 3028 retransmits the request. 3030 CLIENT SERVER 3031 | | 3032 +--- CON [0x7d36] GET /temperature [0x42] ---------------->| 3033 | | 3034 | X----- ACK [0x7d36] 2.00 OK [0x42] "22.3 C" ---+ 3035 | | 3036 : TIMEOUT : 3037 | | 3038 +--- CON [0x7d36] GET /temperature [0x42] ---------------->| 3039 | | 3040 |<---------------- ACK [0x7d36] 2.00 OK [0x42] "22.3 C" ---+ 3041 | | 3043 Figure 15: Confirmable request; Immediate response (retransmitted) 3045 In Figure 16, the server acknowledges the Confirmable request and 3046 sends a 2.00 (OK) response separately in a Confirmable message. Note 3047 that the Acknowledgement message and the Confirmable response do not 3048 necessarily arrive in the same order as they were sent. The client 3049 acknowledges the Confirmable response. 3051 CLIENT SERVER 3052 | | 3053 +--- CON [0x7d36] GET /temperature [0x53] ---------------->| 3054 | | 3055 |<---------------------------------------- ACK [0x7d36] ---+ 3056 | | 3057 |<---------------- CON [0xad7b] 2.00 OK [0x53] "22.3 C" ---+ 3058 | | 3059 +--- ACK [0xad7b] ---------------------------------------->| 3060 | | 3062 Figure 16: Confirmable request; Deferred response 3064 Figure 17 shows an example where the client loses its state (e.g., 3065 crashes and is rebooted) right after sending a Confirmable request, 3066 so the deferred response arriving some time later comes unexpected. 3067 In this case, the client rejects the Confirmable response with a 3068 Reset message. Note that the unexpected ACK is silently ignored. 3070 CLIENT SERVER 3071 | | 3072 +--- CON [0x7d37] GET /temperature [0x64] ---------------->| 3073 XXXXX | 3074 |<---------------------------------------- ACK [0x7d37] ---+ 3075 | | 3076 |<---------------- CON [0xad7c] 2.00 OK [0x64] "22.3 C" ---+ 3077 | | 3078 +--- RST [0xad7c] ---------------------------------------->| 3079 | | 3081 Figure 17: Confirmable request; Deferred response (unexpected) 3083 Figure 18 shows a basic GET request where the request and the 3084 response are non-confirmable, so both may be lost without notice. 3086 CLIENT SERVER 3087 | | 3088 +--- NON [0x7d38] GET /temperature [0x75] ---------------->| 3089 | | 3090 |<---------------- NON [0xad7d] 2.00 OK [0x75] "22.3 C" ---+ 3091 | | 3093 Figure 18: Non-confirmable request; Non-confirmable response 3095 In Figure 19, the client sends a Non-confirmable GET request to a 3096 multicast address: all nodes in link-local scope. There are 3 3097 servers on the link: A, B and C. Servers A and B have a matching 3098 resource, therefore they send back a Non-confirmable 2.00 (OK) 3099 response. The response sent by B is lost. C does not have matching 3100 response, therefore it sends a Non-confirmable 4.04 (Not Found) 3101 response. 3103 CLIENT ff02::1 A B C 3104 | | | | | 3105 +--- NON [0x7d39] GET /temperature [0x86] ------->| | | | 3106 | | | | 3107 |<------------- NON [0x60b1] 2.00 OK [0x86] "22.3 C" ---+ | | 3108 | | | | 3109 | X----- NON [0x01a0] 2.00 OK [0x86] "20.9 C" ---+ | 3110 | | | | 3111 |<------------------ NON [0x952a] 4.04 Not Found [0x86] ------+ 3112 | | | | 3114 Figure 19: Non-confirmable request (multicast); Non-confirmable 3115 response 3117 Appendix C. URI Examples 3119 The following examples demonstrate different sets of Uri options, and 3120 the result after constructing an URI from them. 3122 o coap://[2001:db8::2:1]/ 3124 Destination IP Address = [2001:db8::2:1] 3126 Destination UDP Port = 5683 3128 o coap://example.net/ 3130 Destination IP Address = [2001:db8::2:1] 3132 Destination UDP Port = 5683 3134 Uri-Host = "example.net" 3136 o coap://example.net/.well-known/core 3138 Destination IP Address = [2001:db8::2:1] 3140 Destination UDP Port = 5683 3142 Uri-Host = "example.net" 3144 Uri-Path = ".well-known" 3146 Uri-Path = "core" 3148 o coap:// 3149 xn--18j4d.example/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF 3151 Destination IP Address = [2001:db8::2:1] 3153 Destination UDP Port = 5683 3155 Uri-Host = "xn--18j4d.example" 3157 Uri-Path = the string composed of the Unicode characters U+3053 3158 U+3093 U+306b U+3061 U+306f, usually represented in UTF-8 as 3159 E38193E38293E381ABE381A1E381AF hexadecimal 3161 o coap://198.51.100.1:61616//%2F//?%2F%2F 3163 Destination IP Address = 198.51.100.1 3164 Destination UDP Port = 61616 3166 Uri-Path = "" 3168 Uri-Path = "/" 3170 Uri-Path = "" 3172 Uri-Path = "" 3174 Uri-Query = "%2F%2F" 3176 o coap://[2001:db8::2:1]/sensors/temp 3178 Destination IP Address = [::1] 3180 Destination UDP Port = 61616 3182 Uri-Host = "[2001:db8::2:1]" 3184 Uri-Port = 5683 3186 Uri-Path = "sensors" 3188 Uri-Path = "temp" 3190 Appendix D. Changelog 3192 Changes from ietf-03 to ietf-04: 3194 o Major document reorganization (#51, #63, #71, #81). 3196 o Max-age length set to 0-4 bytes (#30). 3198 o Added variable unsigned integer definition (#31). 3200 o Clarification made on human readable error payloads (#50). 3202 o Definition of POST improved (#52). 3204 o Token length changed to 0-8 bytes (#53). 3206 o Section added on multiplexing CoAP, DTLS and STUN (#56). 3208 o Added cross-protocol attack considerations (#61). 3210 o Used new Immediate/Deferred response definitions (#73). 3212 o Improved request/response matching rules (#74). 3214 o Removed unnecessary media types and added recommendations for 3215 their use in M2M (#76). 3217 o Response codes changed to base 32 coding, new Y.XX naming (#77). 3219 o References updated as per AD review (#79). 3221 o IANA section completed (#80). 3223 o Proxy-Uri option added to diambiguate between proxy and non- 3224 proxy requests (#82). 3226 o Added text on critical options in cached states (#83). 3228 o HTTP mapping sections improved (#88). 3230 o Added text on reverse proxies (#72). 3232 o Some security text on multicast added (#54). 3234 o Trust model text added to introduction (#58, #60). 3236 o AES-CCM vs. AES-CCB text added (#55). 3238 o Text added about device capabilities (#59). 3240 o DTLS section improvements (#87). 3242 o Caching semantics aligned with RFC2616 (#78). 3244 o Uri-Path option split into multiple path segments. 3246 o MAX_RETRANSMIT changed to 4 to adjust for RESPONSE_TIME = 2. 3248 Changes from ietf-02 to ietf-03: 3250 o Token Option and related use in asynchronous requests added 3251 (#25). 3253 o CoAP specific error codes added (#26). 3255 o Erroring out on unknown critical options changed to a MUST 3256 (#27). 3258 o Uri-Query option added. 3260 o Terminology and definitions of URIs improved. 3262 o Security section completed (#22). 3264 Changes from ietf-01 to ietf-02: 3266 o Sending an error on a critical option clarified (#18). 3268 o Clarification on behavior of PUT and idempotent operations 3269 (#19). 3271 o Use of Uri-Authority clarified along with server processing 3272 rules. Uri-Scheme option removed. (#20, #23) 3274 o Resource discovery section removed to a separate CoRE Link 3275 Format draft (#21) 3277 o Initial security section outline added. 3279 Changes from ietf-00 to ietf-01: 3281 o New cleaner transaction message model and header (#5) 3283 o Removed subscription while being designed (#1) 3285 o Section 2 re-written (#3) 3287 o Text added about use of short URIs (#4) 3289 o Improved header option scheme (#5, #14) 3291 o Date option removed whiled being designed (#6) 3293 o New text for CoAP default port (#7) 3295 o Completed proxying section (#8) 3297 o Completed resource discovery section (#9) 3299 o Completed HTTP mapping section (#10) 3301 o Several new examples added (#11) 3303 o URI split into 3 options (#12) 3304 o MIME type defined for link-format (#13, #16) 3306 o New text on maximum message size (#15) 3308 o Location Option added 3310 Changes from shelby-01 to ietf-00: 3312 o Removed the TCP binding section, left open for the future. 3314 o Fixed a bug in the example. 3316 o Marked current Sub/Notify as (Experimental) while under WG 3317 discussion. 3319 o Fixed maximum datagram size to 1280 for both IPv4 and IPv6 (for 3320 CoAP-CoAP proxying to work). 3322 o Temporarily removed the Magic Byte header as TCP is no longer 3323 included as a binding. 3325 o Removed the Uri-code Option as different URI encoding schemes 3326 are being discussed. 3328 o Changed the rel= field to desc= for resource discovery. 3330 o Changed the maximum message size to 1024 bytes to allow for IP/ 3331 UDP headers. 3333 o Made the URI slash optimization and method impotence MUSTs 3335 o Minor editing and bug fixing. 3337 Changes from shelby-00 to shelby-01: 3339 o Unified the message header and added a notify message type. 3341 o Renamed methods with HTTP names and removed the NOTIFY method. 3343 o Added a number of options field to the header. 3345 o Combines the Option Type and Length into an 8-bit field. 3347 o Added the magic byte header. 3349 o Added new Etag option. 3351 o Added new Date option. 3353 o Added new Subscription option. 3355 o Completed the HTTP Code - CoAP Code mapping table appendix. 3357 o Completed the Content-type Identifier appendix and tables. 3359 o Added more simplifications for URI support. 3361 o Initial subscription and discovery sections. 3363 o A Flag requirements simplified. 3365 Authors' Addresses 3367 Zach Shelby 3368 Sensinode 3369 Kidekuja 2 3370 Vuokatti 88600 3371 Finland 3373 Phone: +358407796297 3374 Email: zach@sensinode.com 3376 Klaus Hartke 3377 Universitaet Bremen TZI 3378 Postfach 330440 3379 Bremen D-28359 3380 Germany 3382 Phone: +49-421-218-63905 3383 Fax: +49-421-218-7000 3384 Email: hartke@tzi.org 3386 Carsten Bormann 3387 Universitaet Bremen TZI 3388 Postfach 330440 3389 Bremen D-28359 3390 Germany 3392 Phone: +49-421-218-63921 3393 Fax: +49-421-218-7000 3394 Email: cabo@tzi.org 3395 Brian Frank 3396 SkyFoundry 3397 Richmond, VA 3398 USA 3400 Phone: 3401 Email: brian@skyfoundry.com