idnits 2.17.1 draft-ietf-core-http-mapping-15.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == The document seems to lack the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. (The document does seem to have the reference to RFC 2119 which the ID-Checklist requires). -- The document date (October 3, 2016) is 2755 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: Informational ---------------------------------------------------------------------------- == Missing Reference: 'C-T' is mentioned on line 803, but not defined == Missing Reference: 'C-E' is mentioned on line 789, but not defined ** Obsolete normative reference: RFC 7230 (Obsoleted by RFC 9110, RFC 9112) ** Obsolete normative reference: RFC 7231 (Obsoleted by RFC 9110) ** Obsolete normative reference: RFC 7232 (Obsoleted by RFC 9110) ** Obsolete normative reference: RFC 7235 (Obsoleted by RFC 9110) == Outdated reference: A later version (-10) exists of draft-ietf-core-links-json-06 == Outdated reference: A later version (-28) exists of draft-ietf-core-resource-directory-08 -- Obsolete informational reference (is this intentional?): RFC 2616 (Obsoleted by RFC 7230, RFC 7231, RFC 7232, RFC 7233, RFC 7234, RFC 7235) -- Obsolete informational reference (is this intentional?): RFC 7049 (Obsoleted by RFC 8949) Summary: 4 errors (**), 0 flaws (~~), 6 warnings (==), 4 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 CoRE Working Group A. Castellani 3 Internet-Draft University of Padova 4 Intended status: Informational S. Loreto 5 Expires: April 6, 2017 Ericsson 6 A. Rahman 7 InterDigital Communications, LLC 8 T. Fossati 9 Nokia 10 E. Dijk 11 Philips Lighting 12 October 3, 2016 14 Guidelines for HTTP-to-CoAP Mapping Implementations 15 draft-ietf-core-http-mapping-15 17 Abstract 19 This document provides reference information for implementing a 20 cross-protocol network proxy that performs translation from the HTTP 21 protocol to CoAP (Constrained Application Protocol). This will 22 enable a HTTP client to access resources on a CoAP server through the 23 proxy. This document describes how a HTTP request is mapped to a 24 CoAP request, and then how a CoAP response is mapped back to a HTTP 25 response. This includes guidelines for URI mapping, media type 26 mapping and additional proxy implementation issues. 28 Status of This Memo 30 This Internet-Draft is submitted in full conformance with the 31 provisions of BCP 78 and BCP 79. 33 Internet-Drafts are working documents of the Internet Engineering 34 Task Force (IETF). Note that other groups may also distribute 35 working documents as Internet-Drafts. The list of current Internet- 36 Drafts is at http://datatracker.ietf.org/drafts/current/. 38 Internet-Drafts are draft documents valid for a maximum of six months 39 and may be updated, replaced, or obsoleted by other documents at any 40 time. It is inappropriate to use Internet-Drafts as reference 41 material or to cite them other than as "work in progress." 43 This Internet-Draft will expire on April 6, 2017. 45 Copyright Notice 47 Copyright (c) 2016 IETF Trust and the persons identified as the 48 document authors. All rights reserved. 50 This document is subject to BCP 78 and the IETF Trust's Legal 51 Provisions Relating to IETF Documents 52 (http://trustee.ietf.org/license-info) in effect on the date of 53 publication of this document. Please review these documents 54 carefully, as they describe your rights and restrictions with respect 55 to this document. Code Components extracted from this document must 56 include Simplified BSD License text as described in Section 4.e of 57 the Trust Legal Provisions and are provided without warranty as 58 described in the Simplified BSD License. 60 Table of Contents 62 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 63 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 4 64 3. HTTP-to-CoAP Proxy . . . . . . . . . . . . . . . . . . . . . 5 65 4. Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . 6 66 5. URI Mapping . . . . . . . . . . . . . . . . . . . . . . . . . 7 67 5.1. URI Terminology . . . . . . . . . . . . . . . . . . . . . 8 68 5.2. Null Mapping . . . . . . . . . . . . . . . . . . . . . . 8 69 5.3. Default Mapping . . . . . . . . . . . . . . . . . . . . . 8 70 5.3.1. Optional Scheme Omission . . . . . . . . . . . . . . 9 71 5.3.2. Encoding Caveats . . . . . . . . . . . . . . . . . . 9 72 5.4. URI Mapping Template . . . . . . . . . . . . . . . . . . 10 73 5.4.1. Simple Form . . . . . . . . . . . . . . . . . . . . . 10 74 5.4.2. Enhanced Form . . . . . . . . . . . . . . . . . . . . 11 75 5.5. Discovery . . . . . . . . . . . . . . . . . . . . . . . . 13 76 5.5.1. Examples . . . . . . . . . . . . . . . . . . . . . . 13 77 6. Media Type Mapping . . . . . . . . . . . . . . . . . . . . . 15 78 6.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . 15 79 6.2. 'application/coap-payload' Media Type . . . . . . . . . . 16 80 6.3. Loose Media Type Mapping . . . . . . . . . . . . . . . . 17 81 6.4. Media Type to Content Format Mapping Algorithm . . . . . 18 82 6.5. Content Transcoding . . . . . . . . . . . . . . . . . . . 19 83 6.5.1. General . . . . . . . . . . . . . . . . . . . . . . . 19 84 6.5.2. CoRE Link Format . . . . . . . . . . . . . . . . . . 20 85 6.5.3. Diagnostic Messages . . . . . . . . . . . . . . . . . 20 86 7. Response Code Mapping . . . . . . . . . . . . . . . . . . . . 21 87 8. Additional Mapping Guidelines . . . . . . . . . . . . . . . . 23 88 8.1. Caching and Congestion Control . . . . . . . . . . . . . 23 89 8.2. Cache Refresh via Observe . . . . . . . . . . . . . . . . 23 90 8.3. Use of CoAP Blockwise Transfer . . . . . . . . . . . . . 24 91 8.4. CoAP Multicast . . . . . . . . . . . . . . . . . . . . . 25 92 8.5. Timeouts . . . . . . . . . . . . . . . . . . . . . . . . 25 94 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 26 95 9.1. New 'core.hc' Resource Type . . . . . . . . . . . . . . . 26 96 9.2. New 'coap-payload' Internet Media Type . . . . . . . . . 26 97 10. Security Considerations . . . . . . . . . . . . . . . . . . . 27 98 10.1. Multicast . . . . . . . . . . . . . . . . . . . . . . . 28 99 10.2. Traffic Overflow . . . . . . . . . . . . . . . . . . . . 28 100 10.3. Handling Secured Exchanges . . . . . . . . . . . . . . . 29 101 10.4. URI Mapping . . . . . . . . . . . . . . . . . . . . . . 30 102 11. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 30 103 12. References . . . . . . . . . . . . . . . . . . . . . . . . . 30 104 12.1. Normative References . . . . . . . . . . . . . . . . . . 31 105 12.2. Informative References . . . . . . . . . . . . . . . . . 32 106 Appendix A. Change Log . . . . . . . . . . . . . . . . . . . . . 33 107 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 37 109 1. Introduction 111 CoAP (Constrained Application Protocol) [RFC7252] has been designed 112 with the twofold aim to be an application protocol specialized for 113 constrained environments and to be easily used in Representational 114 State Transfer (REST) based architectures such as the Web. The 115 latter goal has led to defining CoAP to easily interoperate with HTTP 116 [RFC7230] through an intermediary proxy which performs cross-protocol 117 conversion. 119 Section 10 of [RFC7252] describes the fundamentals of the CoAP-to- 120 HTTP and the HTTP-to-CoAP cross-protocol mapping process. However, 121 [RFC7252] focuses on the basic mapping of request methods and simple 122 response code mapping between HTTP and CoAP, and it leaves many 123 details of the cross-protocol proxy for future definition. 124 Therefore, a primary goal of this informational document is to define 125 a consistent set of guidelines that an HTTP-to-CoAP proxy 126 implementation should adhere to. The key benefit to adhering to such 127 guidelines is to reduce variation between proxy implementations, 128 thereby increasing interoperability between an HTTP client and a CoAP 129 server independent of the proxy that implements the cross-protocol 130 mapping. (For example, a proxy conforming to these guidelines made 131 by vendor A can be easily replaced by a proxy from vendor B that also 132 conforms to the guidelines.) 134 This document describes HTTP mappings that apply to protocol elements 135 defined in the base CoAP specification [RFC7252]. It is up to CoAP 136 protocol extensions (new methods, response codes, options, content- 137 formats) to describe their own HTTP mappings, if applicable. 139 This document is organized as follows: 141 o Section 2 defines proxy terminology; 142 o Section 3 introduces the HTTP-to-CoAP proxy; 144 o Section 4 lists use cases in which HTTP clients need to contact 145 CoAP servers; 147 o Section 5 introduces a null, default and advanced HTTP-to-CoAP URI 148 mapping syntax; 150 o Section 6 describes how to map HTTP media types to CoAP content 151 formats and vice versa; 153 o Section 7 describes how to map CoAP responses to HTTP responses; 155 o Section 8 describes additional mapping guidelines related to 156 caching, congestion, timeouts, etc.; 158 o Section 10 discusses possible security impact of HTTP-to-CoAP 159 protocol mapping. 161 2. Terminology 163 The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 164 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 165 "OPTIONAL" in this document are to be interpreted as described in 166 [RFC2119]. 168 HC Proxy: a proxy performing a cross-protocol mapping, in the context 169 of this document an HTTP-to-CoAP (HC) mapping. Specifically, the HC 170 proxy acts as an HTTP server and a CoAP client. The HC Proxy can 171 take on the role of a Forward, Reverse or Interception Proxy. 173 Forward Proxy (or Forward HC Proxy): a message forwarding agent that 174 is selected by the HTTP client, usually via local configuration 175 rules, to receive requests for some type(s) of absolute URI and to 176 attempt to satisfy those requests via translation to the protocol 177 indicated by the absolute URI. The user decides (is willing) to use 178 the proxy as the forwarding/de-referencing agent for a predefined 179 subset of the URI space. In [RFC7230] this is called a Proxy. 180 [RFC7252] defines Forward-Proxy similarly. 182 Reverse Proxy (or Reverse HC Proxy): as in [RFC7230], a receiving 183 agent that acts as a layer above some other server(s) and translates 184 the received requests to the underlying server's protocol. A Reverse 185 HC Proxy behaves as an origin (HTTP) server on its connection from 186 the HTTP client. The HTTP client uses the "origin-form" 187 (Section 5.3.1 of [RFC7230]) as a request-target URI. 189 (Note that a Reverse Proxy appears to an HTTP client as an origin 190 server while a Forward Proxy does not. So, when communicating with a 191 Reverse Proxy a client may be unaware it is communicating with a 192 proxy at all.) 194 Interception Proxy (or Interception HC Proxy) [RFC3040]: a proxy that 195 receives inbound HTTP traffic flows through the process of traffic 196 redirection; transparent to the HTTP client. 198 3. HTTP-to-CoAP Proxy 200 A HC proxy is accessed by an HTTP client which wants to access a 201 resource on a CoAP server. The HC proxy handles the HTTP request by 202 mapping it to the equivalent CoAP request, which is then forwarded to 203 the appropriate CoAP server. The received CoAP response is then 204 mapped to an appropriate HTTP response and finally sent back to the 205 originating HTTP client. 207 See Figure 1 for an example deployment scenario. Here a HC proxy is 208 located at the boundary of the Constrained Network domain, to avoid 209 sending any HTTP traffic into the Constrained Network and to avoid 210 any CoAP multicast traffic outside the Constrained Network. A DNS 211 server (not shown) is used by the HTTP Client to resolve the IP 212 address of the HC proxy and optionally also used by the HC proxy to 213 resolve IP addresses of CoAP servers. 215 Constrained Network 216 .-------------------. 217 / .------. \ 218 / | CoAP | \ 219 / |server| \ 220 || '------' || 221 || || 222 .--------. HTTP Request .------------. CoAP Req .------. || 223 | HTTP |---------------->|HTTP-to-CoAP|----------->| CoAP | || 224 | Client |<----------------| Proxy |<-----------|Server| || 225 '--------' HTTP Response '------------' CoAP Resp '------' || 226 || || 227 || .------. || 228 || | CoAP | || 229 \ |server| .------. / 230 \ '------' | CoAP | / 231 \ |server| / 232 \ '------' / 233 '-----------------' 235 Figure 1: HTTP-To-CoAP Proxy Deployment Scenario 237 Normative requirements on the translation of HTTP requests to CoAP 238 requests and of the CoAP responses back to HTTP responses are defined 239 in Section 10.2 of [RFC7252]. However, [RFC7252] focuses on the 240 basic mapping of request methods and simple response code mapping 241 between HTTP and CoAP, and leaves many details of the cross-protocol 242 HC proxy for future definition. This document provides additional 243 guidelines and more details for the implementation of a HC Proxy, 244 which should be followed in addition to the normative requirements. 245 Note that the guidelines apply to all forms of an HC proxy (i.e., 246 Reverse, Forward, Intercepting) unless explicitly otherwise noted. 248 4. Use Cases 250 To illustrate the situations HTTP to CoAP protocol translation may be 251 used, three use cases are described below. 253 1. Legacy building control application without CoAP: A building 254 control application that uses HTTP but not CoAP can check the status 255 of CoAP sensors and/or control actuators via a HC proxy. 257 2. Making sensor data available to 3rd parties on the Web: For 258 demonstration or public interest purposes, a HC proxy may be 259 configured to expose the contents of a CoAP sensor to the world via 260 the web (HTTP and/or HTTPS). Some sensors may only accept secure 261 'coaps' requests, therefore the proxy is configured to translate 262 request to those devices accordingly. The HC proxy is furthermore 263 configured to only pass through GET requests in order to protect the 264 constrained network. 266 3. Smartphone and home sensor: A smartphone can access directly a 267 CoAP home sensor using a mutually authenticated 'https' request, 268 provided its home router runs a HC proxy and is configured with the 269 appropriate certificate. An HTML5 [W3C.REC-html5-20141028] 270 application on the smartphone can provide a friendly UI using the 271 standard (HTTP) networking functions of HTML5. 273 A key point in the above use cases is the expected nature of the URI 274 to be used by the HTTP client initiating the HTTP request to the HC 275 proxy. Specifically, in use case #1, there will be no "coap" or 276 "coaps" related information embedded in the HTTP URI as it is a 277 legacy HTTP client sending the request. Use case #2 is also expected 278 to be similar. In contrast, in use case #3, it is expected that the 279 HTTP client will specifically embed "coap" or "coaps" related 280 information in the HTTP URI of the HTTP request to the HC proxy. 282 5. URI Mapping 284 Though, in principle, a CoAP URI could be directly used by a HTTP 285 client to de-reference a CoAP resource through a HC proxy, the 286 reality is that all major web browsers, networking libraries and 287 command line tools do not allow making HTTP requests using URIs with 288 a scheme "coap" or "coaps". 290 Thus, there is a need for web applications to embed or "pack" a CoAP 291 URI into a HTTP URI so that it can be (non-destructively) transported 292 from the HTTP client to the HC proxy. The HC proxy can then "unpack" 293 the CoAP URI and finally de-reference it via a CoAP request to the 294 target Server. 296 URI Mapping is the term used in the document to describe the process 297 through which the URI of a CoAP resource is transformed into an HTTP 298 URI so that: 300 o the requesting HTTP client can handle it; 302 o the receiving HC proxy can extract the intended CoAP URI 303 unambiguously. 305 To this end, the remainder of this section will identify: 307 o the default mechanism to map a CoAP URI into a HTTP URI; 308 o the URI template format to express a class of CoAP-HTTP URI 309 mapping functions; 311 o the discovery mechanism based on CoRE Link Format [RFC6690] 312 through which clients of a HC proxy can dynamically discover 313 information about the supported URI Mapping Template(s), as well 314 as the URI where the HC proxy function is anchored. 316 5.1. URI Terminology 318 In the remainder of this section, the following terms will be used 319 with a distinctive meaning: 321 HC Proxy URI: 322 URI which refers to the HC proxy function. It conforms to 323 syntax defined in Section 2.7 of [RFC7230]. 325 Target CoAP URI: 326 URI which refers to the (final) CoAP resource that has to be 327 de-referenced. It conforms to syntax defined in Section 6 of 328 [RFC7252]. Specifically, its scheme is either "coap" or 329 "coaps". 331 Hosting HTTP URI: 332 URI that conforms to syntax in Section 2.7 of [RFC7230]. Its 333 authority component refers to a HC proxy, whereas path (and 334 query) component(s) embed the information used by a HC proxy 335 to extract the Target CoAP URI. 337 5.2. Null Mapping 339 The null mapping is the case where there is no Target CoAP URI 340 appended to the HC Proxy URI. In other words, it is a "pure" HTTP 341 URI that is sent to the HC Proxy. This would typically occur in 342 situations like Use Case #1 described in Section 4, and the Proxy 343 would typically be a Reverse Proxy. In this scenario, the HC Proxy 344 will determine through its own proprietary algorithms what the Target 345 CoAP URI should be. 347 5.3. Default Mapping 349 The default mapping is for the Target CoAP URI to be appended as-is 350 to the HC Proxy URI, to form the Hosting HTTP URI. This is the URI 351 that will then be sent by the HTTP client in the HTTP request to the 352 HC proxy. 354 For example: given a HC Proxy URI http://p.example.com/hc/ and a 355 Target CoAP URI coap://s.example.com/light, the resulting Hosting 356 HTTP URI would be http://p.example.com/hc/coap://s.example.com/light. 358 Provided a correct Target CoAP URI, the Hosting HTTP URI resulting 359 from the default mapping is always syntactically correct. 360 Furthermore, the Target CoAP URI can always be extracted 361 unambiguously from the Hosting HTTP URI. Also, it is worth noting 362 that, using the default mapping, a query component in the target CoAP 363 resource URI is naturally encoded into the query component of the 364 Hosting URI, e.g., coap://s.example.com/light?dim=5 becomes 365 http://p.example.com/hc/coap://s.example.com/light?dim=5. 367 There is no default for the HC Proxy URI. Therefore, it is either 368 known in advance, e.g., as a configuration preset, or dynamically 369 discovered using the mechanism described in Section 5.5. 371 The default URI mapping function SHOULD be implemented and SHOULD be 372 activated by default in a HC proxy, unless there are valid reasons, 373 e.g., application specific, to use a different mapping function. 375 5.3.1. Optional Scheme Omission 377 When found in a Hosting HTTP URI, the scheme (i.e., "coap" or 378 "coaps"), the scheme component delimiter (":"), and the double slash 379 ("//") preceding the authority MAY be omitted if a local default - 380 not defined by this document - applies. If no prior mutual agreement 381 exists between the client and the HC proxy, then a Target CoAP URI 382 without the scheme component is syntactically incorrect, and 383 therefore: 385 o it MUST NOT be emitted by clients; 387 o it MUST elicit a suitable client error status (i.e., 4xx) by the 388 HC proxy. 390 5.3.2. Encoding Caveats 392 When the authority of the Target CoAP URI is given as an IPv6address, 393 then the surrounding square brackets must be percent-encoded in the 394 Hosting HTTP URI, in order to comply with the syntax defined in 395 Section 3.3. of [RFC3986] for a URI path segment. E.g.: 396 coap://[2001:db8::1]/light?on becomes 397 http://p.example.com/hc/coap://%5B2001:db8::1%5D/light?on. (Note 398 that the percent-encoded square brackets shall be reverted to their 399 non-percent-encoded form when the HC proxy unpacks the Target CoAP 400 URI.) 401 Everything else can be safely copied verbatim from the Target CoAP 402 URI to the Hosting HTTP URI. 404 5.4. URI Mapping Template 406 This section defines a format for the URI template [RFC6570] used by 407 a HC proxy to inform its clients about the expected syntax for the 408 Hosting HTTP URI. This will then be used by the HTTP client to 409 construct the URI to be sent in the HTTP request to the HC proxy. 411 When instantiated, an URI Mapping Template is always concatenated to 412 a HC Proxy URI provided by the HC proxy via discovery (see 413 Section 5.5), or by other means. 415 A simple form (Section 5.4.1) and an enhanced form (Section 5.4.2) 416 are provided to fit different users' requirements. 418 Both forms are expressed as level 2 URI templates [RFC6570] to take 419 care of the expansion of values that are allowed to include reserved 420 URI characters. The syntax of all URI formats is specified in this 421 section in Augmented Backus-Naur Form (ABNF) [RFC5234]. 423 5.4.1. Simple Form 425 The simple form MUST be used for mappings where the Target CoAP URI 426 is going to be copied (using rules of Section 5.3.2) at some fixed 427 position into the Hosting HTTP URI. 429 The "tu" template variable is intended to be used in a template 430 definition to represent a Target CoAP URI: 432 tu = [ ( "coap:" / "coaps:" ) "//" ] host [ ":" port ] path-abempty 433 [ "?" query ] 435 Note that the same considerations as in Section 5.3.1 apply, in that 436 the CoAP scheme may be omitted from the Hosting HTTP URI. 438 5.4.1.1. Examples 440 All the following examples (given as a specific URI mapping template, 441 a Target CoAP URI, and the produced Hosting HTTP URI) use 442 http://p.example.com/hc/ as the HC Proxy URI. Note that these 443 examples all define mapping templates that deviate from the default 444 template of Section 5.3 to be able to illustrate the use of the above 445 template variables. 447 1. Target CoAP URI is a query argument of the Hosting HTTP URI: 449 ?target_uri={+tu} 451 coap://s.example.com/light 453 http://p.example.com/hc/?target_uri=coap://s.example.com/light 455 or 457 coaps://s.example.com/light 459 http://p.example.com/hc/?target_uri=coaps://s.example.com/light 461 2. Target CoAP URI in the path component of the Hosting HTTP URI: 463 forward/{+tu} 465 coap://s.example.com/light 467 http://p.example.com/hc/forward/coap://s.example.com/light 469 or 471 coaps://s.example.com/light 473 http://p.example.com/hc/forward/coaps://s.example.com/light 475 3. "coap" URI is a query argument of the Hosting HTTP URI; client 476 decides to omit scheme because a default scheme is agreed 477 beforehand between client and proxy: 479 ?coap_uri={+tu} 481 coap://s.example.com/light 483 http://p.example.com/hc/?coap_uri=s.example.com/light 485 5.4.2. Enhanced Form 487 The enhanced form can be used to express more sophisticated mappings 488 of the Target CoAP URI into the Hosting HTTP URI, i.e., mappings that 489 do not fit into the simple form. 491 There MUST be at most one instance of each of the following template 492 variables in a template definition: 494 s = "coap" / "coaps" ; from [RFC7252], Sections 6.1 and 6.2 495 hp = host [":" port] ; from [RFC3986], Sections 3.2.2 and 3.2.3 496 p = path-abempty ; from [RFC3986], Section 3.3 497 q = query ; from [RFC3986], Section 3.4 498 qq = [ "?" query ] ; qq is empty if and only if 'query' is empty 500 The qq form is used when the path and the (optional) query components 501 are to be copied verbatim from the Target CoAP URI into the Hosting 502 HTTP URI, i.e., as "{+p}{+qq}". Instead, the q form is used when the 503 query and path are mapped as separate entities, e.g., as in 504 "coap_path={+p}&coap_query={+q}". 506 5.4.2.1. Examples 508 All the following examples (given as a specific URI mapping template, 509 a Target CoAP URI, and the produced Hosting HTTP URI) use 510 http://p.example.com/hc/ as the HC Proxy URI. 512 1. Target CoAP URI components in path segments, and optional query 513 in query component: 515 {+s}/{+hp}{+p}{+qq} 517 coap://s.example.com/light 519 http://p.example.com/hc/coap/s.example.com/light 521 or 523 coap://s.example.com/light?on 525 http://p.example.com/hc/coap/s.example.com/light?on 527 2. Target CoAP URI components split in individual query arguments: 529 ?s={+s}&hp={+hp}&p={+p}&q={+q} 531 coap://s.example.com/light 533 http://p.example.com/hc/?s=coap&hp=s.example.com&p=/light&q= 535 or 537 coaps://s.example.com/light?on 539 http://p.example.com/hc/?s=coaps&hp=s.example.com&p=/light&q=on 541 5.5. Discovery 543 In order to accommodate site specific needs while allowing third 544 parties to discover the proxy function, the HC proxy SHOULD publish 545 information related to the location and syntax of the HC proxy 546 function using the CoRE Link Format [RFC6690] interface. 548 To this aim a new Resource Type, "core.hc", is defined in this 549 document. It can be used as the value for the "rt" attribute in a 550 query to the /.well-known/core in order to locate the URI where the 551 HC proxy function is anchored, i.e., the HC Proxy URI. 553 Along with it, the new target attribute "hct" is defined in this 554 document. This attribute MAY be returned in a "core.hc" link to 555 provide the URI Mapping Template associated to the mapping resource. 556 The default template given in Section 5.3, i.e., {+tu}, MUST be 557 assumed if no "hct" attribute is found in the returned link. If a 558 "hct" attribute is present in the returned link, then a client MUST 559 use it to create the Hosting HTTP URI. 561 The URI mapping SHOULD be discoverable (as specified in [RFC6690]) on 562 both the HTTP and the CoAP side of the HC proxy, with one important 563 difference: on the CoAP side the link associated to the "core.hc" 564 resource needs an explicit anchor referring to the HTTP origin, while 565 on the HTTP interface the link context is already the HTTP origin 566 carried in the request's Host header, and doesn't have to be made 567 explicit. 569 5.5.1. Examples 571 o The first example exercises the CoAP interface, and assumes that 572 the default template, {+tu}, is used. For example, in use case #3 573 in section Section 4, the smartphone may discover the public HC 574 proxy before leaving the home network. Then when outside the home 575 network, the smartphone will be able to query the appropriate home 576 sensor. 578 Req: GET coap://[ff02::1]/.well-known/core?rt=core.hc 580 Res: 2.05 Content 581 ;anchor="http://p.example.com";rt="core.hc" 583 o The second example - also on the CoAP side of the HC proxy - uses 584 a custom template, i.e., one where the CoAP URI is carried inside 585 the query component, thus the returned link carries the URI 586 template to be used in an explicit "hct" attribute: 588 Req: GET coap://[ff02::1]/.well-known/core?rt=core.hc 590 Res: 2.05 Content 591 ;anchor="http://p.example.com"; 592 rt="core.hc";hct="?uri={+tu}" 594 On the HTTP side, link information can be serialized in more than one 595 way: 597 o using the 'application/link-format' content type: 599 Req: GET /.well-known/core?rt=core.hc HTTP/1.1 600 Host: p.example.com 602 Res: HTTP/1.1 200 OK 603 Content-Type: application/link-format 604 Content-Length: 18 606 ;rt="core.hc" 608 o using the 'application/link-format+json' content type as defined 609 in [I-D.ietf-core-links-json]: 611 Req: GET /.well-known/core?rt=core.hc HTTP/1.1 612 Host: p.example.com 614 Res: HTTP/1.1 200 OK 615 Content-Type: application/link-format+json 616 Content-Length: 31 618 [{"href":"/hc/","rt":"core.hc"}] 620 o using the Link header: 622 Req: GET /.well-known/core?rt=core.hc HTTP/1.1 623 Host: p.example.com 625 Res: HTTP/1.1 200 OK 626 Link: ;rt="core.hc" 628 6. Media Type Mapping 630 6.1. Overview 632 A HC proxy needs to translate HTTP media types (Section 3.1.1.1 of 633 [RFC7231]) and content encodings (Section 3.1.2.2 of [RFC7231]) into 634 CoAP content formats (Section 12.3 of [RFC7252]) and vice versa. 636 Media type translation can happen in GET, PUT or POST requests going 637 from HTTP to CoAP, and in 2.xx (i.e., successful) responses going 638 from CoAP to HTTP. Specifically, PUT and POST need to map both the 639 Content-Type and Content-Encoding HTTP headers into a single CoAP 640 Content-Format option, whereas GET needs to map Accept and Accept- 641 Encoding HTTP headers into a single CoAP Accept option. To generate 642 the HTTP response, the CoAP Content-Format option is mapped back to a 643 suitable HTTP Content-Type and Content-Encoding combination. 645 An HTTP request carrying a Content-Type and Content-Encoding 646 combination which the HC proxy is unable to map to an equivalent CoAP 647 Content-Format, SHALL elicit a 415 (Unsupported Media Type) response 648 by the HC proxy. 650 On the content negotiation side, failure to map Accept and Accept-* 651 headers SHOULD be silently ignored: the HC proxy SHOULD therefore 652 forward as a CoAP request with no Accept option. The HC proxy thus 653 disregards the Accept/Accept-* header fields by treating the response 654 as if it is not subject to content negotiation, as mentioned in 655 Sections 5.3.* of [RFC7231]. However, a HC proxy implementation is 656 free to attempt mapping a single Accept header in a GET request to 657 multiple CoAP GET requests, each with a single Accept option, which 658 are then tried in sequence until one succeeds. Note that an HTTP 659 Accept */* MUST be mapped to a CoAP request without Accept option. 661 While the CoAP to HTTP direction has always a well defined mapping 662 (with the exception examined in Section 6.2), the HTTP to CoAP 663 direction is more problematic because the source set, i.e., 664 potentially 1000+ IANA registered media types, is much bigger than 665 the destination set, i.e., the mere 6 values initially defined in 666 Section 12.3 of [RFC7252]. 668 Depending on the tight/loose coupling with the application(s) for 669 which it proxies, the HC proxy could implement different media type 670 mappings. 672 When tightly coupled, the HC proxy knows exactly which content 673 formats are supported by the applications, and can be strict when 674 enforcing its forwarding policies in general, and the media type 675 mapping in particular. 677 On the other side, when the HC proxy is a general purpose application 678 layer gateway, being too strict could significantly reduce the amount 679 of traffic that it would be able to successfully forward. In this 680 case, the "loose" media type mapping detailed in Section 6.3 MAY be 681 implemented. 683 The latter grants more evolution of the surrounding ecosystem, at the 684 cost of allowing more attack surface. In fact, as a result of such 685 strategy, payloads would be forwarded more liberally across the 686 unconstrained/constrained network boundary of the communication path. 687 Therefore, when applied, some form of access control must be set in 688 place to avoid unauthorized users to deplete or abuse systems and 689 network resources. 691 6.2. 'application/coap-payload' Media Type 693 If the HC proxy receives a CoAP response with a Content-Format that 694 it does not recognize (e.g., because the value has been registered 695 after the proxy has been deployed, or the CoAP server uses an 696 experimental value which is not registered), then the HC proxy SHALL 697 return a generic "application/coap-payload" media type with numeric 698 parameter "cf" as defined in Section 9.2. 700 For example, the CoAP content format '60' ("application/cbor") would 701 be represented by "application/coap-payload;cf=60", if the HC Proxy 702 doesn't recognize the content format '60'. 704 A HTTP client may use the media type "application/coap-payload" as a 705 means to send a specific content format to a CoAP server via a HC 706 Proxy if the client has determined that the HC Proxy does not 707 directly support the type mapping it needs. This case may happen 708 when dealing for example with newly registered, yet to be registered, 709 or experimental CoAP content formats. However, unless explicitly 710 configured to allow pass-through of unknown content formats, the HC 711 proxy SHOULD NOT forward requests carrying a Content-Type or Accept 712 header with an "application/coap-payload", and return an appropriate 713 client error instead. 715 6.3. Loose Media Type Mapping 717 By structuring the type information in a super-class (e.g., "text") 718 followed by a finer grained sub-class (e.g., "html"), and optional 719 parameters (e.g., "charset=utf-8"), Internet media types provide a 720 rich and scalable framework for encoding the type of any given 721 entity. 723 This approach is not applicable to CoAP, where Content Formats 724 conflate an Internet media type (potentially with specific 725 parameters) and a content encoding into one small integer value. 727 To remedy this loss of flexibility, we introduce the concept of a 728 "loose" media type mapping, where media types that are 729 specializations of a more generic media type can be aliased to their 730 super-class and then mapped (if possible) to one of the CoAP content 731 formats. For example, "application/soap+xml" can be aliased to 732 "application/xml", which has a known conversion to CoAP. In the 733 context of this "loose" media type mapping, "application/octet- 734 stream" can be used as a fallback when no better alias is found for a 735 specific media type. 737 Table 1 defines the default lookup table for the "loose" media type 738 mapping. It is expected that an implementation can refine it either 739 given application-specific knowledge, or because new Content-Formats 740 are defined. Given an input media type, the table returns its best 741 generalized media type using the most specific match i.e., the table 742 entries are compared to the input in top to bottom order until an 743 entry matches. 745 +---------------------+--------------------------+ 746 | Internet media type | Generalized media type | 747 +---------------------+--------------------------+ 748 | application/*+xml | application/xml | 749 | application/*+json | application/json | 750 | text/xml | application/xml | 751 | text/* | text/plain | 752 | */* | application/octet-stream | 753 +---------------------+--------------------------+ 755 Table 1: Media type generalization lookup table 757 The "loose" media type mapping is an OPTIONAL feature. 758 Implementations supporting this kind of mapping should provide a 759 flexible way to define the set of media type generalizations allowed. 761 6.4. Media Type to Content Format Mapping Algorithm 763 This section defines the algorithm used to map an HTTP Internet media 764 type to its correspondent CoAP content format. 766 The algorithm uses the mapping table defined in Section 12.3 of 767 [RFC7252] plus, possibly, any locally defined extension of it. 768 Optionally, the table and lookup mechanism described in Section 6.3 769 can be used if the implementation chooses so. 771 Note that the algorithm may have side effects on the associated 772 representation (see also Section 6.5). 774 In the following: 776 o C-T, C-E, and C-F stand for the values of the Content-Type (or 777 Accept) HTTP header, Content-Encoding (or Accept-Encoding) HTTP 778 header, and Content-Format CoAP option respectively. 780 o If C-E is not given it is assumed to be "identity". 782 o MAP is the mandatory lookup table, GMAP is the optional 783 generalized table. 785 INPUT: C-T and C-E 786 OUTPUT: C-F or Fail 788 1. if no C-T: return Fail 789 2. C-F = MAP[C-T, C-E] 790 3. if C-F is not None: return C-F 791 4. if C-E is not "identity": 792 5. if C-E is supported (e.g., gzip): 793 6. decode the representation accordingly 794 7. set C-E to "identity" 795 8. else: 796 9. return Fail 797 10. repeat steps 2. and 3. 798 11. if C-T allows a non-lossy transformation into \ 799 12. one of the supported C-F: 800 13. transcode the representation accordingly 801 14. return C-F 802 15. if GMAP is defined: 803 16. C-F = GMAP[C-T] 804 17. if C-F is not None: return C-F 805 18. return Fail 807 Figure 2 809 6.5. Content Transcoding 811 6.5.1. General 813 Payload content transcoding (e.g., see steps 11-14 of Figure 2) is an 814 OPTIONAL feature. Implementations supporting this feature should 815 provide a flexible way to define the set of transcodings allowed. 817 As noted in Section 6.4, the process of mapping the media type can 818 have side effects on the forwarded entity body. This may be caused 819 by the removal or addition of a specific content encoding, or because 820 the HC proxy decides to transcode the representation to a different 821 (compatible) format. The latter proves useful when an optimized 822 version of a specific format exists. For example a XML-encoded 823 resource could be transcoded to Efficient XML Interchange (EXI) 824 format, or a JSON-encoded resource into CBOR [RFC7049], effectively 825 achieving compression without losing any information. 827 However, there are at least two important factors to keep in mind 828 when implementing and enabling a transcoding function: 830 1. Maliciously crafted inputs coming from the HTTP side might 831 inflate in size (see for example Section 4.2 of [RFC7049]), 832 therefore creating a security threat for both the HC proxy and 833 the target resource; 835 2. Transcoding can lose information in non-obvious ways. For 836 example, encoding a XML document using schema-informed EXI 837 encoding leads to a loss of information when the destination does 838 not know the exact schema version used by the encoder. That 839 means that whenever the HC proxy transcodes an application/XML to 840 application/EXI in-band metadata could be lost. 842 It is crucial that these risks are well understood and carefully 843 weighed against the actual benefits before deploying the transcoding 844 function. 846 6.5.2. CoRE Link Format 848 The CoRE Link Format [RFC6690] is a set of links (i.e., URIs and 849 their formal relationships) which is carried as content payload in a 850 CoAP response. These links usually include CoAP URIs that might be 851 translated by the HC proxy to the correspondent HTTP URIs using the 852 implemented URI mapping function (see Section 5). Such a process 853 would inspect the forwarded traffic and attempt to re-write the body 854 of resources with an application/link-format media type, mapping the 855 embedded CoAP URIs to their HTTP counterparts. Some potential issues 856 with this approach are: 858 1. The client may be interested to retrieve original (unaltered) 859 CoAP payloads through the HC proxy, not modified versions. 861 2. Tampering with payloads is incompatible with resources that are 862 integrity protected (although this is a problem with transcoding 863 in general). 865 3. The HC proxy needs to fully understand [RFC6690] syntax and 866 semantics, otherwise there is an inherent risk to corrupt the 867 payloads. 869 Therefore, CoRE Link Format payload should only be transcoded at the 870 risk and discretion of the proxy implementer. 872 6.5.3. Diagnostic Messages 874 CoAP responses may, in certain error cases, contain a diagnostic 875 message in the payload explaining the error situation, as described 876 in Section 5.5.2 of [RFC7252]. If present, the CoAP response 877 diagnostic payload SHOULD be copied in the HTTP response body. The 878 CoAP diagnostic message MUST NOT be copied into the HTTP reason- 879 phrase, since it potentially contains CR-LF characters which are 880 incompatible with HTTP reason-phrase syntax. 882 7. Response Code Mapping 884 Table 2 defines the HTTP response status codes to which each CoAP 885 response code SHOULD be mapped. Multiple appearances of a HTTP 886 status code in the second column indicates multiple equivalent HTTP 887 responses are possible based on the same CoAP response code, 888 depending on the conditions cited in the Notes (third column and text 889 below table). 891 +-----------------------------+-----------------------------+-------+ 892 | CoAP Response Code | HTTP Status Code | Notes | 893 +-----------------------------+-----------------------------+-------+ 894 | 2.01 Created | 201 Created | 1 | 895 | 2.02 Deleted | 200 OK | 2 | 896 | | 204 No Content | 2 | 897 | 2.03 Valid | 304 Not Modified | 3 | 898 | | 200 OK | 4 | 899 | 2.04 Changed | 200 OK | 2 | 900 | | 204 No Content | 2 | 901 | 2.05 Content | 200 OK | | 902 | 4.00 Bad Request | 400 Bad Request | | 903 | 4.01 Unauthorized | 403 Forbidden | 5 | 904 | 4.02 Bad Option | 400 Bad Request | 6 | 905 | 4.02 Bad Option | 500 Internal Server Error | 6 | 906 | 4.03 Forbidden | 403 Forbidden | | 907 | 4.04 Not Found | 404 Not Found | | 908 | 4.05 Method Not Allowed | 400 Bad Request | 7 | 909 | 4.06 Not Acceptable | 406 Not Acceptable | | 910 | 4.12 Precondition Failed | 412 Precondition Failed | | 911 | 4.13 Request Ent. Too Large | 413 Request Repr. Too Large | | 912 | 4.15 Unsupported Media Type | 415 Unsupported Media Type | | 913 | 5.00 Internal Server Error | 500 Internal Server Error | | 914 | 5.01 Not Implemented | 501 Not Implemented | | 915 | 5.02 Bad Gateway | 502 Bad Gateway | | 916 | 5.03 Service Unavailable | 503 Service Unavailable | 8 | 917 | 5.04 Gateway Timeout | 504 Gateway Timeout | | 918 | 5.05 Proxying Not Supported | 502 Bad Gateway | 9 | 919 +-----------------------------+-----------------------------+-------+ 921 Table 2: CoAP-HTTP Response Code Mappings 923 Notes: 925 1. A CoAP server may return an arbitrary format payload along with 926 this response. If present, this payload MUST be returned as 927 entity in the HTTP 201 response. Section 7.3.2 of [RFC7231] does 928 not put any requirement on the format of the entity. (In the 929 past, [RFC2616] did.) 931 2. The HTTP code is 200 or 204 respectively for the case that a CoAP 932 server returns a payload or not. [RFC7231] Section 5.3 requires 933 code 200 in case a representation of the action result is 934 returned for DELETE/POST/PUT, and code 204 if not. Hence, a 935 proxy MUST transfer any CoAP payload contained in a CoAP 2.02 936 response to the HTTP client using a 200 OK response. 938 3. HTTP code 304 (Not Modified) is sent if the HTTP client performed 939 a conditional HTTP request and the CoAP server responded with 940 2.03 (Valid) to the corresponding CoAP validation request. Note 941 that Section 4.1 of [RFC7232] puts some requirements on header 942 fields that must be present in the HTTP 304 response. 944 4. A 200 response to a CoAP 2.03 occurs only when the HC proxy, for 945 efficiency reasons, is running a local cache. An unconditional 946 HTTP GET which produces a cache-hit, could trigger a re- 947 validation (i.e., a conditional GET) on the CoAP side. The proxy 948 receiving 2.03 updates the freshness of its cached representation 949 and returns it to the HTTP client. 951 5. A HTTP 401 Unauthorized (Section 3.1 of [RFC7235]) response is 952 not applicable because there is no equivalent in CoAP of WWW- 953 Authenticate which is mandatory in a HTTP 401 response. 955 6. If the proxy has a way to determine that the Bad Option is due to 956 the straightforward mapping of a client request header into a 957 CoAP option, then returning HTTP 400 (Bad Request) is 958 appropriate. In all other cases, the proxy MUST return HTTP 500 959 (Internal Server Error) stating its inability to provide a 960 suitable translation to the client's request. 962 7. A CoAP 4.05 (Method Not Allowed) response SHOULD normally be 963 mapped to a HTTP 400 (Bad Request) code, because the HTTP 405 964 response would require specifying the supported methods - which 965 are generally unknown. In this case the HC Proxy SHOULD also 966 return a HTTP reason-phrase in the HTTP status line that starts 967 with the string "CoAP server returned 4.05" in order to 968 facilitate troubleshooting. However, if the HC proxy has more 969 granular information about the supported methods for the 970 requested resource (e.g., via a Resource Directory 971 ([I-D.ietf-core-resource-directory])) then it MAY send back a 972 HTTP 405 (Method Not Allowed) with a properly filled in "Allow" 973 response-header field (Section 7.4.1 of [RFC7231]). 975 8. The value of the HTTP "Retry-After" response-header field is 976 taken from the value of the CoAP Max-Age Option, if present. 978 9. This CoAP response can only happen if the proxy itself is 979 configured to use a CoAP forward-proxy (Section 5.7 of [RFC7252]) 980 to execute some, or all, of its CoAP requests. 982 8. Additional Mapping Guidelines 984 8.1. Caching and Congestion Control 986 A HC proxy should cache CoAP responses, and reply whenever applicable 987 with a cached representation of the requested resource. 989 If the HTTP client drops the connection after the HTTP request was 990 made, a HC proxy should wait for the associated CoAP response and 991 cache it if possible. Subsequent requests to the HC proxy for the 992 same resource can use the result present in cache, or, if a response 993 has still to come, the HTTP requests will wait on the open CoAP 994 request. 996 According to [RFC7252], a proxy must limit the number of outstanding 997 requests to a given CoAP server to NSTART. To limit the amount of 998 aggregate traffic to a constrained network, the HC proxy should also 999 put a limit on the number of concurrent CoAP requests pending on the 1000 same constrained network; further incoming requests may either be 1001 queued or dropped (returning 503 Service Unavailable). This limit 1002 and the proxy queueing/dropping behavior should be configurable. 1004 Highly volatile resources that are being frequently requested may be 1005 observed [RFC7641] by the HC proxy to keep their cached 1006 representation fresh while minimizing the amount of CoAP traffic in 1007 the constrained network. See Section 8.2. 1009 8.2. Cache Refresh via Observe 1011 There are cases where using the CoAP observe protocol [RFC7641] to 1012 handle proxy cache refresh is preferable to the validation mechanism 1013 based on ETag as defined in [RFC7252]. Such scenarios include, but 1014 are not limited to, sleepy CoAP nodes -- with possibly high variance 1015 in requests' distribution -- which would greatly benefit from a 1016 server driven cache update mechanism. Ideal candidates for CoAP 1017 observe are also crowded or very low throughput networks, where 1018 reduction of the total number of exchanged messages is an important 1019 requirement. 1021 This subsection aims at providing a practical evaluation method to 1022 decide whether refreshing a cached resource R is more efficiently 1023 handled via ETag validation or by establishing an observation on R. 1024 The idea being that the HC proxy proactively installs an observation 1025 on a "popular enough" resource and actively monitors: 1027 a. Its update pattern on the CoAP side; and 1029 b. The request pattern on the HTTP side; 1031 and uses the formula below to determine whether the observation 1032 should be kept alive or shut down. 1034 Let T_R be the mean time between two client requests to resource R, 1035 let T_C be the mean time between two representation changes of R, and 1036 let M_R be the mean number of CoAP messages per second exchanged to 1037 and from resource R. If we assume that the initial cost for 1038 establishing the observation is negligible, an observation on R 1039 reduces M_R if and only if T_R < 2*T_C with respect to using ETag 1040 validation, that is if and only if the mean arrival rate of requests 1041 for resource R is greater than half the change rate of R. 1043 When observing the resource R, M_R is always upper bounded by 2/T_C. 1045 8.3. Use of CoAP Blockwise Transfer 1047 A HC proxy SHOULD support CoAP blockwise transfers [RFC7959] to allow 1048 transport of large CoAP payloads while avoiding excessive link-layer 1049 fragmentation in constrained networks, and to cope with small 1050 datagram buffers in CoAP end-points as described in [RFC7252] 1051 Section 4.6. 1053 A HC proxy SHOULD attempt to retry a payload-carrying CoAP PUT or 1054 POST request with blockwise transfer if the destination CoAP server 1055 responded with 4.13 (Request Entity Too Large) to the original 1056 request. A HC proxy SHOULD attempt to use blockwise transfer when 1057 sending a CoAP PUT or POST request message that is larger than 1058 BLOCKWISE_THRESHOLD bytes. The value of BLOCKWISE_THRESHOLD is 1059 implementation-specific, for example it can be: 1061 o calculated based on a known or typical UDP datagram buffer size 1062 for CoAP end-points, or 1064 o set to N times the known size of a link-layer frame in a 1065 constrained network where e.g., N=5, or 1067 o preset to a known IP MTU value, or 1069 o set to a known Path MTU value. 1071 The value BLOCKWISE_THRESHOLD, or the parameters from which it is 1072 calculated, should be configurable in a proxy implementation. The 1073 maximum block size the proxy will attempt to use in CoAP requests 1074 should also be configurable. 1076 The HC proxy SHOULD detect CoAP end-points not supporting blockwise 1077 transfers. This can be done by checking for a 4.02 (Bad Option) 1078 response returned by an end-point in response to a CoAP request with 1079 a Block* Option, and subsequent absence of the 4.02 in response to 1080 the same request without Block* Options. This allows the HC proxy to 1081 be more efficient, not attempting repeated blockwise transfers to 1082 CoAP servers that do not support it. 1084 8.4. CoAP Multicast 1086 A HC proxy MAY support CoAP multicast. If it does, the HC proxy 1087 sends out a multicast CoAP request if the Target CoAP URI's authority 1088 is a multicast IP literal or resolves to a multicast IP address. If 1089 the HC proxy does not support CoAP multicast, it SHOULD respond 403 1090 (Forbidden) to any valid HTTP request that maps to a CoAP multicast 1091 request. 1093 Details related to supporting CoAP multicast are currently out of 1094 scope of this document since in a proxy scenario a HTTP client 1095 typically expects to receive a single response, not multiple. 1096 However, a HC proxy that implements CoAP multicast may include 1097 application-specific functions to aggregate multiple CoAP responses 1098 into a single HTTP response. We suggest using the "application/http" 1099 internet media type (Section 8.3.2 of [RFC7230]) to enclose a set of 1100 one or more HTTP response messages, each representing the mapping of 1101 one CoAP response. 1103 For further considerations related to the handling of multicast 1104 requests, see Section 10.1. 1106 8.5. Timeouts 1108 If the CoAP server takes a long time in responding, the HTTP client 1109 or any other proxy in between may timeout. Further discussion of 1110 timeouts in HTTP is available in Section 6.2.4 of [RFC7230]. 1112 A HC proxy MUST define an internal timeout for each pending CoAP 1113 request, because the CoAP server may silently die before completing 1114 the request. Assuming the Proxy uses confirmable CoAP requests, such 1115 timeout value T SHOULD be at least 1117 T = MAX_RTT + MAX_SERVER_RESPONSE_DELAY 1118 where MAX_RTT is defined in [RFC7252] and MAX_SERVER_RESPONSE_DELAY 1119 is defined in [RFC7390]. 1121 9. IANA Considerations 1123 9.1. New 'core.hc' Resource Type 1125 This document registers a new Resource Type (rt=) Link Target 1126 Attribute, 'core.hc', in the "Resource Type (rt=) Link Target 1127 Attribute Values" subregistry under the "Constrained RESTful 1128 Environments (CoRE) Parameters" registry. 1130 Attribute Value: core.hc 1132 Description: HTTP to CoAP mapping base resource. 1134 Reference: See Section 5.5. 1136 9.2. New 'coap-payload' Internet Media Type 1138 This document defines the "application/coap-payload" media type with 1139 a single parameter "cf". This media type represents any payload that 1140 a CoAP message can carry, having a content format that can be 1141 identified by an integer in range 0-65535 corresponding to a CoAP 1142 Content-Format parameter ([RFC7252], Section 12.3). The parameter 1143 "cf" is the integer defining the CoAP content format. 1145 Type name: application 1147 Subtype name: coap-payload 1149 Required parameters: cf (CoAP Content-Format integer in range 0-65535 1150 denoting the content format of the CoAP payload carried, as defined 1151 by the "CoAP Content-Formats" subregistry that is part of the 1152 "Constrained RESTful Environments (CoRE) Parameters" registry.) 1154 Optional parameters: None 1156 Encoding considerations: Common use is BINARY. The specific CoAP 1157 content format encoding considerations for the selected Content- 1158 Format (cf parameter) apply. The encoding can vary based on the 1159 value of the cf parameter. 1161 Security considerations: The specific CoAP content format security 1162 considerations for the selected Content-Format (cf parameter) apply. 1164 Interoperability considerations: This media type can never be used 1165 directly in CoAP messages because there is no means available to 1166 encode the mandatory 'cf' parameter in CoAP. 1168 Published specification: (this I-D - TBD) 1170 Applications that use this media type: HTTP-to-CoAP Proxies. 1172 Fragment identifier considerations: CoAP does not support URI 1173 fragments; therefore a CoAP payload fragment cannot be identified. 1174 Fragments are not applicable for this media type. 1176 Additional information: 1178 Deprecated alias names for this type: N/A 1180 Magic number(s): N/A 1182 File extension(s): N/A 1184 Macintosh file type code(s): N/A 1186 Person and email address to contact for further information: 1188 Esko Dijk ("esko@ieee.org") 1190 Intended usage: COMMON 1192 Restrictions on usage: 1194 An application (or user) can only use this media type if it has to 1195 represent a CoAP payload of which the specified CoAP Content-Format 1196 is an unrecognized number; such that a proper translation directly to 1197 the equivalent HTTP media type is not possible. 1199 Author: CoRE WG 1201 Change controller: IETF 1203 Provisional registration: No 1205 10. Security Considerations 1207 The security concerns raised in Section 9.2 of [RFC7230] also apply 1208 to the HC proxy scenario. 1210 A HC proxy deployed at the boundary of a constrained network is an 1211 easy single point of failure for reducing availability. As such, 1212 special care should be taken in designing, developing and operating 1213 it, keeping in mind that, in most cases, it has fewer limitations 1214 than the constrained devices it is serving. 1216 The correctness of the request parsing in general (including any 1217 content transcoding), and of the URI translation process in 1218 particular, is essential to the security of the HC proxy function. 1219 This is especially true when the internal network hosts devices with 1220 genuinely limited capabilities. The quality of implementation and 1221 operation -- i.e., careful implementation and/or selection of the 1222 third party libraries, sane configuration defaults, an expedite way 1223 to upgrade a running instance, etc. - is therefore an essential 1224 attribute of the HC proxy. For this purpose, see also Sections 9.3, 1225 9.4, 9.5 and 9.6 of [RFC7230] for well known issues related to HTTP 1226 request parsing, and section 11.1 of [RFC7252] for an overview of 1227 CoAP specific concerns related to URI processing -- in particular the 1228 potential fall-out on access control logics. 1230 The following sub paragraphs categorize and discuss a set of specific 1231 security issues related to the translation, caching and forwarding 1232 functionality exposed by a HC proxy. 1234 10.1. Multicast 1236 Multicast requests impose a non-trivial cost on the constrained 1237 network and endpoints, and might be exploited as a DoS attack vector 1238 (see also Section 10.2). From a privacy perspective, they can be 1239 used to gather detailed information about the resources hosted in the 1240 constrained network. For example, an outsider that is able to 1241 successfully query the /.well-known/core could obtain a comprehensive 1242 list of the target's home appliances and devices. From a security 1243 perspective, they can be used to carry out a network reconnaissance 1244 attack to gather information about possible vulnerabilities that 1245 could be exploited at a later point in time. For these reasons, it 1246 is RECOMMENDED that requests to multicast resources are access 1247 controlled with a default-deny policy. It is RECOMMENDED that the 1248 requestor of a multicast resource be strongly authenticated. If 1249 privacy and / or security are first class requirements, for example 1250 whenever the HTTP request transits through the public Internet, the 1251 request SHOULD be transported over a mutually authenticated and 1252 encrypted TLS connection. 1254 10.2. Traffic Overflow 1256 Due to the typically constrained nature of CoAP nodes, particular 1257 attention should be given to the implementation of traffic reduction 1258 mechanisms (see Section 8.1), because inefficient proxy 1259 implementations can be targeted by unconstrained Internet attackers. 1260 Bandwidth or complexity involved in such attacks is very low. 1262 An amplification attack to the constrained network may be triggered 1263 by a multicast request generated by a single HTTP request which is 1264 mapped to a CoAP multicast resource, as discussed in Section 11.3 of 1265 [RFC7252]. 1267 The risk likelihood of this amplification technique is higher than an 1268 amplification attack carried out by a malicious constrained device 1269 (e.g., ICMPv6 flooding, like Packet Too Big, or Parameter Problem on 1270 a multicast destination [RFC4732]), since it does not require direct 1271 access to the constrained network. 1273 The feasibility of this attack which disrupts availability of the 1274 targeted CoAP server can be limited by access controlling the exposed 1275 multicast resources, so that only known/authorized users can access 1276 such URIs. 1278 10.3. Handling Secured Exchanges 1280 An HTTP request can be sent to the HC proxy over a secured 1281 connection. However, there may not always exist a secure connection 1282 mapping to CoAP. For example, a secure distribution method for 1283 multicast traffic is complex and may not be implemented (see 1284 [RFC7390]). 1286 A HC proxy should implement rules for security context translations. 1287 For example all "https" unicast requests are translated to "coaps" 1288 requests, or "https" requests are translated to unsecured "coap" 1289 requests. Another rule could specify the security policy and 1290 parameters used for DTLS sessions [RFC7925]. Such rules will largely 1291 depend on the application and network context in which the HC proxy 1292 operates. These rules should be configurable. 1294 It is RECOMMENDED that, by default, accessing a "coaps" URI is only 1295 allowed from a corresponding "https" URI. 1297 By default, a HC proxy SHOULD reject any secured CoAP client request 1298 (i.e., one with a "coaps" scheme) if there is no configured security 1299 policy mapping. This recommendation may be relaxed in case the 1300 destination network is believed to be secured by other means. 1301 Assuming that CoAP nodes are isolated behind a firewall as in the HC 1302 proxy deployment shown in Figure 1, the HC proxy may be configured to 1303 translate the incoming HTTPS request using plain CoAP (NoSec mode). 1305 10.4. URI Mapping 1307 The following risks related to the URI mapping described in Section 5 1308 and its use by HC proxies have been identified: 1310 DoS attack on the constrained/CoAP network. 1311 Mitigation: by default deny any Target CoAP URI whose authority is 1312 (or maps to) a multicast address. Then explicitly white-list 1313 multicast resources/authorities that are allowed to be de- 1314 referenced. See also Section 8.4. 1316 Leaking information on the constrained/CoAP network resources and 1317 topology. 1318 Mitigation: by default deny any Target CoAP URI (especially 1319 /.well-known/core is a resource to be protected), and then 1320 explicitly white-list resources that are allowed to be seen from 1321 outside. 1323 The internal CoAP Target resource is totally transparent from 1324 outside. 1325 Mitigation: implement a HTTPS-only interface, which makes the 1326 Target CoAP URI totally opaque to a passive attacker. 1328 11. Acknowledgments 1330 An initial version of Table 2 in Section 7 has been provided in 1331 revision -05 of the CoRE CoAP I-D. Special thanks to Peter van der 1332 Stok for countless comments and discussions on this document, that 1333 contributed to its current structure and text. 1335 Thanks to Abhijan Bhattacharyya, Alexey Melnikov, Brian Frank, 1336 Carsten Bormann, Christian Amsuess, Christian Groves, Cullen 1337 Jennings, Dorothy Gellert, Francesco Corazza, Francis Dupont, Hannes 1338 Tschofenig, Jaime Jimenez, Kathleen Moriarty, Kepeng Li, Kerry Lynn, 1339 Klaus Hartke, Linyi Tian, Michele Rossi, Michele Zorzi, Nicola Bui, 1340 Peter Saint-Andre, Sean Leonard, Spencer Dawkins, Stephen Farrell, 1341 Suresh Krishnan, Zach Shelby for helpful comments and discussions 1342 that have shaped the document. 1344 The research leading to these results has received funding from the 1345 European Community's Seventh Framework Programme [FP7/2007-2013] 1346 under grant agreement n.251557. 1348 12. References 1349 12.1. Normative References 1351 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1352 Requirement Levels", BCP 14, RFC 2119, 1353 DOI 10.17487/RFC2119, March 1997, 1354 . 1356 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 1357 Resource Identifier (URI): Generic Syntax", STD 66, 1358 RFC 3986, DOI 10.17487/RFC3986, January 2005, 1359 . 1361 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 1362 Specifications: ABNF", STD 68, RFC 5234, 1363 DOI 10.17487/RFC5234, January 2008, 1364 . 1366 [RFC6570] Gregorio, J., Fielding, R., Hadley, M., Nottingham, M., 1367 and D. Orchard, "URI Template", RFC 6570, 1368 DOI 10.17487/RFC6570, March 2012, 1369 . 1371 [RFC6690] Shelby, Z., "Constrained RESTful Environments (CoRE) Link 1372 Format", RFC 6690, DOI 10.17487/RFC6690, August 2012, 1373 . 1375 [RFC7230] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1376 Protocol (HTTP/1.1): Message Syntax and Routing", 1377 RFC 7230, DOI 10.17487/RFC7230, June 2014, 1378 . 1380 [RFC7231] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1381 Protocol (HTTP/1.1): Semantics and Content", RFC 7231, 1382 DOI 10.17487/RFC7231, June 2014, 1383 . 1385 [RFC7232] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1386 Protocol (HTTP/1.1): Conditional Requests", RFC 7232, 1387 DOI 10.17487/RFC7232, June 2014, 1388 . 1390 [RFC7235] Fielding, R., Ed. and J. Reschke, Ed., "Hypertext Transfer 1391 Protocol (HTTP/1.1): Authentication", RFC 7235, 1392 DOI 10.17487/RFC7235, June 2014, 1393 . 1395 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 1396 Application Protocol (CoAP)", RFC 7252, 1397 DOI 10.17487/RFC7252, June 2014, 1398 . 1400 [RFC7641] Hartke, K., "Observing Resources in the Constrained 1401 Application Protocol (CoAP)", RFC 7641, 1402 DOI 10.17487/RFC7641, September 2015, 1403 . 1405 [RFC7959] Bormann, C. and Z. Shelby, Ed., "Block-Wise Transfers in 1406 the Constrained Application Protocol (CoAP)", RFC 7959, 1407 DOI 10.17487/RFC7959, August 2016, 1408 . 1410 12.2. Informative References 1412 [I-D.ietf-core-links-json] 1413 Li, K., Rahman, A., and C. Bormann, "Representing CoRE 1414 Formats in JSON and CBOR", draft-ietf-core-links-json-06 1415 (work in progress), July 2016. 1417 [I-D.ietf-core-resource-directory] 1418 Shelby, Z., Koster, M., Bormann, C., and P. Stok, "CoRE 1419 Resource Directory", draft-ietf-core-resource-directory-08 1420 (work in progress), July 2016. 1422 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 1423 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 1424 Transfer Protocol -- HTTP/1.1", RFC 2616, 1425 DOI 10.17487/RFC2616, June 1999, 1426 . 1428 [RFC3040] Cooper, I., Melve, I., and G. Tomlinson, "Internet Web 1429 Replication and Caching Taxonomy", RFC 3040, 1430 DOI 10.17487/RFC3040, January 2001, 1431 . 1433 [RFC4732] Handley, M., Ed., Rescorla, E., Ed., and IAB, "Internet 1434 Denial-of-Service Considerations", RFC 4732, 1435 DOI 10.17487/RFC4732, December 2006, 1436 . 1438 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 1439 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 1440 October 2013, . 1442 [RFC7390] Rahman, A., Ed. and E. Dijk, Ed., "Group Communication for 1443 the Constrained Application Protocol (CoAP)", RFC 7390, 1444 DOI 10.17487/RFC7390, October 2014, 1445 . 1447 [RFC7925] Tschofenig, H., Ed. and T. Fossati, "Transport Layer 1448 Security (TLS) / Datagram Transport Layer Security (DTLS) 1449 Profiles for the Internet of Things", RFC 7925, 1450 DOI 10.17487/RFC7925, July 2016, 1451 . 1453 [W3C.REC-html5-20141028] 1454 Hickson, I., Berjon, R., Faulkner, S., Leithead, T., 1455 Navara, E., O'Connor, E., and S. Pfeiffer, "HTML5", W3C 1456 Recommendation REC-html5-20141028, 2014, 1457 . 1459 Appendix A. Change Log 1461 [Note to RFC Editor: Please remove this section before publication.] 1463 Changes from ietf-14 to ietf-15 (IESG review): 1465 o Kathleen Moriarty's DISCUSS and COMMENT; 1467 o Stephen Farrell's COMMENT; 1469 o Suresh Krishnan DISCUSS; 1471 o Spencer Dawkins' DISCUSS and COMMENT; 1473 Changes from ietf-13 to ietf-14: 1475 o Addressed Gen-ART and AD review comments. 1477 Changes from ietf-12 to ietf-13 (Christian Amsuess' comments): 1479 o More missing slashes in URI mapping template examples. 1481 Changes from ietf-11 to ietf-12 (2nd WGLC): 1483 o Addressed a few editorial issues (including a clarification on 1484 when to use qq vs q in the URI mapping template). 1486 o Fixed missing slash in one template example. 1488 o Added para about the need for future CoAP protocol elements to 1489 define their own HTTP mappings. 1491 Changes from ietf-10 to ietf-11 (Chair review): 1493 o Removed cu/su distinction from the URI mapping template. 1495 o Addressed a few editorial issues. 1497 Changes from ietf-09 to ietf-10: 1499 o Addressed Ticket #401 - Clarified that draft covers not only 1500 Reverse HC Proxy but that many parts also apply to Forward and 1501 Interception Proxies. 1503 o Clarified that draft concentrates on the HTTP-to-CoAP mapping 1504 direction (i.e., the HC proxy is a HTTP server and a CoAP client). 1506 o Clarified the "null mapping" case where no CoAP URI information is 1507 embedded in the HTTP request URI. 1509 o Moved multicast related security text to the "Security 1510 Considerations" to consolidate all security information in one 1511 location. 1513 o Removed references to "placement" of proxy (e.g., server-side vs 1514 client-side) as is confusing and provides little added value. 1516 o Fixed version numbers on references that were corrupted in last 1517 revision due to outdated xml2rfc conversion tool local cache. 1519 o Various editorial improvements. 1521 Changes from ietf-08 to ietf-09: 1523 o Clean up requirements language as per Klaus' comment. 1525 Changes from ietf-07 to ietf-08: 1527 o Addressed WGLC review comments from Klaus Hartke as per the 1528 correspondence of March 9, 2016 on the CORE WG mailing list. 1530 Changes from ietf-06 to ietf-07: 1532 o Addressed Ticket #384 - Section 5.4.1 describes briefly 1533 (informative) how to discover CoAP resources from an HTTP client. 1535 o Addressed Ticket #378 - For HTTP media type to CoAP content format 1536 mapping and vice versa: a new draft (TBD) may be proposed in CoRE 1537 which describes an approach for automatic updating of the media 1538 type mapping. This was noted in Section 6.1 but is otherwise 1539 outside the scope of this draft. 1541 o Addressed Ticket #377 - Added IANA section that defines a new HTTP 1542 media type "application/coap-payload" and created new Section 6.2 1543 on how to use it. 1545 o Addressed Ticket #376 - Updated Table 2 (and corresponding note 7) 1546 to indicate that a CoAP 4.05 (Method Not Allowed) Response Code 1547 should be mapped to a HTTP 400 (Bad Request). 1549 o Added note to comply to ABNF when translating CoAP diagnostic 1550 payload to reason-phrase in Section 6.5.3. 1552 Changes from ietf-05 to ietf-06: 1554 o Fully restructured the draft, bringing introductory text more to 1555 the front and allocating main sections to each of the key topics; 1556 addressing Ticket #379; 1558 o Addressed Ticket #382, fix of enhanced form URI template 1559 definition of q in Section 5.3.2; 1561 o Addressed Ticket #381, found a mapping 4.01 to 401 Unauthorized in 1562 Section 7; 1564 o Addressed Ticket #380 (Add IANA registration for "core.hc" 1565 Resource Type) in Section 9; 1567 o Addressed Ticket #376 (CoAP 4.05 response can't be translated to 1568 HTTP 405 by HC proxy) in Section 7 by use of empty 'Allow' header; 1570 o Removed details on the pros and cons of HC proxy placement 1571 options; 1573 o Addressed review comments of Carsten Bormann; 1575 o Clarified failure in mapping of HTTP Accept headers (Section 6.3); 1577 o Clarified detection of CoAP servers not supporting blockwise 1578 (Section 8.3); 1580 o Changed CoAP request timeout min value to MAX_RTT + 1581 MAX_SERVER_RESPONSE_DELAY (Section 8.6); 1583 o Added security section item (Section 10.3) related to use of CoAP 1584 blockwise transfers; 1586 o Many editorial improvements. 1588 Changes from ietf-04 to ietf-05: 1590 o Addressed Ticket #366 (Mapping of CoRE Link Format payloads to be 1591 valid in HTTP Domain?) in Section 6.3.3.2 (Content Transcoding - 1592 CORE Link Format); 1594 o Addressed Ticket #375 (Add requirement on mapping of CoAP 1595 diagnostic payload) in Section 6.3.3.3 (Content Transcoding - 1596 Diagnostic Messages); 1598 o Addressed comment from Yusuke (http://www.ietf.org/mail- 1599 archive/web/core/current/msg05491.html) in Section 6.3.3.1 1600 (Content Transcoding - General); 1602 o Various editorial improvements. 1604 Changes from ietf-03 to ietf-04: 1606 o Expanded use case descriptions in Section 4; 1608 o Fixed/enhanced discovery examples in Section 5.4.1; 1610 o Addressed Ticket #365 (Add text on media type conversion by HTTP- 1611 CoAP proxy) in new Section 6.3.1 (Generalized media type mapping) 1612 and new Section 6.3.2 (Content translation); 1614 o Updated HTTPBis WG draft references to recently published RFC 1615 numbers. 1617 o Various editorial improvements. 1619 Changes from ietf-02 to ietf-03: 1621 o Closed Ticket #351 "Add security implications of proposed default 1622 HTTP-CoAP URI mapping"; 1624 o Closed Ticket #363 "Remove CoAP scheme in default HTTP-CoAP URI 1625 mapping"; 1627 o Closed Ticket #364 "Add discovery of HTTP-CoAP mapping 1628 resource(s)". 1630 Changes from ietf-01 to ietf-02: 1632 o Selection of single default URI mapping proposal as proposed to WG 1633 mailing list 2013-10-09. 1635 Changes from ietf-00 to ietf-01: 1637 o Added URI mapping proposals to Section 4 as per the Email 1638 proposals to WG mailing list from Esko. 1640 Authors' Addresses 1642 Angelo P. Castellani 1643 University of Padova 1644 Via Gradenigo 6/B 1645 Padova 35131 1646 Italy 1648 Email: angelo@castellani.net 1650 Salvatore Loreto 1651 Ericsson 1652 Hirsalantie 11 1653 Jorvas 02420 1654 Finland 1656 Email: salvatore.loreto@ericsson.com 1658 Akbar Rahman 1659 InterDigital Communications, LLC 1660 1000 Sherbrooke Street West 1661 Montreal H3A 3G4 1662 Canada 1664 Phone: +1 514 585 0761 1665 Email: Akbar.Rahman@InterDigital.com 1667 Thomas Fossati 1668 Nokia 1669 3 Ely Road 1670 Milton, Cambridge CB24 6DD 1671 UK 1673 Email: thomas.fossati@nokia.com 1674 Esko Dijk 1675 Philips Lighting 1676 High Tech Campus 7 1677 Eindhoven 5656 AE 1678 The Netherlands 1680 Email: esko.dijk@philips.com