idnits 2.17.1 draft-ietf-core-coap-17.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 : ---------------------------------------------------------------------------- == There are 1 instance of lines with non-RFC6890-compliant IPv4 addresses in the document. If these are example addresses, they should be changed. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == Line 4913 has weird spacing: '... Client ff02:...' -- The document date (May 26, 2013) is 3989 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. 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 497, but not defined == Missing Reference: '0x01a0' is mentioned on line 512, but not defined == Missing Reference: '0xbc90' is mentioned on line 558, but not defined == Missing Reference: '0xbc91' is mentioned on line 558, but not defined == Missing Reference: '0x7a10' is mentioned on line 582, but not defined == Missing Reference: '0x23bb' is mentioned on line 593, but not defined == Missing Reference: '0x7a11' is mentioned on line 606, but not defined == Missing Reference: '0x23bc' is mentioned on line 611, but not defined == Missing Reference: 'RFCXXXX' is mentioned on line 4394, but not defined == Missing Reference: 'TBD1' is mentioned on line 4405, but not defined == Missing Reference: 'TBD2' is mentioned on line 4410, but not defined == Outdated reference: A later version (-11) exists of draft-ietf-tls-oob-pubkey-07 == Outdated reference: A later version (-08) exists of draft-mcgrew-tls-aes-ccm-ecc-06 ** Downref: Normative reference to an Informational draft: draft-mcgrew-tls-aes-ccm-ecc (ref. 'I-D.mcgrew-tls-aes-ccm-ecc') ** Obsolete normative reference: RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) ** Obsolete normative reference: RFC 3023 (Obsoleted by RFC 7303) ** Obsolete normative reference: RFC 4395 (Obsoleted by RFC 7595) ** Obsolete normative reference: RFC 5226 (Obsoleted by RFC 8126) ** Obsolete normative reference: RFC 5246 (Obsoleted by RFC 8446) ** Obsolete normative reference: RFC 5785 (Obsoleted by RFC 8615) ** Obsolete normative reference: RFC 5988 (Obsoleted by RFC 8288) ** Obsolete normative reference: RFC 6347 (Obsoleted by RFC 9147) == Outdated reference: A later version (-03) exists of draft-allman-tcpm-rto-consider-01 == Outdated reference: A later version (-27) exists of draft-bormann-coap-misc-25 == Outdated reference: A later version (-21) exists of draft-ietf-core-block-11 == Outdated reference: A later version (-25) exists of draft-ietf-core-groupcomm-07 == Outdated reference: A later version (-16) exists of draft-ietf-core-observe-08 == Outdated reference: A later version (-07) exists of draft-ietf-lwig-terminology-04 -- Obsolete informational reference (is this intentional?): RFC 793 (Obsoleted by RFC 9293) -- Obsolete informational reference (is this intentional?): RFC 2560 (Obsoleted by RFC 6960) -- Obsolete informational reference (is this intentional?): RFC 2818 (Obsoleted by RFC 9110) -- Obsolete informational reference (is this intentional?): RFC 4492 (Obsoleted by RFC 8422) -- Obsolete informational reference (is this intentional?): RFC 4627 (Obsoleted by RFC 7158, RFC 7159) -- Obsolete informational reference (is this intentional?): RFC 5405 (Obsoleted by RFC 8085) Summary: 9 errors (**), 0 flaws (~~), 22 warnings (==), 8 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: November 27, 2013 C. Bormann 6 Universitaet Bremen TZI 7 May 26, 2013 9 Constrained Application Protocol (CoAP) 10 draft-ietf-core-coap-17 12 Abstract 14 The Constrained Application Protocol (CoAP) is a specialized web 15 transfer protocol for use with constrained nodes and constrained 16 (e.g., low-power, lossy) networks. The nodes often have 8-bit 17 microcontrollers with small amounts of ROM and RAM, while constrained 18 networks such as 6LoWPAN often have high packet error rates and a 19 typical throughput of 10s of kbit/s. The protocol is designed for 20 machine-to-machine (M2M) applications such as smart energy and 21 building automation. 23 CoAP provides a request/response interaction model between 24 application endpoints, supports built-in discovery of services and 25 resources, and includes key concepts of the Web such as URIs and 26 Internet media types. CoAP is designed to easily interface with HTTP 27 for integration with the Web while meeting specialized requirements 28 such as multicast support, very low overhead and simplicity for 29 constrained environments. 31 Status of this Memo 33 This Internet-Draft is submitted in full conformance with the 34 provisions of BCP 78 and BCP 79. 36 Internet-Drafts are working documents of the Internet Engineering 37 Task Force (IETF). Note that other groups may also distribute 38 working documents as Internet-Drafts. The list of current Internet- 39 Drafts is at http://datatracker.ietf.org/drafts/current/. 41 Internet-Drafts are draft documents valid for a maximum of six months 42 and may be updated, replaced, or obsoleted by other documents at any 43 time. It is inappropriate to use Internet-Drafts as reference 44 material or to cite them other than as "work in progress." 46 This Internet-Draft will expire on November 27, 2013. 48 Copyright Notice 49 Copyright (c) 2013 IETF Trust and the persons identified as the 50 document authors. All rights reserved. 52 This document is subject to BCP 78 and the IETF Trust's Legal 53 Provisions Relating to IETF Documents 54 (http://trustee.ietf.org/license-info) in effect on the date of 55 publication of this document. Please review these documents 56 carefully, as they describe your rights and restrictions with respect 57 to this document. Code Components extracted from this document must 58 include Simplified BSD License text as described in Section 4.e of 59 the Trust Legal Provisions and are provided without warranty as 60 described in the Simplified BSD License. 62 Table of Contents 64 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 5 65 1.1. Features . . . . . . . . . . . . . . . . . . . . . . . . 5 66 1.2. Terminology . . . . . . . . . . . . . . . . . . . . . . . 6 67 2. Constrained Application Protocol . . . . . . . . . . . . . . 9 68 2.1. Messaging Model . . . . . . . . . . . . . . . . . . . . . 10 69 2.2. Request/Response Model . . . . . . . . . . . . . . . . . 12 70 2.3. Intermediaries and Caching . . . . . . . . . . . . . . . 14 71 2.4. Resource Discovery . . . . . . . . . . . . . . . . . . . 14 72 3. Message Format . . . . . . . . . . . . . . . . . . . . . . . 15 73 3.1. Option Format . . . . . . . . . . . . . . . . . . . . . . 17 74 3.2. Option Value Formats . . . . . . . . . . . . . . . . . . 19 75 4. Message Transmission . . . . . . . . . . . . . . . . . . . . 20 76 4.1. Messages and Endpoints . . . . . . . . . . . . . . . . . 20 77 4.2. Messages Transmitted Reliably . . . . . . . . . . . . . . 21 78 4.3. Messages Transmitted Without Reliability . . . . . . . . 22 79 4.4. Message Correlation . . . . . . . . . . . . . . . . . . . 23 80 4.5. Message Deduplication . . . . . . . . . . . . . . . . . . 24 81 4.6. Message Size . . . . . . . . . . . . . . . . . . . . . . 25 82 4.7. Congestion Control . . . . . . . . . . . . . . . . . . . 26 83 4.8. Transmission Parameters . . . . . . . . . . . . . . . . . 27 84 4.8.1. Changing The Parameters . . . . . . . . . . . . . . . 27 85 4.8.2. Time Values derived from Transmission Parameters . . 28 86 5. Request/Response Semantics . . . . . . . . . . . . . . . . . 30 87 5.1. Requests . . . . . . . . . . . . . . . . . . . . . . . . 30 88 5.2. Responses . . . . . . . . . . . . . . . . . . . . . . . . 31 89 5.2.1. Piggy-backed . . . . . . . . . . . . . . . . . . . . 32 90 5.2.2. Separate . . . . . . . . . . . . . . . . . . . . . . 32 91 5.2.3. Non-confirmable . . . . . . . . . . . . . . . . . . . 34 92 5.3. Request/Response Matching . . . . . . . . . . . . . . . . 34 93 5.3.1. Token . . . . . . . . . . . . . . . . . . . . . . . . 34 94 5.3.2. Request/Response Matching Rules . . . . . . . . . . . 35 95 5.4. Options . . . . . . . . . . . . . . . . . . . . . . . . . 35 96 5.4.1. Critical/Elective . . . . . . . . . . . . . . . . . . 36 97 5.4.2. Proxy Unsafe/Safe-to-Forward and NoCacheKey . . . . . 37 98 5.4.3. Length . . . . . . . . . . . . . . . . . . . . . . . 38 99 5.4.4. Default Values . . . . . . . . . . . . . . . . . . . 38 100 5.4.5. Repeatable Options . . . . . . . . . . . . . . . . . 38 101 5.4.6. Option Numbers . . . . . . . . . . . . . . . . . . . 38 102 5.5. Payloads and Representations . . . . . . . . . . . . . . 39 103 5.5.1. Representation . . . . . . . . . . . . . . . . . . . 39 104 5.5.2. Diagnostic Payload . . . . . . . . . . . . . . . . . 40 105 5.5.3. Selected Representation . . . . . . . . . . . . . . . 40 106 5.5.4. Content Negotiation . . . . . . . . . . . . . . . . . 41 107 5.6. Caching . . . . . . . . . . . . . . . . . . . . . . . . . 41 108 5.6.1. Freshness Model . . . . . . . . . . . . . . . . . . . 42 109 5.6.2. Validation Model . . . . . . . . . . . . . . . . . . 42 110 5.7. Proxying . . . . . . . . . . . . . . . . . . . . . . . . 43 111 5.7.1. Proxy Operation . . . . . . . . . . . . . . . . . . . 43 112 5.7.2. Forward-Proxies . . . . . . . . . . . . . . . . . . . 45 113 5.7.3. Reverse-Proxies . . . . . . . . . . . . . . . . . . . 45 114 5.8. Method Definitions . . . . . . . . . . . . . . . . . . . 46 115 5.8.1. GET . . . . . . . . . . . . . . . . . . . . . . . . . 46 116 5.8.2. POST . . . . . . . . . . . . . . . . . . . . . . . . 46 117 5.8.3. PUT . . . . . . . . . . . . . . . . . . . . . . . . . 47 118 5.8.4. DELETE . . . . . . . . . . . . . . . . . . . . . . . 47 119 5.9. Response Code Definitions . . . . . . . . . . . . . . . . 47 120 5.9.1. Success 2.xx . . . . . . . . . . . . . . . . . . . . 47 121 5.9.2. Client Error 4.xx . . . . . . . . . . . . . . . . . . 49 122 5.9.3. Server Error 5.xx . . . . . . . . . . . . . . . . . . 50 123 5.10. Option Definitions . . . . . . . . . . . . . . . . . . . 51 124 5.10.1. Uri-Host, Uri-Port, Uri-Path and Uri-Query . . . . . 52 125 5.10.2. Proxy-Uri and Proxy-Scheme . . . . . . . . . . . . . 53 126 5.10.3. Content-Format . . . . . . . . . . . . . . . . . . . 54 127 5.10.4. Accept . . . . . . . . . . . . . . . . . . . . . . . 54 128 5.10.5. Max-Age . . . . . . . . . . . . . . . . . . . . . . . 54 129 5.10.6. ETag . . . . . . . . . . . . . . . . . . . . . . . . 55 130 5.10.7. Location-Path and Location-Query . . . . . . . . . . 56 131 5.10.8. Conditional Request Options . . . . . . . . . . . . . 56 132 6. CoAP URIs . . . . . . . . . . . . . . . . . . . . . . . . . . 58 133 6.1. coap URI Scheme . . . . . . . . . . . . . . . . . . . . . 58 134 6.2. coaps URI Scheme . . . . . . . . . . . . . . . . . . . . 59 135 6.3. Normalization and Comparison Rules . . . . . . . . . . . 59 136 6.4. Decomposing URIs into Options . . . . . . . . . . . . . . 60 137 6.5. Composing URIs from Options . . . . . . . . . . . . . . . 61 138 7. Discovery . . . . . . . . . . . . . . . . . . . . . . . . . . 62 139 7.1. Service Discovery . . . . . . . . . . . . . . . . . . . . 62 140 7.2. Resource Discovery . . . . . . . . . . . . . . . . . . . 63 141 7.2.1. 'ct' Attribute . . . . . . . . . . . . . . . . . . . 63 142 8. Multicast CoAP . . . . . . . . . . . . . . . . . . . . . . . 64 143 8.1. Messaging Layer . . . . . . . . . . . . . . . . . . . . . 64 144 8.2. Request/Response Layer . . . . . . . . . . . . . . . . . 64 145 8.2.1. Caching . . . . . . . . . . . . . . . . . . . . . . . 65 146 8.2.2. Proxying . . . . . . . . . . . . . . . . . . . . . . 66 147 9. Securing CoAP . . . . . . . . . . . . . . . . . . . . . . . . 66 148 9.1. DTLS-secured CoAP . . . . . . . . . . . . . . . . . . . . 68 149 9.1.1. Messaging Layer . . . . . . . . . . . . . . . . . . . 69 150 9.1.2. Request/Response Layer . . . . . . . . . . . . . . . 69 151 9.1.3. Endpoint Identity . . . . . . . . . . . . . . . . . . 70 152 10. Cross-Protocol Proxying between CoAP and HTTP . . . . . . . . 73 153 10.1. CoAP-HTTP Proxying . . . . . . . . . . . . . . . . . . . 74 154 10.1.1. GET . . . . . . . . . . . . . . . . . . . . . . . . . 74 155 10.1.2. PUT . . . . . . . . . . . . . . . . . . . . . . . . . 75 156 10.1.3. DELETE . . . . . . . . . . . . . . . . . . . . . . . 75 157 10.1.4. POST . . . . . . . . . . . . . . . . . . . . . . . . 75 158 10.2. HTTP-CoAP Proxying . . . . . . . . . . . . . . . . . . . 76 159 10.2.1. OPTIONS and TRACE . . . . . . . . . . . . . . . . . . 76 160 10.2.2. GET . . . . . . . . . . . . . . . . . . . . . . . . . 76 161 10.2.3. HEAD . . . . . . . . . . . . . . . . . . . . . . . . 77 162 10.2.4. POST . . . . . . . . . . . . . . . . . . . . . . . . 77 163 10.2.5. PUT . . . . . . . . . . . . . . . . . . . . . . . . . 78 164 10.2.6. DELETE . . . . . . . . . . . . . . . . . . . . . . . 78 165 10.2.7. CONNECT . . . . . . . . . . . . . . . . . . . . . . . 78 166 11. Security Considerations . . . . . . . . . . . . . . . . . . . 78 167 11.1. Protocol Parsing, Processing URIs . . . . . . . . . . . . 78 168 11.2. Proxying and Caching . . . . . . . . . . . . . . . . . . 79 169 11.3. Risk of amplification . . . . . . . . . . . . . . . . . . 80 170 11.4. IP Address Spoofing Attacks . . . . . . . . . . . . . . . 81 171 11.5. Cross-Protocol Attacks . . . . . . . . . . . . . . . . . 82 172 11.6. Constrained node considerations . . . . . . . . . . . . . 84 173 12. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 84 174 12.1. CoAP Code Registries . . . . . . . . . . . . . . . . . . 84 175 12.1.1. Method Codes . . . . . . . . . . . . . . . . . . . . 85 176 12.1.2. Response Codes . . . . . . . . . . . . . . . . . . . 86 177 12.2. Option Number Registry . . . . . . . . . . . . . . . . . 87 178 12.3. Content-Format Registry . . . . . . . . . . . . . . . . . 89 179 12.4. URI Scheme Registration . . . . . . . . . . . . . . . . . 90 180 12.5. Secure URI Scheme Registration . . . . . . . . . . . . . 91 181 12.6. Service Name and Port Number Registration . . . . . . . . 92 182 12.7. Secure Service Name and Port Number Registration . . . . 93 183 12.8. Multicast Address Registration . . . . . . . . . . . . . 94 184 13. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 94 185 14. References . . . . . . . . . . . . . . . . . . . . . . . . . 95 186 14.1. Normative References . . . . . . . . . . . . . . . . . . 95 187 14.2. Informative References . . . . . . . . . . . . . . . . . 97 188 Appendix A. Examples . . . . . . . . . . . . . . . . . . . . . . 100 189 Appendix B. URI Examples . . . . . . . . . . . . . . . . . . . . 106 190 Appendix C. Changelog . . . . . . . . . . . . . . . . . . . . . 108 191 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 118 193 1. Introduction 195 The use of web services (web APIs) on the Internet has become 196 ubiquitous in most applications, and depends on the fundamental 197 Representational State Transfer [REST] architecture of the web. 199 The Constrained RESTful Environments (CoRE) work aims at realizing 200 the REST architecture in a suitable form for the most constrained 201 nodes (e.g. 8-bit microcontrollers with limited RAM and ROM) and 202 networks (e.g. 6LoWPAN, [RFC4944]). Constrained networks such as 203 6LoWPAN support the fragmentation of IPv6 packets into small link- 204 layer frames, however incurring significant reduction in packet 205 delivery probability. One design goal of CoAP has been to keep 206 message overhead small, thus limiting the need for fragmentation. 208 One of the main goals of CoAP is to design a generic web protocol for 209 the special requirements of this constrained environment, especially 210 considering energy, building automation and other machine-to-machine 211 (M2M) applications. The goal of CoAP is not to blindly compress HTTP 212 [RFC2616], but rather to realize a subset of REST common with HTTP 213 but optimized for M2M applications. Although CoAP could be used for 214 refashioning simple HTTP interfaces into a more compact protocol, it 215 more importantly also offers features for M2M such as built-in 216 discovery, multicast support and asynchronous message exchanges. 218 This document specifies the Constrained Application Protocol (CoAP), 219 which easily translates to HTTP for integration with the existing web 220 while meeting specialized requirements such as multicast support, 221 very low overhead and simplicity for constrained environments and M2M 222 applications. 224 1.1. Features 226 CoAP has the following main features: 228 o Constrained web protocol fulfilling M2M requirements. 230 o UDP [RFC0768] binding with optional reliability supporting unicast 231 and multicast requests. 233 o Asynchronous message exchanges. 235 o Low header overhead and parsing complexity. 237 o URI and Content-type support. 239 o Simple proxy and caching capabilities. 241 o A stateless HTTP mapping, allowing proxies to be built providing 242 access to CoAP resources via HTTP in a uniform way or for HTTP 243 simple interfaces to be realized alternatively over CoAP. 245 o Security binding to Datagram Transport Layer Security (DTLS) 246 [RFC6347]. 248 1.2. Terminology 250 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 251 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 252 "OPTIONAL" in this document are to be interpreted as described in 253 [RFC2119] when they appear in ALL CAPS. These words may also appear 254 in this document in lower case as plain English words, absent their 255 normative meanings. 257 This specification requires readers to be familiar with all the terms 258 and concepts that are discussed in [RFC2616], including "resource", 259 "representation", "cache", and "fresh". In addition, this 260 specification defines the following terminology: 262 Endpoint 263 An entity participating in the CoAP protocol. Colloquially, an 264 endpoint lives on a "Node", although "Host" would be more 265 consistent with Internet standards usage, and is further 266 identified by transport layer multiplexing information that can 267 include a UDP port number and a security association 268 (Section 4.1). 270 Sender 271 The originating endpoint of a message. When the aspect of 272 identification of the specific sender is in focus, also "source 273 endpoint". 275 Recipient 276 The destination endpoint of a message. When the aspect of 277 identification of the specific recipient is in focus, also 278 "destination endpoint". 280 Client 281 The originating endpoint of a request; the destination endpoint of 282 a response. 284 Server 285 The destination endpoint of a request; the originating endpoint of 286 a response. 288 Origin Server 289 The server on which a given resource resides or is to be created. 291 Intermediary 292 A CoAP endpoint that acts both as a server and as a client towards 293 (possibly via further intermediaries) an origin server. A common 294 form of an intermediary is a proxy; several classes of such 295 proxies are discussed in this specification. 297 Proxy 298 An intermediary that mainly is concerned with forwarding requests 299 and relaying back responses, possibly performing caching, 300 namespace translation, or protocol translation in the process. As 301 opposed to intermediaries in the general sense, proxies generally 302 do not implement specific application semantics. Based on the 303 position in the overall structure of the request forwarding, there 304 are two common forms of proxy: forward-proxy and reverse-proxy. 305 In some cases, a single endpoint might act as an origin server, 306 forward-proxy, or reverse-proxy, switching behavior based on the 307 nature of each request. 309 Forward-Proxy 310 A "forward-proxy" is an endpoint selected by a client, usually via 311 local configuration rules, to perform requests on behalf of the 312 client, doing any necessary translations. Some translations are 313 minimal, such as for proxy requests for "coap" URIs, whereas other 314 requests might require translation to and from entirely different 315 application-layer protocols. 317 Reverse-Proxy 318 A "reverse-proxy" is an endpoint that stands in for one or more 319 other server(s) and satisfies requests on behalf of these, doing 320 any necessary translations. Unlike a forward-proxy, the client 321 may not be aware that it is communicating with a reverse-proxy; a 322 reverse-proxy receives requests as if it was the origin server for 323 the target resource. 325 CoAP-to-CoAP Proxy 326 A proxy that maps from a CoAP request to a CoAP request, i.e. uses 327 the CoAP protocol both on the server and the client side. 328 Contrast to cross-proxy. 330 Cross-Proxy 331 A cross-protocol proxy, or "cross-proxy" for short, is a proxy 332 that translates between different protocols, such as a CoAP-to- 333 HTTP proxy or an HTTP-to-CoAP proxy. While this specification 334 makes very specific demands of CoAP-to-CoAP proxies, there is more 335 variation possible in cross-proxies. 337 Confirmable Message 338 Some messages require an acknowledgement. These messages are 339 called "Confirmable". When no packets are lost, each Confirmable 340 message elicits exactly one return message of type Acknowledgement 341 or type Reset. 343 Non-confirmable Message 344 Some other messages do not require an acknowledgement. This is 345 particularly true for messages that are repeated regularly for 346 application requirements, such as repeated readings from a sensor. 348 Acknowledgement Message 349 An Acknowledgement message acknowledges that a specific 350 Confirmable message arrived. By itself, an Acknowledgement 351 message does not indicate success or failure of any request 352 encapsulated in the Confirmable message, but the Acknowledgement 353 message may also carry a Piggy-Backed Response (q.v.). 355 Reset Message 356 A Reset message indicates that a specific message (Confirmable or 357 Non-confirmable) was received, but some context is missing to 358 properly process it. This condition is usually caused when the 359 receiving node has rebooted and has forgotten some state that 360 would be required to interpret the message. Provoking a Reset 361 message (e.g., by sending an empty Confirmable message) is also 362 useful as an inexpensive check of the liveness of an endpoint 363 ("CoAP ping"). 365 Piggy-backed Response 366 A Piggy-backed Response is included right in a CoAP 367 Acknowledgement (ACK) message that is sent to acknowledge receipt 368 of the Request for this Response (Section 5.2.1). 370 Separate Response 371 When a Confirmable message carrying a Request is acknowledged with 372 an empty message (e.g., because the server doesn't have the answer 373 right away), a Separate Response is sent in a separate message 374 exchange (Section 5.2.2). 376 Critical Option 377 An option that would need to be understood by the endpoint 378 ultimately receiving the message in order to properly process the 379 message (Section 5.4.1). Note that the implementation of critical 380 options is, as the name "Option" implies, generally optional: 381 unsupported critical options lead to an error response or summary 382 rejection of the message. 384 Elective Option 385 An option that is intended to be ignored by an endpoint that does 386 not understand it. Processing the message even without 387 understanding the option is acceptable (Section 5.4.1). 389 Unsafe Option 390 An option that would need to be understood by a proxy receiving 391 the message in order to safely forward the message 392 (Section 5.4.2). Not every critical option is an unsafe option. 394 Safe-to-Forward Option 395 An option that is intended to be safe for forwarding by a proxy 396 that does not understand it. Forwarding the message even without 397 understanding the option is acceptable (Section 5.4.2). 399 Resource Discovery 400 The process where a CoAP client queries a server for its list of 401 hosted resources (i.e., links, Section 7). 403 Content-Format 404 The combination of an Internet media type, potentially with 405 specific parameters given, and a content-coding (which is often 406 the identity content-coding), identified by a numeric identifier 407 defined by the CoAP Content-Format Registry. When the focus is 408 less on the numeric identifier than on the combination of these 409 characteristics of a resource representation, this is also called 410 "representation format". 412 Additional terminology for constrained nodes and constrained node 413 networks can be found in [I-D.ietf-lwig-terminology]. 415 In this specification, the term "byte" is used in its now customary 416 sense as a synonym for "octet". 418 All multi-byte integers in this protocol are interpreted in network 419 byte order. 421 Where arithmetic is used, this specification uses the notation 422 familiar from the programming language C, except that the operator 423 "**" stands for exponentiation. 425 2. Constrained Application Protocol 427 The interaction model of CoAP is similar to the client/server model 428 of HTTP. However, machine-to-machine interactions typically result 429 in a CoAP implementation acting in both client and server roles. A 430 CoAP request is equivalent to that of HTTP, and is sent by a client 431 to request an action (using a method code) on a resource (identified 432 by a URI) on a server. The server then sends a response with a 433 response code; this response may include a resource representation. 435 Unlike HTTP, CoAP deals with these interchanges asynchronously over a 436 datagram-oriented transport such as UDP. This is done logically 437 using a layer of messages that supports optional reliability (with 438 exponential back-off). CoAP defines four types of messages: 439 Confirmable, Non-confirmable, Acknowledgement, Reset; method codes 440 and response codes included in some of these messages make them carry 441 requests or responses. The basic exchanges of the four types of 442 messages are somewhat orthogonal to the request/response 443 interactions; requests can be carried in Confirmable and Non- 444 confirmable messages, and responses can be carried in these as well 445 as piggy-backed in Acknowledgement messages. 447 One could think of CoAP logically as using a two-layer approach, a 448 CoAP messaging layer used to deal with UDP and the asynchronous 449 nature of the interactions, and the request/response interactions 450 using Method and Response codes (see Figure 1). CoAP is however a 451 single protocol, with messaging and request/response just features of 452 the CoAP header. 454 +----------------------+ 455 | Application | 456 +----------------------+ 457 +----------------------+ \ 458 | Requests/Responses | | 459 |----------------------| | CoAP 460 | Messages | | 461 +----------------------+ / 462 +----------------------+ 463 | UDP | 464 +----------------------+ 466 Figure 1: Abstract layering of CoAP 468 2.1. Messaging Model 470 The CoAP messaging model is based on the exchange of messages over 471 UDP between endpoints. 473 CoAP uses a short fixed-length binary header (4 bytes) that may be 474 followed by compact binary options and a payload. This message 475 format is shared by requests and responses. The CoAP message format 476 is specified in Section 3. Each message contains a Message ID used 477 to detect duplicates and for optional reliability. (The Message ID 478 is compact; its 16-bit size enables up to about 250 messages per 479 second from one endpoint to another with default protocol 480 parameters.) 482 Reliability is provided by marking a message as Confirmable (CON). A 483 Confirmable message is retransmitted using a default timeout and 484 exponential back-off between retransmissions, until the recipient 485 sends an Acknowledgement message (ACK) with the same Message ID (in 486 this example, 0x7d34) from the corresponding endpoint; see Figure 2. 487 When a recipient is not at all able to process a Confirmable message 488 (i.e., not even able to provide a suitable error response), it 489 replies with a Reset message (RST) instead of an Acknowledgement 490 (ACK). 492 Client Server 493 | | 494 | CON [0x7d34] | 495 +----------------->| 496 | | 497 | ACK [0x7d34] | 498 |<-----------------+ 499 | | 501 Figure 2: Reliable message transmission 503 A message that does not require reliable transmission, for example 504 each single measurement out of a stream of sensor data, can be sent 505 as a Non-confirmable message (NON). These are not acknowledged, but 506 still have a Message ID for duplicate detection (in this example, 507 0x01a0); see Figure 3. When a recipient is not able to process a 508 Non-confirmable message, it may reply with a Reset message (RST). 510 Client Server 511 | | 512 | NON [0x01a0] | 513 +----------------->| 514 | | 516 Figure 3: Unreliable message transmission 518 See Section 4 for details of CoAP messages. 520 As CoAP runs over UDP, it also supports the use of multicast IP 521 destination addresses, enabling multicast CoAP requests. Section 8 522 discusses the proper use of CoAP messages with multicast addresses 523 and precautions for avoiding response congestion. 525 Several security modes are defined for CoAP in Section 9 ranging from 526 no security to certificate-based security. This document specifies a 527 binding to DTLS for securing the protocol; the use of IPsec with CoAP 528 is discussed in [I-D.bormann-core-ipsec-for-coap]. 530 2.2. Request/Response Model 532 CoAP request and response semantics are carried in CoAP messages, 533 which include either a Method code or Response code, respectively. 534 Optional (or default) request and response information, such as the 535 URI and payload media type are carried as CoAP options. A Token is 536 used to match responses to requests independently from the underlying 537 messages (Section 5.3). (Note that the Token is a concept separate 538 from the Message ID.) 540 A request is carried in a Confirmable (CON) or Non-confirmable (NON) 541 message, and if immediately available, the response to a request 542 carried in a Confirmable message is carried in the resulting 543 Acknowledgement (ACK) message. This is called a piggy-backed 544 response, detailed in Section 5.2.1. (There is no need for 545 separately acknowledging a piggy-backed response, as the client will 546 retransmit the request if the Acknowledgement message carrying the 547 piggy-backed response is lost.) Two examples for a basic GET request 548 with piggy-backed response are shown in Figure 4, one successful, one 549 resulting in a 4.04 (Not Found) response. 551 Client Server Client Server 552 | | | | 553 | CON [0xbc90] | | CON [0xbc91] | 554 | GET /temperature | | GET /temperature | 555 | (Token 0x71) | | (Token 0x72) | 556 +----------------->| +----------------->| 557 | | | | 558 | ACK [0xbc90] | | ACK [0xbc91] | 559 | 2.05 Content | | 4.04 Not Found | 560 | (Token 0x71) | | (Token 0x72) | 561 | "22.5 C" | | "Not found" | 562 |<-----------------+ |<-----------------+ 563 | | | | 565 Figure 4: Two GET requests with piggy-backed responses 567 If the server is not able to respond immediately to a request carried 568 in a Confirmable message, it simply responds with an empty 569 Acknowledgement message so that the client can stop retransmitting 570 the request. When the response is ready, the server sends it in a 571 new Confirmable message (which then in turn needs to be acknowledged 572 by the client). This is called a separate response, as illustrated 573 in Figure 5 and described in more detail in Section 5.2.2. 575 Client Server 576 | | 577 | CON [0x7a10] | 578 | GET /temperature | 579 | (Token 0x73) | 580 +----------------->| 581 | | 582 | ACK [0x7a10] | 583 |<-----------------+ 584 | | 585 ... Time Passes ... 586 | | 587 | CON [0x23bb] | 588 | 2.05 Content | 589 | (Token 0x73) | 590 | "22.5 C" | 591 |<-----------------+ 592 | | 593 | ACK [0x23bb] | 594 +----------------->| 595 | | 597 Figure 5: A GET request with a separate response 599 If a request is sent in a Non-confirmable message, then the response 600 is sent using a new Non-confirmable message, although the server may 601 instead send a Confirmable message. This type of exchange is 602 illustrated in Figure 6. 604 Client Server 605 | | 606 | NON [0x7a11] | 607 | GET /temperature | 608 | (Token 0x74) | 609 +----------------->| 610 | | 611 | NON [0x23bc] | 612 | 2.05 Content | 613 | (Token 0x74) | 614 | "22.5 C" | 615 |<-----------------+ 616 | | 618 Figure 6: A NON request and response 620 CoAP makes use of GET, PUT, POST and DELETE methods in a similar 621 manner to HTTP, with the semantics specified in Section 5.8. (Note 622 that the detailed semantics of CoAP methods are "almost, but not 623 entirely unlike" [HHGTTG] those of HTTP methods: Intuition taken from 624 HTTP experience generally does apply well, but there are enough 625 differences that make it worthwhile to actually read the present 626 specification.) 628 Methods beyond the basic four can be added to CoAP in separate 629 specifications. New methods do not necessarily have to use requests 630 and responses in pairs. Even for existing methods, a single request 631 may yield multiple responses, e.g. for a multicast request 632 (Section 8) or with the Observe option [I-D.ietf-core-observe]. 634 URI support in a server is simplified as the client already parses 635 the URI and splits it into host, port, path and query components, 636 making use of default values for efficiency. Response codes relate 637 to a small subset of HTTP response codes with a few CoAP specific 638 codes added, as defined in Section 5.9. 640 2.3. Intermediaries and Caching 642 The protocol supports the caching of responses in order to 643 efficiently fulfill requests. Simple caching is enabled using 644 freshness and validity information carried with CoAP responses. A 645 cache could be located in an endpoint or an intermediary. Caching 646 functionality is specified in Section 5.6. 648 Proxying is useful in constrained networks for several reasons, 649 including network traffic limiting, to improve performance, to access 650 resources of sleeping devices or for security reasons. The proxying 651 of requests on behalf of another CoAP endpoint is supported in the 652 protocol. When using a proxy, the URI of the resource to request is 653 included in the request, while the destination IP address is set to 654 the address of the proxy. See Section 5.7 for more information on 655 proxy functionality. 657 As CoAP was designed according to the REST architecture [REST] and 658 thus exhibits functionality similar to that of the HTTP protocol, it 659 is quite straightforward to map from CoAP to HTTP and from HTTP to 660 CoAP. Such a mapping may be used to realize an HTTP REST interface 661 using CoAP, or for converting between HTTP and CoAP. This conversion 662 can be carried out by a cross-protocol proxy ("cross-proxy"), which 663 converts the method or response code, media type, and options to the 664 corresponding HTTP feature. Section 10 provides more detail about 665 HTTP mapping. 667 2.4. Resource Discovery 669 Resource discovery is important for machine-to-machine interactions, 670 and is supported using the CoRE Link Format [RFC6690] as discussed in 671 Section 7. 673 3. Message Format 675 CoAP is based on the exchange of compact messages which, by default, 676 are transported over UDP (i.e. each CoAP message occupies the data 677 section of one UDP datagram). CoAP may also be used over Datagram 678 Transport Layer Security (DTLS) (see Section 9.1). It could also be 679 used over other transports such as SMS, TCP or SCTP, the 680 specification of which is out of this document's scope. (UDP-lite 681 [RFC3828] and UDP zero checksum [RFC6936] are not supported by CoAP.) 683 CoAP messages are encoded in a simple binary format. The message 684 format starts with a fixed-size 4-byte header. This is followed by a 685 variable-length Token value which can be between 0 and 8 bytes long. 686 Following the Token value comes a sequence of zero or more CoAP 687 Options in Type-Length-Value (TLV) format, optionally followed by a 688 payload which takes up the rest of the datagram. 690 0 1 2 3 691 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 692 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 693 |Ver| T | TKL | Code | Message ID | 694 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 695 | Token (if any, TKL bytes) ... 696 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 697 | Options (if any) ... 698 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 699 |1 1 1 1 1 1 1 1| Payload (if any) ... 700 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 702 Figure 7: Message Format 704 The fields in the header are defined as follows: 706 Version (Ver): 2-bit unsigned integer. Indicates the CoAP version 707 number. Implementations of this specification MUST set this field 708 to 1 (01 binary). Other values are reserved for future versions. 709 Messages with unknown version numbers MUST be silently ignored. 711 Type (T): 2-bit unsigned integer. Indicates if this message is of 712 type Confirmable (0), Non-confirmable (1), Acknowledgement (2) or 713 Reset (3). The semantics of these message types are defined in 714 Section 4. 716 Token Length (TKL): 4-bit unsigned integer. Indicates the length of 717 the variable-length Token field (0-8 bytes). Lengths 9-15 are 718 reserved, MUST NOT be sent, and MUST be processed as a message 719 format error. 721 Code: 8-bit unsigned integer, split into a 3-bit class (most 722 significant bits) and a 5-bit detail (least significant bits), 723 documented as c.dd where c is a digit from 0 to 7 for the 3-bit 724 subfield and dd are two digits from 00 to 31 for the 5-bit 725 subfield. Indicates if the message carries a request (0.01-0.31) 726 or a response (2.00-5.31), or is empty (0.00). (All other code 727 values are reserved.) In case of a request, the Code field 728 indicates the Request Method; in case of a response a Response 729 Code. Possible values are maintained in the CoAP Code Registries 730 (Section 12.1). The semantics of requests and responses are 731 defined in Section 5. 733 Message ID: 16-bit unsigned integer in network byte order. Used for 734 the detection of message duplication, and to match messages of 735 type Acknowledgement/Reset to messages of type Confirmable/ 736 Non-confirmable. The rules for generating a Message ID and 737 matching messages are defined in Section 4. 739 The header is followed by the Token value, which may be 0 to 8 bytes, 740 as given by the Token Length field. The Token value is used to 741 correlate requests and responses. The rules for generating a Token 742 and correlating requests and responses are defined in Section 5.3.1. 744 Header and Token are followed by zero or more Options (Section 3.1). 745 An Option can be followed by the end of the message, by another 746 Option, or by the Payload Marker and the payload. 748 Following the header, token, and options, if any, comes the optional 749 payload. If present and of non-zero length, it is prefixed by a 750 fixed, one-byte Payload Marker (0xFF) which indicates the end of 751 options and the start of the payload. The payload data extends from 752 after the marker to the end of the UDP datagram, i.e., the Payload 753 Length is calculated from the datagram size. The absence of the 754 Payload Marker denotes a zero-length payload. The presence of a 755 marker followed by a zero-length payload MUST be processed as a 756 message format error. 758 Implementation Note: The byte value 0xFF may also occur within an 759 option length or value, so simple byte-wise scanning for 0xFF is 760 not a viable technique for finding the payload marker. The byte 761 0xFF has the meaning of a payload marker only where the beginning 762 of another option could occur. 764 3.1. Option Format 766 CoAP defines a number of options which can be included in a message. 767 Each option instance in a message specifies the Option Number of the 768 defined CoAP option, the length of the Option Value and the Option 769 Value itself. 771 Instead of specifying the Option Number directly, the instances MUST 772 appear in order of their Option Numbers and a delta encoding is used 773 between them: The Option Number for each instance is calculated as 774 the sum of its delta and the Option Number of the preceding instance 775 in the message. For the first instance in a message, a preceding 776 option instance with Option Number zero is assumed. Multiple 777 instances of the same option can be included by using a delta of 778 zero. 780 Option Numbers are maintained in the CoAP Option Number Registry 781 (Section 12.2). See Section 5.4 for the semantics of the options 782 defined in this document. 784 0 1 2 3 4 5 6 7 785 +---------------+---------------+ 786 | | | 787 | Option Delta | Option Length | 1 byte 788 | | | 789 +---------------+---------------+ 790 \ \ 791 / Option Delta / 0-2 bytes 792 \ (extended) \ 793 +-------------------------------+ 794 \ \ 795 / Option Length / 0-2 bytes 796 \ (extended) \ 797 +-------------------------------+ 798 \ \ 799 / / 800 \ \ 801 / Option Value / 0 or more bytes 802 \ \ 803 / / 804 \ \ 805 +-------------------------------+ 807 Figure 8: Option Format 809 The fields in an option are defined as follows: 811 Option Delta: 4-bit unsigned integer. A value between 0 and 12 812 indicates the Option Delta. Three values are reserved for special 813 constructs: 815 13: An 8-bit unsigned integer follows the initial byte and 816 indicates the Option Delta minus 13. 818 14: A 16-bit unsigned integer in network byte order follows the 819 initial byte and indicates the Option Delta minus 269. 821 15: Reserved for the Payload Marker. If the field is set to this 822 value but the entire byte is not the payload marker, this MUST 823 be processed as a message format error. 825 The resulting Option Delta is used as the difference between the 826 Option Number of this option and that of the previous option (or 827 zero for the first option). In other words, the Option Number is 828 calculated by simply summing the Option Delta values of this and 829 all previous options before it. 831 Option Length: 4-bit unsigned integer. A value between 0 and 12 832 indicates the length of the Option Value, in bytes. Three values 833 are reserved for special constructs: 835 13: An 8-bit unsigned integer precedes the Option Value and 836 indicates the Option Length minus 13. 838 14: A 16-bit unsigned integer in network byte order precedes the 839 Option Value and indicates the Option Length minus 269. 841 15: Reserved for future use. If the field is set to this value, 842 it MUST be processed as a message format error. 844 Value: A sequence of exactly Option Length bytes. The length and 845 format of the Option Value depend on the respective option, which 846 MAY define variable length values. See Section 3.2 for the 847 formats used in this document; options defined in other documents 848 MAY make use of other option value formats. 850 3.2. Option Value Formats 852 The options defined in this document make use of the following option 853 value formats. 855 empty: A zero-length sequence of bytes. 857 opaque: An opaque sequence of bytes. 859 uint: A non-negative integer which is represented in network byte 860 order using the number of bytes given by the Option Length 861 field. 863 An option definition may specify a range of permissible 864 numbers of bytes; if it has a choice, a sender SHOULD 865 represent the integer with as few bytes as possible, i.e., 866 without leading zero bytes. For example, the number 0 is 867 represented with an empty option value (a zero-length 868 sequence of bytes), and the number 1 by a single byte with 869 the numerical value of 1 (bit combination 00000001 in most 870 significant bit first notation). A recipient MUST be 871 prepared to process values with leading zero bytes. 873 Implementation Note: The exceptional behavior permitted 874 for the sender is intended for highly 875 constrained, templated implementations (e.g., 876 hardware implementations) that use fixed size 877 options in the templates. 879 string: A Unicode string which is encoded using UTF-8 [RFC3629] in 880 Net-Unicode form [RFC5198]. 882 Note that here and in all other places where UTF-8 encoding 883 is used in the CoAP protocol, the intention is that the 884 encoded strings can be directly used and compared as opaque 885 byte strings by CoAP protocol implementations. There is no 886 expectation and no need to perform normalization within a 887 CoAP implementation (except where Unicode strings that are 888 not known to be normalized are imported from sources 889 outside the CoAP protocol). Note also that ASCII strings 890 (that do not make use of special control characters) are 891 always valid UTF-8 Net-Unicode strings. 893 4. Message Transmission 895 CoAP messages are exchanged asynchronously between CoAP endpoints. 896 They are used to transport CoAP requests and responses, the semantics 897 of which are defined in Section 5. 899 As CoAP is bound to non-reliable transports such as UDP, CoAP 900 messages may arrive out of order, appear duplicated, or go missing 901 without notice. For this reason, CoAP implements a lightweight 902 reliability mechanism, without trying to re-create the full feature 903 set of a transport like TCP. It has the following features: 905 o Simple stop-and-wait retransmission reliability with exponential 906 back-off for Confirmable messages. 908 o Duplicate detection for both Confirmable and Non-confirmable 909 messages. 911 4.1. Messages and Endpoints 913 A CoAP endpoint is the source or destination of a CoAP message. The 914 specific definition of an endpoint depends on the transport being 915 used for CoAP. For the transports defined in this specification, the 916 endpoint is identified depending on the security mode used (see 917 Section 9): With no security, the endpoint is solely identified by an 918 IP address and a UDP port number. With other security modes, the 919 endpoint is identified as defined by the security mode. 921 There are different types of messages. The type of a message is 922 specified by the Type field of the CoAP Header. 924 Separate from the message type, a message may carry a request, a 925 response, or be empty. This is signaled by the Request/Response Code 926 field in the CoAP Header and is relevant to the request/response 927 model. Possible values for the field are maintained in the CoAP Code 928 Registries (Section 12.1). 930 An empty message has the Code field set to 0.00. The Token Length 931 field MUST be set to 0 and bytes of data MUST NOT be present after 932 the Message ID field. If there are any bytes, they MUST be processed 933 as a message format error. 935 4.2. Messages Transmitted Reliably 937 The reliable transmission of a message is initiated by marking the 938 message as Confirmable in the CoAP header. A Confirmable message 939 always carries either a request or response, unless it is used only 940 to elicit a Reset message in which case it is empty. A recipient 941 MUST acknowledge a Confirmable message with an Acknowledgement 942 message or, if it lacks context to process the message properly 943 (including the case where the message is empty, uses a code with a 944 reserved class (1, 6 or 7), or has a message format error), MUST 945 reject it; rejecting a Confirmable message is effected by sending a 946 matching Reset message and otherwise ignoring it. The 947 Acknowledgement message MUST echo the Message ID of the Confirmable 948 message, and MUST carry a response or be empty (see Section 5.2.1 and 949 Section 5.2.2). The Reset message MUST echo the Message ID of the 950 Confirmable message, and MUST be empty. Rejecting an Acknowledgement 951 or Reset message (including the case where the Acknowledgement 952 carries a request or a code with a reserved class, or the Reset 953 message is not empty) is effected by silently ignoring it. More 954 generally, recipients of Acknowledgement and Reset messages MUST NOT 955 respond with either Acknowledgement or Reset messages. 957 The sender retransmits the Confirmable message at exponentially 958 increasing intervals, until it receives an acknowledgement (or Reset 959 message), or runs out of attempts. 961 Retransmission is controlled by two things that a CoAP endpoint MUST 962 keep track of for each Confirmable message it sends while waiting for 963 an acknowledgement (or reset): a timeout and a retransmission 964 counter. For a new Confirmable message, the initial timeout is set 965 to a random duration (often not an integral number of seconds) 966 between ACK_TIMEOUT and (ACK_TIMEOUT * ACK_RANDOM_FACTOR) (see 967 Section 4.8), and the retransmission counter is set to 0. When the 968 timeout is triggered and the retransmission counter is less than 969 MAX_RETRANSMIT, the message is retransmitted, the retransmission 970 counter is incremented, and the timeout is doubled. If the 971 retransmission counter reaches MAX_RETRANSMIT on a timeout, or if the 972 endpoint receives a Reset message, then the attempt to transmit the 973 message is canceled and the application process informed of failure. 975 On the other hand, if the endpoint receives an acknowledgement in 976 time, transmission is considered successful. 978 This specification makes no strong requirements on the accuracy of 979 the clocks used to implement the above binary exponential backoff 980 algorithm. In particular, an endpoint may be late for a specific 981 retransmission due to its sleep schedule, and maybe catch up on the 982 next one. However, the minimum spacing before another retransmission 983 is ACK_TIMEOUT, and the entire sequence of (re-)transmissions MUST 984 stay in the envelope of MAX_TRANSMIT_SPAN (see Section 4.8.2), even 985 if that means a sender may miss an opportunity to transmit. 987 A CoAP endpoint that sent a Confirmable message MAY give up in 988 attempting to obtain an ACK even before the MAX_RETRANSMIT counter 989 value is reached: E.g., the application has canceled the request as 990 it no longer needs a response, or there is some other indication that 991 the CON message did arrive. In particular, a CoAP request message 992 may have elicited a separate response, in which case it is clear to 993 the requester that only the ACK was lost and a retransmission of the 994 request would serve no purpose. However, a responder MUST NOT in 995 turn rely on this cross-layer behavior from a requester, i.e. it MUST 996 retain the state to create the ACK for the request, if needed, even 997 if a Confirmable response was already acknowledged by the requester. 999 Another reason for giving up retransmission MAY be the receipt of 1000 ICMP errors. If it is desired to take account of ICMP errors, to 1001 mitigate potential spoofing attacks, implementations SHOULD take care 1002 to check the information about the original datagram in the ICMP 1003 message, including port numbers and CoAP header information such as 1004 message type and code, Message ID, and Token; if this is not possible 1005 due to limitations of the UDP service API, ICMP errors SHOULD be 1006 ignored. Packet Too Big errors [RFC4443] ("fragmentation needed and 1007 DF set" for IPv4 [RFC0792]) cannot properly occur and SHOULD be 1008 ignored if the implementation note in Section 4.6 is followed; 1009 otherwise, they SHOULD feed into a path MTU discovery algorithm 1010 [RFC4821]. Source Quench and Time Exceeded ICMP messages SHOULD be 1011 ignored. Host, network, port or protocol unreachable errors, or 1012 parameter problem errors MAY, after appropriate vetting, be used to 1013 inform the application of a failure in sending. 1015 4.3. Messages Transmitted Without Reliability 1017 Some messages do not require an acknowledgement. This is 1018 particularly true for messages that are repeated regularly for 1019 application requirements, such as repeated readings from a sensor 1020 where eventual success is sufficient. 1022 As a more lightweight alternative, a message can be transmitted less 1023 reliably by marking the message as Non-confirmable. A Non- 1024 confirmable message always carries either a request or response and 1025 MUST NOT be empty. A Non-confirmable message MUST NOT be 1026 acknowledged by the recipient. If a recipient lacks context to 1027 process the message properly (including the case where the message is 1028 empty, uses a code with a reserved class (1, 6 or 7), or has a 1029 message format error), it MUST reject the message; rejecting a Non- 1030 confirmable message MAY involve sending a matching Reset message, and 1031 apart from the Reset message the rejected message MUST be silently 1032 ignored. 1034 At the CoAP level, there is no way for the sender to detect if a Non- 1035 confirmable message was received or not. A sender MAY choose to 1036 transmit multiple copies of a Non-confirmable message within 1037 MAX_TRANSMIT_SPAN (limited by the provisions of Section 4.7, in 1038 particular by PROBING_RATE if no response is received), or the 1039 network may duplicate the message in transit. To enable the receiver 1040 to act only once on the message, Non-confirmable messages specify a 1041 Message ID as well. (This Message ID is drawn from the same number 1042 space as the Message IDs for Confirmable messages.) 1044 Summarizing Section 4.2 and Section 4.3, the four message types can 1045 be used as in Table 1. "*" means that the combination is not used in 1046 normal operation, but only to elicit a Reset message ("CoAP ping"). 1048 +----------+-----+-----+-----+-----+ 1049 | | CON | NON | ACK | RST | 1050 +----------+-----+-----+-----+-----+ 1051 | Request | X | X | - | - | 1052 | Response | X | X | X | - | 1053 | Empty | * | - | X | X | 1054 +----------+-----+-----+-----+-----+ 1056 Table 1: Usage of message types 1058 4.4. Message Correlation 1060 An Acknowledgement or Reset message is related to a Confirmable 1061 message or Non-confirmable message by means of a Message ID along 1062 with additional address information of the corresponding endpoint. 1063 The Message ID is a 16-bit unsigned integer that is generated by the 1064 sender of a Confirmable or Non-confirmable message and included in 1065 the CoAP header. The Message ID MUST be echoed in the 1066 Acknowledgement or Reset message by the recipient. 1068 The same Message ID MUST NOT be re-used (in communicating with the 1069 same endpoint) within the EXCHANGE_LIFETIME (Section 4.8.2). 1071 Implementation Note: Several implementation strategies can be 1072 employed for generating Message IDs. In the simplest case a CoAP 1073 endpoint generates Message IDs by keeping a single Message ID 1074 variable, which is changed each time a new Confirmable or Non- 1075 confirmable message is sent regardless of the destination address 1076 or port. Endpoints dealing with large numbers of transactions 1077 could keep multiple Message ID variables, for example per prefix 1078 or destination address (note that some receiving endpoints may not 1079 be able to distinguish unicast and multicast packets addressed to 1080 it, so endpoints generating Message IDs need to make sure these do 1081 not overlap). It is strongly recommended that the initial value 1082 of the variable (e.g., on startup) be randomized, in order to make 1083 successful off-path attacks on the protocol less likely. 1085 For an Acknowledgement or Reset message to match a Confirmable or 1086 Non-confirmable message, the Message ID and source endpoint of the 1087 Acknowledgement or Reset message MUST match the Message ID and 1088 destination endpoint of the Confirmable or Non-confirmable message. 1090 4.5. Message Deduplication 1092 A recipient might receive the same Confirmable message (as indicated 1093 by the Message ID and source endpoint) multiple times within the 1094 EXCHANGE_LIFETIME (Section 4.8.2), for example, when its 1095 Acknowledgement went missing or didn't reach the original sender 1096 before the first timeout. The recipient SHOULD acknowledge each 1097 duplicate copy of a Confirmable message using the same 1098 Acknowledgement or Reset message, but SHOULD process any request or 1099 response in the message only once. This rule MAY be relaxed in case 1100 the Confirmable message transports a request that is idempotent (see 1101 Section 5.1) or can be handled in an idempotent fashion. Examples 1102 for relaxed message deduplication: 1104 o A server might relax the requirement to answer all retransmissions 1105 of an idempotent request with the same response (Section 4.2), so 1106 that it does not have to maintain state for Message IDs. For 1107 example, an implementation might want to process duplicate 1108 transmissions of a GET, PUT or DELETE request as separate requests 1109 if the effort incurred by duplicate processing is less expensive 1110 than keeping track of previous responses would be. 1112 o A constrained server might even want to relax this requirement for 1113 certain non-idempotent requests if the application semantics make 1114 this trade-off favorable. For example, if the result of a POST 1115 request is just the creation of some short-lived state at the 1116 server, it may be less expensive to incur this effort multiple 1117 times for a request than keeping track of whether a previous 1118 transmission of the same request already was processed. 1120 A recipient might receive the same Non-confirmable message (as 1121 indicated by the Message ID and source endpoint) multiple times 1122 within NON_LIFETIME (Section 4.8.2). As a general rule that MAY be 1123 relaxed based on the specific semantics of a message, the recipient 1124 SHOULD silently ignore any duplicated Non-confirmable message, and 1125 SHOULD process any request or response in the message only once. 1127 4.6. Message Size 1129 While specific link layers make it beneficial to keep CoAP messages 1130 small enough to fit into their link layer packets (see Section 1), 1131 this is a matter of implementation quality. The CoAP specification 1132 itself provides only an upper bound to the message size. Messages 1133 larger than an IP packet result in undesirable packet fragmentation. 1134 A CoAP message, appropriately encapsulated, SHOULD fit within a 1135 single IP packet (i.e., avoid IP fragmentation) and (by fitting into 1136 one UDP payload) obviously needs to fit within a single IP datagram. 1137 If the Path MTU is not known for a destination, an IP MTU of 1280 1138 bytes SHOULD be assumed; if nothing is known about the size of the 1139 headers, good upper bounds are 1152 bytes for the message size and 1140 1024 bytes for the payload size. 1142 Implementation Note: CoAP's choice of message size parameters works 1143 well with IPv6 and with most of today's IPv4 paths. (However, 1144 with IPv4, it is harder to absolutely ensure that there is no IP 1145 fragmentation. If IPv4 support on unusual networks is a 1146 consideration, implementations may want to limit themselves to 1147 more conservative IPv4 datagram sizes such as 576 bytes; worse, 1148 the absolute minimum value of the IP MTU for IPv4 is as low as 68 1149 bytes, which would leave only 40 bytes minus security overhead for 1150 a UDP payload. Implementations extremely focused on this problem 1151 set might also set the IPv4 DF bit and perform some form of path 1152 MTU discovery [RFC4821]; this should generally be unnecessary in 1153 most realistic use cases for CoAP, however.) A more important 1154 kind of fragmentation in many constrained networks is that on the 1155 adaptation layer (e.g., 6LoWPAN L2 packets are limited to 127 1156 bytes including various overheads); this may motivate 1157 implementations to be frugal in their packet sizes and to move to 1158 block-wise transfers [I-D.ietf-core-block] when approaching three- 1159 digit message sizes. 1161 Message sizes are also of considerable importance to 1162 implementations on constrained nodes. Many implementations will 1163 need to allocate a buffer for incoming messages. If an 1164 implementation is too constrained to allow for allocating the 1165 above-mentioned upper bound, it could apply the following 1166 implementation strategy for messages not using DTLS security: 1167 Implementations receiving a datagram into a buffer that is too 1168 small are usually able to determine if the trailing portion of a 1169 datagram was discarded and to retrieve the initial portion. So, 1170 if not all of the payload, at least the CoAP header and options 1171 are likely to fit within the buffer. A server can thus fully 1172 interpret a request and return a 4.13 (Request Entity Too Large, 1173 see Section 5.9.2.9) response code if the payload was truncated. 1174 A client sending an idempotent request and receiving a response 1175 larger than would fit in the buffer can repeat the request with a 1176 suitable value for the Block Option [I-D.ietf-core-block]. 1178 4.7. Congestion Control 1180 Basic congestion control for CoAP is provided by the exponential 1181 back-off mechanism in Section 4.2. 1183 In order not to cause congestion, Clients (including proxies) MUST 1184 strictly limit the number of simultaneous outstanding interactions 1185 that they maintain to a given server (including proxies) to NSTART. 1186 An outstanding interaction is either a CON for which an ACK has not 1187 yet been received but is still expected (message layer) or a request 1188 for which neither a response nor an Acknowledgment message has yet 1189 been received but is still expected (which may both occur at the same 1190 time, counting as one outstanding interaction). The default value of 1191 NSTART for this specification is 1. 1193 Further congestion control optimizations and considerations are 1194 expected in the future, which may for example provide automatic 1195 initialization of the CoAP transmission parameters defined in 1196 Section 4.8, and thus may allow a value for NSTART greater than one. 1198 A client stops expecting a response to a Confirmable request for 1199 which no acknowledgment message was received, after 1200 EXCHANGE_LIFETIME. The specific algorithm by which a client stops to 1201 "expect" a response to a Confirmable request that was acknowledged, 1202 or to a Non-confirmable request, is not defined. Unless this is 1203 modified by additional congestion control optimizations, it MUST be 1204 chosen in such a way that an endpoint does not exceed an average data 1205 rate of PROBING_RATE in sending to another endpoint that does not 1206 respond. 1208 Note: CoAP places the onus of congestion control mostly on the 1209 clients. However, clients may malfunction or actually be 1210 attackers, e.g. to perform amplification attacks (Section 11.3). 1211 To limit the damage (to the network and to its own energy 1212 resources), a server SHOULD implement some rate limiting for its 1213 response transmission based on reasonable assumptions about 1214 application requirements. This is most helpful if the rate limit 1215 can be made effective for the misbehaving endpoints, only. 1217 4.8. Transmission Parameters 1219 Message transmission is controlled by the following parameters: 1221 +-------------------+---------------+ 1222 | name | default value | 1223 +-------------------+---------------+ 1224 | ACK_TIMEOUT | 2 seconds | 1225 | ACK_RANDOM_FACTOR | 1.5 | 1226 | MAX_RETRANSMIT | 4 | 1227 | NSTART | 1 | 1228 | DEFAULT_LEISURE | 5 seconds | 1229 | PROBING_RATE | 1 Byte/second | 1230 +-------------------+---------------+ 1232 Table 2: CoAP Protocol Parameters 1234 4.8.1. Changing The Parameters 1236 The values for ACK_TIMEOUT, ACK_RANDOM_FACTOR, MAX_RETRANSMIT, 1237 NSTART, DEFAULT_LEISURE (Section 8.2), and PROBING_RATE may be 1238 configured to values specific to the application environment 1239 (including dynamically adjusted values), however the configuration 1240 method is out of scope of this document. It is RECOMMENDED that an 1241 application environment use consistent values for these parameters; 1242 the specific effects of operating with inconsistent values in an 1243 application environment are outside the scope of the present 1244 specification. 1246 The transmission parameters have been chosen to achieve a behavior in 1247 the presence of congestion that is safe in the Internet. If a 1248 configuration desires to use different values, the onus is on the 1249 configuration to ensure these congestion control properties are not 1250 violated. In particular, a decrease of ACK_TIMEOUT below 1 second 1251 would violate the guidelines of [RFC5405]. 1252 ([I-D.allman-tcpm-rto-consider] provides some additional background.) 1253 CoAP was designed to enable implementations that do not maintain 1254 round-trip-time (RTT) measurements. However, where it is desired to 1255 decrease the ACK_TIMEOUT significantly or increase NSTART, this can 1256 only be done safely when maintaining such measurements. 1257 Configurations MUST NOT decrease ACK_TIMEOUT or increase NSTART 1258 without using mechanisms that ensure congestion control safety, 1259 either defined in the configuration or in future standards documents. 1261 ACK_RANDOM_FACTOR MUST NOT be decreased below 1.0, and it SHOULD have 1262 a value that is sufficiently different from 1.0 to provide some 1263 protection from synchronization effects. 1265 MAX_RETRANSMIT can be freely adjusted, but a too small value will 1266 reduce the probability that a Confirmable message is actually 1267 received, while a larger value than given here will require further 1268 adjustments in the time values (see Section 4.8.2). 1270 If the choice of transmission parameters leads to an increase of 1271 derived time values (see Section 4.8.2), the configuration mechanism 1272 MUST ensure the adjusted value is also available to all the endpoints 1273 that these adjusted values are to be used to communicate with. 1275 4.8.2. Time Values derived from Transmission Parameters 1277 The combination of ACK_TIMEOUT, ACK_RANDOM_FACTOR and MAX_RETRANSMIT 1278 influences the timing of retransmissions, which in turn influences 1279 how long certain information items need to be kept by an 1280 implementation. To be able to unambiguously reference these derived 1281 time values, we give them names as follows: 1283 o MAX_TRANSMIT_SPAN is the maximum time from the first transmission 1284 of a Confirmable message to its last retransmission. For the 1285 default transmission parameters, the value is (2+4+8+16)*1.5 = 45 1286 seconds, or more generally: 1288 ACK_TIMEOUT * ((2 ** MAX_RETRANSMIT) - 1) * ACK_RANDOM_FACTOR 1290 o MAX_TRANSMIT_WAIT is the maximum time from the first transmission 1291 of a Confirmable message to the time when the sender gives up on 1292 receiving an acknowledgement or reset. For the default 1293 transmission parameters, the value is (2+4+8+16+32)*1.5 = 93 1294 seconds, or more generally: 1296 ACK_TIMEOUT * ((2 ** (MAX_RETRANSMIT + 1)) - 1) * 1297 ACK_RANDOM_FACTOR 1299 In addition, some assumptions need to be made on the characteristics 1300 of the network and the nodes. 1302 o MAX_LATENCY is the maximum time a datagram is expected to take 1303 from the start of its transmission to the completion of its 1304 reception. This constant is related to the MSL (Maximum Segment 1305 Lifetime) of [RFC0793], which is "arbitrarily defined to be 2 1306 minutes" ([RFC0793] glossary, page 81). Note that this is not 1307 necessarily smaller than MAX_TRANSMIT_WAIT, as MAX_LATENCY is not 1308 intended to describe a situation when the protocol works well, but 1309 the worst case situation against which the protocol has to guard. 1310 We, also arbitrarily, define MAX_LATENCY to be 100 seconds. Apart 1311 from being reasonably realistic for the bulk of configurations as 1312 well as close to the historic choice for TCP, this value also 1313 allows Message ID lifetime timers to be represented in 8 bits 1314 (when measured in seconds). In these calculations, there is no 1315 assumption that the direction of the transmission is irrelevant 1316 (i.e. that the network is symmetric), just that the same value can 1317 reasonably be used as a maximum value for both directions. If 1318 that is not the case, the following calculations become only 1319 slightly more complex. 1321 o PROCESSING_DELAY is the time a node takes to turn around a 1322 Confirmable message into an acknowledgement. We assume the node 1323 will attempt to send an ACK before having the sender time out, so 1324 as a conservative assumption we set it equal to ACK_TIMEOUT. 1326 o MAX_RTT is the maximum round-trip time, or: 1328 (2 * MAX_LATENCY) + PROCESSING_DELAY 1330 From these values, we can derive the following values relevant to the 1331 protocol operation: 1333 o EXCHANGE_LIFETIME is the time from starting to send a Confirmable 1334 message to the time when an acknowledgement is no longer expected, 1335 i.e. message layer information about the message exchange can be 1336 purged. EXCHANGE_LIFETIME includes a MAX_TRANSMIT_SPAN, a 1337 MAX_LATENCY forward, PROCESSING_DELAY, and a MAX_LATENCY for the 1338 way back. Note that there is no need to consider 1339 MAX_TRANSMIT_WAIT if the configuration is chosen such that the 1340 last waiting period (ACK_TIMEOUT * (2 ** MAX_RETRANSMIT) or the 1341 difference between MAX_TRANSMIT_SPAN and MAX_TRANSMIT_WAIT) is 1342 less than MAX_LATENCY -- which is a likely choice, as MAX_LATENCY 1343 is a worst case value unlikely to be met in the real world. In 1344 this case, EXCHANGE_LIFETIME simplifies to: 1346 MAX_TRANSMIT_SPAN + (2 * MAX_LATENCY) + PROCESSING_DELAY 1348 or 247 seconds with the default transmission parameters. 1350 o NON_LIFETIME is the time from sending a Non-confirmable message to 1351 the time its Message ID can be safely reused. If multiple 1352 transmission of a NON message is not used, its value is 1353 MAX_LATENCY, or 100 seconds. However, a CoAP sender might send a 1354 NON message multiple times, in particular for multicast 1355 applications. While the period of re-use is not bounded by the 1356 specification, an expectation of reliable detection of duplication 1357 at the receiver is in the timescales of MAX_TRANSMIT_SPAN. 1358 Therefore, for this purpose, it is safer to use the value: 1360 MAX_TRANSMIT_SPAN + MAX_LATENCY 1362 or 145 seconds with the default transmission parameters; however, 1363 an implementation that just wants to use a single timeout value 1364 for retiring Message IDs can safely use the larger value for 1365 EXCHANGE_LIFETIME. 1367 Table 3 summarizes the derived parameters introduced in this 1368 subsection with their default values. 1370 +-------------------+---------------+ 1371 | name | default value | 1372 +-------------------+---------------+ 1373 | MAX_TRANSMIT_SPAN | 45 s | 1374 | MAX_TRANSMIT_WAIT | 93 s | 1375 | MAX_LATENCY | 100 s | 1376 | PROCESSING_DELAY | 2 s | 1377 | MAX_RTT | 202 s | 1378 | EXCHANGE_LIFETIME | 247 s | 1379 | NON_LIFETIME | 145 s | 1380 +-------------------+---------------+ 1382 Table 3: Derived Protocol Parameters 1384 5. Request/Response Semantics 1386 CoAP operates under a similar request/response model as HTTP: a CoAP 1387 endpoint in the role of a "client" sends one or more CoAP requests to 1388 a "server", which services the requests by sending CoAP responses. 1389 Unlike HTTP, requests and responses are not sent over a previously 1390 established connection, but exchanged asynchronously over CoAP 1391 messages. 1393 5.1. Requests 1395 A CoAP request consists of the method to be applied to the resource, 1396 the identifier of the resource, a payload and Internet media type (if 1397 any), and optional meta-data about the request. 1399 CoAP supports the basic methods of GET, POST, PUT, DELETE, which are 1400 easily mapped to HTTP. They have the same properties of safe (only 1401 retrieval) and idempotent (you can invoke it multiple times with the 1402 same effects) as HTTP (see Section 9.1 of [RFC2616]). The GET method 1403 is safe, therefore it MUST NOT take any other action on a resource 1404 other than retrieval. The GET, PUT and DELETE methods MUST be 1405 performed in such a way that they are idempotent. POST is not 1406 idempotent, because its effect is determined by the origin server and 1407 dependent on the target resource; it usually results in a new 1408 resource being created or the target resource being updated. 1410 A request is initiated by setting the Code field in the CoAP header 1411 of a Confirmable or a Non-confirmable message to a Method Code and 1412 including request information. 1414 The methods used in requests are described in detail in Section 5.8. 1416 5.2. Responses 1418 After receiving and interpreting a request, a server responds with a 1419 CoAP response, which is matched to the request by means of a client- 1420 generated token (Section 5.3, note that this is different from the 1421 Message ID that matches a Confirmable message to its 1422 Acknowledgement). 1424 A response is identified by the Code field in the CoAP header being 1425 set to a Response Code. Similar to the HTTP Status Code, the CoAP 1426 Response Code indicates the result of the attempt to understand and 1427 satisfy the request. These codes are fully defined in Section 5.9. 1428 The Response Code numbers to be set in the Code field of the CoAP 1429 header are maintained in the CoAP Response Code Registry 1430 (Section 12.1.2). 1432 0 1433 0 1 2 3 4 5 6 7 1434 +-+-+-+-+-+-+-+-+ 1435 |class| detail | 1436 +-+-+-+-+-+-+-+-+ 1438 Figure 9: Structure of a Response Code 1440 The upper three bits of the 8-bit Response Code number define the 1441 class of response. The lower five bits do not have any 1442 categorization role; they give additional detail to the overall class 1443 (Figure 9). 1445 As a human readable notation for specifications and protocol 1446 diagnostics, CoAP code numbers including the response code are 1447 documented in the format "c.dd", where "c" is the class in decimal, 1448 and "dd" is the detail as a two-digit decimal. For example, 1449 "Forbidden" is written as 4.03 -- indicating an 8-bit code value of 1450 hexadecimal 0x83 (4*0x20+3) or decimal 131 (4*32+3). 1452 There are 3 classes of response codes: 1454 2 - Success: The request was successfully received, understood, and 1455 accepted. 1457 4 - Client Error: The request contains bad syntax or cannot be 1458 fulfilled. 1460 5 - Server Error: The server failed to fulfill an apparently valid 1461 request. 1463 The response codes are designed to be extensible: Response Codes in 1464 the Client Error and Server Error class that are unrecognized by an 1465 endpoint are treated as being equivalent to the generic Response Code 1466 of that class (4.00 and 5.00, respectively). However, there is no 1467 generic Response Code indicating success, so a Response Code in the 1468 Success class that is unrecognized by an endpoint can only be used to 1469 determine that the request was successful without any further 1470 details. 1472 The possible response codes are described in detail in Section 5.9. 1474 Responses can be sent in multiple ways, which are defined in the 1475 following subsections. 1477 5.2.1. Piggy-backed 1479 In the most basic case, the response is carried directly in the 1480 Acknowledgement message that acknowledges the request (which requires 1481 that the request was carried in a Confirmable message). This is 1482 called a "Piggy-backed" Response. 1484 The response is returned in the Acknowledgement message independent 1485 of whether the response indicates success or failure. In effect, the 1486 response is piggy-backed on the Acknowledgement message, and no 1487 separate message is required to return the response. 1489 Implementation Note: The protocol leaves the decision whether to 1490 piggy-back a response or not (i.e., send a separate response) to 1491 the server. The client MUST be prepared to receive either. On 1492 the quality of implementation level, there is a strong expectation 1493 that servers will implement code to piggy-back whenever possible 1494 -- saving resources in the network and both at the client and at 1495 the server. 1497 5.2.2. Separate 1499 It may not be possible to return a piggy-backed response in all 1500 cases. For example, a server might need longer to obtain the 1501 representation of the resource requested than it can wait sending 1502 back the Acknowledgement message, without risking the client to 1503 repeatedly retransmit the request message (see also the discussion of 1504 PROCESSING_DELAY in Section 4.8.2). The Response to a request 1505 carried in a Non-confirmable message is always sent separately (as 1506 there is no Acknowledgement message). 1508 One way to implement this in a server is to initiate the attempt to 1509 obtain the resource representation and, while that is in progress, 1510 time out an acknowledgement timer. A server may also immediately 1511 send an acknowledgement knowing in advance that there will be no 1512 piggy-backed response. In both cases, the acknowledgement 1513 effectively is a promise that the request will be acted upon later. 1515 When the server finally has obtained the resource representation, it 1516 sends the response. When it is desired that this message is not 1517 lost, it is sent as a Confirmable message from the server to the 1518 client and answered by the client with an Acknowledgement, echoing 1519 the new Message ID chosen by the server. (It may also be sent as a 1520 Non-confirmable message; see Section 5.2.3.) 1522 When the server chooses to use a separate response, it sends the 1523 Acknowledgement to the Confirmable request as an empty message. Once 1524 the server sends back an empty Acknowledgement, it MUST NOT send back 1525 the response in another Acknowledgement, even if the client 1526 retransmits another identical request. If a retransmitted request is 1527 received (perhaps because the original Acknowledgement was delayed), 1528 another empty Acknowledgement is sent and any response MUST be sent 1529 as a separate response. 1531 If the server then sends a Confirmable response, the client's 1532 Acknowledgement to that response MUST also be an empty message (one 1533 that carries neither a request nor a response). The server MUST stop 1534 retransmitting its response on any matching Acknowledgement (silently 1535 ignoring any response code or payload) or Reset message. 1537 Implementation Notes: Note that, as the underlying datagram 1538 transport may not be sequence-preserving, the Confirmable message 1539 carrying the response may actually arrive before or after the 1540 Acknowledgement message for the request; for the purposes of 1541 terminating the retransmission sequence, this also serves as an 1542 acknowledgement. Note also that, while the CoAP protocol itself 1543 does not make any specific demands here, there is an expectation 1544 that the response will come within a time frame that is reasonable 1545 from an application point of view; as there is no underlying 1546 transport protocol that could be instructed to run a keep-alive 1547 mechanism, the requester may want to set up a timeout that is 1548 unrelated to CoAP's retransmission timers in case the server is 1549 destroyed or otherwise unable to send the response.) 1551 5.2.3. Non-confirmable 1553 If the request message is Non-confirmable, then the response SHOULD 1554 be returned in a Non-confirmable message as well. However, an 1555 endpoint MUST be prepared to receive a Non-confirmable response 1556 (preceded or followed by an empty Acknowledgement message) in reply 1557 to a Confirmable request, or a Confirmable response in reply to a 1558 Non-confirmable request. 1560 5.3. Request/Response Matching 1562 Regardless of how a response is sent, it is matched to the request by 1563 means of a token that is included by the client in the request, along 1564 with additional address information of the corresponding endpoint. 1566 5.3.1. Token 1568 The Token is used to match a response with a request. The token 1569 value is a sequence of 0 to 8 bytes. (Note that every message 1570 carries a token, even if it is of zero length.) Every request 1571 carries a client-generated token, which the server MUST echo in any 1572 resulting response without modification. 1574 A token is intended for use as a client-local identifier for 1575 differentiating between concurrent requests (see Section 5.3); it 1576 could have been called a "request ID". 1578 The client SHOULD generate tokens in such a way that tokens currently 1579 in use for a given source/destination endpoint pair are unique. 1580 (Note that a client implementation can use the same token for any 1581 request if it uses a different endpoint each time, e.g. a different 1582 source port number.) An empty token value is appropriate e.g. when 1583 no other tokens are in use to a destination, or when requests are 1584 made serially per destination and receive piggy-backed responses. 1585 There are however multiple possible implementation strategies to 1586 fulfill this. 1588 A client sending a request without using transport layer security 1589 (Section 9) SHOULD use a non-trivial, randomized token to guard 1590 against spoofing of responses (Section 11.4). This protective use of 1591 tokens is the reason they are allowed to be up to 8 bytes in size. 1592 The actual size of the random component to be used for the Token 1593 depends on the security requirements of the client and the level of 1594 threat posed by spoofing of responses. A client that is connected to 1595 the general Internet SHOULD use at least 32 bits of randomness; 1596 keeping in mind that not being directly connected to the Internet is 1597 not necessarily sufficient protection against spoofing. (Note that 1598 the Message ID adds little in protection as it is usually 1599 sequentially assigned, i.e. guessable, and can be circumvented by 1600 spoofing a separate response.) Clients that want to optimize the 1601 Token length may further want to detect the level of ongoing attacks 1602 (e.g., by tallying recent Token mismatches in incoming messages) and 1603 adjust the Token length upwards appropriately. [RFC4086] discusses 1604 randomness requirements for security. 1606 An endpoint receiving a token it did not generate MUST treat it as 1607 opaque and make no assumptions about its content or structure. 1609 5.3.2. Request/Response Matching Rules 1611 The exact rules for matching a response to a request are as follows: 1613 1. The source endpoint of the response MUST be the same as the 1614 destination endpoint of the original request. 1616 2. In a piggy-backed response, both the Message ID of the 1617 Confirmable request and the Acknowledgement, and the token of the 1618 response and original request MUST match. In a separate 1619 response, just the token of the response and original request 1620 MUST match. 1622 In case a message carrying a response is unexpected (the client is 1623 not waiting for a response from the identified endpoint, at the 1624 endpoint addressed, and/or with the given token), the response is 1625 rejected (Section 4.2, Section 4.3). 1627 Implementation Note: A client that receives a response in a CON 1628 message may want to clean up the message state right after sending 1629 the ACK. If that ACK is lost and the server retransmits the CON, 1630 the client may no longer have any state to correlate this response 1631 to, making the retransmission an unexpected message; the client 1632 will likely send a Reset message so it does not receive any more 1633 retransmissions. This behavior is normal and not an indication of 1634 an error. (Clients that are not aggressively optimized in their 1635 state memory usage will still have message state that will 1636 identify the second CON as a retransmission. Clients that 1637 actually expect more messages from the server 1638 [I-D.ietf-core-observe] will have to keep state in any case.) 1640 5.4. Options 1642 Both requests and responses may include a list of one or more 1643 options. For example, the URI in a request is transported in several 1644 options, and meta-data that would be carried in an HTTP header in 1645 HTTP is supplied as options as well. 1647 CoAP defines a single set of options that are used in both requests 1648 and responses: 1650 o Content-Format 1652 o ETag 1654 o Location-Path 1656 o Location-Query 1658 o Max-Age 1660 o Proxy-Uri 1662 o Proxy-Scheme 1664 o Uri-Host 1666 o Uri-Path 1668 o Uri-Port 1670 o Uri-Query 1672 o Accept 1674 o If-Match 1676 o If-None-Match 1678 The semantics of these options along with their properties are 1679 defined in detail in Section 5.10. 1681 Not all options are defined for use with all methods and response 1682 codes. The possible options for methods and response codes are 1683 defined in Section 5.8 and Section 5.9 respectively. In case an 1684 option is not defined for a method or response code, it MUST NOT be 1685 included by a sender and MUST be treated like an unrecognized option 1686 by a recipient. 1688 5.4.1. Critical/Elective 1690 Options fall into one of two classes: "critical" or "elective". The 1691 difference between these is how an option unrecognized by an endpoint 1692 is handled: 1694 o Upon reception, unrecognized options of class "elective" MUST be 1695 silently ignored. 1697 o Unrecognized options of class "critical" that occur in a 1698 Confirmable request MUST cause the return of a 4.02 (Bad Option) 1699 response. This response SHOULD include a diagnostic payload 1700 describing the unrecognized option(s) (see Section 5.5.2). 1702 o Unrecognized options of class "critical" that occur in a 1703 Confirmable response, or piggy-backed in an Acknowledgement, MUST 1704 cause the response to be rejected (Section 4.2). 1706 o Unrecognized options of class "critical" that occur in a Non- 1707 confirmable message MUST cause the message to be rejected 1708 (Section 4.3). 1710 Note that, whether critical or elective, an option is never 1711 "mandatory" (it is always optional): These rules are defined in order 1712 to enable implementations to stop processing options they do not 1713 understand or implement. 1715 Critical/Elective rules apply to non-proxying endpoints. A proxy 1716 processes options based on Unsafe/Safe-to-Forward classes as defined 1717 in Section 5.7. 1719 5.4.2. Proxy Unsafe/Safe-to-Forward and NoCacheKey 1721 In addition to an option being marked as Critical or Elective, 1722 options are also classified based on how a proxy is to deal with the 1723 option if it does not recognize it. For this purpose, an option can 1724 either be considered Unsafe to Forward (UnSafe is set) or Safe-to- 1725 Forward (UnSafe is clear). 1727 In addition, for an option that is marked Safe-to-Forward, the option 1728 number indicates whether it is intended to be part of the Cache-Key 1729 (Section 5.6) in a request or not; if some of the NoCacheKey bits are 1730 0, it is, if all NoCacheKey bits are 1, it is not (see 1731 Section 5.4.6). 1733 Note: The Cache-Key indication is relevant only for proxies that do 1734 not implement the given option as a request option and instead 1735 rely on the Unsafe/Safe-to-Forward indication only. E.g., for 1736 ETag, actually using the request option as a part of the Cache-Key 1737 is grossly inefficient, but it is the best thing one can do if 1738 ETag is not implemented by a proxy, as the response is going to 1739 differ based on the presence of the request option. A more useful 1740 proxy that does implement the ETag request option is not using 1741 ETag as a part of the Cache-Key. 1743 NoCacheKey is indicated in three bits so that only one out of 1744 eight codepoints is qualified as NoCacheKey, assuming this is the 1745 less likely case. 1747 Proxy behavior with regard to these classes is defined in 1748 Section 5.7. 1750 5.4.3. Length 1752 Option values are defined to have a specific length, often in the 1753 form of an upper and lower bound. If the length of an option value 1754 in a request is outside the defined range, that option MUST be 1755 treated like an unrecognized option (see Section 5.4.1). 1757 5.4.4. Default Values 1759 Options may be defined to have a default value. If the value of 1760 option is intended to be this default value, the option SHOULD NOT be 1761 included in the message. If the option is not present, the default 1762 value MUST be assumed. 1764 Where a critical option has a default value, this is chosen in such a 1765 way that the absence of the option in a message can be processed 1766 properly both by implementations unaware of the critical option and 1767 by implementations that interpret this absence as the presence of the 1768 default value for the option. 1770 5.4.5. Repeatable Options 1772 The definition of some options specifies that those options are 1773 repeatable. An option that is repeatable MAY be included one or more 1774 times in a message. An option that is not repeatable MUST NOT be 1775 included more than once in a message. 1777 If a message includes an option with more occurrences than the option 1778 is defined for, each supernumerary option occurrence that appears 1779 subsequently in the message MUST be treated like an unrecognized 1780 option (see Section 5.4.1). 1782 5.4.6. Option Numbers 1784 An Option is identified by an option number, which also provides some 1785 additional semantics information: e.g., odd numbers indicate a 1786 critical option, while even numbers indicate an elective option. 1787 Note that this is not just a convention, it is a feature of the 1788 protocol: Whether an option is elective or critical is entirely 1789 determined by whether its option number is even or odd. 1791 More generally speaking, an Option number is constructed with a bit 1792 mask to indicate if an option is Critical/Elective, Unsafe/ 1793 Safe-to-Forward and in the case of Safe-to-Forward, also a Cache-Key 1794 indication as shown by the following figure. In the following text, 1795 the bit mask is expressed as a single byte that is applied to the 1796 least significant byte of the option number in unsigned integer 1797 representation. When bit 7 (the least significant bit) is 1, an 1798 option is Critical (and likewise Elective when 0). When bit 6 is 1, 1799 an option is Unsafe (and likewise Safe-to-Forward when 0). When bit 1800 6 is 0, i.e., the option is not Unsafe, it is not a Cache-Key 1801 (NoCacheKey) if and only if bits 3-5 are all set to 1; all other bit 1802 combinations mean that it indeed is a Cache-Key. These classes of 1803 options are explained in the next sections. 1805 0 1 2 3 4 5 6 7 1806 +---+---+---+---+---+---+---+---+ 1807 | | NoCacheKey| U | C | 1808 +---+---+---+---+---+---+---+---+ 1810 Figure 10: Option Number Mask (Least Significant Byte) 1812 An endpoint may use an equivalent of the C code in Figure 11 to 1813 derive the characteristics of an option number "onum". 1815 Critical = (onum & 1); 1816 UnSafe = (onum & 2); 1817 NoCacheKey = ((onum & 0x1e) == 0x1c); 1819 Figure 11: Determining Characteristics from an Option Number 1821 The option numbers for the options defined in this document are 1822 listed in the CoAP Option Number Registry (Section 12.2). 1824 5.5. Payloads and Representations 1826 Both requests and responses may include a payload, depending on the 1827 method or response code respectively. If a method or response code 1828 is not defined to have a payload, then a sender MUST NOT include one, 1829 and a recipient MUST ignore it. 1831 5.5.1. Representation 1833 The payload of requests or of responses indicating success is 1834 typically a representation of a resource ("resource representation") 1835 or the result of the requested action ("action result"). Its format 1836 is specified by the Internet media type and content coding given by 1837 the Content-Format Option. In the absence of this option, no default 1838 value is assumed and the format will need to be inferred by the 1839 application (e.g., from the application context). Payload "sniffing" 1840 SHOULD only be attempted if no content type is given. 1842 Implementation Note: On a quality of implementation level, there is 1843 a strong expectation that a Content-Format indication will be 1844 provided with resource representations whenever possible. This is 1845 not a "SHOULD"-level requirement solely because it is not a 1846 protocol requirement, and it also would be difficult to outline 1847 exactly in what cases this expectation can be violated. 1849 For responses indicating a client or server error, the payload is 1850 considered a representation of the result of the requested action 1851 only if a Content-Format Option is given. In the absence of this 1852 option, the payload is a Diagnostic Payload (Section 5.5.2). 1854 5.5.2. Diagnostic Payload 1856 If no Content-Format option is given, the payload of responses 1857 indicating a client or server error is a brief human-readable 1858 diagnostic message, explaining the error situation. This diagnostic 1859 message MUST be encoded using UTF-8 [RFC3629], more specifically 1860 using Net-Unicode form [RFC5198]. 1862 The message is similar to the Reason-Phrase on an HTTP status line. 1863 It is not intended for end-users but for software engineers that 1864 during debugging need to interpret it in the context of the present, 1865 English-language specification; therefore no mechanism for language 1866 tagging is needed or provided. In contrast to what is usual in HTTP, 1867 the payload SHOULD be empty if there is no additional information 1868 beyond the response code. 1870 5.5.3. Selected Representation 1872 Not all responses carry a payload that provides a representation of 1873 the resource addressed by the request. It is, however, sometimes 1874 useful to be able to refer to such a representation in relation to a 1875 response, independent of whether it actually was enclosed. 1877 We use the term "selected representation" to refer to the current 1878 representation of a target resource that would have been selected in 1879 a successful response if the corresponding request had used the 1880 method GET and excluded any conditional request options 1881 (Section 5.10.8). 1883 Certain response options provide metadata about the selected 1884 representation, which might differ from the representation included 1885 in the message for responses to some state-changing methods. Of the 1886 response options defined in this specification, only the ETag 1887 response option (Section 5.10.6) is defined as selected 1888 representation metadata. 1890 5.5.4. Content Negotiation 1892 A server may be able to supply a representation for a resource in one 1893 of multiple representation formats. Without further information from 1894 the client, it will provide the representation in the format it 1895 prefers. 1897 By using the Accept Option (Section 5.10.4) in a request, the client 1898 can indicate which content-format it prefers to receive. 1900 5.6. Caching 1902 CoAP endpoints MAY cache responses in order to reduce the response 1903 time and network bandwidth consumption on future, equivalent 1904 requests. 1906 The goal of caching in CoAP is to reuse a prior response message to 1907 satisfy a current request. In some cases, a stored response can be 1908 reused without the need for a network request, reducing latency and 1909 network round-trips; a "freshness" mechanism is used for this purpose 1910 (see Section 5.6.1). Even when a new request is required, it is 1911 often possible to reuse the payload of a prior response to satisfy 1912 the request, thereby reducing network bandwidth usage; a "validation" 1913 mechanism is used for this purpose (see Section 5.6.2). 1915 Unlike HTTP, the cacheability of CoAP responses does not depend on 1916 the request method, but the Response Code. The cacheability of each 1917 Response Code is defined along the Response Code definitions in 1918 Section 5.9. Response Codes that indicate success and are 1919 unrecognized by an endpoint MUST NOT be cached. 1921 For a presented request, a CoAP endpoint MUST NOT use a stored 1922 response, unless: 1924 o the presented request method and that used to obtain the stored 1925 response match, 1927 o all options match between those in the presented request and those 1928 of the request used to obtain the stored response (which includes 1929 the request URI), except that there is no need for a match of any 1930 request options marked as NoCacheKey (Section 5.4) or recognized 1931 by the Cache and fully interpreted with respect to its specified 1932 cache behavior (such as the ETag request option, Section 5.10.6, 1933 see also Section 5.4.2), and 1935 o the stored response is either fresh or successfully validated as 1936 defined below. 1938 The set of request options that is used for matching the cache entry 1939 is also collectively referred to as the "Cache-Key". For URI schemes 1940 other than coap and coaps, matching of those options that constitute 1941 the request URI may be performed under rules specific to the URI 1942 scheme. 1944 5.6.1. Freshness Model 1946 When a response is "fresh" in the cache, it can be used to satisfy 1947 subsequent requests without contacting the origin server, thereby 1948 improving efficiency. 1950 The mechanism for determining freshness is for an origin server to 1951 provide an explicit expiration time in the future, using the Max-Age 1952 Option (see Section 5.10.5). The Max-Age Option indicates that the 1953 response is to be considered not fresh after its age is greater than 1954 the specified number of seconds. 1956 The Max-Age Option defaults to a value of 60. Thus, if it is not 1957 present in a cacheable response, then the response is considered not 1958 fresh after its age is greater than 60 seconds. If an origin server 1959 wishes to prevent caching, it MUST explicitly include a Max-Age 1960 Option with a value of zero seconds. 1962 If a client has a fresh stored response and makes a new request 1963 matching the request for that stored response, the new response 1964 invalidates the old response. 1966 5.6.2. Validation Model 1968 When an endpoint has one or more stored responses for a GET request, 1969 but cannot use any of them (e.g., because they are not fresh), it can 1970 use the ETag Option (Section 5.10.6) in the GET request to give the 1971 origin server an opportunity to both select a stored response to be 1972 used, and to update its freshness. This process is known as 1973 "validating" or "revalidating" the stored response. 1975 When sending such a request, the endpoint SHOULD add an ETag Option 1976 specifying the entity-tag of each stored response that is applicable. 1978 A 2.03 (Valid) response indicates the stored response identified by 1979 the entity-tag given in the response's ETag Option can be reused, 1980 after updating it as described in Section 5.9.1.3. 1982 Any other response code indicates that none of the stored responses 1983 nominated in the request is suitable. Instead, the response SHOULD 1984 be used to satisfy the request and MAY replace the stored response. 1986 5.7. Proxying 1988 A proxy is a CoAP endpoint that can be tasked by CoAP clients to 1989 perform requests on their behalf. This may be useful, for example, 1990 when the request could otherwise not be made, or to service the 1991 response from a cache in order to reduce response time and network 1992 bandwidth or energy consumption. 1994 In an overall architecture for a Constrained RESTful Environment, 1995 proxies can serve quite different purposes. Proxies can be 1996 explicitly selected by clients, a role that we term "forward-proxy". 1997 Proxies can also be inserted to stand in for origin servers, a role 1998 that we term "reverse-proxy". Orthogonal to this distinction, a 1999 proxy can map from a CoAP request to a CoAP request (CoAP-to-CoAP 2000 proxy) or translate from or to a different protocol ("cross-proxy"). 2001 Full definitions of these terms are provided in Section 1.2. 2003 Notes: The terminology in this specification has been selected to be 2004 culturally compatible with the terminology used in the wider Web 2005 application environments, without necessarily matching it in every 2006 detail (which may not even be relevant to Constrained RESTful 2007 Environments). Not too much semantics should be ascribed to the 2008 components of the terms (such as "forward", "reverse", or 2009 "cross"). 2011 HTTP proxies, besides acting as HTTP proxies, often offer a 2012 transport protocol proxying function ("CONNECT") to enable end-to- 2013 end transport layer security through the proxy. No such function 2014 is defined for CoAP-to-CoAP proxies in this specification, as 2015 forwarding of UDP packets is unlikely to be of much value in 2016 Constrained RESTful environments. See also Section 10.2.7 for the 2017 cross-proxy case. 2019 When a client uses a proxy to make a request that will use a secure 2020 URI scheme (e.g., coaps or https), the request towards the proxy 2021 SHOULD be sent using DTLS security except where equivalent lower 2022 layer security is used for the leg between the client and the proxy. 2024 5.7.1. Proxy Operation 2026 A proxy generally needs a way to determine potential request 2027 parameters for a request to a destination based on the request it 2028 received. This way is fully specified for a forward-proxy, but may 2029 depend on the specific configuration for a reverse-proxy. In 2030 particular, the client of a reverse-proxy generally does not indicate 2031 a locator for the destination, necessitating some form of namespace 2032 translation in the reverse-proxy. However, some aspects of the 2033 operation of proxies are common to all its forms. 2035 If a proxy does not employ a cache, then it simply forwards the 2036 translated request to the determined destination. Otherwise, if it 2037 does employ a cache but does not have a stored response that matches 2038 the translated request and is considered fresh, then it needs to 2039 refresh its cache according to Section 5.6. For options in the 2040 request that the proxy recognizes, it knows whether the option is 2041 intended to act as part of the key used in looking up the cached 2042 value or not. E.g., since requests for different Uri-Path values 2043 address different resources, Uri-Path values are always part of the 2044 Cache-Key, while, e.g., Token values are never part of the Cache-Key. 2045 For options that the proxy does not recognize but that are marked 2046 Safe-to-Forward in the option number, the option also indicates 2047 whether it is to be included in the Cache-Key (NoCacheKey is not all 2048 set) or not (NoCacheKey is all set). (Options that are unrecognized 2049 and marked Unsafe lead to 4.02 Bad Option.) 2051 If the request to the destination times out, then a 5.04 (Gateway 2052 Timeout) response MUST be returned. If the request to the 2053 destination returns a response that cannot be processed by the proxy 2054 (e.g, due to unrecognized critical options, message format errors), 2055 then a 5.02 (Bad Gateway) response MUST be returned. Otherwise, the 2056 proxy returns the response to the client. 2058 If a response is generated out of a cache, the generated (or implied) 2059 Max-Age Option MUST NOT extend the max-age originally set by the 2060 server, considering the time the resource representation spent in the 2061 cache. E.g., the Max-Age Option could be adjusted by the proxy for 2062 each response using the formula: 2064 proxy-max-age = original-max-age - cache-age 2066 For example if a request is made to a proxied resource that was 2067 refreshed 20 seconds ago and had an original Max-Age of 60 seconds, 2068 then that resource's proxied max-age is now 40 seconds. Considering 2069 potential network delays on the way from the origin server, a proxy 2070 SHOULD be conservative in the max-age values offered. 2072 All options present in a proxy request MUST be processed at the 2073 proxy. Unsafe options in a request that are not recognized by the 2074 proxy MUST lead to a 4.02 (Bad Option) response being returned by the 2075 proxy. A CoAP-to-CoAP proxy MUST forward to the origin server all 2076 Safe-to-Forward options that it does not recognize. Similarly, 2077 Unsafe options in a response that are not recognized by the CoAP-to- 2078 CoAP proxy server MUST lead to a 5.02 (Bad Gateway) response. Again, 2079 Safe-to-Forward options that are not recognized MUST be forwarded. 2081 Additional considerations for cross-protocol proxying between CoAP 2082 and HTTP are discussed in Section 10. 2084 5.7.2. Forward-Proxies 2086 CoAP distinguishes between requests made (as if) to an origin server 2087 and a request made through a forward-proxy. CoAP requests to a 2088 forward-proxy are made as normal Confirmable or Non-confirmable 2089 requests to the forward-proxy endpoint, but specify the request URI 2090 in a different way: The request URI in a proxy request is specified 2091 as a string in the Proxy-Uri Option (see Section 5.10.2), while the 2092 request URI in a request to an origin server is split into the Uri- 2093 Host, Uri-Port, Uri-Path and Uri-Query Options (see Section 5.10.1); 2094 alternatively the URI in a proxy request can be assembled from a 2095 Proxy-Scheme option and the split options mentioned. 2097 When a proxy request is made to an endpoint and the endpoint is 2098 unwilling or unable to act as proxy for the request URI, it MUST 2099 return a 5.05 (Proxying Not Supported) response. If the authority 2100 (host and port) is recognized as identifying the proxy endpoint 2101 itself (see Section 5.10.2), then the request MUST be treated as a 2102 local (non-proxied) request. 2104 Unless a proxy is configured to forward the proxy request to another 2105 proxy, it MUST translate the request as follows: The scheme of the 2106 request URI defines the outgoing protocol and its details (e.g., CoAP 2107 is used over UDP for the "coap" scheme and over DTLS for the "coaps" 2108 scheme.) For a CoAP-to-CoAP proxy, the origin server's IP address 2109 and port are determined by the authority component of the request 2110 URI, and the request URI is decoded and split into the Uri-Host, Uri- 2111 Port, Uri-Path and Uri-Query Options. This consumes the Proxy-Uri or 2112 Proxy-Scheme option, which is therefore not forwarded to the origin 2113 server. 2115 5.7.3. Reverse-Proxies 2117 Reverse-proxies do not make use of the Proxy-Uri or Proxy-Scheme 2118 options, but need to determine the destination (next hop) of a 2119 request from information in the request and information in their 2120 configuration. E.g., a reverse-proxy might offer various resources 2121 the existence of which it has learned through resource discovery as 2122 if they were its own resources. The reverse-proxy is free to build a 2123 namespace for the URIs that identify these resources. A reverse- 2124 proxy may also build a namespace that gives the client more control 2125 over where the request goes, e.g. by embedding host identifiers and 2126 port numbers into the URI path of the resources offered. 2128 In processing the response, a reverse-proxy has to be careful that 2129 ETag option values from different sources are not mixed up on one 2130 resource offered to its clients. In many cases, the ETag can be 2131 forwarded unchanged. If the mapping from a resource offered by the 2132 reverse-proxy to resources offered by its various origin servers is 2133 not unique, the reverse-proxy may need to generate a new ETag, making 2134 sure the semantics of this option are properly preserved. 2136 5.8. Method Definitions 2138 In this section each method is defined along with its behavior. A 2139 request with an unrecognized or unsupported Method Code MUST generate 2140 a 4.05 (Method Not Allowed) piggy-backed response. 2142 5.8.1. GET 2144 The GET method retrieves a representation for the information that 2145 currently corresponds to the resource identified by the request URI. 2146 If the request includes an Accept Option, that indicates the 2147 preferred content-format of a response. If the request includes an 2148 ETag Option, the GET method requests that ETag be validated and that 2149 the representation be transferred only if validation failed. Upon 2150 success a 2.05 (Content) or 2.03 (Valid) response code SHOULD be 2151 present in the response. 2153 The GET method is safe and idempotent. 2155 5.8.2. POST 2157 The POST method requests that the representation enclosed in the 2158 request be processed. The actual function performed by the POST 2159 method is determined by the origin server and dependent on the target 2160 resource. It usually results in a new resource being created or the 2161 target resource being updated. 2163 If a resource has been created on the server, the response returned 2164 by the server SHOULD have a 2.01 (Created) response code and SHOULD 2165 include the URI of the new resource in a sequence of one or more 2166 Location-Path and/or Location-Query Options (Section 5.10.7). If the 2167 POST succeeds but does not result in a new resource being created on 2168 the server, the response SHOULD have a 2.04 (Changed) response code. 2169 If the POST succeeds and results in the target resource being 2170 deleted, the response SHOULD have a 2.02 (Deleted) response code. 2172 POST is neither safe nor idempotent. 2174 5.8.3. PUT 2176 The PUT method requests that the resource identified by the request 2177 URI be updated or created with the enclosed representation. The 2178 representation format is specified by the media type and content 2179 coding given in the Content-Format Option, if provided. 2181 If a resource exists at the request URI the enclosed representation 2182 SHOULD be considered a modified version of that resource, and a 2.04 2183 (Changed) response code SHOULD be returned. If no resource exists 2184 then the server MAY create a new resource with that URI, resulting in 2185 a 2.01 (Created) response code. If the resource could not be created 2186 or modified, then an appropriate error response code SHOULD be sent. 2188 Further restrictions to a PUT can be made by including the If-Match 2189 (see Section 5.10.8.1) or If-None-Match (see Section 5.10.8.2) 2190 options in the request. 2192 PUT is not safe, but is idempotent. 2194 5.8.4. DELETE 2196 The DELETE method requests that the resource identified by the 2197 request URI be deleted. A 2.02 (Deleted) response code SHOULD be 2198 used on success or in case the resource did not exist before the 2199 request. 2201 DELETE is not safe, but is idempotent. 2203 5.9. Response Code Definitions 2205 Each response code is described below, including any options required 2206 in the response. Where appropriate, some of the codes will be 2207 specified in regards to related response codes in HTTP [RFC2616]; 2208 this does not mean that any such relationship modifies the HTTP 2209 mapping specified in Section 10. 2211 5.9.1. Success 2.xx 2213 This class of status code indicates that the clients request was 2214 successfully received, understood, and accepted. 2216 5.9.1.1. 2.01 Created 2218 Like HTTP 201 "Created", but only used in response to POST and PUT 2219 requests. The payload returned with the response, if any, is a 2220 representation of the action result. 2222 If the response includes one or more Location-Path and/or Location- 2223 Query Options, the values of these options specify the location at 2224 which the resource was created. Otherwise, the resource was created 2225 at the request URI. A cache receiving this response MUST mark any 2226 stored response for the created resource as not fresh. 2228 This response is not cacheable. 2230 5.9.1.2. 2.02 Deleted 2232 Like HTTP 204 "No Content", but only used in response to requests 2233 that cause the resource to cease being available, such as DELETE and 2234 in certain circumstances POST. The payload returned with the 2235 response, if any, is a representation of the action result. 2237 This response is not cacheable. However, a cache MUST mark any 2238 stored response for the deleted resource as not fresh. 2240 5.9.1.3. 2.03 Valid 2242 Related to HTTP 304 "Not Modified", but only used to indicate that 2243 the response identified by the entity-tag identified by the included 2244 ETag Option is valid. Accordingly, the response MUST include an ETag 2245 Option, and MUST NOT include a payload. 2247 When a cache that recognizes and processes the ETag response option 2248 receives a 2.03 (Valid) response, it MUST update the stored response 2249 with the value of the Max-Age Option included in the response 2250 (explicitly, or implicitly as a default value; see also 2251 Section 5.6.2). For each type of Safe-to-Forward option present in 2252 the response, the (possibly empty) set of options of this type that 2253 are present in the stored response MUST be replaced with the set of 2254 options of this type in the response received. (Unsafe options may 2255 trigger similar option specific processing as defined by the option.) 2257 5.9.1.4. 2.04 Changed 2259 Like HTTP 204 "No Content", but only used in response to POST and PUT 2260 requests. The payload returned with the response, if any, is a 2261 representation of the action result. 2263 This response is not cacheable. However, a cache MUST mark any 2264 stored response for the changed resource as not fresh. 2266 5.9.1.5. 2.05 Content 2268 Like HTTP 200 "OK", but only used in response to GET requests. 2270 The payload returned with the response is a representation of the 2271 target resource. 2273 This response is cacheable: Caches can use the Max-Age Option to 2274 determine freshness (see Section 5.6.1) and (if present) the ETag 2275 Option for validation (see Section 5.6.2). 2277 5.9.2. Client Error 4.xx 2279 This class of response code is intended for cases in which the client 2280 seems to have erred. These response codes are applicable to any 2281 request method. 2283 The server SHOULD include a diagnostic payload under the conditions 2284 detailed in Section 5.5.2. 2286 Responses of this class are cacheable: Caches can use the Max-Age 2287 Option to determine freshness (see Section 5.6.1). They cannot be 2288 validated. 2290 5.9.2.1. 4.00 Bad Request 2292 Like HTTP 400 "Bad Request". 2294 5.9.2.2. 4.01 Unauthorized 2296 The client is not authorized to perform the requested action. The 2297 client SHOULD NOT repeat the request without first improving its 2298 authentication status to the server. Which specific mechanism can be 2299 used for this is outside this document's scope; see also Section 9. 2301 5.9.2.3. 4.02 Bad Option 2303 The request could not be understood by the server due to one or more 2304 unrecognized or malformed options. The client SHOULD NOT repeat the 2305 request without modification. 2307 5.9.2.4. 4.03 Forbidden 2309 Like HTTP 403 "Forbidden". 2311 5.9.2.5. 4.04 Not Found 2313 Like HTTP 404 "Not Found". 2315 5.9.2.6. 4.05 Method Not Allowed 2317 Like HTTP 405 "Method Not Allowed", but with no parallel to the 2318 "Allow" header field. 2320 5.9.2.7. 4.06 Not Acceptable 2322 Like HTTP 406 "Not Acceptable", but with no response entity. 2324 5.9.2.8. 4.12 Precondition Failed 2326 Like HTTP 412 "Precondition Failed". 2328 5.9.2.9. 4.13 Request Entity Too Large 2330 Like HTTP 413 "Request Entity Too Large". 2332 5.9.2.10. 4.15 Unsupported Content-Format 2334 Like HTTP 415 "Unsupported Media Type". 2336 5.9.3. Server Error 5.xx 2338 This class of response code indicates cases in which the server is 2339 aware that it has erred or is incapable of performing the request. 2340 These response codes are applicable to any request method. 2342 The server SHOULD include a diagnostic payload under the conditions 2343 detailed in Section 5.5.2. 2345 Responses of this class are cacheable: Caches can use the Max-Age 2346 Option to determine freshness (see Section 5.6.1). They cannot be 2347 validated. 2349 5.9.3.1. 5.00 Internal Server Error 2351 Like HTTP 500 "Internal Server Error". 2353 5.9.3.2. 5.01 Not Implemented 2355 Like HTTP 501 "Not Implemented". 2357 5.9.3.3. 5.02 Bad Gateway 2359 Like HTTP 502 "Bad Gateway". 2361 5.9.3.4. 5.03 Service Unavailable 2363 Like HTTP 503 "Service Unavailable", but using the Max-Age Option in 2364 place of the "Retry-After" header field to indicate the number of 2365 seconds after which to retry. 2367 5.9.3.5. 5.04 Gateway Timeout 2369 Like HTTP 504 "Gateway Timeout". 2371 5.9.3.6. 5.05 Proxying Not Supported 2373 The server is unable or unwilling to act as a forward-proxy for the 2374 URI specified in the Proxy-Uri Option or using Proxy-Scheme (see 2375 Section 5.10.2). 2377 5.10. Option Definitions 2379 The individual CoAP options are summarized in Table 4 and explained 2380 in the subsections of this section. 2382 In this table, the C, U, and N columns indicate the properties, 2383 Critical, UnSafe, and NoCacheKey, respectively. Since NoCacheKey 2384 only has a meaning for options that are Safe-to-Forward (not marked 2385 Unsafe), the column is filled with a dash for UnSafe options. (The 2386 present specification does not define any NoCacheKey options, but the 2387 format of the table is intended to be useful for additional 2388 specifications.) 2389 +-----+---+---+---+---+----------------+--------+--------+----------+ 2390 | No. | C | U | N | R | Name | Format | Length | Default | 2391 +-----+---+---+---+---+----------------+--------+--------+----------+ 2392 | 1 | x | | | x | If-Match | opaque | 0-8 | (none) | 2393 | 3 | x | x | - | | Uri-Host | string | 1-255 | (see | 2394 | | | | | | | | | below) | 2395 | 4 | | | | x | ETag | opaque | 1-8 | (none) | 2396 | 5 | x | | | | If-None-Match | empty | 0 | (none) | 2397 | 7 | x | x | - | | Uri-Port | uint | 0-2 | (see | 2398 | | | | | | | | | below) | 2399 | 8 | | | | x | Location-Path | string | 0-255 | (none) | 2400 | 11 | x | x | - | x | Uri-Path | string | 0-255 | (none) | 2401 | 12 | | | | | Content-Format | uint | 0-2 | (none) | 2402 | 14 | | x | - | | Max-Age | uint | 0-4 | 60 | 2403 | 15 | x | x | - | x | Uri-Query | string | 0-255 | (none) | 2404 | 16 | | | | | Accept | uint | 0-2 | (none) | 2405 | 20 | | | | x | Location-Query | string | 0-255 | (none) | 2406 | 35 | x | x | - | | Proxy-Uri | string | 1-1034 | (none) | 2407 | 39 | x | x | - | | Proxy-Scheme | string | 1-255 | (none) | 2408 +-----+---+---+---+---+----------------+--------+--------+----------+ 2410 C=Critical, U=Unsafe, N=NoCacheKey, R=Repeatable 2412 Table 4: Options 2414 5.10.1. Uri-Host, Uri-Port, Uri-Path and Uri-Query 2416 The Uri-Host, Uri-Port, Uri-Path and Uri-Query Options are used to 2417 specify the target resource of a request to a CoAP origin server. 2418 The options encode the different components of the request URI in a 2419 way that no percent-encoding is visible in the option values and that 2420 the full URI can be reconstructed at any involved endpoint. The 2421 syntax of CoAP URIs is defined in Section 6. 2423 The steps for parsing URIs into options is defined in Section 6.4. 2424 These steps result in zero or more Uri-Host, Uri-Port, Uri-Path and 2425 Uri-Query Options being included in a request, where each option 2426 holds the following values: 2428 o the Uri-Host Option specifies the Internet host of the resource 2429 being requested, 2431 o the Uri-Port Option specifies the transport layer port number of 2432 the resource, 2434 o each Uri-Path Option specifies one segment of the absolute path to 2435 the resource, and 2437 o each Uri-Query Option specifies one argument parameterizing the 2438 resource. 2440 Note: Fragments ([RFC3986], Section 3.5) are not part of the request 2441 URI and thus will not be transmitted in a CoAP request. 2443 The default value of the Uri-Host Option is the IP literal 2444 representing the destination IP address of the request message. 2445 Likewise, the default value of the Uri-Port Option is the destination 2446 UDP port. The default values for the Uri-Host and Uri-Port Options 2447 are sufficient for requests to most servers. Explicit Uri-Host and 2448 Uri-Port Options are typically used when an endpoint hosts multiple 2449 virtual servers. 2451 The Uri-Path and Uri-Query Option can contain any character sequence. 2452 No percent-encoding is performed. The value of a Uri-Path Option 2453 MUST NOT be "." or ".." (as the request URI must be resolved before 2454 parsing it into options). 2456 The steps for constructing the request URI from the options are 2457 defined in Section 6.5. Note that an implementation does not 2458 necessarily have to construct the URI; it can simply look up the 2459 target resource by looking at the individual options. 2461 Examples can be found in Appendix B. 2463 5.10.2. Proxy-Uri and Proxy-Scheme 2465 The Proxy-Uri Option is used to make a request to a forward-proxy 2466 (see Section 5.7). The forward-proxy is requested to forward the 2467 request or service it from a valid cache, and return the response. 2469 The option value is an absolute-URI ([RFC3986], Section 4.3). 2471 Note that the forward-proxy MAY forward the request on to another 2472 proxy or directly to the server specified by the absolute-URI. In 2473 order to avoid request loops, a proxy MUST be able to recognize all 2474 of its server names, including any aliases, local variations, and the 2475 numeric IP addresses. 2477 An endpoint receiving a request with a Proxy-Uri Option that is 2478 unable or unwilling to act as a forward-proxy for the request MUST 2479 cause the return of a 5.05 (Proxying Not Supported) response. 2481 The Proxy-Uri Option MUST take precedence over any of the Uri-Host, 2482 Uri-Port, Uri-Path or Uri-Query options (which MUST NOT be included 2483 at the same time in a request containing the Proxy-Uri Option). 2485 As a special case to simplify many proxy clients, the absolute-URI 2486 can be constructed from the Uri-* options. When a Proxy-Scheme 2487 Option is present, the absolute-URI is constructed as follows: A CoAP 2488 URI is constructed from the Uri-* options as defined in Section 6.5. 2489 In the resulting URI, the initial scheme up to, but not including the 2490 following colon is then replaced by the content of the Proxy-Scheme 2491 Option. Note that this case is only applicable if the components of 2492 the desired URI other than the scheme component actually can be 2493 expressed using Uri-* options; e.g., to represent a URI with a 2494 userinfo component in the authority, only Proxy-Uri can be used. 2496 5.10.3. Content-Format 2498 The Content-Format Option indicates the representation format of the 2499 message payload. The representation format is given as a numeric 2500 content format identifier that is defined in the CoAP Content Format 2501 Registry (Section 12.3). In the absence of the option, no default 2502 value is assumed, i.e. the representation format of any 2503 representation message payload is indeterminate (Section 5.5). 2505 5.10.4. Accept 2507 The CoAP Accept option can be used to indicate which Content-Format 2508 is acceptable to the client. The representation format is given as a 2509 numeric Content-Format identifier that is defined in the CoAP 2510 Content-Format Registry (Section 12.3). If no Accept option is 2511 given, the client does not express a preference (thus no default 2512 value is assumed). The client prefers the representation returned by 2513 the server to be in the Content-Format indicated. The server SHOULD 2514 return the preferred Content-Format if available. If the preferred 2515 Content-Format cannot be returned, then a 4.06 "Not Acceptable" 2516 SHOULD be sent as a response. 2518 Note that as a server might not support the Accept option (and thus 2519 would ignore it as it is elective), the client needs to be prepared 2520 to receive a representation in a different Content-Format. The 2521 client can simply discard a representation it can not make use of. 2523 5.10.5. Max-Age 2525 The Max-Age Option indicates the maximum time a response may be 2526 cached before it MUST be considered not fresh (see Section 5.6.1). 2528 The option value is an integer number of seconds between 0 and 2529 2**32-1 inclusive (about 136.1 years). A default value of 60 seconds 2530 is assumed in the absence of the option in a response. 2532 The value is intended to be current at the time of transmission. 2534 Servers that provide resources with strict tolerances on the value of 2535 Max-Age SHOULD update the value before each retransmission. (See 2536 also Section 5.7.1.) 2538 5.10.6. ETag 2540 An entity-tag is intended for use as a resource-local identifier for 2541 differentiating between representations of the same resource that 2542 vary over time. It is generated by the server providing the 2543 resource, which may generate it in any number of ways including a 2544 version, checksum, hash or time. An endpoint receiving an entity-tag 2545 MUST treat it as opaque and make no assumptions about its content or 2546 structure. (Endpoints that generate an entity-tag are encouraged to 2547 use the most compact representation possible, in particular in 2548 regards to clients and intermediaries that may want to store multiple 2549 ETag values.) 2551 5.10.6.1. ETag as a Response Option 2553 The ETag Option in a response provides the current value (i.e., after 2554 the request was processed) of the entity-tag for the "tagged 2555 representation". If no Location-* options are present, the tagged 2556 representation is the selected representation (Section 5.5.3) of the 2557 target resource. If one or more Location-* options are present and 2558 thus a location URI is indicated (Section 5.10.7), the tagged 2559 representation is the representation that would be retrieved by a GET 2560 request to the location URI. 2562 An ETag response option can be included with any response for which 2563 there is a tagged representation (e.g., it would not be meaningful in 2564 a 4.04 or 4.00 response). The ETag Option MUST NOT occur more than 2565 once in a response. 2567 There is no default value for the ETag Option; if it is not present 2568 in a response, the server makes no statement about the entity-tag for 2569 the tagged representation. 2571 5.10.6.2. ETag as a Request Option 2573 In a GET request, an endpoint that has one or more representations 2574 previously obtained from the resource, and has obtained ETag response 2575 options with these, can specify an instance of the ETag Option for 2576 one or more of these stored responses. 2578 A server can issue a 2.03 Valid response (Section 5.9.1.3) in place 2579 of a 2.05 Content response if one of the ETags given is the entity- 2580 tag for the current representation, i.e. is valid; the 2.03 Valid 2581 response then echoes this specific ETag in a response option. 2583 In effect, a client can determine if any of the stored 2584 representations is current (see Section 5.6.2) without needing to 2585 transfer them again. 2587 The ETag Option MAY occur zero, one or more times in a request. 2589 5.10.7. Location-Path and Location-Query 2591 The Location-Path and Location-Query Options together indicate a 2592 relative URI that consists either of an absolute path, a query string 2593 or both. A combination of these options is included in a 2.01 2594 (Created) response to indicate the location of the resource created 2595 as the result of a POST request (see Section 5.8.2). The location is 2596 resolved relative to the request URI. 2598 If a response with one or more Location-Path and/or Location-Query 2599 Options passes through a cache that interprets these options and the 2600 implied URI identifies one or more currently stored responses, those 2601 entries MUST be marked as not fresh. 2603 Each Location-Path Option specifies one segment of the absolute path 2604 to the resource, and each Location-Query Option specifies one 2605 argument parameterizing the resource. The Location-Path and 2606 Location-Query Option can contain any character sequence. No 2607 percent-encoding is performed. The value of a Location-Path Option 2608 MUST NOT be "." or "..". 2610 The steps for constructing the location URI from the options are 2611 analogous to Section 6.5, except that the first five steps are 2612 skipped and the result is a relative URI-reference, which is then 2613 interpreted relative to the request URI. Note that the relative URI- 2614 reference constructed this way always includes an absolute-path 2615 (e.g., leaving out Location-Path but supplying Location-Query means 2616 the path component in the URI is "/"). 2618 The options that are used to compute the relative URI-reference are 2619 collectively called Location-* options. Beyond Location-Path and 2620 Location-Query, more Location-* options may be defined in the future, 2621 and have been reserved option numbers 128, 132, 136, and 140. If any 2622 of these reserved option numbers occurs in addition to Location-Path 2623 and/or Location-Query and are not supported, then a 4.02 (Bad Option) 2624 error MUST be returned. 2626 5.10.8. Conditional Request Options 2628 Conditional request options enable a client to ask the server to 2629 perform the request only if certain conditions specified by the 2630 option are fulfilled. 2632 For each of these options, if the condition given is not fulfilled, 2633 then the server MUST NOT perform the requested method. Instead, the 2634 server MUST respond with the 4.12 (Precondition Failed) response 2635 code. 2637 If the condition is fulfilled, the server performs the request method 2638 as if the conditional request options were not present. 2640 If the request would, without the conditional request options, result 2641 in anything other than a 2.xx or 4.12 response code, then any 2642 conditional request options MAY be ignored. 2644 5.10.8.1. If-Match 2646 The If-Match Option MAY be used to make a request conditional on the 2647 current existence or value of an ETag for one or more representations 2648 of the target resource. If-Match is generally useful for resource 2649 update requests, such as PUT requests, as a means for protecting 2650 against accidental overwrites when multiple clients are acting in 2651 parallel on the same resource (i.e., the "lost update" problem). 2653 The value of an If-Match option is either an ETag or the empty 2654 string. An If-Match option with an ETag matches a representation 2655 with that exact ETag. An If-Match option with an empty value matches 2656 any existing representation (i.e., it places the precondition on the 2657 existence of any current representation for the target resource). 2659 The If-Match Option can occur multiple times. If any of the options 2660 match, then the condition is fulfilled. 2662 If there is one or more If-Match Option, but none of the options 2663 match, then the condition is not fulfilled. 2665 5.10.8.2. If-None-Match 2667 The If-None-Match Option MAY be used to make a request conditional on 2668 the non-existence of the target resource. If-None-Match is useful 2669 for resource creation requests, such as PUT requests, as a means for 2670 protecting against accidental overwrites when multiple clients are 2671 acting in parallel on the same resource. The If-None-Match Option 2672 carries no value. 2674 If the target resource does exist, then the condition is not 2675 fulfilled. 2677 (It is not very useful to combine If-Match and If-None-Match options 2678 in one request, because the condition will then never be fulfilled.) 2680 6. CoAP URIs 2682 CoAP uses the "coap" and "coaps" URI schemes for identifying CoAP 2683 resources and providing a means of locating the resource. Resources 2684 are organized hierarchically and governed by a potential CoAP origin 2685 server listening for CoAP requests ("coap") or DTLS-secured CoAP 2686 requests ("coaps") on a given UDP port. The CoAP server is 2687 identified via the generic syntax's authority component, which 2688 includes a host component and optional UDP port number. The 2689 remainder of the URI is considered to be identifying a resource which 2690 can be operated on by the methods defined by the CoAP protocol. The 2691 "coap" and "coaps" URI schemes can thus be compared to the "http" and 2692 "https" URI schemes respectively. 2694 The syntax of the "coap" and "coaps" URI schemes is specified in this 2695 section in Augmented Backus-Naur Form (ABNF) [RFC5234]. The 2696 definitions of "host", "port", "path-abempty", "query", "segment", 2697 "IP-literal", "IPv4address" and "reg-name" are adopted from 2698 [RFC3986]. 2700 Implementation Note: Unfortunately, over time the URI format has 2701 acquired significant complexity. Implementers are encouraged to 2702 examine [RFC3986] closely. E.g., the ABNF for IPv6 addresses is 2703 more complicated than maybe expected. Also, implementers should 2704 take care to perform the processing of percent decoding/encoding 2705 exactly once on the way from a URI to its decoded components or 2706 back. Percent encoding is crucial for data transparency, but may 2707 lead to unusual results such as a slash in a path component. 2709 6.1. coap URI Scheme 2711 coap-URI = "coap:" "//" host [ ":" port ] path-abempty [ "?" query ] 2713 If the host component is provided as an IP-literal or IPv4address, 2714 then the CoAP server can be reached at that IP address. If host is a 2715 registered name, then that name is considered an indirect identifier 2716 and the endpoint might use a name resolution service, such as DNS, to 2717 find the address of that host. The host MUST NOT be empty; if a URI 2718 is received with a missing authority or an empty host, then it MUST 2719 be considered invalid. The port subcomponent indicates the UDP port 2720 at which the CoAP server is located. If it is empty or not given, 2721 then the default port 5683 is assumed. 2723 The path identifies a resource within the scope of the host and port. 2724 It consists of a sequence of path segments separated by a slash 2725 character (U+002F SOLIDUS "/"). 2727 The query serves to further parameterize the resource. It consists 2728 of a sequence of arguments separated by an ampersand character 2729 (U+0026 AMPERSAND "&"). An argument is often in the form of a 2730 "key=value" pair. 2732 The "coap" URI scheme supports the path prefix "/.well-known/" 2733 defined by [RFC5785] for "well-known locations" in the name-space of 2734 a host. This enables discovery of policy or other information about 2735 a host ("site-wide metadata"), such as hosted resources (see 2736 Section 7). 2738 Application designers are encouraged to make use of short, but 2739 descriptive URIs. As the environments that CoAP is used in are 2740 usually constrained for bandwidth and energy, the trade-off between 2741 these two qualities should lean towards the shortness, without 2742 ignoring descriptiveness. 2744 6.2. coaps URI Scheme 2746 coaps-URI = "coaps:" "//" host [ ":" port ] path-abempty 2747 [ "?" query ] 2749 All of the requirements listed above for the "coap" scheme are also 2750 requirements for the "coaps" scheme, except that a default UDP port 2751 of [IANA_TBD_PORT] is assumed if the port subcomponent is empty or 2752 not given, and the UDP datagrams MUST be secured through the use of 2753 DTLS as described in Section 9.1. 2755 Considerations for caching of responses to "coaps" identified 2756 requests are discussed in Section 11.2. 2758 Resources made available via the "coaps" scheme have no shared 2759 identity with the "coap" scheme even if their resource identifiers 2760 indicate the same authority (the same host listening to the same UDP 2761 port). They are distinct name spaces and are considered to be 2762 distinct origin servers. 2764 6.3. Normalization and Comparison Rules 2766 Since the "coap" and "coaps" schemes conform to the URI generic 2767 syntax, such URIs are normalized and compared according to the 2768 algorithm defined in [RFC3986], Section 6, using the defaults 2769 described above for each scheme. 2771 If the port is equal to the default port for a scheme, the normal 2772 form is to elide the port subcomponent. Likewise, an empty path 2773 component is equivalent to an absolute path of "/", so the normal 2774 form is to provide a path of "/" instead. The scheme and host are 2775 case-insensitive and normally provided in lowercase; IP-literals are 2776 in recommended form [RFC5952]; all other components are compared in a 2777 case-sensitive manner. Characters other than those in the "reserved" 2778 set are equivalent to their percent-encoded bytes (see [RFC3986], 2779 Section 2.1): the normal form is to not encode them. 2781 For example, the following three URIs are equivalent, and cause the 2782 same options and option values to appear in the CoAP messages: 2784 coap://example.com:5683/~sensors/temp.xml 2785 coap://EXAMPLE.com/%7Esensors/temp.xml 2786 coap://EXAMPLE.com:/%7esensors/temp.xml 2788 6.4. Decomposing URIs into Options 2790 The steps to parse a request's options from a string |url| are as 2791 follows. These steps either result in zero or more of the Uri-Host, 2792 Uri-Port, Uri-Path and Uri-Query Options being included in the 2793 request, or they fail. 2795 1. If the |url| string is not an absolute URI ([RFC3986]), then fail 2796 this algorithm. 2798 2. Resolve the |url| string using the process of reference 2799 resolution defined by [RFC3986]. At this stage the URL is in 2800 ASCII encoding [RFC0020], even though the decoded components will 2801 be interpreted in UTF-8 [RFC3629] after step 5, 8 and 9. 2803 NOTE: It doesn't matter what it is resolved relative to, since we 2804 already know it is an absolute URL at this point. 2806 3. If |url| does not have a component whose value, when 2807 converted to ASCII lowercase, is "coap" or "coaps", then fail 2808 this algorithm. 2810 4. If |url| has a component, then fail this algorithm. 2812 5. If the component of |url| does not represent the request's 2813 destination IP address as an IP-literal or IPv4address, include a 2814 Uri-Host Option and let that option's value be the value of the 2815 component of |url|, converted to ASCII lowercase, and then 2816 converting all percent-encodings ("%" followed by two hexadecimal 2817 digits) to the corresponding characters. 2819 NOTE: In the usual case where the request's destination IP 2820 address is derived from the host part, this ensures that a Uri- 2821 Host Option is only used for a component of the form reg- 2822 name. 2824 6. If |url| has a component, then let |port| be that 2825 component's value interpreted as a decimal integer; otherwise, 2826 let |port| be the default port for the scheme. 2828 7. If |port| does not equal the request's destination UDP port, 2829 include a Uri-Port Option and let that option's value be |port|. 2831 8. If the value of the component of |url| is empty or 2832 consists of a single slash character (U+002F SOLIDUS "/"), then 2833 move to the next step. 2835 Otherwise, for each segment in the component, include a 2836 Uri-Path Option and let that option's value be the segment (not 2837 including the delimiting slash characters) after converting each 2838 percent-encoding ("%" followed by two hexadecimal digits) to the 2839 corresponding byte. 2841 9. If |url| has a component, then, for each argument in the 2842 component, include a Uri-Query Option and let that 2843 option's value be the argument (not including the question mark 2844 and the delimiting ampersand characters) after converting each 2845 percent-encoding to the corresponding byte. 2847 Note that these rules completely resolve any percent-encoding. 2849 6.5. Composing URIs from Options 2851 The steps to construct a URI from a request's options are as follows. 2852 These steps either result in a URI, or they fail. In these steps, 2853 percent-encoding a character means replacing each of its (UTF-8 2854 encoded) bytes by a "%" character followed by two hexadecimal digits 2855 representing the byte, where the digits A-F are in upper case (as 2856 defined in [RFC3986] Section 2.1; to reduce variability, the 2857 hexadecimal notation for percent-encoding in CoAP URIs MUST use 2858 uppercase letters). The definitions of "unreserved" and "sub-delims" 2859 are adopted from [RFC3986]. 2861 1. If the request is secured using DTLS, let |url| be the string 2862 "coaps://". Otherwise, let |url| be the string "coap://". 2864 2. If the request includes a Uri-Host Option, let |host| be that 2865 option's value, where any non-ASCII characters are replaced by 2866 their corresponding percent-encoding. If |host| is not a valid 2867 reg-name or IP-literal or IPv4address, fail the algorithm. If 2868 the request does not include a Uri-Host Option, let |host| be 2869 the IP-literal (making use of the conventions of [RFC5952]) or 2870 IPv4address representing the request's destination IP address. 2872 3. Append |host| to |url|. 2874 4. If the request includes a Uri-Port Option, let |port| be that 2875 option's value. Otherwise, let |port| be the request's 2876 destination UDP port. 2878 5. If |port| is not the default port for the scheme, then append a 2879 single U+003A COLON character (:) followed by the decimal 2880 representation of |port| to |url|. 2882 6. Let |resource name| be the empty string. For each Uri-Path 2883 Option in the request, append a single character U+002F SOLIDUS 2884 (/) followed by the option's value to |resource name|, after 2885 converting any character that is not either in the "unreserved" 2886 set, "sub-delims" set, a U+003A COLON (:) or U+0040 COMMERCIAL 2887 AT (@) character, to its percent-encoded form. 2889 7. If |resource name| is the empty string, set it to a single 2890 character U+002F SOLIDUS (/). 2892 8. For each Uri-Query Option in the request, append a single 2893 character U+003F QUESTION MARK (?) (first option) or U+0026 2894 AMPERSAND (&) (subsequent options) followed by the option's 2895 value to |resource name|, after converting any character that is 2896 not either in the "unreserved" set, "sub-delims" set (except 2897 U+0026 AMPERSAND (&)), a U+003A COLON (:), U+0040 COMMERCIAL AT 2898 (@), U+002F SOLIDUS (/) or U+003F QUESTION MARK (?) character, 2899 to its percent-encoded form. 2901 9. Append |resource name| to |url|. 2903 10. Return |url|. 2905 Note that these steps have been designed to lead to a URI in normal 2906 form (see Section 6.3). 2908 7. Discovery 2910 7.1. Service Discovery 2912 As a part of discovering the services offered by a CoAP server, a 2913 client has to learn about the endpoint used by a server. 2915 A server is discovered by a client by the client (knowing or) 2916 learning a URI that references a resource in the namespace of the 2917 server. Alternatively, clients can use Multicast CoAP (see 2918 Section 8) and the "All CoAP Nodes" multicast address to find CoAP 2919 servers. 2921 Unless the port subcomponent in a "coap" or "coaps" URI indicates the 2922 UDP port at which the CoAP server is located, the server is assumed 2923 to be reachable at the default port. 2925 The CoAP default port number 5683 MUST be supported by a server that 2926 offers resources for resource discovery (see Section 7.2 below) and 2927 SHOULD be supported for providing access to other resources. The 2928 default port number [IANA_TBD_PORT] for DTLS-secured CoAP MAY be 2929 supported by a server for resource discovery and for providing access 2930 to other resources. In addition other endpoints may be hosted at 2931 other ports, e.g. in the dynamic port space. 2933 Implementation Note: When a CoAP server is hosted by a 6LoWPAN node, 2934 header compression efficiency is improved when it also supports a 2935 port number in the 61616-61631 compressed UDP port space defined 2936 in [RFC4944] (note that, as its UDP port differs from the default 2937 port, it is a different endpoint from the server at the default 2938 port). 2940 7.2. Resource Discovery 2942 The discovery of resources offered by a CoAP endpoint is extremely 2943 important in machine-to-machine applications where there are no 2944 humans in the loop and static interfaces result in fragility. To 2945 maximize interoperability in a CoRE environment, a CoAP endpoint 2946 SHOULD support the CoRE Link Format of discoverable resources as 2947 described in [RFC6690], except where fully manual configuration is 2948 desired. It is up to the server which resources are made 2949 discoverable (if any). 2951 7.2.1. 'ct' Attribute 2953 This section defines a new Web Linking [RFC5988] attribute for use 2954 with [RFC6690]. The Content-Format code "ct" attribute provides a 2955 hint about the Content-Formats this resource returns. Note that this 2956 is only a hint, and does not override the Content-Format Option of a 2957 CoAP response obtained by actually requesting the representation of 2958 the resource. The value is in the CoAP identifier code format as a 2959 decimal ASCII integer and MUST be in the range of 0-65535 (16-bit 2960 unsigned integer). For example application/xml would be indicated as 2961 "ct=41". If no Content-Format code attribute is present then nothing 2962 about the type can be assumed. The Content-Format code attribute MAY 2963 include a space-separated sequence of Content-Format codes, 2964 indicating that multiple content-formats are available. The syntax 2965 of the attribute value is summarized in the production ct-value in 2966 Figure 12, where cardinal, SP and DQUOTE are defined as in [RFC6690]. 2968 ct-value = cardinal 2969 / DQUOTE cardinal *( 1*SP cardinal ) DQUOTE 2971 Figure 12 2973 8. Multicast CoAP 2975 CoAP supports making requests to a IP multicast group. This is 2976 defined by a series of deltas to Unicast CoAP. A more general 2977 discussion of group communication with CoAP is in 2978 [I-D.ietf-core-groupcomm]. 2980 CoAP endpoints that offer services that they want other endpoints to 2981 be able to find using multicast service discovery, join one or more 2982 of the appropriate all-CoAP-nodes multicast addresses (Section 12.8) 2983 and listen on the default CoAP port. Note that an endpoint might 2984 receive multicast requests on other multicast addresses, including 2985 the all-nodes IPv6 address (or via broadcast on IPv4); an endpoint 2986 MUST therefore be prepared to receive such messages but MAY ignore 2987 them if multicast service discovery is not desired. 2989 8.1. Messaging Layer 2991 A multicast request is characterized by being transported in a CoAP 2992 message that is addressed to an IP multicast address instead of a 2993 CoAP endpoint. Such multicast requests MUST be Non-confirmable. 2995 A server SHOULD be aware that a request arrived via multicast, e.g. 2996 by making use of modern APIs such as IPV6_RECVPKTINFO [RFC3542], if 2997 available. 2999 To avoid an implosion of error responses, when a server is aware that 3000 a request arrived via multicast, it MUST NOT return a RST in reply to 3001 NON. If it is not aware, it MAY return a RST in reply to NON as 3002 usual. Because such a Reset message will look identical to an RST 3003 for a unicast message from the sender, the sender MUST avoid using a 3004 Message ID that is also still active from this endpoint with any 3005 unicast endpoint that might receive the multicast message. 3007 At the time of writing, multicast messages can only be carried in 3008 UDP, not in DTLS. This means that the security modes defined for 3009 CoAP in this document are not applicable to multicast. 3011 8.2. Request/Response Layer 3013 When a server is aware that a request arrived via multicast, the 3014 server MAY always ignore the request, in particular if it doesn't 3015 have anything useful to respond (e.g., if it only has an empty 3016 payload or an error response). The decision for this may depend on 3017 the application. (For example, in [RFC6690] query filtering, a 3018 server should not respond to a multicast request if the filter does 3019 not match. More examples are in [I-D.ietf-core-groupcomm].) 3021 If a server does decide to respond to a multicast request, it should 3022 not respond immediately. Instead, it should pick a duration for the 3023 period of time during which it intends to respond. For purposes of 3024 this exposition, we call the length of this period the Leisure. The 3025 specific value of this Leisure may depend on the application, or MAY 3026 be derived as described below. The server SHOULD then pick a random 3027 point of time within the chosen Leisure period to send back the 3028 unicast response to the multicast request. If further responses need 3029 to be sent based on the same multicast address membership, a new 3030 leisure period starts at the earliest after the previous one 3031 finishes. 3033 To compute a value for Leisure, the server should have a group size 3034 estimate G, a target data transfer rate R (which both should be 3035 chosen conservatively) and an estimated response size S; a rough 3036 lower bound for Leisure can then be computed as 3037 lb_Leisure = S * G / R 3039 E.g., for a multicast request with link-local scope on an 2.4 GHz 3040 IEEE 802.15.4 (6LoWPAN) network, G could be (relatively 3041 conservatively) set to 100, S to 100 bytes, and the target rate to 8 3042 kbit/s = 1 kB/s. The resulting lower bound for the Leisure is 10 3043 seconds. 3045 If a CoAP endpoint does not have suitable data to compute a value for 3046 Leisure, it MAY resort to DEFAULT_LEISURE. 3048 When matching a response to a multicast request, only the token MUST 3049 match; the source endpoint of the response does not need to (and will 3050 not) be the same as the destination endpoint of the original request. 3052 For the purposes of interpreting the Location-* options and any links 3053 embedded in the representation and, the request URI (base URI) 3054 relative to which the response is interpreted, is formed by replacing 3055 the multicast address in the Host component of the original request 3056 URI by the literal IP address of the endpoint actually responding. 3058 8.2.1. Caching 3060 When a client makes a multicast request, it always makes a new 3061 request to the multicast group (since there may be new group members 3062 that joined meanwhile or ones that did not get the previous request). 3064 It MAY update a cache with the received responses. Then it uses both 3065 cached-still-fresh and 'new' responses as the result of the request. 3067 A response received in reply to a GET request to a multicast group 3068 MAY be used to satisfy a subsequent request on the related unicast 3069 request URI. The unicast request URI is obtained by replacing the 3070 authority part of the request URI with the transport layer source 3071 address of the response message. 3073 A cache MAY revalidate a response by making a GET request on the 3074 related unicast request URI. 3076 A GET request to a multicast group MUST NOT contain an ETag option. 3077 A mechanism to suppress responses the client already has is left for 3078 further study. 3080 8.2.2. Proxying 3082 When a forward-proxy receives a request with a Proxy-Uri or URI 3083 constructed from Proxy-Scheme that indicates a multicast address, the 3084 proxy obtains a set of responses as described above and sends all 3085 responses (both cached-still-fresh and new) back to the original 3086 client. 3088 This specification does not provide a way to indicate the unicast- 3089 modified request URI (base URI) in responses thus forwarded. 3090 Proxying multicast requests is discussed in more detail in 3091 [I-D.ietf-core-groupcomm]; one proposal to address the base URI issue 3092 can be found in section 3 of [I-D.bormann-coap-misc]. 3094 9. Securing CoAP 3096 This section defines the DTLS binding for CoAP. 3098 During the provisioning phase, a CoAP device is provided with the 3099 security information that it needs, including keying materials and 3100 access control lists. This specification defines provisioning for 3101 the RawPublicKey mode in Section 9.1.3.2.1. At the end of the 3102 provisioning phase, the device will be in one of four security modes 3103 with the following information for the given mode. The NoSec and 3104 RawPublicKey modes are mandatory to implement for this specification. 3106 NoSec: There is no protocol level security (DTLS is disabled). 3107 Alternative techniques to provide lower layer security SHOULD be 3108 used when appropriate. The use of IPsec is discussed in 3109 [I-D.bormann-core-ipsec-for-coap]. Certain link layers in use 3110 with constrained nodes also provide link layer security, which may 3111 be appropriate with proper key management. 3113 PreSharedKey: DTLS is enabled and there is a list of pre-shared keys 3114 [RFC4279] and each key includes a list of which nodes it can be 3115 used to communicate with as described in Section 9.1.3.1. At the 3116 extreme there may be one key for each node this CoAP node needs to 3117 communicate with (1:1 node/key ratio). Conversely, if more than 3118 two entities share a specific pre-shared key, this key only 3119 enables the entities to authenticate as a member of that group and 3120 not as a specific peer. 3122 RawPublicKey: DTLS is enabled and the device has an asymmetric key 3123 pair without a certificate (a raw public key) that is validated 3124 using an out-of-band mechanism [I-D.ietf-tls-oob-pubkey] as 3125 described in Section 9.1.3.2. The device also has an identity 3126 calculated from the public key and a list of identities of the 3127 nodes it can communicate with. 3129 Certificate: DTLS is enabled and the device has an asymmetric key 3130 pair with an X.509 certificate [RFC5280] that binds it to its 3131 Authority Name and is signed by some common trust root as 3132 described in Section 9.1.3.3. The device also has a list of root 3133 trust anchors that can be used for validating a certificate. 3135 In the "NoSec" mode, the system simply sends the packets over normal 3136 UDP over IP and is indicated by the "coap" scheme and the CoAP 3137 default port. The system is secured only by keeping attackers from 3138 being able to send or receive packets from the network with the CoAP 3139 nodes; see Section 11.5 for an additional complication with this 3140 approach. 3142 The other three security modes are achieved using DTLS and are 3143 indicated by the "coaps" scheme and DTLS-secured CoAP default port. 3144 The result is a security association that can be used to authenticate 3145 (within the limits of the security model) and, based on this 3146 authentication, authorize the communication partner. CoAP itself 3147 does not provide protocol primitives for authentication or 3148 authorization; where this is required, it can either be provided by 3149 communication security (i.e., IPsec or DTLS) or by object security 3150 (within the payload). Devices that require authorization for certain 3151 operations are expected to require one of these two forms of 3152 security. Necessarily, where an intermediary is involved, 3153 communication security only works when that intermediary is part of 3154 the trust relationships; CoAP does not provide a way to forward 3155 different levels of authorization that clients may have with an 3156 intermediary to further intermediaries or origin servers -- it 3157 therefore may be required to perform all authorization at the first 3158 intermediary. 3160 9.1. DTLS-secured CoAP 3162 Just as HTTP is secured using Transport Layer Security (TLS) over 3163 TCP, CoAP is secured using Datagram TLS (DTLS) [RFC6347] over UDP 3164 (see Figure 13). This section defines the CoAP binding to DTLS, 3165 along with the minimal mandatory-to-implement configurations 3166 appropriate for constrained environments. The binding is defined by 3167 a series of deltas to Unicast CoAP. DTLS is in practice TLS with 3168 added features to deal with the unreliable nature of the UDP 3169 transport. 3171 +----------------------+ 3172 | Application | 3173 +----------------------+ 3174 +----------------------+ 3175 | Requests/Responses | 3176 |----------------------| CoAP 3177 | Messages | 3178 +----------------------+ 3179 +----------------------+ 3180 | DTLS | 3181 +----------------------+ 3182 +----------------------+ 3183 | UDP | 3184 +----------------------+ 3186 Figure 13: Abstract layering of DTLS-secured CoAP 3188 In some constrained nodes (limited flash and/or RAM) and networks 3189 (limited bandwidth or high scalability requirements), and depending 3190 on the specific cipher suites in use, all modes of DTLS may not be 3191 applicable. Some DTLS cipher suites can add significant 3192 implementation complexity as well as some initial handshake overhead 3193 needed when setting up the security association. Once the initial 3194 handshake is completed, DTLS adds a limited per-datagram overhead of 3195 approximately 13 bytes, not including any initialization vectors/ 3196 nonces (e.g., 8 bytes with TLS_PSK_WITH_AES_128_CCM_8 [RFC6655]), 3197 integrity check values (e.g., 8 bytes with TLS_PSK_WITH_AES_128_CCM_8 3198 [RFC6655]) and padding required by the cipher suite. Whether and 3199 which mode of using DTLS is applicable for a CoAP-based application 3200 should be carefully weighed considering the specific cipher suites 3201 that may be applicable, and whether the session maintenance makes it 3202 compatible with application flows and sufficient resources are 3203 available on the constrained nodes and for the added network 3204 overhead. (For some modes of using DTLS, this specification 3205 identifies a mandatory to implement cipher suite. This is an 3206 implementation requirement to maximize interoperability in those 3207 cases where these cipher suites are indeed appropriate. The specific 3208 security policies of an application may determine the actual (set of) 3209 cipher suites that can be used.) DTLS is not applicable to group 3210 keying (multicast communication); however, it may be a component in a 3211 future group key management protocol. 3213 9.1.1. Messaging Layer 3215 The endpoint acting as the CoAP client should also act as the DTLS 3216 client. It should initiate a session to the server on the 3217 appropriate port. When the DTLS handshake has finished, the client 3218 may initiate the first CoAP request. All CoAP messages MUST be sent 3219 as DTLS "application data". 3221 The following rules are added for matching an ACK or RST to a CON 3222 message or a RST to a NON message: The DTLS session MUST be the same 3223 and the epoch MUST be the same. 3225 A message is the same when it is sent within the same DTLS session 3226 and same epoch and has the same Message ID. 3228 Note: When a Confirmable message is retransmitted, a new DTLS 3229 sequence_number is used for each attempt, even though the CoAP 3230 Message ID stays the same. So a recipient still has to perform 3231 deduplication as described in Section 4.5. Retransmissions MUST NOT 3232 be performed across epochs. 3234 DTLS connections in RawPublicKey and Certificate mode are set up 3235 using mutual authentication so they can remain up and be reused for 3236 future message exchanges in either direction. Devices can close a 3237 DTLS connection when they need to recover resources but in general 3238 they should keep the connection up for as long as possible. Closing 3239 the DTLS connection after every CoAP message exchange is very 3240 inefficient. 3242 9.1.2. Request/Response Layer 3244 The following rules are added for matching a response to a request: 3245 The DTLS session MUST be the same and the epoch MUST be the same. 3247 This means the response to a DTLS secured request MUST always be DTLS 3248 secured using the same security session and epoch. Any attempt to 3249 supply a NoSec response to a DTLS request simply does not match the 3250 request and (unless it does match an unrelated NoSec request) 3251 therefore MUST be rejected. 3253 9.1.3. Endpoint Identity 3255 Devices SHOULD support the Server Name Indication (SNI) to indicate 3256 their Authority Name in the SNI HostName field as defined in Section 3257 3 of [RFC6066]. This is needed so that when a host that acts as a 3258 virtual server for multiple Authorities receives a new DTLS 3259 connection, it knows which keys to use for the DTLS session. 3261 9.1.3.1. Pre-Shared Keys 3263 When forming a connection to a new node, the system selects an 3264 appropriate key based on which nodes it is trying to reach and then 3265 forms a DTLS session using a PSK (Pre-Shared Key) mode of DTLS. 3266 Implementations in these modes MUST support the mandatory to 3267 implement cipher suite TLS_PSK_WITH_AES_128_CCM_8 as specified in 3268 [RFC6655]. 3270 Depending on the commissioning model, applications may need to define 3271 an application profile for identity hints as required and detailed in 3272 [RFC4279] (Section 5.2) to enable the use of PSK identity hints. 3274 The security considerations of [RFC4279] (Section 7) apply. In 3275 particular, applications should carefully weigh whether they need 3276 Perfect Forward Secrecy (PFS) or not and select an appropriate cipher 3277 suite (7.1). The entropy of the PSK must be sufficient to mitigate 3278 against brute-force and (where the PSK is not chosen randomly but by 3279 a human) dictionary attacks (7.2). The cleartext communication of 3280 client identities may leak data or compromise privacy (7.3). 3282 9.1.3.2. Raw Public Key Certificates 3284 In this mode the device has an asymmetric key pair but without an 3285 X.509 certificate (called a raw public key); e.g., the asymmetric key 3286 pair is generated by the manufacturer and installed on the device 3287 (see also Section 11.6). A device MAY be configured with multiple 3288 raw public keys. The type and length of the raw public key depends 3289 on the cipher suite used. Implementations in RawPublicKey mode MUST 3290 support the mandatory to implement cipher suite 3291 TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 as specified in 3292 [I-D.mcgrew-tls-aes-ccm-ecc], [RFC5246], [RFC4492]. The key used 3293 MUST be ECDSA-capable. The curve secp256r1 MUST be supported 3294 [RFC4492]; this curve is equivalent to the NIST P-256 curve. The 3295 hash algorithm is SHA-256. Implementations MUST use the Supported 3296 Elliptic Curves Extension and Supported Point Format extensions 3297 [RFC4492]; the uncompressed point format MUST be supported; [RFC6090] 3298 can be used as an implementation method. Some guidance relevant to 3299 the implementation of this cipher suite can be found in [W3CXMLSEC]. 3300 The mechanism for using raw public keys with TLS is specified in 3302 [I-D.ietf-tls-oob-pubkey]. 3304 Implementation Note: Specifically, this means the extensions listed 3305 in Figure 14 with at least the values listed will be present in 3306 the DTLS handshake. 3308 Extension: elliptic_curves 3309 Type: elliptic_curves (0x000a) 3310 Length: 4 3311 Elliptic Curves Length: 2 3312 Elliptic curves (1 curve) 3313 Elliptic curve: secp256r1 (0x0017) 3315 Extension: ec_point_formats 3316 Type: ec_point_formats (0x000b) 3317 Length: 2 3318 EC point formats Length: 1 3319 Elliptic curves point formats (1) 3320 EC point format: uncompressed (0) 3322 Extension: signature_algorithms 3323 Type: signature_algorithms (0x000d) 3324 Length: 4 3325 Data (4 bytes): 00 02 04 03 3326 HashAlgorithm: sha256 (4) 3327 SignatureAlgorithm: ecdsa (3) 3329 Figure 14: DTLS extensions present for 3330 TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 3332 9.1.3.2.1. Provisioning 3334 The RawPublicKey mode was designed to be easily provisioned in M2M 3335 deployments. It is assumed that each device has an appropriate 3336 asymmetric public key pair installed. An identifier is calculated by 3337 the endpoint from the public key as described in Section 2 of 3338 [RFC6920]. All implementations that support checking RawPublicKey 3339 identities MUST support at least the sha-256-120 mode (SHA-256 3340 truncated to 120 bits). Implementations SHOULD support also longer 3341 length identifiers and MAY support shorter lengths. Note that the 3342 shorter lengths provide less security against attacks and their use 3343 is NOT RECOMMENDED. 3345 Depending on how identifiers are given to the system that verifies 3346 them, support for URI, binary, and/or human-speakable format 3347 [RFC6920] needs to be implemented. All implementations SHOULD 3348 support the binary mode and implementations that have a user 3349 interface SHOULD also support the human-speakable format. 3351 During provisioning, the identifier of each node is collected, for 3352 example by reading a barcode on the outside of the device or by 3353 obtaining a pre-compiled list of the identifiers. These identifiers 3354 are then installed in the corresponding endpoint, for example an M2M 3355 data collection server. The identifier is used for two purposes, to 3356 associate the endpoint with further device information and to perform 3357 access control. During (initial and ongoing) provisioning, an access 3358 control list of identifiers the device may start DTLS sessions with 3359 SHOULD also be installed and maintained. 3361 9.1.3.3. X.509 Certificates 3363 Implementations in Certificate Mode MUST support the mandatory to 3364 implement cipher suite TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 as 3365 specified in [I-D.mcgrew-tls-aes-ccm-ecc], [RFC5246], [RFC4492]. 3366 Namely, the certificate includes a SubjectPublicKeyInfo that 3367 indicates an algorithm of id-ecPublicKey with namedCurves secp256r1 3368 [RFC5480]; the public key format is uncompressed [RFC5480]; the hash 3369 algorithm is SHA-256; if included the key usage extension indicates 3370 digitalSignature. Certificates MUST be signed with ECDSA using 3371 secp256r1, and the signature MUST use SHA-256. The key used MUST be 3372 ECDSA-capable. The curve secp256r1 MUST be supported [RFC4492]; this 3373 curve is equivalent to the NIST P-256 curve. The hash algorithm is 3374 SHA-256. Implementations MUST use the Supported Elliptic Curves 3375 Extension and Supported Point Format extensions [RFC4492]; the 3376 uncompressed point format MUST be supported; [RFC6090] can be used as 3377 an implementation method. 3379 The Authority Name in the certificate would be built out of a long 3380 term unique identifier for the device such as the EUI-64 [EUI64]. 3381 The Authority Name could also be based on the FQDN that was used as 3382 the Host part of the CoAP URI. However, the device's IP address 3383 should not typically be used as the Authority name as it would change 3384 over time. The discovery process used in the system would build up 3385 the mapping between IP addresses of the given devices and the 3386 Authority Name for each device. Some devices could have more than 3387 one Authority and would need more than a single certificate. 3389 When a new connection is formed, the certificate from the remote 3390 device needs to be verified. If the CoAP node has a source of 3391 absolute time, then the node SHOULD check that the validity dates of 3392 the certificate are within range. The certificate MUST be validated 3393 as appropriate for the security requirements, using functionality 3394 equivalent to the algorithm specified in [RFC5280] section 6. If the 3395 certificate contains a SubjectAltName, then the Authority Name MUST 3396 match at least one of the authority names of any CoAP URI found in a 3397 field of URI type in the SubjectAltName set. If there is no 3398 SubjectAltName in the certificate, then the Authoritative Name MUST 3399 match the CN found in the certificate using the matching rules 3400 defined in [RFC2818] with the exception that certificates with 3401 wildcards are not allowed. 3403 CoRE support for certificate status checking requires further study. 3404 As a mapping of OCSP [RFC2560] onto CoAP is not currently defined and 3405 OCSP may also not be easily applicable in all environments, an 3406 alternative approach may be using the TLS Certificate Status Request 3407 extension ([RFC6066] section 8, also known as "OCSP stapling") or 3408 preferably the Multiple Certificate Status Extension 3409 ([I-D.ietf-tls-multiple-cert-status-extension]), if available. 3411 If the system has a shared key in addition to the certificate, then a 3412 cipher suite that includes the shared key such as 3413 TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA [RFC5489] SHOULD be used. 3415 10. Cross-Protocol Proxying between CoAP and HTTP 3417 CoAP supports a limited subset of HTTP functionality, and thus cross- 3418 protocol proxying to HTTP is straightforward. There might be several 3419 reasons for proxying between CoAP and HTTP, for example when 3420 designing a web interface for use over either protocol or when 3421 realizing a CoAP-HTTP proxy. Likewise, CoAP could equally be proxied 3422 to other protocols such as XMPP [RFC6120] or SIP [RFC3264]; the 3423 definition of these mechanisms is out of scope of this specification. 3425 There are two possible directions to access a resource via a forward- 3426 proxy: 3428 CoAP-HTTP Proxying: Enables CoAP clients to access resources on HTTP 3429 servers through an intermediary. This is initiated by including 3430 the Proxy-Uri or Proxy-Scheme Option with an "http" or "https" URI 3431 in a CoAP request to a CoAP-HTTP proxy. 3433 HTTP-CoAP Proxying: Enables HTTP clients to access resources on CoAP 3434 servers through an intermediary. This is initiated by specifying 3435 a "coap" or "coaps" URI in the Request-Line of an HTTP request to 3436 an HTTP-CoAP proxy. 3438 Either way, only the Request/Response model of CoAP is mapped to 3439 HTTP. The underlying model of Confirmable or Non-confirmable 3440 messages, etc., is invisible and MUST have no effect on a proxy 3441 function. The following sections describe the handling of requests 3442 to a forward-proxy. Reverse proxies are not specified as the proxy 3443 function is transparent to the client with the proxy acting as if it 3444 was the origin server. However, similar considerations apply to 3445 reverse-proxies as to forward-proxies, and there generally will be an 3446 expectation that reverse-proxies operate in a similar way forward- 3447 proxies would. As an implementation note, HTTP client libraries may 3448 make it hard to operate an HTTP-CoAP forward proxy by not providing a 3449 way to put a CoAP URI on the HTTP Request-Line; reverse-proxying may 3450 therefore lead to wider applicability of a proxy. A separate 3451 specification may define a convention for URIs operating such a HTTP- 3452 CoAP reverse proxy [I-D.castellani-core-http-mapping]. 3454 10.1. CoAP-HTTP Proxying 3456 If a request contains a Proxy-Uri or Proxy-Scheme Option with an 3457 'http' or 'https' URI [RFC2616], then the receiving CoAP endpoint 3458 (called "the proxy" henceforth) is requested to perform the operation 3459 specified by the request method on the indicated HTTP resource and 3460 return the result to the client. (See also Section 5.7 for how the 3461 request to the proxy is formulated, including security requirements.) 3463 This section specifies for any CoAP request the CoAP response that 3464 the proxy should return to the client. How the proxy actually 3465 satisfies the request is an implementation detail, although the 3466 typical case is expected to be the proxy translating and forwarding 3467 the request to an HTTP origin server. 3469 Since HTTP and CoAP share the basic set of request methods, 3470 performing a CoAP request on an HTTP resource is not so different 3471 from performing it on a CoAP resource. The meanings of the 3472 individual CoAP methods when performed on HTTP resources are 3473 explained in the subsections of this section. 3475 If the proxy is unable or unwilling to service a request with an HTTP 3476 URI, a 5.05 (Proxying Not Supported) response is returned to the 3477 client. If the proxy services the request by interacting with a 3478 third party (such as the HTTP origin server) and is unable to obtain 3479 a result within a reasonable time frame, a 5.04 (Gateway Timeout) 3480 response is returned; if a result can be obtained but is not 3481 understood, a 5.02 (Bad Gateway) response is returned. 3483 10.1.1. GET 3485 The GET method requests the proxy to return a representation of the 3486 HTTP resource identified by the request URI. 3488 Upon success, a 2.05 (Content) response code SHOULD be returned. The 3489 payload of the response MUST be a representation of the target HTTP 3490 resource, and the Content-Format Option be set accordingly. The 3491 response MUST indicate a Max-Age value that is no greater than the 3492 remaining time the representation can be considered fresh. If the 3493 HTTP entity has an entity tag, the proxy SHOULD include an ETag 3494 Option in the response and process ETag Options in requests as 3495 described below. 3497 A client can influence the processing of a GET request by including 3498 the following option: 3500 Accept: The request MAY include an Accept Option, identifying the 3501 preferred response content-format. 3503 ETag: The request MAY include one or more ETag Options, identifying 3504 responses that the client has stored. This requests the proxy to 3505 send a 2.03 (Valid) response whenever it would send a 2.05 3506 (Content) response with an entity tag in the requested set 3507 otherwise. Note that CoAP ETags are always strong ETags in the 3508 HTTP sense; CoAP does not have the equivalent of HTTP weak ETags, 3509 and there is no good way to make use of these in a cross-proxy. 3511 10.1.2. PUT 3513 The PUT method requests the proxy to update or create the HTTP 3514 resource identified by the request URI with the enclosed 3515 representation. 3517 If a new resource is created at the request URI, a 2.01 (Created) 3518 response MUST be returned to the client. If an existing resource is 3519 modified, a 2.04 (Changed) response MUST be returned to indicate 3520 successful completion of the request. 3522 10.1.3. DELETE 3524 The DELETE method requests the proxy to delete the HTTP resource 3525 identified by the request URI at the HTTP origin server. 3527 A 2.02 (Deleted) response MUST be returned to client upon success or 3528 if the resource does not exist at the time of the request. 3530 10.1.4. POST 3532 The POST method requests the proxy to have the representation 3533 enclosed in the request be processed by the HTTP origin server. The 3534 actual function performed by the POST method is determined by the 3535 origin server and dependent on the resource identified by the request 3536 URI. 3538 If the action performed by the POST method does not result in a 3539 resource that can be identified by a URI, a 2.04 (Changed) response 3540 MUST be returned to the client. If a resource has been created on 3541 the origin server, a 2.01 (Created) response MUST be returned. 3543 10.2. HTTP-CoAP Proxying 3545 If an HTTP request contains a Request-URI with a 'coap' or 'coaps' 3546 URI, then the receiving HTTP endpoint (called "the proxy" henceforth) 3547 is requested to perform the operation specified by the request method 3548 on the indicated CoAP resource and return the result to the client. 3550 This section specifies for any HTTP request the HTTP response that 3551 the proxy should return to the client. Unless otherwise specified 3552 all the statements made are RECOMMENDED behavior; some highly 3553 constrained implementations may need to resort to shortcuts. How the 3554 proxy actually satisfies the request is an implementation detail, 3555 although the typical case is expected to be the proxy translating and 3556 forwarding the request to a CoAP origin server. The meanings of the 3557 individual HTTP methods when performed on CoAP resources are 3558 explained in the subsections of this section. 3560 If the proxy is unable or unwilling to service a request with a CoAP 3561 URI, a 501 (Not Implemented) response is returned to the client. If 3562 the proxy services the request by interacting with a third party 3563 (such as the CoAP origin server) and is unable to obtain a result 3564 within a reasonable time frame, a 504 (Gateway Timeout) response is 3565 returned; if a result can be obtained but is not understood, a 502 3566 (Bad Gateway) response is returned. 3568 10.2.1. OPTIONS and TRACE 3570 As the OPTIONS and TRACE methods are not supported in CoAP a 501 (Not 3571 Implemented) error MUST be returned to the client. 3573 10.2.2. GET 3575 The GET method requests the proxy to return a representation of the 3576 CoAP resource identified by the Request-URI. 3578 Upon success, a 200 (OK) response is returned. The payload of the 3579 response MUST be a representation of the target CoAP resource, and 3580 the Content-Type and Content-Encoding header fields be set 3581 accordingly. The response MUST indicate a max-age directive that 3582 indicates a value no greater than the remaining time the 3583 representation can be considered fresh. If the CoAP response has an 3584 ETag option, the proxy should include an ETag header field in the 3585 response. 3587 A client can influence the processing of a GET request by including 3588 the following options: 3590 Accept: The most preferred Media-type of the HTTP Accept header 3591 field in a request is mapped to a CoAP Accept option. HTTP Accept 3592 Media-type ranges, parameters and extensions are not supported by 3593 the CoAP Accept option. If the proxy cannot send a response which 3594 is acceptable according to the combined Accept field value, then 3595 the proxy sends a 406 (not acceptable) response. The proxy MAY 3596 then retry the request with further Media-types from the HTTP 3597 Accept header field. 3599 Conditional GETs: Conditional HTTP GET requests that include an "If- 3600 Match" or "If-None-Match" request-header field can be mapped to a 3601 corresponding CoAP request. The "If-Modified-Since" and "If- 3602 Unmodified-Since" request-header fields are not directly supported 3603 by CoAP, but are implemented locally by a caching proxy. 3605 10.2.3. HEAD 3607 The HEAD method is identical to GET except that the server MUST NOT 3608 return a message-body in the response. 3610 Although there is no direct equivalent of HTTP's HEAD method in CoAP, 3611 an HTTP-CoAP proxy responds to HEAD requests for CoAP resources, and 3612 the HTTP headers are returned without a message-body. 3614 Implementation Note: An HTTP-CoAP proxy may want to try using a 3615 block-wise transfer [I-D.ietf-core-block] option to minimize the 3616 amount of data actually transferred, but needs to be prepared for 3617 the case that the origin server does not support block-wise 3618 transfers. 3620 10.2.4. POST 3622 The POST method requests the proxy to have the representation 3623 enclosed in the request be processed by the CoAP origin server. The 3624 actual function performed by the POST method is determined by the 3625 origin server and dependent on the resource identified by the request 3626 URI. 3628 If the action performed by the POST method does not result in a 3629 resource that can be identified by a URI, a 200 (OK) or 204 (No 3630 Content) response MUST be returned to the client. If a resource has 3631 been created on the origin server, a 201 (Created) response MUST be 3632 returned. 3634 If any of the Location-* Options are present in the CoAP response, a 3635 Location header field constructed from the values of these options is 3636 returned. 3638 10.2.5. PUT 3640 The PUT method requests the proxy to update or create the CoAP 3641 resource identified by the Request-URI with the enclosed 3642 representation. 3644 If a new resource is created at the Request-URI, a 201 (Created) 3645 response is returned to the client. If an existing resource is 3646 modified, either the 200 (OK) or 204 (No Content) response codes is 3647 sent to indicate successful completion of the request. 3649 10.2.6. DELETE 3651 The DELETE method requests the proxy to delete the CoAP resource 3652 identified by the Request-URI at the CoAP origin server. 3654 A successful response is 200 (OK) if the response includes an entity 3655 describing the status or 204 (No Content) if the action has been 3656 enacted but the response does not include an entity. 3658 10.2.7. CONNECT 3660 This method can not currently be satisfied by an HTTP-CoAP proxy 3661 function as TLS to DTLS tunneling has not yet been specified. For 3662 now, a 501 (Not Implemented) error is returned to the client. 3664 11. Security Considerations 3666 This section analyzes the possible threats to the protocol. It is 3667 meant to inform protocol and application developers about the 3668 security limitations of CoAP as described in this document. As CoAP 3669 realizes a subset of the features in HTTP/1.1, the security 3670 considerations in Section 15 of [RFC2616] are also pertinent to CoAP. 3671 This section concentrates on describing limitations specific to CoAP. 3673 11.1. Protocol Parsing, Processing URIs 3675 A network-facing application can exhibit vulnerabilities in its 3676 processing logic for incoming packets. Complex parsers are well- 3677 known as a likely source of such vulnerabilities, such as the ability 3678 to remotely crash a node, or even remotely execute arbitrary code on 3679 it. CoAP attempts to narrow the opportunities for introducing such 3680 vulnerabilities by reducing parser complexity, by giving the entire 3681 range of encodable values a meaning where possible, and by 3682 aggressively reducing complexity that is often caused by unnecessary 3683 choice between multiple representations that mean the same thing. 3684 Much of the URI processing has been moved to the clients, further 3685 reducing the opportunities for introducing vulnerabilities into the 3686 servers. Even so, the URI processing code in CoAP implementations is 3687 likely to be a large source of remaining vulnerabilities and should 3688 be implemented with special care. CoAP access control 3689 implementations need to ensure they don't introduce vulnerabilities 3690 through discrepancies between the code deriving access control 3691 decisions from a URI and the code finally serving up the resource 3692 addressed by the URI. The most complex parser remaining could be the 3693 one for the CoRE Link Format, although this also has been designed 3694 with a goal of reduced implementation complexity [RFC6690]. (See 3695 also section 15.2 of [RFC2616].) 3697 11.2. Proxying and Caching 3699 As mentioned in 15.7 of [RFC2616], proxies are by their very nature 3700 men-in-the-middle, breaking any IPsec or DTLS protection that a 3701 direct CoAP message exchange might have. They are therefore 3702 interesting targets for breaking confidentiality or integrity of CoAP 3703 message exchanges. As noted in [RFC2616], they are also interesting 3704 targets for breaking availability. 3706 The threat to confidentiality and integrity of request/response data 3707 is amplified where proxies also cache. Note that CoAP does not 3708 define any of the cache-suppressing Cache-Control options that 3709 HTTP/1.1 provides to better protect sensitive data. 3711 For a caching implementation, any access control considerations that 3712 would apply to making the request that generated the cache entry also 3713 need to be applied to the value in the cache. This is relevant for 3714 clients that implement multiple security domains, as well as for 3715 proxies that may serve multiple clients. Also, a caching proxy MUST 3716 NOT make cached values available to requests that have lesser 3717 transport security properties than to which it would make available 3718 the process of forwarding the request in the first place. 3720 Unlike the "coap" scheme, responses to "coaps" identified requests 3721 are never "public" and thus MUST NOT be reused for shared caching 3722 unless the cache is able to make equivalent access control decisions 3723 to the ones that led to the cached entry. They can, however, be 3724 reused in a private cache if the message is cacheable by default in 3725 CoAP. 3727 Finally, a proxy that fans out Separate Responses (as opposed to 3728 Piggy-backed Responses) to multiple original requesters may provide 3729 additional amplification (see Section 11.3). 3731 11.3. Risk of amplification 3733 CoAP servers generally reply to a request packet with a response 3734 packet. This response packet may be significantly larger than the 3735 request packet. An attacker might use CoAP nodes to turn a small 3736 attack packet into a larger attack packet, an approach known as 3737 amplification. There is therefore a danger that CoAP nodes could 3738 become implicated in denial of service (DoS) attacks by using the 3739 amplifying properties of the protocol: An attacker that is attempting 3740 to overload a victim but is limited in the amount of traffic it can 3741 generate, can use amplification to generate a larger amount of 3742 traffic. 3744 This is particularly a problem in nodes that enable NoSec access, 3745 that are accessible from an attacker and can access potential victims 3746 (e.g. on the general Internet), as the UDP protocol provides no way 3747 to verify the source address given in the request packet. An 3748 attacker need only place the IP address of the victim in the source 3749 address of a suitable request packet to generate a larger packet 3750 directed at the victim. 3752 As a mitigating factor, many constrained networks will only be able 3753 to generate a small amount of traffic, which may make CoAP nodes less 3754 attractive for this attack. However, the limited capacity of the 3755 constrained network makes the network itself a likely victim of an 3756 amplification attack. 3758 Therefore, large amplification factors SHOULD NOT be provided in the 3759 response if the request is not authenticated. A CoAP server can 3760 reduce the amount of amplification it provides to an attacker by 3761 using slicing/blocking modes of CoAP [I-D.ietf-core-block] and 3762 offering large resource representations only in relatively small 3763 slices. E.g., for a 1000 byte resource, a 10-byte request might 3764 result in an 80-byte response (with a 64-byte block) instead of a 3765 1016-byte response, considerably reducing the amplification provided. 3767 CoAP also supports the use of multicast IP addresses in requests, an 3768 important requirement for M2M. Multicast CoAP requests may be the 3769 source of accidental or deliberate denial of service attacks, 3770 especially over constrained networks. This specification attempts to 3771 reduce the amplification effects of multicast requests by limiting 3772 when a response is returned. To limit the possibility of malicious 3773 use, CoAP servers SHOULD NOT accept multicast requests that can not 3774 be authenticated in some way, cryptographically or by some multicast 3775 boundary limiting the potential sources. If possible a CoAP server 3776 SHOULD limit the support for multicast requests to the specific 3777 resources where the feature is required. 3779 On some general purpose operating systems providing a Posix-style 3780 API, it is not straightforward to find out whether a packet received 3781 was addressed to a multicast address. While many implementations 3782 will know whether they have joined a multicast group, this creates a 3783 problem for packets addressed to multicast addresses of the form 3784 FF0x::1, which are received by every IPv6 node. Implementations 3785 SHOULD make use of modern APIs such as IPV6_RECVPKTINFO [RFC3542], if 3786 available, to make this determination. 3788 11.4. IP Address Spoofing Attacks 3790 Due to the lack of a handshake in UDP, a rogue endpoint which is free 3791 to read and write messages carried by the constrained network (i.e. 3792 NoSec or PreSharedKey deployments with nodes/key ratio > 1:1), may 3793 easily attack a single endpoint, a group of endpoints, as well as the 3794 whole network e.g. by: 3796 1. spoofing RST in response to a CON or NON message, thus making an 3797 endpoint "deaf"; or 3799 2. spoofing an ACK in response to a CON message, thus potentially 3800 preventing the sender of the CON message from retransmitting, and 3801 drowning out the actual response; or 3803 3. spoofing the entire response with forged payload/options (this 3804 has different levels of impact: from single response disruption, 3805 to much bolder attacks on the supporting infrastructure, e.g. 3806 poisoning proxy caches, or tricking validation / lookup 3807 interfaces in resource directories and, more generally, any 3808 component that stores global network state and uses CoAP as the 3809 messaging facility to handle state set/update's is a potential 3810 target.); or 3812 4. spoofing a multicast request for a target node which may result 3813 in both network congestion/collapse and victim DoS'ing / forced 3814 wakeup from sleeping; or 3816 5. spoofing observe messages, etc. 3818 Response spoofing by off-path attackers can be detected and mitigated 3819 even without transport layer security by choosing a non-trivial, 3820 randomized token in the request (Section 5.3.1). [RFC4086] discusses 3821 randomness requirements for security. 3823 In principle, other kinds of spoofing can be detected by CoAP only in 3824 case CON semantics is used, because of unexpected ACK/RSTs coming 3825 from the deceived endpoint. But this imposes keeping track of the 3826 used Message IDs which is not always possible, and moreover detection 3827 becomes available usually after the damage is already done. This 3828 kind of attack can be prevented using security modes other than 3829 NoSec. 3831 With or without source address spoofing, a client can attempt to 3832 overload a server by sending requests, preferably complex ones, to a 3833 server; address spoofing makes tracing back, and blocking, this 3834 attack harder. Given that the cost of a CON request is small, this 3835 attack can easily be executed. Under this attack, a constrained node 3836 with limited total energy available may exhaust that energy much more 3837 quickly than planned (battery depletion attack). Also, if the client 3838 uses a Confirmable message and the server responds with a Confirmable 3839 separate response to a (possibly spoofed) address that does not 3840 respond, the server will have to allocate buffer and retransmission 3841 logic for each response up to the exhaustion of MAX_TRANSMIT_SPAN, 3842 making it more likely that it runs out of resources for processing 3843 legitimate traffic. The latter problem can be mitigated somewhat by 3844 limiting the rate of responses as discussed in Section 4.7. An 3845 attacker could also spoof the address of a legitimate client, which, 3846 if the server uses separate responses, might block legitimate 3847 responses to that client because of NSTART=1. All these attacks can 3848 be prevented using a security mode other than NoSec, leaving only 3849 attacks on the security protocol. 3851 11.5. Cross-Protocol Attacks 3853 The ability to incite a CoAP endpoint to send packets to a fake 3854 source address can be used not only for amplification, but also for 3855 cross-protocol attacks against a victim listening to UDP packets at a 3856 given address (IP address and port): 3858 o the attacker sends a message to a CoAP endpoint with the given 3859 address as the fake source address, 3861 o the CoAP endpoint replies with a message to the given source 3862 address, 3864 o the victim at the given address receives a UDP packet that it 3865 interprets according to the rules of a different protocol. 3867 This may be used to circumvent firewall rules that prevent direct 3868 communication from the attacker to the victim, but happen to allow 3869 communication from the CoAP endpoint (which may also host a valid 3870 role in the other protocol) to the victim. 3872 Also, CoAP endpoints may be the victim of a cross-protocol attack 3873 generated through an endpoint of another UDP-based protocol such as 3874 DNS. In both cases, attacks are possible if the security properties 3875 of the endpoints rely on checking IP addresses (and firewalling off 3876 direct attacks sent from outside using fake IP addresses). In 3877 general, because of their lack of context, UDP-based protocols are 3878 relatively easy targets for cross-protocol attacks. 3880 Finally, CoAP URIs transported by other means could be used to incite 3881 clients to send messages to endpoints of other protocols. 3883 One mitigation against cross-protocol attacks is strict checking of 3884 the syntax of packets received, combined with sufficient difference 3885 in syntax. As an example, it might help if it were difficult to 3886 incite a DNS server to send a DNS response that would pass the checks 3887 of a CoAP endpoint. Unfortunately, the first two bytes of a DNS 3888 reply are an ID that can be chosen by the attacker, which map into 3889 the interesting part of the CoAP header, and the next two bytes are 3890 then interpreted as CoAP's Message ID (i.e., any value is 3891 acceptable). The DNS count words may be interpreted as multiple 3892 instances of a (non-existent, but elective) CoAP option 0, or 3893 possibly as a Token. The echoed query finally may be manufactured by 3894 the attacker to achieve a desired effect on the CoAP endpoint; the 3895 response added by the server (if any) might then just be interpreted 3896 as added payload. 3898 1 1 1 1 1 1 3899 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 3900 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3901 | ID | T, TKL, code 3902 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3903 |QR| Opcode |AA|TC|RD|RA| Z | RCODE | Message ID 3904 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3905 | QDCOUNT | (options 0) 3906 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3907 | ANCOUNT | (options 0) 3908 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3909 | NSCOUNT | (options 0) 3910 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3911 | ARCOUNT | (options 0) 3912 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 3914 Figure 15: DNS Header vs. CoAP Message 3916 In general, for any pair of protocols, one of the protocols can very 3917 well have been designed in a way that enables an attacker to cause 3918 the generation of replies that look like messages of the other 3919 protocol. It is often much harder to ensure or prove the absence of 3920 viable attacks than to generate examples that may not yet completely 3921 enable an attack but might be further developed by more creative 3922 minds. Cross-protocol attacks can therefore only be completely 3923 mitigated if endpoints don't authorize actions desired by an attacker 3924 just based on trusting the source IP address of a packet. 3925 Conversely, a NoSec environment that completely relies on a firewall 3926 for CoAP security not only needs to firewall off the CoAP endpoints 3927 but also all other endpoints that might be incited to send UDP 3928 messages to CoAP endpoints using some other UDP-based protocol. 3930 In addition to the considerations above, the security considerations 3931 for DTLS with respect to cross-protocol attacks apply. E.g., if the 3932 same DTLS security association ("connection") is used to carry data 3933 of multiple protocols, DTLS no longer provides protection against 3934 cross-protocol attacks between these protocols. 3936 11.6. Constrained node considerations 3938 Implementers on constrained nodes often find themselves without a 3939 good source of entropy [RFC4086]. If that is the case, the node MUST 3940 NOT be used for processes that require good entropy, such as key 3941 generation. Instead, keys should be generated externally and added 3942 to the device during manufacturing or commissioning. 3944 Due to their low processing power, constrained nodes are particularly 3945 susceptible to timing attacks. Special care must be taken in 3946 implementation of cryptographic primitives. 3948 Large numbers of constrained nodes will be installed in exposed 3949 environments and will have little resistance to tampering, including 3950 recovery of keying materials. This needs to be considered when 3951 defining the scope of credentials assigned to them. In particular, 3952 assigning a shared key to a group of nodes may make any single 3953 constrained node a target for subverting the entire group. 3955 12. IANA Considerations 3957 12.1. CoAP Code Registries 3959 This document defines two sub-registries for the values of the Code 3960 field in the CoAP header within the Constrained RESTful Environments 3961 (CoRE) Parameters ("CoRE Parameters") registry. 3963 Values in the two sub-registries are eight-bit values notated as 3964 three decimal digits c.dd separated by a period between the first and 3965 the second digit; the first digit c is between 0 and 7 and denotes 3966 the code class; the second and third digit dd denote a decimal number 3967 between 00 and 31 for the detail. 3969 All Code values are assigned by sub-registries according to the 3970 following ranges: 3972 0.00 Indicates an empty message (see Section 4.1). 3974 0.01-0.31 Indicates a request. Values in this range are assigned by 3975 the "CoAP Method Codes" sub-registry (see Section 12.1.1). 3977 1.00-1.31 Reserved 3979 2.00-5.31 Indicates a response. Values in this range are assigned by 3980 the "CoAP Response Codes" sub-registry (see 3981 Section 12.1.2). 3983 6.00-7.31 Reserved 3985 12.1.1. Method Codes 3987 The name of the sub-registry is "CoAP Method Codes". 3989 Each entry in the sub-registry must include the Method Code in the 3990 range 0.01-0.31, the name of the method, and a reference to the 3991 method's documentation. 3993 Initial entries in this sub-registry are as follows: 3995 +------+--------+-----------+ 3996 | Code | Name | Reference | 3997 +------+--------+-----------+ 3998 | 0.01 | GET | [RFCXXXX] | 3999 | 0.02 | POST | [RFCXXXX] | 4000 | 0.03 | PUT | [RFCXXXX] | 4001 | 0.04 | DELETE | [RFCXXXX] | 4002 +------+--------+-----------+ 4004 Table 5: CoAP Method Codes 4006 All other Method Codes are Unassigned. 4008 The IANA policy for future additions to this sub-registry is "IETF 4009 Review or IESG approval" as described in [RFC5226]. 4011 The documentation of a method code should specify the semantics of a 4012 request with that code, including the following properties: 4014 o The response codes the method returns in the success case. 4016 o Whether the method is idempotent, safe, or both. 4018 12.1.2. Response Codes 4020 The name of the sub-registry is "CoAP Response Codes". 4022 Each entry in the sub-registry must include the Response Code in the 4023 range 2.00-5.31, a description of the Response Code, and a reference 4024 to the Response Code's documentation. 4026 Initial entries in this sub-registry are as follows: 4028 +------+----------------------------+-----------+ 4029 | Code | Description | Reference | 4030 +------+----------------------------+-----------+ 4031 | 2.01 | Created | [RFCXXXX] | 4032 | 2.02 | Deleted | [RFCXXXX] | 4033 | 2.03 | Valid | [RFCXXXX] | 4034 | 2.04 | Changed | [RFCXXXX] | 4035 | 2.05 | Content | [RFCXXXX] | 4036 | 4.00 | Bad Request | [RFCXXXX] | 4037 | 4.01 | Unauthorized | [RFCXXXX] | 4038 | 4.02 | Bad Option | [RFCXXXX] | 4039 | 4.03 | Forbidden | [RFCXXXX] | 4040 | 4.04 | Not Found | [RFCXXXX] | 4041 | 4.05 | Method Not Allowed | [RFCXXXX] | 4042 | 4.06 | Not Acceptable | [RFCXXXX] | 4043 | 4.12 | Precondition Failed | [RFCXXXX] | 4044 | 4.13 | Request Entity Too Large | [RFCXXXX] | 4045 | 4.15 | Unsupported Content-Format | [RFCXXXX] | 4046 | 5.00 | Internal Server Error | [RFCXXXX] | 4047 | 5.01 | Not Implemented | [RFCXXXX] | 4048 | 5.02 | Bad Gateway | [RFCXXXX] | 4049 | 5.03 | Service Unavailable | [RFCXXXX] | 4050 | 5.04 | Gateway Timeout | [RFCXXXX] | 4051 | 5.05 | Proxying Not Supported | [RFCXXXX] | 4052 +------+----------------------------+-----------+ 4054 Table 6: CoAP Response Codes 4056 The Response Codes 3.00-3.31 are Reserved for future use. All other 4057 Response Codes are Unassigned. 4059 The IANA policy for future additions to this sub-registry is "IETF 4060 Review or IESG approval" as described in [RFC5226]. 4062 The documentation of a response code should specify the semantics of 4063 a response with that code, including the following properties: 4065 o The methods the response code applies to. 4067 o Whether payload is required, optional or not allowed. 4069 o The semantics of the payload. For example, the payload of a 2.05 4070 (Content) response is a representation of the target resource; the 4071 payload in an error response is a human-readable diagnostic 4072 payload. 4074 o The format of the payload. For example, the format in a 2.05 4075 (Content) response is indicated by the Content-Format Option; the 4076 format of the payload in an error response is always Net-Unicode 4077 text. 4079 o Whether the response is cacheable according to the freshness 4080 model. 4082 o Whether the response is validatable according to the validation 4083 model. 4085 o Whether the response causes a cache to mark responses stored for 4086 the request URI as not fresh. 4088 12.2. Option Number Registry 4090 This document defines a sub-registry for the Option Numbers used in 4091 CoAP options within the "CoRE Parameters" registry. The name of the 4092 sub-registry is "CoAP Option Numbers". 4094 Each entry in the sub-registry must include the Option Number, the 4095 name of the option and a reference to the option's documentation. 4097 Initial entries in this sub-registry are as follows: 4099 +--------+----------------+-----------+ 4100 | Number | Name | Reference | 4101 +--------+----------------+-----------+ 4102 | 0 | (Reserved) | [RFCXXXX] | 4103 | 1 | If-Match | [RFCXXXX] | 4104 | 3 | Uri-Host | [RFCXXXX] | 4105 | 4 | ETag | [RFCXXXX] | 4106 | 5 | If-None-Match | [RFCXXXX] | 4107 | 7 | Uri-Port | [RFCXXXX] | 4108 | 8 | Location-Path | [RFCXXXX] | 4109 | 11 | Uri-Path | [RFCXXXX] | 4110 | 12 | Content-Format | [RFCXXXX] | 4111 | 14 | Max-Age | [RFCXXXX] | 4112 | 15 | Uri-Query | [RFCXXXX] | 4113 | 16 | Accept | [RFCXXXX] | 4114 | 20 | Location-Query | [RFCXXXX] | 4115 | 35 | Proxy-Uri | [RFCXXXX] | 4116 | 39 | Proxy-Scheme | [RFCXXXX] | 4117 | 128 | (Reserved) | [RFCXXXX] | 4118 | 132 | (Reserved) | [RFCXXXX] | 4119 | 136 | (Reserved) | [RFCXXXX] | 4120 | 140 | (Reserved) | [RFCXXXX] | 4121 +--------+----------------+-----------+ 4123 Table 7: CoAP Option Numbers 4125 The IANA policy for future additions to this sub-registry is split 4126 into three tiers as follows. The range of 0..255 is reserved for 4127 options defined by the IETF (IETF Review or IESG approval). The 4128 range of 256..2047 is reserved for commonly used options with public 4129 specifications (Specification Required). The range of 2048..64999 is 4130 for all other options including private or vendor specific ones, 4131 which undergo a Designated Expert review to help ensure that the 4132 option semantics are defined correctly. The option numbers between 4133 65000 and 65535 inclusive are reserved for experiments. They are not 4134 meant for vendor specific use of any kind and MUST NOT be used in 4135 operational deployments. 4137 +---------------+------------------------------+ 4138 | Option Number | Policy [RFC5226] | 4139 +---------------+------------------------------+ 4140 | 0..255 | IETF Review or IESG approval | 4141 | 256..2047 | Specification Required | 4142 | 2048..64999 | Designated Expert | 4143 | 65000..65535 | Reserved for experiments | 4144 +---------------+------------------------------+ 4146 Table 8: CoAP Option Number Registry Policy 4148 The documentation of an Option Number should specify the semantics of 4149 an option with that number, including the following properties: 4151 o The meaning of the option in a request. 4153 o The meaning of the option in a response. 4155 o Whether the option is critical or elective, as determined by the 4156 Option Number. 4158 o Whether the option is Safe-to-Forward, and, if yes, whether it is 4159 part of the Cache-Key, as determined by the Option Number (see 4160 Section 5.4.2). 4162 o The format and length of the option's value. 4164 o Whether the option must occur at most once or whether it can occur 4165 multiple times. 4167 o The default value, if any. For a critical option with a default 4168 value, a discussion on how the default value enables processing by 4169 implementations not implementing the critical option 4170 (Section 5.4.4). 4172 12.3. Content-Format Registry 4174 Internet media types are identified by a string, such as 4175 "application/xml" [RFC2046]. In order to minimize the overhead of 4176 using these media types to indicate the format of payloads, this 4177 document defines a sub-registry for a subset of Internet media types 4178 to be used in CoAP and assigns each, in combination with a content- 4179 coding, a numeric identifier. The name of the sub-registry is "CoAP 4180 Content-Formats", within the "CoRE Parameters" registry. 4182 Each entry in the sub-registry must include the media type registered 4183 with IANA, the numeric identifier in the range 0-65535 to be used for 4184 that media type in CoAP, the content-coding associated with this 4185 identifier, and a reference to a document describing what a payload 4186 with that media type means semantically. 4188 CoAP does not include a separate way to convey content-encoding 4189 information with a request or response, and for that reason the 4190 content-encoding is also specified for each identifier (if any). If 4191 multiple content-encodings will be used with a media type, then a 4192 separate Content-Format identifier for each is to be registered. 4193 Similarly, other parameters related to an Internet media type, such 4194 as level, can be defined for a CoAP Content-Format entry. 4196 Initial entries in this sub-registry are as follows: 4198 +--------------------+----------+-----+-----------------------------+ 4199 | Media type | Encoding | Id. | Reference | 4200 +--------------------+----------+-----+-----------------------------+ 4201 | text/plain; | - | 0 | [RFC2046][RFC3676][RFC5147] | 4202 | charset=utf-8 | | | | 4203 | application/ | - | 40 | [RFC6690] | 4204 | link-format | | | | 4205 | application/xml | - | 41 | [RFC3023] | 4206 | application/ | - | 42 | [RFC2045][RFC2046] | 4207 | octet-stream | | | | 4208 | application/exi | - | 47 | [EXIMIME] | 4209 | application/json | - | 50 | [RFC4627] | 4210 +--------------------+----------+-----+-----------------------------+ 4212 Table 9: CoAP Content-Formats 4214 The identifiers between 65000 and 65535 inclusive are reserved for 4215 experiments. They are not meant for vendor specific use of any kind 4216 and MUST NOT be used in operational deployments. The identifiers 4217 between 256 and 9999 are reserved for future use in IETF 4218 specifications (IETF review or IESG approval). All other identifiers 4219 are Unassigned. 4221 Because the name space of single-byte identifiers is so small, the 4222 IANA policy for future additions in the range 0-255 inclusive to the 4223 sub-registry is "Expert Review" as described in [RFC5226]. The IANA 4224 policy for additions in the range 10000-64999 inclusive is "First 4225 Come First Served" as described in [RFC5226]. 4227 In machine to machine applications, it is not expected that generic 4228 Internet media types such as text/plain, application/xml or 4229 application/octet-stream are useful for real applications in the long 4230 term. It is recommended that M2M applications making use of CoAP 4231 will request new Internet media types from IANA indicating semantic 4232 information about how to create or parse a payload. For example, a 4233 Smart Energy application payload carried as XML might request a more 4234 specific type like application/se+xml or application/se-exi. 4236 12.4. URI Scheme Registration 4238 This document requests the registration of the Uniform Resource 4239 Identifier (URI) scheme "coap". The registration request complies 4240 with [RFC4395]. 4242 URI scheme name. 4243 coap 4245 Status. 4246 Permanent. 4248 URI scheme syntax. 4249 Defined in Section 6.1 of [RFCXXXX]. 4251 URI scheme semantics. 4252 The "coap" URI scheme provides a way to identify resources that 4253 are potentially accessible over the Constrained Application 4254 Protocol (CoAP). The resources can be located by contacting the 4255 governing CoAP server and operated on by sending CoAP requests to 4256 the server. This scheme can thus be compared to the "http" URI 4257 scheme [RFC2616]. See Section 6 of [RFCXXXX] for the details of 4258 operation. 4260 Encoding considerations. 4261 The scheme encoding conforms to the encoding rules established for 4262 URIs in [RFC3986], i.e. internationalized and reserved characters 4263 are expressed using UTF-8-based percent-encoding. 4265 Applications/protocols that use this URI scheme name. 4266 The scheme is used by CoAP endpoints to access CoAP resources. 4268 Interoperability considerations. 4269 None. 4271 Security considerations. 4272 See Section 11.1 of [RFCXXXX]. 4274 Contact. 4275 IETF Chair 4277 Author/Change controller. 4278 IESG 4280 References. 4281 [RFCXXXX] 4283 12.5. Secure URI Scheme Registration 4285 This document requests the registration of the Uniform Resource 4286 Identifier (URI) scheme "coaps". The registration request complies 4287 with [RFC4395]. 4289 URI scheme name. 4290 coaps 4292 Status. 4293 Permanent. 4295 URI scheme syntax. 4296 Defined in Section 6.2 of [RFCXXXX]. 4298 URI scheme semantics. 4299 The "coaps" URI scheme provides a way to identify resources that 4300 are potentially accessible over the Constrained Application 4301 Protocol (CoAP) using Datagram Transport Layer Security (DTLS) for 4302 transport security. The resources can be located by contacting 4303 the governing CoAP server and operated on by sending CoAP requests 4304 to the server. This scheme can thus be compared to the "https" 4305 URI scheme [RFC2616]. See Section 6 of [RFCXXXX] for the details 4306 of operation. 4308 Encoding considerations. 4309 The scheme encoding conforms to the encoding rules established for 4310 URIs in [RFC3986], i.e. internationalized and reserved characters 4311 are expressed using UTF-8-based percent-encoding. 4313 Applications/protocols that use this URI scheme name. 4314 The scheme is used by CoAP endpoints to access CoAP resources 4315 using DTLS. 4317 Interoperability considerations. 4318 None. 4320 Security considerations. 4321 See Section 11.1 of [RFCXXXX]. 4323 Contact. 4324 IETF Chair 4326 Author/Change controller. 4327 IESG 4329 References. 4330 [RFCXXXX] 4332 12.6. Service Name and Port Number Registration 4334 One of the functions of CoAP is resource discovery: a CoAP client can 4335 ask a CoAP server about the resources offered by it (see Section 7). 4336 To enable resource discovery just based on the knowledge of an IP 4337 address, the CoAP port for resource discovery needs to be 4338 standardized. 4340 IANA has assigned the port number 5683 and the service name "coap", 4341 in accordance with [RFC6335]. 4343 Besides unicast, CoAP can be used with both multicast and anycast. 4345 Service Name. 4346 coap 4348 Transport Protocol. 4349 UDP 4351 Assignee. 4352 IESG 4354 Contact. 4355 IETF Chair 4357 Description. 4358 Constrained Application Protocol (CoAP) 4360 Reference. 4361 [RFCXXXX] 4363 Port Number. 4364 5683 4366 12.7. Secure Service Name and Port Number Registration 4368 CoAP resource discovery may also be provided using the DTLS-secured 4369 CoAP "coaps" scheme. Thus the CoAP port for secure resource 4370 discovery needs to be standardized. 4372 This document requests the assignment of the port number 4373 [IANA_TBD_PORT] and the service name "coaps", in accordance with 4374 [RFC6335]. 4376 Besides unicast, DTLS-secured CoAP can be used with anycast. 4378 Service Name. 4379 coaps 4381 Transport Protocol. 4382 UDP 4384 Assignee. 4385 IESG 4387 Contact. 4388 IETF Chair 4390 Description. 4391 DTLS-secured CoAP 4393 Reference. 4394 [RFCXXXX] 4396 Port Number. 4397 [IANA_TBD_PORT] 4399 12.8. Multicast Address Registration 4401 Section 8, "Multicast CoAP", defines the use of multicast. This 4402 document requests the assignment of the following multicast addresses 4403 for use by CoAP nodes: 4405 IPv4 -- "All CoAP Nodes" address [TBD1], from the IPv4 Multicast 4406 Address Space Registry. As the address is used for discovery that 4407 may span beyond a single network, it should come from the 4408 Internetwork Control Block (224.0.1.x, RFC 5771). 4410 IPv6 -- "All CoAP Nodes" address [TBD2], from the IPv6 Multicast 4411 Address Space Registry, in the Variable Scope Multicast Addresses 4412 space (RFC3307). Note that there is a distinct multicast address 4413 for each scope that interested CoAP nodes should listen to; CoAP 4414 needs the Link-Local and Site-Local scopes only. The address 4415 should be of the form FF0x::nn, where nn is a single byte, to 4416 ensure good compression of the local-scope address with [RFC6282]. 4418 [The explanatory text to be removed upon allocation of the addresses, 4419 except for the note about the distinct multicast addresses.] 4421 13. Acknowledgements 4423 Brian Frank was a contributor to and co-author of previous drafts of 4424 this specification. 4426 Special thanks to Peter Bigot, Esko Dijk and Cullen Jennings for 4427 substantial contributions to the ideas and text in the document, 4428 along with countless detailed reviews and discussions. 4430 Thanks to Ed Beroset, Angelo P. Castellani, Gilbert Clark, Robert 4431 Cragie, Esko Dijk, Lisa Dusseault, Mehmet Ersue, Thomas Fossati, Tom 4432 Herbst, Richard Kelsey, Ari Keranen, Matthias Kovatsch, Salvatore 4433 Loreto, Kerry Lynn, Alexey Melnikov, Guido Moritz, Petri Mutka, Colin 4434 O'Flynn, Charles Palmer, Adriano Pezzuto, Robert Quattlebaum, Akbar 4435 Rahman, Eric Rescorla, Dan Romascanu, David Ryan, Szymon Sasin, 4436 Michael Scharf, Dale Seed, Robby Simpson, Peter van der Stok, Michael 4437 Stuber, Linyi Tian, Gilman Tolle, Matthieu Vial and Alper Yegin for 4438 helpful comments and discussions that have shaped the document. 4439 Special thanks also to the IESG reviewers, Adrian Farrel, Martin 4440 Stiemerling, Pete Resnick, Richard Barnes, Sean Turner, Spencer 4441 Dawkins, Stephen Farrell, and Ted Lemon, who contributed in-depth 4442 reviews. 4444 Some of the text has been borrowed from the working documents of the 4445 IETF httpbis working group. 4447 14. References 4449 14.1. Normative References 4451 [I-D.ietf-tls-oob-pubkey] 4452 Wouters, P., Tschofenig, H., Gilmore, J., Weiler, S., and 4453 T. Kivinen, "Out-of-Band Public Key Validation for 4454 Transport Layer Security (TLS)", 4455 draft-ietf-tls-oob-pubkey-07 (work in progress), 4456 February 2013. 4458 [I-D.mcgrew-tls-aes-ccm-ecc] 4459 McGrew, D., Bailey, D., Campagna, M., and R. Dugal, "AES- 4460 CCM ECC Cipher Suites for TLS", 4461 draft-mcgrew-tls-aes-ccm-ecc-06 (work in progress), 4462 February 2013. 4464 [RFC0768] Postel, J., "User Datagram Protocol", STD 6, RFC 768, 4465 August 1980. 4467 [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 4468 Extensions (MIME) Part One: Format of Internet Message 4469 Bodies", RFC 2045, November 1996. 4471 [RFC2046] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 4472 Extensions (MIME) Part Two: Media Types", RFC 2046, 4473 November 1996. 4475 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 4476 Requirement Levels", BCP 14, RFC 2119, March 1997. 4478 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 4479 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 4480 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 4482 [RFC3023] Murata, M., St. Laurent, S., and D. Kohn, "XML Media 4483 Types", RFC 3023, January 2001. 4485 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 4486 10646", STD 63, RFC 3629, November 2003. 4488 [RFC3676] Gellens, R., "The Text/Plain Format and DelSp Parameters", 4489 RFC 3676, February 2004. 4491 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 4492 Resource Identifier (URI): Generic Syntax", STD 66, 4493 RFC 3986, January 2005. 4495 [RFC4279] Eronen, P. and H. Tschofenig, "Pre-Shared Key Ciphersuites 4496 for Transport Layer Security (TLS)", RFC 4279, 4497 December 2005. 4499 [RFC4395] Hansen, T., Hardie, T., and L. Masinter, "Guidelines and 4500 Registration Procedures for New URI Schemes", BCP 35, 4501 RFC 4395, February 2006. 4503 [RFC5147] Wilde, E. and M. Duerst, "URI Fragment Identifiers for the 4504 text/plain Media Type", RFC 5147, April 2008. 4506 [RFC5198] Klensin, J. and M. Padlipsky, "Unicode Format for Network 4507 Interchange", RFC 5198, March 2008. 4509 [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an 4510 IANA Considerations Section in RFCs", BCP 26, RFC 5226, 4511 May 2008. 4513 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax 4514 Specifications: ABNF", STD 68, RFC 5234, January 2008. 4516 [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security 4517 (TLS) Protocol Version 1.2", RFC 5246, August 2008. 4519 [RFC5280] Cooper, D., Santesson, S., Farrell, S., Boeyen, S., 4520 Housley, R., and W. Polk, "Internet X.509 Public Key 4521 Infrastructure Certificate and Certificate Revocation List 4522 (CRL) Profile", RFC 5280, May 2008. 4524 [RFC5480] Turner, S., Brown, D., Yiu, K., Housley, R., and T. Polk, 4525 "Elliptic Curve Cryptography Subject Public Key 4526 Information", RFC 5480, March 2009. 4528 [RFC5785] Nottingham, M. and E. Hammer-Lahav, "Defining Well-Known 4529 Uniform Resource Identifiers (URIs)", RFC 5785, 4530 April 2010. 4532 [RFC5952] Kawamura, S. and M. Kawashima, "A Recommendation for IPv6 4533 Address Text Representation", RFC 5952, August 2010. 4535 [RFC5988] Nottingham, M., "Web Linking", RFC 5988, October 2010. 4537 [RFC6066] Eastlake, D., "Transport Layer Security (TLS) Extensions: 4538 Extension Definitions", RFC 6066, January 2011. 4540 [RFC6347] Rescorla, E. and N. Modadugu, "Datagram Transport Layer 4541 Security Version 1.2", RFC 6347, January 2012. 4543 [RFC6690] Shelby, Z., "Constrained RESTful Environments (CoRE) Link 4544 Format", RFC 6690, August 2012. 4546 [RFC6920] Farrell, S., Kutscher, D., Dannewitz, C., Ohlman, B., 4547 Keranen, A., and P. Hallam-Baker, "Naming Things with 4548 Hashes", RFC 6920, April 2013. 4550 14.2. Informative References 4552 [EUI64] "GUIDELINES FOR 64-BIT GLOBAL IDENTIFIER (EUI-64) 4553 REGISTRATION AUTHORITY", April 2010, . 4556 [EXIMIME] "Efficient XML Interchange (EXI) Format 1.0", 4557 December 2009, . 4560 [HHGTTG] Adams, D., "The Hitchhiker's Guide to the Galaxy", 4561 October 1979. 4563 [I-D.allman-tcpm-rto-consider] 4564 Allman, M., "Retransmission Timeout Considerations", 4565 draft-allman-tcpm-rto-consider-01 (work in progress), 4566 May 2012. 4568 [I-D.bormann-coap-misc] 4569 Bormann, C. and K. Hartke, "Miscellaneous additions to 4570 CoAP", draft-bormann-coap-misc-25 (work in progress), 4571 May 2013. 4573 [I-D.bormann-core-ipsec-for-coap] 4574 Bormann, C., "Using CoAP with IPsec", 4575 draft-bormann-core-ipsec-for-coap-00 (work in progress), 4576 December 2012. 4578 [I-D.castellani-core-http-mapping] 4579 Castellani, A., Loreto, S., Rahman, A., Fossati, T., and 4580 E. Dijk, "Best Practices for HTTP-CoAP Mapping 4581 Implementation", draft-castellani-core-http-mapping-07 4582 (work in progress), February 2013. 4584 [I-D.ietf-core-block] 4585 Bormann, C. and Z. Shelby, "Blockwise transfers in CoAP", 4586 draft-ietf-core-block-11 (work in progress), March 2013. 4588 [I-D.ietf-core-groupcomm] 4589 Rahman, A. and E. Dijk, "Group Communication for CoAP", 4590 draft-ietf-core-groupcomm-07 (work in progress), May 2013. 4592 [I-D.ietf-core-observe] 4593 Hartke, K., "Observing Resources in CoAP", 4594 draft-ietf-core-observe-08 (work in progress), 4595 February 2013. 4597 [I-D.ietf-lwig-terminology] 4598 Bormann, C., Ersue, M., and A. Keraenen, "Terminology for 4599 Constrained Node Networks", draft-ietf-lwig-terminology-04 4600 (work in progress), April 2013. 4602 [I-D.ietf-tls-multiple-cert-status-extension] 4603 Pettersen, Y., "The TLS Multiple Certificate Status 4604 Request Extension", 4605 draft-ietf-tls-multiple-cert-status-extension-08 (work in 4606 progress), April 2013. 4608 [REST] Fielding, R., "Architectural Styles and the Design of 4609 Network-based Software Architectures", Ph.D. Dissertation, 4610 University of California, Irvine, 2000, . 4614 [RFC0020] Cerf, V., "ASCII format for network interchange", RFC 20, 4615 October 1969. 4617 [RFC0792] Postel, J., "Internet Control Message Protocol", STD 5, 4618 RFC 792, September 1981. 4620 [RFC0793] Postel, J., "Transmission Control Protocol", STD 7, 4621 RFC 793, September 1981. 4623 [RFC2560] Myers, M., Ankney, R., Malpani, A., Galperin, S., and C. 4624 Adams, "X.509 Internet Public Key Infrastructure Online 4625 Certificate Status Protocol - OCSP", RFC 2560, June 1999. 4627 [RFC2818] Rescorla, E., "HTTP Over TLS", RFC 2818, May 2000. 4629 [RFC3264] Rosenberg, J. and H. Schulzrinne, "An Offer/Answer Model 4630 with Session Description Protocol (SDP)", RFC 3264, 4631 June 2002. 4633 [RFC3542] Stevens, W., Thomas, M., Nordmark, E., and T. Jinmei, 4634 "Advanced Sockets Application Program Interface (API) for 4635 IPv6", RFC 3542, May 2003. 4637 [RFC3828] Larzon, L-A., Degermark, M., Pink, S., Jonsson, L-E., and 4638 G. Fairhurst, "The Lightweight User Datagram Protocol 4639 (UDP-Lite)", RFC 3828, July 2004. 4641 [RFC4086] Eastlake, D., Schiller, J., and S. Crocker, "Randomness 4642 Requirements for Security", BCP 106, RFC 4086, June 2005. 4644 [RFC4443] Conta, A., Deering, S., and M. Gupta, "Internet Control 4645 Message Protocol (ICMPv6) for the Internet Protocol 4646 Version 6 (IPv6) Specification", RFC 4443, March 2006. 4648 [RFC4492] Blake-Wilson, S., Bolyard, N., Gupta, V., Hawk, C., and B. 4649 Moeller, "Elliptic Curve Cryptography (ECC) Cipher Suites 4650 for Transport Layer Security (TLS)", RFC 4492, May 2006. 4652 [RFC4627] Crockford, D., "The application/json Media Type for 4653 JavaScript Object Notation (JSON)", RFC 4627, July 2006. 4655 [RFC4821] Mathis, M. and J. Heffner, "Packetization Layer Path MTU 4656 Discovery", RFC 4821, March 2007. 4658 [RFC4944] Montenegro, G., Kushalnagar, N., Hui, J., and D. Culler, 4659 "Transmission of IPv6 Packets over IEEE 802.15.4 4660 Networks", RFC 4944, September 2007. 4662 [RFC5405] Eggert, L. and G. Fairhurst, "Unicast UDP Usage Guidelines 4663 for Application Designers", BCP 145, RFC 5405, 4664 November 2008. 4666 [RFC5489] Badra, M. and I. Hajjeh, "ECDHE_PSK Cipher Suites for 4667 Transport Layer Security (TLS)", RFC 5489, March 2009. 4669 [RFC6090] McGrew, D., Igoe, K., and M. Salter, "Fundamental Elliptic 4670 Curve Cryptography Algorithms", RFC 6090, February 2011. 4672 [RFC6120] Saint-Andre, P., "Extensible Messaging and Presence 4673 Protocol (XMPP): Core", RFC 6120, March 2011. 4675 [RFC6282] Hui, J. and P. Thubert, "Compression Format for IPv6 4676 Datagrams over IEEE 802.15.4-Based Networks", RFC 6282, 4677 September 2011. 4679 [RFC6335] Cotton, M., Eggert, L., Touch, J., Westerlund, M., and S. 4680 Cheshire, "Internet Assigned Numbers Authority (IANA) 4681 Procedures for the Management of the Service Name and 4682 Transport Protocol Port Number Registry", BCP 165, 4683 RFC 6335, August 2011. 4685 [RFC6655] McGrew, D. and D. Bailey, "AES-CCM Cipher Suites for 4686 Transport Layer Security (TLS)", RFC 6655, July 2012. 4688 [RFC6936] Fairhurst, G. and M. Westerlund, "Applicability Statement 4689 for the Use of IPv6 UDP Datagrams with Zero Checksums", 4690 RFC 6936, April 2013. 4692 [W3CXMLSEC] 4693 Wenning, R., "Report of the XML Security PAG", 4694 October 2012, 4695 . 4697 Appendix A. Examples 4699 This section gives a number of short examples with message flows for 4700 GET requests. These examples demonstrate the basic operation, the 4701 operation in the presence of retransmissions, and multicast. 4703 Figure 16 shows a basic GET request causing a piggy-backed response: 4704 The client sends a Confirmable GET request for the resource 4705 coap://server/temperature to the server with a Message ID of 0x7d34. 4706 The request includes one Uri-Path Option (Delta 0 + 11 = 11, Length 4707 11, Value "temperature"); the Token is left empty. This request is a 4708 total of 16 bytes long. A 2.05 (Content) response is returned in the 4709 Acknowledgement message that acknowledges the Confirmable request, 4710 echoing both the Message ID 0x7d34 and the empty Token value. The 4711 response includes a Payload of "22.3 C" and is 11 bytes long. 4713 Client Server 4714 | | 4715 | | 4716 +----->| Header: GET (T=CON, Code=0.01, MID=0x7d34) 4717 | GET | Uri-Path: "temperature" 4718 | | 4719 | | 4720 |<-----+ Header: 2.05 Content (T=ACK, Code=2.05, MID=0x7d34) 4721 | 2.05 | Payload: "22.3 C" 4722 | | 4724 0 1 2 3 4725 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 4726 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4727 | 1 | 0 | 0 | GET=1 | MID=0x7d34 | 4728 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4729 | 11 | 11 | "temperature" (11 B) ... 4730 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4732 0 1 2 3 4733 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 4734 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4735 | 1 | 2 | 0 | 2.05=69 | MID=0x7d34 | 4736 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4737 |1 1 1 1 1 1 1 1| "22.3 C" (6 B) ... 4738 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4740 Figure 16: Confirmable request; piggy-backed response 4742 Figure 17 shows a similar example, but with the inclusion of an non- 4743 empty Token (Value 0x20) in the request and the response, increasing 4744 the sizes to 17 and 12 bytes, respectively. 4746 Client Server 4747 | | 4748 | | 4749 +----->| Header: GET (T=CON, Code=0.01, MID=0x7d35) 4750 | GET | Token: 0x20 4751 | | Uri-Path: "temperature" 4752 | | 4753 | | 4754 |<-----+ Header: 2.05 Content (T=ACK, Code=2.05, MID=0x7d35) 4755 | 2.05 | Token: 0x20 4756 | | Payload: "22.3 C" 4757 | | 4759 0 1 2 3 4760 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 4761 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4762 | 1 | 0 | 1 | GET=1 | MID=0x7d35 | 4763 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4764 | 0x20 | 4765 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4766 | 11 | 11 | "temperature" (11 B) ... 4767 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4769 0 1 2 3 4770 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 4771 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4772 | 1 | 2 | 1 | 2.05=69 | MID=0x7d35 | 4773 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4774 | 0x20 | 4775 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4776 |1 1 1 1 1 1 1 1| "22.3 C" (6 B) ... 4777 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 4779 Figure 17: Confirmable request; piggy-backed response 4781 In Figure 18, the Confirmable GET request is lost. After ACK_TIMEOUT 4782 seconds, the client retransmits the request, resulting in a piggy- 4783 backed response as in the previous example. 4785 Client Server 4786 | | 4787 | | 4788 +----X | Header: GET (T=CON, Code=0.01, MID=0x7d36) 4789 | GET | Token: 0x31 4790 | | Uri-Path: "temperature" 4791 TIMEOUT | 4792 | | 4793 +----->| Header: GET (T=CON, Code=0.01, MID=0x7d36) 4794 | GET | Token: 0x31 4795 | | Uri-Path: "temperature" 4796 | | 4797 | | 4798 |<-----+ Header: 2.05 Content (T=ACK, Code=2.05, MID=0x7d36) 4799 | 2.05 | Token: 0x31 4800 | | Payload: "22.3 C" 4801 | | 4803 Figure 18: Confirmable request (retransmitted); piggy-backed response 4805 In Figure 19, the first Acknowledgement message from the server to 4806 the client is lost. After ACK_TIMEOUT seconds, the client 4807 retransmits the request. 4809 Client Server 4810 | | 4811 | | 4812 +----->| Header: GET (T=CON, Code=0.01, MID=0x7d37) 4813 | GET | Token: 0x42 4814 | | Uri-Path: "temperature" 4815 | | 4816 | | 4817 | X----+ Header: 2.05 Content (T=ACK, Code=2.05, MID=0x7d37) 4818 | 2.05 | Token: 0x42 4819 | | Payload: "22.3 C" 4820 TIMEOUT | 4821 | | 4822 +----->| Header: GET (T=CON, Code=0.01, MID=0x7d37) 4823 | GET | Token: 0x42 4824 | | Uri-Path: "temperature" 4825 | | 4826 | | 4827 |<-----+ Header: 2.05 Content (T=ACK, Code=2.05, MID=0x7d37) 4828 | 2.05 | Token: 0x42 4829 | | Payload: "22.3 C" 4830 | | 4832 Figure 19: Confirmable request; piggy-backed response (retransmitted) 4833 In Figure 20, the server acknowledges the Confirmable request and 4834 sends a 2.05 (Content) response separately in a Confirmable message. 4835 Note that the Acknowledgement message and the Confirmable response do 4836 not necessarily arrive in the same order as they were sent. The 4837 client acknowledges the Confirmable response. 4839 Client Server 4840 | | 4841 | | 4842 +----->| Header: GET (T=CON, Code=0.01, MID=0x7d38) 4843 | GET | Token: 0x53 4844 | | Uri-Path: "temperature" 4845 | | 4846 | | 4847 |<- - -+ Header: (T=ACK, Code=0.00, MID=0x7d38) 4848 | | 4849 | | 4850 |<-----+ Header: 2.05 Content (T=CON, Code=2.05, MID=0xad7b) 4851 | 2.05 | Token: 0x53 4852 | | Payload: "22.3 C" 4853 | | 4854 | | 4855 +- - ->| Header: (T=ACK, Code=0.00, MID=0xad7b) 4856 | | 4858 Figure 20: Confirmable request; separate response 4860 Figure 21 shows an example where the client loses its state (e.g., 4861 crashes and is rebooted) right after sending a Confirmable request, 4862 so the separate response arriving some time later comes unexpected. 4863 In this case, the client rejects the Confirmable response with a 4864 Reset message. Note that the unexpected ACK is silently ignored. 4866 Client Server 4867 | | 4868 | | 4869 +----->| Header: GET (T=CON, Code=0.01, MID=0x7d39) 4870 | GET | Token: 0x64 4871 | | Uri-Path: "temperature" 4872 CRASH | 4873 | | 4874 |<- - -+ Header: (T=ACK, Code=0.00, MID=0x7d39) 4875 | | 4876 | | 4877 |<-----+ Header: 2.05 Content (T=CON, Code=2.05, MID=0xad7c) 4878 | 2.05 | Token: 0x64 4879 | | Payload: "22.3 C" 4880 | | 4881 | | 4882 +- - ->| Header: (T=RST, Code=0.00, MID=0xad7c) 4883 | | 4885 Figure 21: Confirmable request; separate response (unexpected) 4887 Figure 22 shows a basic GET request where the request and the 4888 response are Non-confirmable, so both may be lost without notice. 4890 Client Server 4891 | | 4892 | | 4893 +----->| Header: GET (T=NON, Code=0.01, MID=0x7d40) 4894 | GET | Token: 0x75 4895 | | Uri-Path: "temperature" 4896 | | 4897 | | 4898 |<-----+ Header: 2.05 Content (T=NON, Code=2.05, MID=0xad7d) 4899 | 2.05 | Token: 0x75 4900 | | Payload: "22.3 C" 4901 | | 4903 Figure 22: Non-confirmable request; Non-confirmable response 4905 In Figure 23, the client sends a Non-confirmable GET request to a 4906 multicast address: all nodes in link-local scope. There are 3 4907 servers on the link: A, B and C. Servers A and B have a matching 4908 resource, therefore they send back a Non-confirmable 2.05 (Content) 4909 response. The response sent by B is lost. C does not have matching 4910 response, therefore it sends a Non-confirmable 4.04 (Not Found) 4911 response. 4913 Client ff02::1 A B C 4914 | | | | | 4915 | | | | | 4916 +------>| | | | Header: GET (T=NON, Code=0.01, MID=0x7d41) 4917 | GET | | | | Token: 0x86 4918 | | | | Uri-Path: "temperature" 4919 | | | | 4920 | | | | 4921 |<------------+ | | Header: 2.05 (T=NON, Code=2.05, MID=0x60b1) 4922 | 2.05 | | | Token: 0x86 4923 | | | | Payload: "22.3 C" 4924 | | | | 4925 | | | | 4926 | X------------+ | Header: 2.05 (T=NON, Code=2.05, MID=0x01a0) 4927 | 2.05 | | | Token: 0x86 4928 | | | | Payload: "20.9 C" 4929 | | | | 4930 | | | | 4931 |<------------------+ Header: 4.04 (T=NON, Code=4.04, MID=0x952a) 4932 | 4.04 | | | Token: 0x86 4933 | | | | 4935 Figure 23: Non-confirmable request (multicast); Non-confirmable 4936 response 4938 Appendix B. URI Examples 4940 The following examples demonstrate different sets of Uri options, and 4941 the result after constructing an URI from them. In addition to the 4942 options, Section 6.5 refers to the destination IP address and port, 4943 but not all paths of the algorithm cause the destination IP address 4944 and port to be included in the URI. 4946 o Input: 4948 Destination IP Address = [2001:db8::2:1] 4949 Destination UDP Port = 5683 4951 Output: 4953 coap://[2001:db8::2:1]/ 4955 o Input: 4957 Destination IP Address = [2001:db8::2:1] 4958 Destination UDP Port = 5683 4959 Uri-Host = "example.net" 4961 Output: 4963 coap://example.net/ 4965 o Input: 4967 Destination IP Address = [2001:db8::2:1] 4968 Destination UDP Port = 5683 4969 Uri-Host = "example.net" 4970 Uri-Path = ".well-known" 4971 Uri-Path = "core" 4973 Output: 4975 coap://example.net/.well-known/core 4977 o Input: 4979 Destination IP Address = [2001:db8::2:1] 4980 Destination UDP Port = 5683 4981 Uri-Host = "xn--18j4d.example" 4982 Uri-Path = the string composed of the Unicode characters U+3053 4983 U+3093 U+306b U+3061 U+306f, usually represented in UTF-8 as 4984 E38193E38293E381ABE381A1E381AF hexadecimal 4986 Output: 4988 coap:// 4989 xn--18j4d.example/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF 4991 (The line break has been inserted for readability; it is not 4992 part of the URI.) 4994 o Input: 4996 Destination IP Address = 198.51.100.1 4997 Destination UDP Port = 61616 4998 Uri-Path = "" 4999 Uri-Path = "/" 5000 Uri-Path = "" 5001 Uri-Path = "" 5002 Uri-Query = "//" 5003 Uri-Query = "?&" 5005 Output: 5007 coap://198.51.100.1:61616//%2F//?%2F%2F&?%26 5009 Appendix C. Changelog 5011 (To be removed by RFC editor before publication.) 5013 Changes from ietf-15 to ietf-16: Address comments from the IESG 5014 reviews. These should not impact interoperability. 5016 o Clarify that once there has been an empty ACK, all further ACKs to 5017 the same message also must be empty (#301). 5019 o Define Cache-key properly (#302). 5021 o Clarify that ACKs don't get retransmitted, the CONs do (#303). 5023 o Clarify: NON is like separate for CON (#304). 5025 o Don't use decimal response codes, keep the 3+5 structure 5026 throughout (#305). 5028 o RFC 2119 usage in 4.5 (#306) and 8.2 (#307). 5030 o Ensure all protocol reactions to reserved or prohibited values are 5031 defined (#308). 5033 o URI matching rules may be scheme specific (#309). 5035 o Don't dally beyond MAX_TRANSMIT_SPAN during retransmission (#310). 5037 o More about selecting a token length for anti-spoofing (#311). 5039 o Discuss spoofing ACKs (#312). 5041 o Qualify partial discard strategy implementation note as UDP only 5042 (#313). 5044 o Explicitly point out that UDP and DTLS don't mix (#314). 5046 o Point out security consideration re URIs and access control 5047 (#315). 5049 o Point to RFC5280 section 6 (#316). 5051 o Add a paragraph about cert status checking (#317). 5053 o RSA is out, ECDHE is in for cert-with-PSK, too (#318). 5055 o Point out that requests and responses don't always come in pairs 5056 (#319). 5058 o Clarify when there is a need for Unicode normalization (#320). 5060 o Point out that Uri-Host doesn't handle user-part (#321). 5062 o Clarify the use of non-FQDN Authority Names in certificates. 5064 o Numerous editorial improvements and clarifications. 5066 Changes from ietf-14 to ietf-15: Address comments from IETF last- 5067 call, mostly implementation notes and editorial improvements. These 5068 should not impact interoperability. 5070 o Clarify bytes/characters and UTF-8/ASCII in "Decomposing URIs into 5071 Options" (#282). 5073 o Make reference to ECC/CCM DTLS ciphersuite normative (#286). 5075 o Add a quick warning that bytewise scanning for a payload marker is 5076 not a good idea (#287). 5078 o Make reference to PROBING_RATE explicit for saturation discussion 5079 (#288). 5081 o Mention PROCESSING_DELAY when discussion piggy-backing (#290). 5083 o Various editorial nits: Clarify use of noun "service" (#283), 5084 Reference terminology from lwig-terminology (#284), make reference 5085 to HTTP terms more explicit (#285), add a forward reference to 5086 5.9.2.9 (#289), 8 kbit/s is not "conservative" (#291). 5088 o Add description of resource depletion attack (#292). 5090 o Add description of DoS attack on congestion control (#293). 5092 o Add discussion of using non-trivial token for protecting against 5093 hijacking (#294). 5095 o Clarify implementation note about per-destination Message ID 5096 generation. 5098 Changed from ietf-13 to ietf-14: 5100 o Made Accept option non-repeatable. 5102 o Clarified that Safe options in a 2.03 Valid response update the 5103 cache. 5105 o Clarified that payload sniffing is acceptable only if no Content- 5106 Format was supplied. 5108 o Clarified URI examples (Appendix B). 5110 o Numerous editorial improvements and clarifications. 5112 Changed from ietf-12 to ietf-13: 5114 o Simplified message format. 5116 * Removed the OC (Option Count) field in the CoAP Header. 5118 * Changed the End-of-Options Marker into the Payload Marker. 5120 * Changed the format of Options: use 4 bits for option length and 5121 delta; insert one or two additional bytes after the option 5122 header if necessary. 5124 * Promoted the Token Option to a field following the CoAP Header. 5126 o Clarified when a payload is a diagnostic payload (#264). 5128 o Moved IPsec discussion to separate draft (#262). 5130 o Added a reference to a separate draft on reverse-proxy URI 5131 embedding (#259). 5133 o Clarified the use of ETags and of 2.03 responses (#265, #254, 5134 #256). 5136 o Added reserved Location-* numbers and clarified Location-*. 5138 o Added Proxy-Scheme proposal. 5140 o Clarified terms such as content negotiation, selected 5141 representation, representation-format, message format error. 5143 o Numerous clarifications and a few bugfixes. 5145 Changed from ietf-11 to ietf-12: 5147 o Extended options to support lengths of up to 1034 bytes (#202). 5149 o Added new Jump mechanism for options and removed Fenceposting 5150 (#214). 5152 o Added new IANA option number registration policy (#214). 5154 o Added Proxy Unsafe/Safe and Cache-Key masking to option numbers 5155 (#241). 5157 o Re-numbered option numbers to use Unsafe/Safe and Cache-Key 5158 compliant numbers (#241). 5160 o Defined NSTART and restricted the value to 1 with a MUST (#215). 5162 o Defined PROBING_RATE and set it to 1 Byte/second (#215). 5164 o Defined DEFAULT_LEISURE (#246). 5166 o Renamed Content-Type into Content-Format, and Media Type registry 5167 into Content-Format registry. 5169 o A large number of small editorial changes, clarifications and 5170 improvements have been made. 5172 Changed from ietf-10 to ietf-11: 5174 o Expanded section 4.8 on Transmission Parameters, and used the 5175 derived values defined there (#201). Changed parameter names to 5176 be shorter and more to the point. 5178 o Several more small editorial changes, clarifications and 5179 improvements have been made. 5181 Changed from ietf-09 to ietf-10: 5183 o Option deltas are restricted to 0 to 14; the option delta 15 is 5184 used exclusively for the end-of-options marker (#239). 5186 o Option numbers that are a multiple of 14 are not reserved, but are 5187 required to have an empty default value (#212). 5189 o Fixed misleading language that was introduced in 5.10.2 in coap-07 5190 re Uri-Host and Uri-Port (#208). 5192 o Segments and arguments can have a length of zero characters 5193 (#213). 5195 o The Location-* options describe together describe one location. 5196 The location is a relative URI, not an "absolute path URI" (#218). 5198 o The value of the Location-Path Option must not be '.' or '..' 5199 (#218). 5201 o Added a sentence on constructing URIs from Location-* options 5202 (#231). 5204 o Reserved option numbers for future Location-* options (#230). 5206 o Fixed response codes with payload inconsistency (#233). 5208 o Added advice on default values for critical options (#207). 5210 o Clarified use of identifiers in RawPublicKey Mode Provisioning 5211 (#222). 5213 o Moved "Securing CoAP" out of the "Security Considerations" (#229). 5215 o Added "All CoAP Nodes" multicast addresses to "IANA 5216 Considerations" (#216). 5218 o Over 100 small editorial changes, clarifications and improvements 5219 have been made. 5221 Changed from ietf-08 to ietf-09: 5223 o Improved consistency of statements about RST on NON: RST is a 5224 valid response to a NON message (#183). 5226 o Clarified that the protocol constants can be configured for 5227 specific application environments. 5229 o Added implementation note recommending piggy-backing whenever 5230 possible (#182). 5232 o Added a content-encoding column to the media type registry (#181). 5234 o Minor improvements to Appendix D. 5236 o Added text about multicast response suppression (#177). 5238 o Included the new End-of-options Marker (#176). 5240 o Added a reference to draft-ietf-tls-oob-pubkey and updated the RPK 5241 text accordingly. 5243 Changed from ietf-07 to ietf-08: 5245 o Clarified matching rules for messages (#175) 5247 o Fixed a bug in Section 8.2.2 on Etags (#168) 5248 o Added an IP address spoofing threat analysis contribution (#167) 5250 o Re-focused the security section on raw public keys (#166) 5252 o Added an 4.06 error to Accept (#165) 5254 Changed from ietf-06 to ietf-07: 5256 o application/link-format added to Media types registration (#160) 5258 o Moved content-type attribute to the document from link-format. 5260 o Added coaps scheme and DTLS-secured CoAP default port (#154) 5262 o Allowed 0-length Content-type options (#150) 5264 o Added congestion control recommendations (#153) 5266 o Improved text on PUT/POST response payloads (#149) 5268 o Added an Accept option for content-negotiation (#163) 5270 o Added If-Match and If-None-Match options (#155) 5272 o Improved Token Option explanation (#147) 5274 o Clarified mandatory to implement security (#156) 5276 o Added first come first server policy for 2-byte Media type codes 5277 (#161) 5279 o Clarify matching rules for messages and tokens (#151) 5281 o Changed OPTIONS and TRACE to always return 501 in HTTP-CoAP 5282 mapping (#164) 5284 Changed from ietf-05 to ietf-06: 5286 o HTTP mapping section improved with the minimal protocol standard 5287 text for CoAP-HTTP and HTTP-CoAP forward proxying (#137). 5289 o Eradicated percent-encoding by including one Uri-Query Option per 5290 &-delimited argument in a query. 5292 o Allowed RST message in reply to a NON message with unexpected 5293 token (#135). 5295 o Cache Invalidation only happens upon successful responses (#134). 5297 o 50% jitter added to the initial retransmit timer (#142). 5299 o DTLS cipher suites aligned with ZigBee IP, DTLS clarified as 5300 default CoAP security mechanism (#138, #139) 5302 o Added a minimal reference to draft-kivinen-ipsecme-ikev2-minimal 5303 (#140). 5305 o Clarified the comparison of UTF-8s (#136). 5307 o Minimized the initial media type registry (#101). 5309 Changed from ietf-04 to ietf-05: 5311 o Renamed Immediate into Piggy-backed and Deferred into Separate -- 5312 should finally end the confusion on what this is about. 5314 o GET requests now return a 2.05 (Content) response instead of 2.00 5315 (OK) response (#104). 5317 o Added text to allow 2.02 (Deleted) responses in reply to POST 5318 requests (#105). 5320 o Improved message deduplication rules (#106). 5322 o Section added on message size implementation considerations 5323 (#103). 5325 o Clarification made on human readable error payloads (#109). 5327 o Definition of CoAP methods improved (#108). 5329 o Max-Age removed from requests (#107). 5331 o Clarified uniqueness of tokens (#112). 5333 o Location-Query Option added (#113). 5335 o ETag length set to 1-8 bytes (#123). 5337 o Clarified relation between elective/critical and option numbers 5338 (#110). 5340 o Defined when to update Version header field (#111). 5342 o URI scheme registration improved (#102). 5344 o Added review guidelines for new CoAP codes and numbers. 5346 Changes from ietf-03 to ietf-04: 5348 o Major document reorganization (#51, #63, #71, #81). 5350 o Max-age length set to 0-4 bytes (#30). 5352 o Added variable unsigned integer definition (#31). 5354 o Clarification made on human readable error payloads (#50). 5356 o Definition of POST improved (#52). 5358 o Token length changed to 0-8 bytes (#53). 5360 o Section added on multiplexing CoAP, DTLS and STUN (#56). 5362 o Added cross-protocol attack considerations (#61). 5364 o Used new Immediate/Deferred response definitions (#73). 5366 o Improved request/response matching rules (#74). 5368 o Removed unnecessary media types and added recommendations for 5369 their use in M2M (#76). 5371 o Response codes changed to base 32 coding, new Y.XX naming (#77). 5373 o References updated as per AD review (#79). 5375 o IANA section completed (#80). 5377 o Proxy-Uri Option added to disambiguate between proxy and non-proxy 5378 requests (#82). 5380 o Added text on critical options in cached states (#83). 5382 o HTTP mapping sections improved (#88). 5384 o Added text on reverse proxies (#72). 5386 o Some security text on multicast added (#54). 5388 o Trust model text added to introduction (#58, #60). 5390 o AES-CCM vs. AES-CCB text added (#55). 5392 o Text added about device capabilities (#59). 5394 o DTLS section improvements (#87). 5396 o Caching semantics aligned with RFC2616 (#78). 5398 o Uri-Path Option split into multiple path segments. 5400 o MAX_RETRANSMIT changed to 4 to adjust for RESPONSE_TIME = 2. 5402 Changes from ietf-02 to ietf-03: 5404 o Token Option and related use in asynchronous requests added (#25). 5406 o CoAP specific error codes added (#26). 5408 o Erroring out on unknown critical options changed to a MUST (#27). 5410 o Uri-Query Option added. 5412 o Terminology and definitions of URIs improved. 5414 o Security section completed (#22). 5416 Changes from ietf-01 to ietf-02: 5418 o Sending an error on a critical option clarified (#18). 5420 o Clarification on behavior of PUT and idempotent operations (#19). 5422 o Use of Uri-Authority clarified along with server processing rules; 5423 Uri-Scheme Option removed (#20, #23). 5425 o Resource discovery section removed to a separate CoRE Link Format 5426 draft (#21). 5428 o Initial security section outline added. 5430 Changes from ietf-00 to ietf-01: 5432 o New cleaner transaction message model and header (#5). 5434 o Removed subscription while being designed (#1). 5436 o Section 2 re-written (#3). 5438 o Text added about use of short URIs (#4). 5440 o Improved header option scheme (#5, #14). 5442 o Date option removed whiled being designed (#6). 5444 o New text for CoAP default port (#7). 5446 o Completed proxying section (#8). 5448 o Completed resource discovery section (#9). 5450 o Completed HTTP mapping section (#10). 5452 o Several new examples added (#11). 5454 o URI split into 3 options (#12). 5456 o MIME type defined for link-format (#13, #16). 5458 o New text on maximum message size (#15). 5460 o Location Option added. 5462 Changes from shelby-01 to ietf-00: 5464 o Removed the TCP binding section, left open for the future. 5466 o Fixed a bug in the example. 5468 o Marked current Sub/Notify as (Experimental) while under WG 5469 discussion. 5471 o Fixed maximum datagram size to 1280 for both IPv4 and IPv6 (for 5472 CoAP-CoAP proxying to work). 5474 o Temporarily removed the Magic Byte header as TCP is no longer 5475 included as a binding. 5477 o Removed the Uri-code Option as different URI encoding schemes are 5478 being discussed. 5480 o Changed the rel= field to desc= for resource discovery. 5482 o Changed the maximum message size to 1024 bytes to allow for IP/UDP 5483 headers. 5485 o Made the URI slash optimization and method idempotence MUSTs 5487 o Minor editing and bug fixing. 5489 Changes from shelby-00 to shelby-01: 5491 o Unified the message header and added a notify message type. 5493 o Renamed methods with HTTP names and removed the NOTIFY method. 5495 o Added a number of options field to the header. 5497 o Combines the Option Type and Length into an 8-bit field. 5499 o Added the magic byte header. 5501 o Added new ETag Option. 5503 o Added new Date Option. 5505 o Added new Subscription Option. 5507 o Completed the HTTP Code - CoAP Code mapping table appendix. 5509 o Completed the Content-type Identifier appendix and tables. 5511 o Added more simplifications for URI support. 5513 o Initial subscription and discovery sections. 5515 o A Flag requirements simplified. 5517 Authors' Addresses 5519 Zach Shelby 5520 Sensinode 5521 Kidekuja 2 5522 Vuokatti 88600 5523 Finland 5525 Phone: +358407796297 5526 Email: zach@sensinode.com 5527 Klaus Hartke 5528 Universitaet Bremen TZI 5529 Postfach 330440 5530 Bremen D-28359 5531 Germany 5533 Phone: +49-421-218-63905 5534 Email: hartke@tzi.org 5536 Carsten Bormann 5537 Universitaet Bremen TZI 5538 Postfach 330440 5539 Bremen D-28359 5540 Germany 5542 Phone: +49-421-218-63921 5543 Email: cabo@tzi.org