idnits 2.17.1 draft-ietf-core-http-mapping-07.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 (July 3, 2015) is 3219 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 811, but not defined == Missing Reference: 'C-E' is mentioned on line 797, but not defined == Outdated reference: A later version (-21) exists of draft-ietf-core-block-17 ** 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 (-28) exists of draft-ietf-core-resource-directory-03 -- 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: January 4, 2016 Ericsson 6 A. Rahman 7 InterDigital Communications, LLC 8 T. Fossati 9 Alcatel-Lucent 10 E. Dijk 11 Philips Research 12 July 3, 2015 14 Guidelines for HTTP-CoAP Mapping Implementations 15 draft-ietf-core-http-mapping-07 17 Abstract 19 This document provides reference information for implementing a proxy 20 that performs translation between the HTTP protocol and the CoAP 21 protocol, focusing on the reverse proxy case. It describes how a 22 HTTP request is mapped to a CoAP request and how a CoAP response is 23 mapped back to a HTTP response. Furthermore, it defines a template 24 for URI mapping and provides a set of guidelines for HTTP to CoAP 25 protocol translation and related proxy implementations. 27 Status of This Memo 29 This Internet-Draft is submitted in full conformance with the 30 provisions of BCP 78 and BCP 79. 32 Internet-Drafts are working documents of the Internet Engineering 33 Task Force (IETF). Note that other groups may also distribute 34 working documents as Internet-Drafts. The list of current Internet- 35 Drafts is at http://datatracker.ietf.org/drafts/current/. 37 Internet-Drafts are draft documents valid for a maximum of six months 38 and may be updated, replaced, or obsoleted by other documents at any 39 time. It is inappropriate to use Internet-Drafts as reference 40 material or to cite them other than as "work in progress." 42 This Internet-Draft will expire on January 4, 2016. 44 Copyright Notice 46 Copyright (c) 2015 IETF Trust and the persons identified as the 47 document authors. All rights reserved. 49 This document is subject to BCP 78 and the IETF Trust's Legal 50 Provisions Relating to IETF Documents 51 (http://trustee.ietf.org/license-info) in effect on the date of 52 publication of this document. Please review these documents 53 carefully, as they describe your rights and restrictions with respect 54 to this document. Code Components extracted from this document must 55 include Simplified BSD License text as described in Section 4.e of 56 the Trust Legal Provisions and are provided without warranty as 57 described in the Simplified BSD License. 59 Table of Contents 61 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 62 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 4 63 3. HTTP-CoAP Reverse Proxy . . . . . . . . . . . . . . . . . . . 5 64 4. Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . 6 65 5. URI Mapping . . . . . . . . . . . . . . . . . . . . . . . . . 7 66 5.1. URI Terminology . . . . . . . . . . . . . . . . . . . . . 8 67 5.2. Default Mapping . . . . . . . . . . . . . . . . . . . . . 8 68 5.2.1. Optional Scheme Omission . . . . . . . . . . . . . . 8 69 5.2.2. Encoding Caveats . . . . . . . . . . . . . . . . . . 9 70 5.3. URI Mapping Template . . . . . . . . . . . . . . . . . . 9 71 5.3.1. Simple Form . . . . . . . . . . . . . . . . . . . . . 9 72 5.3.2. Enhanced Form . . . . . . . . . . . . . . . . . . . . 11 73 5.4. Discovery . . . . . . . . . . . . . . . . . . . . . . . . 13 74 5.4.1. Discovering CoAP Resources . . . . . . . . . . . . . 13 75 5.4.2. Examples . . . . . . . . . . . . . . . . . . . . . . 14 76 6. Media Type Mapping . . . . . . . . . . . . . . . . . . . . . 15 77 6.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . 15 78 6.2. 'application/coap-payload' Media Type . . . . . . . . . . 17 79 6.3. Loose Media Type Mapping . . . . . . . . . . . . . . . . 17 80 6.4. Media Type to Content Format Mapping Algorithm . . . . . 18 81 6.5. Content Transcoding . . . . . . . . . . . . . . . . . . . 19 82 6.5.1. General . . . . . . . . . . . . . . . . . . . . . . . 19 83 6.5.2. CoRE Link Format . . . . . . . . . . . . . . . . . . 20 84 6.5.3. Diagnostic Messages . . . . . . . . . . . . . . . . . 20 85 7. Response Code Mapping . . . . . . . . . . . . . . . . . . . . 20 86 8. Additional Mapping Guidelines . . . . . . . . . . . . . . . . 23 87 8.1. Caching and Congestion Control . . . . . . . . . . . . . 23 88 8.2. Cache Refresh via Observe . . . . . . . . . . . . . . . . 23 89 8.3. Use of CoAP Blockwise Transfer . . . . . . . . . . . . . 24 90 8.4. Security Translation . . . . . . . . . . . . . . . . . . 25 91 8.5. CoAP Multicast . . . . . . . . . . . . . . . . . . . . . 25 92 8.6. Timeouts . . . . . . . . . . . . . . . . . . . . . . . . 26 93 8.7. Miscellaneous . . . . . . . . . . . . . . . . . . . . . . 26 94 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 26 95 9.1. New 'core.hc' Resource Type . . . . . . . . . . . . . . . 26 96 9.2. New 'coap-payload' Internet Media Type . . . . . . . . . 27 98 10. Security Considerations . . . . . . . . . . . . . . . . . . . 28 99 10.1. Traffic Overflow . . . . . . . . . . . . . . . . . . . . 29 100 10.2. Handling Secured Exchanges . . . . . . . . . . . . . . . 29 101 10.3. Proxy and CoAP Server Resource Exhaustion . . . . . . . 30 102 10.4. URI Mapping . . . . . . . . . . . . . . . . . . . . . . 30 103 11. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 31 104 12. References . . . . . . . . . . . . . . . . . . . . . . . . . 31 105 12.1. Normative References . . . . . . . . . . . . . . . . . . 31 106 12.2. Informative References . . . . . . . . . . . . . . . . . 32 107 Appendix A. Change Log . . . . . . . . . . . . . . . . . . . . . 33 108 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 35 110 1. Introduction 112 CoAP [RFC7252] has been designed with the twofold aim to be an 113 application protocol specialized for constrained environments and to 114 be easily used in REST architectures such as the Web. The latter 115 goal has led to define 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 implementing such a cross-protocol proxy can be complex, and many 122 details regarding its internal procedures and design choices require 123 further elaboration. Therefore, a first goal of this document is to 124 provide more detailed information to proxy designers and 125 implementers, to help build proxies that correctly inter-work with 126 existing CoAP and HTTP implementations. 128 The second goal of this informational document is to define a 129 consistent set of guidelines that a HTTP-to-CoAP proxy implementation 130 MAY adhere to. The main reason for adhering to such guidelines is to 131 reduce variation between proxy implementations, thereby increasing 132 interoperability. (For example, a proxy conforming to these 133 guidelines made by vendor A can be easily replaced by a proxy from 134 vendor B that also conforms to the guidelines.) 136 This document is organized as follows: 138 o Section 2 describes terminology to identify proxy types, mapping 139 approaches and proxy deployments; 141 o Section 3 introduces the reverse HTTP-CoAP proxy; 143 o Section 4 lists use cases in which HTTP clients need to contact 144 CoAP servers; 146 o Section 5 introduces a default HTTP-to-CoAP URI mapping syntax; 148 o Section 6 describes how to map HTTP media types to CoAP content 149 formats and vice versa; 151 o Section 7 describes how to map CoAP responses to HTTP responses; 153 o Section 8 describes additional mapping guidelines related to 154 caching, congestion, timeouts and CoAP blockwise 155 [I-D.ietf-core-block] transfers; 157 o Section 10 discusses possible security impact of HTTP-CoAP 158 protocol mapping. 160 2. Terminology 162 The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 163 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 164 "OPTIONAL" in this document are to be interpreted as described in 165 [RFC2119]. 167 HC Proxy: a proxy performing a cross-protocol mapping, in the context 168 of this document a HTTP-CoAP mapping. A Cross-Protocol Proxy can 169 behave as a Forward Proxy, Reverse Proxy or Interception Proxy. In 170 this document we focus on the Reverse Proxy case. 172 Forward Proxy: a message forwarding agent that is selected by the 173 client, usually via local configuration rules, to receive requests 174 for some type(s) of absolute URI and to attempt to satisfy those 175 requests via translation to the protocol indicated by the absolute 176 URI. The user decides (is willing to) use the proxy as the 177 forwarding/de-referencing agent for a predefined subset of the URI 178 space. In [RFC7230] this is called a Proxy. [RFC7252] defines 179 Forward-Proxy similarly. 181 Reverse Proxy: as in [RFC7230], a receiving agent that acts as a 182 layer above some other server(s) and translates the received requests 183 to the underlying server's protocol. A Reverse HC Proxy behaves as 184 an origin (HTTP) server on its connection towards the (HTTP) client 185 and as a (CoAP) client on its connection towards the (CoAP) origin 186 server. The (HTTP) client uses the "origin-form" (Section 5.3.1 of 187 [RFC7230]) as a request-target URI. 189 Interception Proxy [RFC3040]: a proxy that receives inbound traffic 190 flows through the process of traffic redirection; transparent to the 191 client. 193 Placement terms: a Server-Side proxy is placed in the same network 194 domain as the server; conversely a Client-Side proxy is placed in the 195 same network domain as the client. In any other case, the proxy is 196 said to be External. 198 Note that a Reverse Proxy appears to a client as an origin server 199 while a Forward Proxy does not, so, when communicating with a Reverse 200 Proxy a client may be unaware it is communicating with a proxy at 201 all. 203 3. HTTP-CoAP Reverse Proxy 205 A Reverse HTTP-CoAP Proxy (HC proxy) is accessed by clients only 206 supporting HTTP, and handles their HTTP requests by mapping these to 207 CoAP requests, which are forwarded to CoAP servers; mapping back 208 received CoAP responses to HTTP responses. This mechanism is 209 transparent to the client, which may assume that it is communicating 210 with the intended target HTTP server. In other words, the client 211 accesses the proxy as an origin server using the "origin-form" 212 (Section 5.3.1 of [RFC7230]) as a request target. 214 See Figure 1 for an example deployment scenario. Here an HC Proxy is 215 placed server-side, at the boundary of the Constrained Network 216 domain, to avoid any HTTP traffic on the Constrained Network and to 217 avoid any (unsecured) CoAP multicast traffic outside the Constrained 218 Network. The DNS server is used by the HTTP Client to resolve the IP 219 address of the HC Proxy and optionally also by the HC Proxy to 220 resolve IP addresses of CoAP servers. 222 Constrained Network 223 .-------------------. 224 / .------. \ 225 / | CoAP | \ 226 / |server| \ 227 || '------' || 228 || || 229 .--------. HTTP Request .-----------. CoAP Req .------. || 230 | HTTP |----------------->| HTTP-CoAP |----------->| CoAP | || 231 | Client |<-----------------| Proxy |<-----------|Server| || 232 '--------' HTTP Response '-----------' CoAP Resp '------' || 233 || || 234 || .------. || 235 || | CoAP | || 236 \ |server| .------. / 237 \ '------' | CoAP | / 238 \ |server| / 239 \ '------' / 240 '-----------------' 242 Figure 1: Reverse Cross-Protocol Proxy Deployment Scenario 244 Other placement options for the HC Proxy (not shown) are client-side, 245 which is in the same domain as the HTTP Client; or external, which is 246 both outside the HTTP Client's domain and the CoAP servers' domain. 248 Normative requirements on the translation of HTTP requests to CoAP 249 requests and of the CoAP responses back to HTTP responses are defined 250 in Section 10.2 of [RFC7252]. However, that section only considers 251 the case of a Forward HC Proxy in which a client explicitly indicates 252 it targets a request to a CoAP server, and does not cover all aspects 253 of proxy implementation in detail. This document provides guidelines 254 and more details for the implementation of a Reverse HC Proxy, which 255 MAY be followed in addition to the normative requirements. Note that 256 most of the guidelines also apply to an Intercepting HC Proxy. 258 4. Use Cases 260 To illustrate in which situations HTTP to CoAP protocol translation 261 may be used, three use cases are described below. 263 1. Smartphone and home sensor: A smartphone can access directly a 264 CoAP home sensor using an authenticated 'https' request, if its home 265 router contains an HC proxy. An HTML5 application on the smartphone 266 can provide a friendly UI to the user using standard (HTTP) 267 networking functions of HTML5. 269 2. Legacy building control application without CoAP: A building 270 control application that uses HTTP but not CoAP, can check the status 271 of CoAP sensors and/or actuators via an HC proxy. 273 3. Making sensor data available to 3rd parties: For demonstration or 274 public interest purposes, a HC proxy may be configured to expose the 275 contents of a CoAP sensor to the world via the web (HTTP and/or 276 HTTPS). Some sensors might only handle secure 'coaps' requests, 277 therefore the proxy is configured to translate any request to a 278 'coaps' secured request. The HC proxy is furthermore configured to 279 only pass through GET requests in order to protect the constrained 280 network. In this way even unattended HTTP clients, such as web 281 crawlers, may index sensor data as regular web pages. 283 5. URI Mapping 285 Though, in principle, a CoAP URI could be directly used by a HTTP 286 user agent to de-reference a CoAP resource through an HC proxy, the 287 reality is that all major web browsers, networking libraries and 288 command line tools do not allow making HTTP requests using URIs with 289 a scheme "coap" or "coaps". 291 Thus, there is a need for web applications to "pack" a CoAP URI into 292 a HTTP URI so that it can be (non-destructively) transported from the 293 user agent to the HC proxy. The HC proxy can then "unpack" the CoAP 294 URI and finally de-reference it via a CoAP request to the target 295 Server. 297 URI Mapping is the process through which the URI of a CoAP resource 298 is transformed into an HTTP URI so that: 300 o the requesting HTTP user agent 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; 309 o the URI template format to express a class of CoAP-HTTP URI 310 mapping functions; 312 o the discovery mechanism based on CoRE Link Format [RFC6690] 313 through which clients of an HC proxy can dynamically discover 314 information about the supported URI Mapping Template(s), as well 315 as the base URI where the HC proxy function is anchored. 317 5.1. URI Terminology 319 In the remainder of this section, the following terms will be used 320 with a distinctive meaning: 322 Target CoAP URI: 323 URI which refers to the (final) CoAP resource that has to be 324 de-referenced. It conforms to syntax defined in Section 6 of 325 [RFC7252]. Specifically, its scheme is either "coap" or 326 "coaps". 328 Hosting HTTP URI: 329 URI that conforms to syntax in Section 2.7 of [RFC7230]. Its 330 authority component refers to an HC proxy, whereas path (and 331 query) component(s) embed the information used by an HC proxy 332 to extract the Target CoAP URI. 334 5.2. Default Mapping 336 The default mapping is for the Target CoAP URI to be appended as-is 337 to a base URI provided by the HC proxy, to form the Hosting HTTP URI. 339 For example: given a base URI http://p.example.com/hc and a Target 340 CoAP URI coap://s.example.com/light, the resulting Hosting HTTP URI 341 would be http://p.example.com/hc/coap://s.example.com/light. 343 Provided a correct Target CoAP URI, the Hosting HTTP URI resulting 344 from the default mapping is always syntactically correct. 345 Furthermore, the Target CoAP URI can always be extracted 346 unambiguously from the Hosting HTTP URI. Also, it is worth noting 347 that, using the default mapping, a query component in the target CoAP 348 resource URI is naturally encoded into the query component of the 349 Hosting URI, e.g.: coap://s.example.com/light?dim=5 becomes 350 http://p.example.com/hc/coap://s.example.com/light?dim=5. 352 There is no default for the base URI. Therefore, it is either known 353 in advance, e.g. as a configuration preset, or dynamically discovered 354 using the mechanism described in Section 5.4. 356 The default URI mapping function is RECOMMENDED to be implemented and 357 activated by default in an HC proxy, unless there are valid reasons, 358 e.g. application specific, to use a different mapping function. 360 5.2.1. Optional Scheme Omission 362 When found in a Hosting HTTP URI, the scheme (i.e., "coap" or 363 "coaps"), the scheme component delimiter (":"), and the double slash 364 ("//") preceding the authority MAY be omitted. In such case, a local 365 default - not defined by this document - applies. 367 So, http://p.example.com/hc/s.coap.example.com/foo could either 368 represent the target coap://s.coap.example.com/foo or 369 coaps://s.coap.example.com/foo depending on application specific 370 presets. 372 5.2.2. Encoding Caveats 374 When the authority of the Target CoAP URI is given as an IPv6address, 375 then the surrounding square brackets MUST be percent-encoded in the 376 Hosting HTTP URI, in order to comply with the syntax defined in 377 Section 3.3. of [RFC3986] for a URI path segment. E.g.: 378 coap://[2001:db8::1]/light?on becomes 379 http://p.example.com/hc/coap://%5B2001:db8::1%5D/light?on. 381 Everything else can be safely copied verbatim from the Target CoAP 382 URI to the Hosting HTTP URI. 384 5.3. URI Mapping Template 386 This section defines a format for the URI template [RFC6570] used by 387 an HC proxy to inform its clients about the expected syntax for the 388 Hosting HTTP URI. 390 When instantiated, an URI Mapping Template is always concatenated to 391 a base URI provided by the HC proxy via discovery (see Section 5.4), 392 or by other means. 394 A simple form (Section 5.3.1) and an enhanced form (Section 5.3.2) 395 are provided to fit different users' requirements. 397 Both forms are expressed as level 2 URI templates [RFC6570] to take 398 care of the expansion of values that are allowed to include reserved 399 URI characters. The syntax of all URI formats is specified in this 400 section in Augmented Backus-Naur Form (ABNF) [RFC5234]. 402 5.3.1. Simple Form 404 The simple form MUST be used for mappings where the Target CoAP URI 405 is going to be copied (using rules of Section 5.2.2) at some fixed 406 position into the Hosting HTTP URI. 408 The following template variables MUST be used in mutual exclusion in 409 a template definition: 411 cu = coap-URI ; from [RFC7252], Section 6.1 412 su = coaps-URI ; from [RFC7252], Section 6.2 413 tu = cu / su 415 The same considerations as in Section 5.2.1 apply, in that the CoAP 416 scheme may be omitted from the Hosting HTTP URI. 418 5.3.1.1. Examples 420 All the following examples (given as a specific URI mapping template, 421 a Target CoAP URI, and the produced Hosting HTTP URI) use 422 http://p.example.com/hc as the base URI. Note that these examples 423 all define mapping templates that deviate from the default template 424 of Section 5.2 to be able to illustrate the use of the above template 425 variables. 427 1. "coap" URI is a query argument of the Hosting HTTP URI: 429 ?coap_target_uri={+cu} 431 coap://s.example.com/light 433 http://p.example.com/hc?coap_target_uri=coap://s.example.com/light 435 2. "coaps" URI is a query argument of the Hosting HTTP URI: 437 ?coaps_target_uri={+su} 439 coaps://s.example.com/light 441 http://p.example.com/hc?coaps_target_uri=coaps://s.example.com/light 443 3. Target CoAP URI as a query argument of the Hosting HTTP URI: 445 ?target_uri={+tu} 447 coap://s.example.com/light 449 http://p.example.com/hc?target_uri=coap://s.example.com/light 451 or 453 coaps://s.example.com/light 455 http://p.example.com/hc?target_uri=coaps://s.example.com/light 457 4. Target CoAP URI in the path component of the Hosting HTTP URI 458 (i.e., the default URI Mapping template): 460 /{+tu} 462 coap://s.example.com/light 464 http://p.example.com/hc/coap://s.example.com/light 466 or 468 coaps://s.example.com/light 470 http://p.example.com/hc/coaps://s.example.com/light 472 5. "coap" URI is a query argument of the Hosting HTTP URI; client 473 decides to omit scheme because a default scheme is agreed 474 beforehand between client and proxy: 476 ?coap_uri={+cu} 478 coap://s.example.com/light 480 http://p.example.com/hc?coap_uri=s.example.com/light 482 5.3.2. Enhanced Form 484 The enhanced form can be used to express more sophisticated mappings, 485 i.e., those that do not fit into the simple form. 487 There MUST be at most one instance of each of the following template 488 variables in a template definition: 490 s = "coap" / "coaps" ; from [RFC7252], Sections 6.1 and 6.2 491 hp = host [":" port] ; from [RFC3986] Sections 3.2.2 and 3.2.3 492 p = path-abempty ; from [RFC3986] Section 3.3 493 q = query ; from [RFC3986] Section 3.4 494 qq = [ "?" query ] ; qq is empty iff 'query' is empty 496 5.3.2.1. Examples 498 All the following examples (given as a specific URI mapping template, 499 a Target CoAP URI, and the produced Hosting HTTP URI) use 500 http://p.example.com/hc as the base URI. 502 1. Target CoAP URI components in path segments, and optional query 503 in query component: 505 {+s}{+hp}{+p}{+qq} 507 coap://s.example.com/light 509 http://p.example.com/hc/coap/s.example.com/light 511 or 513 coap://s.example.com/light?on 515 http://p.example.com/hc/coap/s.example.com/light?on 517 2. Target CoAP URI components split in individual query arguments: 519 ?s={+s}&hp={+hp}&p={+p}&q={+q} 521 coap://s.example.com/light 523 http://p.example.com/hc?s=coap&hp=s.example.com&p=/light&q= 525 or 527 coaps://s.example.com/light?on 529 http://p.example.com/hc?s=coaps&hp=s.example.com&p=/light&q=on 531 5.4. Discovery 533 In order to accommodate site specific needs while allowing third 534 parties to discover the proxy function, the HC proxy SHOULD publish 535 information related to the location and syntax of the HC proxy 536 function using the CoRE Link Format [RFC6690] interface. 538 To this aim a new Resource Type, "core.hc", is defined in this 539 document. It is associated with a base URI, and can be used as the 540 value for the "rt" attribute in a query to the /.well-known/core in 541 order to locate the base URI where the HC proxy function is anchored. 543 Along with it, the new target attribute "hct" is defined in this 544 document. This attribute MAY be returned in a "core.hc" link to 545 provide the URI Mapping Template associated to the mapping resource. 546 The default template given in Section 5.2, i.e., {+tu}, MUST be 547 assumed if no "hct" attribute is found in the returned link. If a 548 "hct" attribute is present in the returned link, then a compliant 549 client MUST use it to create the Hosting HTTP URI. 551 Discovery as specified in [RFC6690] SHOULD be available on both the 552 HTTP and the CoAP side of the HC proxy, with one important 553 difference: on the CoAP side the link associated to the "core.hc" 554 resource needs an explicit anchor referring to the HTTP origin, while 555 on the HTTP interface the link context is already the HTTP origin 556 carried in the request's Host header, and doesn't have to be made 557 explicit. 559 5.4.1. Discovering CoAP Resources 561 For a HTTP client, it may be unknown which CoAP resources are 562 available through a HC Proxy. By default an HC Proxy does not 563 support a method to discover all CoAP resources. However, if an HC 564 Proxy is integrated with a Resource Directory 565 ([I-D.ietf-core-resource-directory]) function, an HTTP client can 566 discover all CoAP resources of its interest by doing an RD Lookup to 567 the HC Proxy, via HTTP. This is possible because a single RD can 568 support both CoAP and HTTP interfaces simultaneously. Of course the 569 HTTP client will this way only discover resources that have been 570 previously registered onto this RD by CoAP devices. 572 5.4.2. Examples 574 o The first example exercises the CoAP interface, and assumes that 575 the default template, {+tu}, is used: 577 Req: GET coap://[ff02::1]/.well-known/core?rt=core.hc 579 Res: 2.05 Content 580 ;anchor="http://p.example.com";rt="core.hc" 582 o The second example - also on the CoAP side of the HC proxy - uses 583 a custom template, i.e., one where the CoAP URI is carried inside 584 the query component, thus the returned link carries the URI 585 template to be used in an explicit "hct" attribute: 587 Req: GET coap://[ff02::1]/.well-known/core?rt=core.hc 589 Res: 2.05 Content 590 ;anchor="http://p.example.com"; 591 rt="core.hc";hct="?uri={+tu}" 593 On the HTTP side, link information can be serialized in more than one 594 way: 596 o using the 'application/link-format' content type: 598 Req: GET /.well-known/core?rt=core.hc HTTP/1.1 599 Host: p.example.com 601 Res: HTTP/1.1 200 OK 602 Content-Type: application/link-format 603 Content-Length: 18 605 ;rt="core.hc" 607 o using the 'application/link-format+json' content type as defined 608 in [I-D.bormann-core-links-json]: 610 Req: GET /.well-known/core?rt=core.hc HTTP/1.1 611 Host: p.example.com 613 Res: HTTP/1.1 200 OK 614 Content-Type: application/link-format+json 615 Content-Length: 31 617 [{"href":"/hc","rt":"core.hc"}] 619 o using the Link header: 621 Req: GET /.well-known/core?rt=core.hc HTTP/1.1 622 Host: p.example.com 624 Res: HTTP/1.1 200 OK 625 Link: ;rt="core.hc" 627 o An HC proxy may expose two different base URIs to differentiate 628 between Target CoAP resources in the "coap" and "coaps" scheme: 630 Req: GET /.well-known/core?rt=core.hc 631 Host: p.example.com 633 Res: HTTP/1.1 200 OK 634 Content-Type: application/link-format+json 635 Content-Length: 111 637 [ 638 {"href":"/hc/plaintext","rt":"core.hc","hct":"{+cu}"}, 639 {"href":"/hc/secure","rt":"core.hc","hct":"{+su}"} 640 ] 642 6. Media Type Mapping 644 6.1. Overview 646 An HC proxy needs to translate HTTP media types (Section 3.1.1.1 of 647 [RFC7231]) and content encodings (Section 3.1.2.2 of [RFC7231]) into 648 CoAP content formats (Section 12.3 of [RFC7252]) and vice versa. 650 Media type translation can happen in GET, PUT or POST requests going 651 from HTTP to CoAP, and in 2.xx (i.e., successful) responses going 652 from CoAP to HTTP. Specifically, PUT and POST need to map both the 653 Content-Type and Content-Encoding HTTP headers into a single CoAP 654 Content-Format option, whereas GET needs to map Accept and Accept- 655 Encoding HTTP headers into a single CoAP Accept option. To generate 656 the HTTP response, the CoAP Content-Format option is mapped back to a 657 suitable HTTP Content-Type and Content-Encoding combination. 659 An HTTP request carrying a Content-Type and Content-Encoding 660 combination which the HC proxy is unable to map to an equivalent CoAP 661 Content-Format, SHALL elicit a 415 (Unsupported Media Type) response 662 by the HC proxy. 664 On the content negotiation side, failure to map Accept and Accept-* 665 headers SHOULD be silently ignored: the HC proxy SHOULD therefore 666 forward as a CoAP request with no Accept option. The HC proxy thus 667 disregards the Accept/Accept-* header fields by treating the response 668 as if it is not subject to content negotiation, as mentioned in 669 Sections 5.3.* of [RFC7231]. However, an HC proxy implementation is 670 free to attempt mapping a single Accept header in a GET request to 671 multiple CoAP GET requests, each with a single Accept option, which 672 are then tried in sequence until one succeeds. Note that an HTTP 673 Accept */* MUST be mapped to a CoAP request without Accept option. 675 While the CoAP to HTTP direction has always a well defined mapping 676 (with the exception examined in Section 6.2), the HTTP to CoAP 677 direction is more problematic because the source set, i.e., 678 potentially 1000+ IANA registered media types, is much bigger than 679 the destination set, i.e., the mere 6 values initially defined in 680 Section 12.3 of [RFC7252]. 682 Depending on the tight/loose coupling with the application(s) for 683 which it proxies, the HC proxy could implement different media type 684 mappings. 686 When tightly coupled, the HC proxy knows exactly which content 687 formats are supported by the applications, and can be strict when 688 enforcing its forwarding policies in general, and the media type 689 mapping in particular. 691 On the other side, when the HC proxy is a general purpose application 692 layer gateway, being too strict could significantly reduce the amount 693 of traffic that it'd be able to successfully forward. In this case, 694 the "loose" media type mapping detailed in Section 6.3 MAY be 695 implemented. 697 The latter grants more evolution of the surrounding ecosystem, at the 698 cost of allowing more attack surface. In fact, as a result of such 699 strategy, payloads would be forwarded more liberally across the 700 unconstrained/constrained network boundary of the communication path. 701 Therefore, when applied, other forms of access control must be set in 702 place to avoid unauthorized users to deplete or abuse systems and 703 network resources. 705 6.2. 'application/coap-payload' Media Type 707 If the HC proxy receives a CoAP response with a Content-Format that 708 it does not recognize (e.g. because the value has been registered 709 after the proxy has been deployed, or the CoAP server uses an 710 experimental value which is not registered), then the HC proxy SHALL 711 return a generic "application/coap-payload" media type with numeric 712 parameter "cf" as defined in Section 9.2. 714 For example, the CoAP content format '60' ("application/cbor") would 715 be represented by "application/coap-payload;cf=60", would '60' be an 716 unknown content format to the HC Proxy. 718 A HTTP client MAY use the media type "application/coap-payload" as a 719 means to send a specific content format to a CoAP server via an HC 720 Proxy if the client has determined that the HC Proxy does not 721 directly support the type mapping it needs. This case may happen 722 when dealing for example with newly registered, yet to be registered, 723 or experimental CoAP content formats. 725 6.3. Loose Media Type Mapping 727 By structuring the type information in a super-class (e.g. "text") 728 followed by a finer grained sub-class (e.g. "html"), and optional 729 parameters (e.g. "charset=utf-8"), Internet media types provide a 730 rich and scalable framework for encoding the type of any given 731 entity. 733 This approach is not applicable to CoAP, where Content Formats 734 conflate an Internet media type (potentially with specific 735 parameters) and a content encoding into one small integer value. 737 To remedy this loss of flexibility, we introduce the concept of a 738 "loose" media type mapping, where media types that are 739 specializations of a more generic media type can be aliased to their 740 super-class and then mapped (if possible) to one of the CoAP content 741 formats. For example, "application/soap+xml" can be aliased to 742 "application/xml", which has a known conversion to CoAP. In the 743 context of this "loose" media type mapping, "application/octet- 744 stream" can be used as a fallback when no better alias is found for a 745 specific media type. 747 Table 1 defines the default lookup table for the "loose" media type 748 mapping. Given an input media type, the table returns its best 749 generalized media type using the most specific match i.e. the table 750 entries are compared to the input in top to bottom order until an 751 entry matches. 753 +---------------------+--------------------------+ 754 | Internet media type | Generalized media type | 755 +---------------------+--------------------------+ 756 | application/*+xml | application/xml | 757 | application/*+json | application/json | 758 | text/xml | application/xml | 759 | text/* | text/plain | 760 | */* | application/octet-stream | 761 +---------------------+--------------------------+ 763 Table 1: Media type generalization lookup table 765 The "loose" media type mapping is an OPTIONAL feature. 766 Implementations supporting this kind of mapping SHOULD provide a 767 flexible way to define the set of media type generalizations allowed. 769 6.4. Media Type to Content Format Mapping Algorithm 771 This section defines the algorithm used to map an HTTP Internet media 772 type to its correspondent CoAP content format. 774 The algorithm uses the mapping table defined in Section 12.3 of 775 [RFC7252] plus, possibly, any locally defined extension of it. 776 Optionally, the table and lookup mechanism described in Section 6.3 777 can be used if the implementation chooses so. 779 Note that the algorithm may have side effects on the associated 780 representation (see also Section 6.5). 782 In the following: 784 o C-T, C-E, and C-F stand for the values of the Content-Type (or 785 Accept) HTTP header, Content-Encoding (or Accept-Encoding) HTTP 786 header, and Content-Format CoAP option respectively. 788 o If C-E is not given it is assumed to be "identity". 790 o MAP is the mandatory lookup table, GMAP is the optional 791 generalized table. 793 INPUT: C-T and C-E 794 OUTPUT: C-F or Fail 796 1. if no C-T: return Fail 797 2. C-F = MAP[C-T, C-E] 798 3. if C-F is not None: return C-F 799 4. if C-E is not "identity": 800 5. if C-E is supported (e.g. gzip): 801 6. decode the representation accordingly 802 7. set C-E to "identity" 803 8. else: 804 9. return Fail 805 10. repeat steps 2. and 3. 806 11. if C-T allows a non-lossy transformation into \ 807 12. one of the supported C-F: 808 13. transcode the representation accordingly 809 14. return C-F 810 15. if GMAP is defined: 811 16. C-F = GMAP[C-T] 812 17. if C-F is not None: return C-F 813 18. return Fail 815 Figure 2 817 6.5. Content Transcoding 819 6.5.1. General 821 Payload content transcoding (e.g. see steps 11-14 of Figure 2) is an 822 OPTIONAL feature. Implementations supporting this feature should 823 provide a flexible way to define the set of transcodings allowed. 825 As noted in Section 6.4, the process of mapping the media type can 826 have side effects on the forwarded entity body. This may be caused 827 by the removal or addition of a specific content encoding, or because 828 the HC proxy decides to transcode the representation to a different 829 (compatible) format. The latter proves useful when an optimized 830 version of a specific format exists. For example an XML-encoded 831 resource could be transcoded to Efficient XML Interchange (EXI) 832 format, or a JSON-encoded resource into CBOR [RFC7049], effectively 833 achieving compression without losing any information. 835 However, it should be noted that in certain cases, transcoding can 836 lose information in a non-obvious manner. For example, encoding an 837 XML document using schema-informed EXI encoding leads to a loss of 838 information when the destination does not know the exact schema 839 version used by the encoder, which means that whenever the HC proxy 840 transcodes an application/XML to application/EXI in-band metadata 841 could be lost. Therefore, the implementer should always carefully 842 verify such lossy payload transformations before triggering the 843 transcoding. 845 6.5.2. CoRE Link Format 847 The CoRE Link Format [RFC6690] is a set of links (i.e., URIs and 848 their formal relationships) which is carried as content payload in a 849 CoAP response. These links usually include CoAP URIs that might be 850 translated by the HC proxy to the correspondent HTTP URIs using the 851 implemented URI mapping function (see Section 5). Such a process 852 would inspect the forwarded traffic and attempt to re-write the body 853 of resources with an application/link-format media type, mapping the 854 embedded CoAP URIs to their HTTP counterparts. Some potential issues 855 with this approach are: 857 1. The client may be interested to retrieve original (unaltered) 858 CoAP payloads through the HC proxy, not modified versions. 860 2. Tampering with payloads is incompatible with resources that are 861 integrity protected (although this is a problem with transcoding 862 in general). 864 3. The HC proxy needs to fully understand [RFC6690] syntax and 865 semantics, otherwise there is an inherent risk to corrupt the 866 payloads. 868 Therefore, CoRE Link Format payload should only be transcoded at the 869 risk and discretion of the proxy implementer. 871 6.5.3. Diagnostic Messages 873 CoAP responses may, in certain error cases, contain a diagnostic 874 message in the payload explaining the error situation, as described 875 in Section 5.5.2 of [RFC7252]. In this scenario, the CoAP response 876 diagnostic payload MUST NOT be returned as the regular HTTP payload 877 (message body). Instead, the CoAP diagnostic payload must be used as 878 the HTTP reason-phrase of the HTTP status line, as defined in 879 Section 3.1.2 of [RFC7230], without any alterations, except those 880 needed to comply to the reason-phrase ABNF definition. 882 7. Response Code Mapping 884 Table 2 defines the HTTP response status codes to which each CoAP 885 response code SHOULD be mapped. This table complies with the 886 requirements in Section 10.2 of [RFC7252] and is intended to cover 887 all possible cases. Multiple appearances of a HTTP status code in 888 the second column indicates multiple equivalent HTTP responses are 889 possible based on the same CoAP response code, depending on the 890 conditions cited in the Notes (third column and text below table). 892 +-----------------------------+-----------------------------+-------+ 893 | CoAP Response Code | HTTP Status Code | Notes | 894 +-----------------------------+-----------------------------+-------+ 895 | 2.01 Created | 201 Created | 1 | 896 | 2.02 Deleted | 200 OK | 2 | 897 | | 204 No Content | 2 | 898 | 2.03 Valid | 304 Not Modified | 3 | 899 | | 200 OK | 4 | 900 | 2.04 Changed | 200 OK | 2 | 901 | | 204 No Content | 2 | 902 | 2.05 Content | 200 OK | | 903 | 4.00 Bad Request | 400 Bad Request | | 904 | 4.01 Unauthorized | 401 Unauthorized | 5 | 905 | 4.02 Bad Option | 400 Bad Request | 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. This payload SHOULD be returned as entity in the 927 HTTP 201 response. Section 7.3.2 of [RFC7231] does not put any 928 requirement on the format of the entity. (In the past, [RFC2616] 929 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 SHOULD 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 caching resources and translated a HTTP 946 request (without conditional request) to a CoAP request that 947 includes ETag validation. The proxy receiving 2.03 updates the 948 freshness of its cached representation and returns the entire 949 representation to the HTTP client. 951 5. A HTTP 401 Unauthorized (Section 3.1 of [RFC7235]) response MUST 952 include a WWW-Authenticate header. Since there is no CoAP 953 equivalent of WWW-Authenticate, the HC proxy must generate this 954 header itself including at least one challenge (Section 4.1 of 955 [RFC7235]). If the HC proxy does not implement a proper 956 authentication method that can be used to gain access to the 957 target CoAP resource, it can include a 'dummy' challenge for 958 example "WWW-Authenticate: None". 960 6. A proxy receiving 4.02 may first retry the request with less CoAP 961 Options in the hope that the CoAP server will understand the 962 newly formulated request. For example, if the proxy tried using 963 a Block Option [I-D.ietf-core-block] which was not recognized by 964 the CoAP server it may retry without that Block Option. Note 965 that HTTP 402 MUST NOT be returned because it is reserved for 966 future use [RFC7231]. 968 7. A CoAP 4.05 (Method Not Allowed) response SHOULD normally be 969 mapped to a HTTP 400 (Method Not Allowed) code, because the HTTP 970 405 response would require specifying the supported methods - 971 which are generally unknown. In this case the HC Proxy SHOULD 972 also return a HTTP reason-phrase in the HTTP status line that 973 starts with the string "405" in order to facilitate 974 troubleshooting. However, if the HC proxy has more granular 975 information about the supported methods for the requested 976 resource (e.g. via a Resource Directory 977 ([I-D.ietf-core-resource-directory])) then it MAY send back a 978 HTTP 405 (Method Not Allowed) with a properly filled in "Allow" 979 response-header field (Section 7.4.1 of [RFC7231]). 981 8. The value of the HTTP "Retry-After" response-header field is 982 taken from the value of the CoAP Max-Age Option, if present. 984 9. This CoAP response can only happen if the proxy itself is 985 configured to use a CoAP forward-proxy (Section 5.7 of [RFC7252]) 986 to execute some, or all, of its CoAP requests. 988 8. Additional Mapping Guidelines 990 8.1. Caching and Congestion Control 992 An HC proxy SHOULD limit the number of requests to CoAP servers by 993 responding, where applicable, with a cached representation of the 994 resource. 996 Duplicate idempotent pending requests by an HC proxy to the same CoAP 997 resource SHOULD in general be avoided, by using the same response for 998 multiple requesting HTTP clients without duplicating the CoAP 999 request. 1001 If the HTTP client times out and drops the HTTP session to the HC 1002 proxy (closing the TCP connection) after the HTTP request was made, 1003 an HC proxy SHOULD wait for the associated CoAP response and cache it 1004 if possible. Subsequent requests to the HC proxy for the same 1005 resource can use the result present in cache, or, if a response has 1006 still to come, the HTTP requests will wait on the open CoAP request. 1008 According to [RFC7252], a proxy MUST limit the number of outstanding 1009 interactions to a given CoAP server to NSTART. To limit the amount 1010 of aggregate traffic to a constrained network, the HC proxy SHOULD 1011 also pose a limit to the number of concurrent CoAP requests pending 1012 on the same constrained network; further incoming requests MAY either 1013 be queued or dropped (returning 503 Service Unavailable). This limit 1014 and the proxy queueing/dropping behavior SHOULD be configurable. In 1015 order to effectively apply above congestion control, the HC proxy 1016 should be server-side placed. 1018 Resources experiencing a high access rate coupled with high 1019 volatility MAY be observed [I-D.ietf-core-observe] by the HC proxy to 1020 keep their cached representation fresh while minimizing the number of 1021 CoAP traffic in the constrained network. See Section 8.2. 1023 8.2. Cache Refresh via Observe 1025 There are cases where using the CoAP observe protocol 1026 [I-D.ietf-core-observe] to handle proxy cache refresh is preferable 1027 to the validation mechanism based on ETag as defined in [RFC7252]. 1028 Such scenarios include, but are not limited to, sleepy CoAP nodes -- 1029 with possibly high variance in requests' distribution -- which would 1030 greatly benefit from a server driven cache update mechanism. Ideal 1031 candidates for CoAP observe are also crowded or very low throughput 1032 networks, where reduction of the total number of exchanged messages 1033 is an important requirement. 1035 This subsection aims at providing a practical evaluation method to 1036 decide whether refreshing a cached resource R is more efficiently 1037 handled via ETag validation or by establishing an observation on R. 1039 Let T_R be the mean time between two client requests to resource R, 1040 let T_C be the mean time between two representation changes of R, and 1041 let M_R be the mean number of CoAP messages per second exchanged to 1042 and from resource R. If we assume that the initial cost for 1043 establishing the observation is negligible, an observation on R 1044 reduces M_R iff T_R < 2*T_C with respect to using ETag validation, 1045 that is iff the mean arrival rate of requests for resource R is 1046 greater than half the change rate of R. 1048 When observing the resource R, M_R is always upper bounded by 2/T_C. 1050 8.3. Use of CoAP Blockwise Transfer 1052 An HC proxy SHOULD support CoAP blockwise transfers 1053 [I-D.ietf-core-block] to allow transport of large CoAP payloads while 1054 avoiding excessive link-layer fragmentation in constrained networks, 1055 and to cope with small datagram buffers in CoAP end-points as 1056 described in [RFC7252] Section 4.6. 1058 An HC proxy SHOULD attempt to retry a payload-carrying CoAP PUT or 1059 POST request with blockwise transfer if the destination CoAP server 1060 responded with 4.13 (Request Entity Too Large) to the original 1061 request. An HC proxy SHOULD attempt to use blockwise transfer when 1062 sending a CoAP PUT or POST request message that is larger than 1063 BLOCKWISE_THRESHOLD bytes. The value of BLOCKWISE_THRESHOLD is 1064 implementation-specific, for example it can be: 1066 o calculated based on a known or typical UDP datagram buffer size 1067 for CoAP end-points, or 1069 o set to N times the known size of a link-layer frame in a 1070 constrained network where e.g. N=5, or 1072 o preset to a known IP MTU value, or 1074 o set to a known Path MTU value. 1076 The value BLOCKWISE_THRESHOLD, or the parameters from which it is 1077 calculated, should be configurable in a proxy implementation. The 1078 maximum block size the proxy will attempt to use in CoAP requests 1079 should also be configurable. 1081 The HC proxy SHOULD detect CoAP end-points not supporting blockwise 1082 transfers by checking for a 4.02 (Bad Option) response returned by an 1083 end-point in response to a CoAP request with a Block* Option, and 1084 subsequent absence of the 4.02 in response to the same request 1085 without Block* Options. This allows the HC proxy to be more 1086 efficient, not attempting repeated blockwise transfers to CoAP 1087 servers that do not support it. However, if a request payload is too 1088 large to be sent as a single CoAP request and blockwise transfer 1089 would be unavoidable, the proxy still SHOULD attempt blockwise 1090 transfer on such an end-point before returning the response 413 1091 (Request Entity Too Large) to the HTTP client. 1093 For improved latency an HC proxy MAY initiate a blockwise CoAP 1094 request triggered by an incoming HTTP request even when the HTTP 1095 request message has not yet been fully received, but enough data has 1096 been received to send one or more data blocks to a CoAP server 1097 already. This is particularly useful on slow client-to-proxy 1098 connections. 1100 8.4. Security Translation 1102 For the guidelines on security context translations for an HC proxy, 1103 see Section 10.2. A translation may involve e.g. applying a rule 1104 that any "https" request is translated to a "coaps" request, or e.g. 1105 applying a rule that a "https" request is translated to an unsecured 1106 "coap" request. 1108 8.5. CoAP Multicast 1110 An HC proxy MAY support CoAP multicast. If it does, the HC proxy 1111 sends out a multicast CoAP request if the Target CoAP URI's authority 1112 is a multicast IP literal or resolves to a multicast IP address; 1113 assuming the proper security measures are in place to mitigate 1114 security risks of CoAP multicast (Section 10). If the security 1115 policies do not allow the specific CoAP multicast request to be made, 1116 the HC proxy SHOULD respond 403 (Forbidden). 1118 If an HC proxy does not support CoAP multicast, it SHOULD respond 403 1119 (Forbidden) to any valid HTTP request that maps to a CoAP multicast 1120 request. 1122 Details related to supporting CoAP multicast are currently out of 1123 scope of this document since in a reverse proxy scenario a HTTP 1124 client typically expects to receive a single response, not multiple. 1125 However, an HC proxy that implements CoAP multicast MAY include 1126 application-specific functions to aggregate multiple CoAP responses 1127 into a single HTTP response. We suggest using the "application/http" 1128 internet media type (Section 8.3.2 of [RFC7230]) to enclose a set of 1129 one or more HTTP response messages, each representing the mapping of 1130 one CoAP response. 1132 8.6. Timeouts 1134 When facing long delays of a CoAP server in responding, the HTTP 1135 client or any other proxy in between MAY timeout. Further discussion 1136 of timeouts in HTTP is available in Section 6.2.4 of [RFC7230]. 1138 An HC proxy MUST define an internal timeout for each pending CoAP 1139 request, because the CoAP server may silently die before completing 1140 the request. Assuming the Proxy may use confirmable CoAP requests, 1141 such timeout value T SHOULD be at least 1143 T = MAX_RTT + MAX_SERVER_RESPONSE_DELAY 1145 where MAX_RTT is defined in [RFC7252] and MAX_SERVER_RESPONSE_DELAY 1146 is defined in [RFC7390]. An exception to this rule occurs when the 1147 HC proxy is configured with a HTTP response timeout value that is 1148 lower than above value T; then the lower value should be also used as 1149 the CoAP request timeout. 1151 8.7. Miscellaneous 1153 In certain use cases, constrained CoAP nodes do not make use of the 1154 DNS protocol. However even when the DNS protocol is not used in a 1155 constrained network, defining valid FQDN (i.e., DNS entries) for 1156 constrained CoAP servers, where possible, may help HTTP clients to 1157 access the resources offered by these servers via an HC proxy. 1159 HTTP connection pipelining (section 6.3.2 of [RFC7230]) may be 1160 supported by an HC proxy. This is transparent to the CoAP servers: 1161 the HC proxy will serve the pipelined requests by issuing different 1162 CoAP requests. The HC proxy in this case needs to respect the NSTART 1163 limit of Section 4.7 of [RFC7252]. 1165 9. IANA Considerations 1167 9.1. New 'core.hc' Resource Type 1169 This document registers a new Resource Type (rt=) Link Target 1170 Attribute, 'core.hc', in the "Resource Type (rt=) Link Target 1171 Attribute Values" subregistry under the "Constrained RESTful 1172 Environments (CoRE) Parameters" registry. 1174 Attribute Value: core.hc 1176 Description: HTTP to CoAP mapping base resource. 1178 Reference: See Section 5.4. 1180 9.2. New 'coap-payload' Internet Media Type 1182 This document defines the "application/coap-payload" media type with 1183 a single parameter "cf". This media type represents any payload that 1184 a CoAP message can carry, having a content format that can be 1185 identified by a CoAP Content-Format parameter (an integer in range 1186 0-65535). The parameter "f" is the integer defining the CoAP content 1187 format. 1189 Type name: application 1191 Subtype name: coap-payload 1193 Required parameters: 1195 cf - CoAP Content-Format integer in range 0-65535 denoting the 1196 content format of the CoAP payload carried. 1198 Optional parameters: None 1200 Encoding considerations: 1202 The specific CoAP content format encoding considerations for the 1203 selected Content-Format (cf parameter) apply. 1205 Security considerations: 1207 The specific CoAP content format security considerations for the 1208 selected Content-Format (cf parameter) apply. 1210 Interoperability considerations: 1212 Published specification: (this I-D - TBD) 1214 Applications that use this media type: 1216 HTTP-to-CoAP Proxies. 1218 Fragment identifier considerations: N/A 1220 Additional information: 1222 Deprecated alias names for this type: N/A 1224 Magic number(s): N/A 1225 File extension(s): N/A 1227 Macintosh file type code(s): N/A 1229 Person and email address to contact for further information: 1231 Esko Dijk ("esko@ieee.org") 1233 Intended usage: COMMON 1235 Restrictions on usage: 1237 An application (or user) can only use this media type if it has to 1238 represent a CoAP payload of which the specified CoAP Content-Format 1239 is an unrecognized number; such that a proper translation directly to 1240 the equivalent HTTP media type is not possible. 1242 Author: CoRE WG 1244 Change controller: IETF 1246 Provisional registration? (standards tree only): N/A 1248 10. Security Considerations 1250 The security concerns raised in Section 9.2 of [RFC7230] also apply 1251 to the HC proxy scenario. In fact, the HC proxy is a trusted (not 1252 rarely a transparently trusted) component in the network path. 1254 The trustworthiness assumption on the HC proxy cannot be dropped, 1255 because the protocol translation function is the core duty of the HC 1256 proxy: it is a necessarily trusted, impossible to bypass, component 1257 in the communication path. 1259 A reverse proxy deployed at the boundary of a constrained network is 1260 an easy single point of failure for reducing availability. As such, 1261 special care should be taken in designing, developing and operating 1262 it, keeping in mind that, in most cases, it has fewer limitations 1263 than the constrained devices it is serving. 1265 The following sub paragraphs categorize and discuss a set of specific 1266 security issues related to the translation, caching and forwarding 1267 functionality exposed by an HC proxy. 1269 10.1. Traffic Overflow 1271 Due to the typically constrained nature of CoAP nodes, particular 1272 attention SHOULD be given to the implementation of traffic reduction 1273 mechanisms (see Section 8.1), because inefficient proxy 1274 implementations can be targeted by unconstrained Internet attackers. 1275 Bandwidth or complexity involved in such attacks is very low. 1277 An amplification attack to the constrained network may be triggered 1278 by a multicast request generated by a single HTTP request which is 1279 mapped to a CoAP multicast resource, as considered in Section 11.3 of 1280 [RFC7252]. 1282 The risk likelihood of this amplification technique is higher than an 1283 amplification attack carried out by a malicious constrained device 1284 (e.g. ICMPv6 flooding, like Packet Too Big, or Parameter Problem on 1285 a multicast destination [RFC4732]), since it does not require direct 1286 access to the constrained network. 1288 The feasibility of this attack, disruptive in terms of CoAP server 1289 availability, can be limited by access controlling the exposed HTTP 1290 multicast resources, so that only known/authorized users access such 1291 URIs. 1293 10.2. Handling Secured Exchanges 1295 An HTTP request can be sent to the HC proxy over a secured 1296 connection. However, there may not always exist a secure connection 1297 mapping to CoAP. For example, a secure distribution method for 1298 multicast traffic is complex and MAY not be implemented (see 1299 [RFC7390]). 1301 An HC proxy SHOULD implement explicit rules for security context 1302 translations. A translation may involve e.g. applying a rule that 1303 any "https" unicast request is translated to a "coaps" request, or 1304 e.g. applying a rule that a "https" request is translated to an 1305 unsecured "coap" request. Another rule could specify the security 1306 policy and parameters used for DTLS connections. Such rules will 1307 largely depend on the application and network context in which a 1308 proxy operates. These rules SHOULD be configurable in an HC proxy. 1310 If a policy for access to 'coaps' URIs is configurable in an HC 1311 proxy, it is RECOMMENDED that the policy is by default configured to 1312 disallow access to any 'coaps' URI by a HTTP client using an 1313 unsecured (non-TLS) connection. Naturally, a user MAY reconfigure 1314 the policy to allow such access in specific cases. 1316 By default, an HC proxy SHOULD reject any secured client request if 1317 there is no configured security policy mapping. This recommendation 1318 MAY be relaxed in case the destination network is believed to be 1319 secured by other, complementary, means. E.g.: assumed that CoAP 1320 nodes are isolated behind a firewall (e.g. as in the SS HC proxy 1321 deployment shown in Figure 1), the HC proxy may be configured to 1322 translate the incoming HTTPS request using plain CoAP (NoSec mode). 1324 The HTTP-CoAP URI mapping (defined in Section 5) MUST NOT map to HTTP 1325 a CoAP resource intended to be only accessed securely. 1327 A secured connection that is terminated at the HC proxy, i.e., the 1328 proxy decrypts secured data locally, raises an ambiguity about the 1329 cacheability of the requested resource. The HC proxy SHOULD NOT 1330 cache any secured content to avoid any leak of secured information. 1331 However, in some specific scenario, a security/efficiency trade-off 1332 could motivate caching secured information; in that case the caching 1333 behavior MAY be tuned to some extent on a per-resource basis. 1335 10.3. Proxy and CoAP Server Resource Exhaustion 1337 If the HC proxy implements the low-latency optimization of 1338 Section 8.3 intended for slow client-to-proxy connections, the Proxy 1339 may become vulnerable to a resource exhaustion attack. In this case 1340 an attacking client could initiate multiple requests using a 1341 relatively large message body which is (after an initial fast 1342 transfer) transferred very slowly to the Proxy. This would trigger 1343 the HC proxy to create state for a blockwise CoAP request per HTTP 1344 request, waiting for the arrival of more data over the HTTP/TCP 1345 connection. Such attacks can be mitigated in the usual ways for HTTP 1346 servers using for example a connection time limit along with a limit 1347 on the number of open TCP connections per IP address. 1349 10.4. URI Mapping 1351 The following risks related to the URI mapping described in Section 5 1352 and its use by HC proxies have been identified: 1354 DoS attack on the constrained/CoAP network. 1355 To mitigate, by default deny any Target CoAP URI whose authority 1356 is (or maps to) a multicast address. Then explicitly white-list 1357 multicast resources/authorities that are allowed to be de- 1358 referenced. See also Section 8.5. 1360 Leaking information on the constrained/CoAP network resources and 1361 topology. 1362 To mitigate, by default deny any Target CoAP URI (especially 1363 /.well-known/core is a resource to be protected), and then 1364 explicit white-list resources that are allowed to be seen from 1365 outside. 1367 Reduced privacy due to the mechanics of the URI mapping. 1368 The internal CoAP Target resource is totally transparent from 1369 outside. An HC proxy can mitigate by implementing a HTTPS-only 1370 interface, making the Target CoAP URI totally opaque to a passive 1371 attacker. 1373 11. Acknowledgements 1375 An initial version of Table 2 in Section 7 has been provided in 1376 revision -05 of the CoRE CoAP I-D. Special thanks to Peter van der 1377 Stok for countless comments and discussions on this document, that 1378 contributed to its current structure and text. 1380 Thanks to Carsten Bormann, Zach Shelby, Michele Rossi, Nicola Bui, 1381 Michele Zorzi, Klaus Hartke, Cullen Jennings, Kepeng Li, Brian Frank, 1382 Peter Saint-Andre, Kerry Lynn, Linyi Tian, Dorothy Gellert, Francesco 1383 Corazza for helpful comments and discussions that have shaped the 1384 document. 1386 The research leading to these results has received funding from the 1387 European Community's Seventh Framework Programme [FP7/2007-2013] 1388 under grant agreement n.251557. 1390 12. References 1392 12.1. Normative References 1394 [I-D.ietf-core-block] 1395 Bormann, C. and Z. Shelby, "Block-wise transfers in CoAP", 1396 draft-ietf-core-block-17 (work in progress), March 2015. 1398 [I-D.ietf-core-observe] 1399 Hartke, K., "Observing Resources in CoAP", draft-ietf- 1400 core-observe-16 (work in progress), December 2014. 1402 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1403 Requirement Levels", BCP 14, RFC 2119, March 1997. 1405 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 1406 Resource Identifier (URI): Generic Syntax", STD 66, RFC 1407 3986, January 2005. 1409 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax 1410 Specifications: ABNF", STD 68, RFC 5234, January 2008. 1412 [RFC6570] Gregorio, J., Fielding, R., Hadley, M., Nottingham, M., 1413 and D. Orchard, "URI Template", RFC 6570, March 2012. 1415 [RFC6690] Shelby, Z., "Constrained RESTful Environments (CoRE) Link 1416 Format", RFC 6690, August 2012. 1418 [RFC7230] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol 1419 (HTTP/1.1): Message Syntax and Routing", RFC 7230, June 1420 2014. 1422 [RFC7231] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol 1423 (HTTP/1.1): Semantics and Content", RFC 7231, June 2014. 1425 [RFC7232] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol 1426 (HTTP/1.1): Conditional Requests", RFC 7232, June 2014. 1428 [RFC7235] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol 1429 (HTTP/1.1): Authentication", RFC 7235, June 2014. 1431 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 1432 Application Protocol (CoAP)", RFC 7252, June 2014. 1434 12.2. Informative References 1436 [I-D.bormann-core-links-json] 1437 Bormann, C., "Representing CoRE Link Collections in JSON", 1438 draft-bormann-core-links-json-02 (work in progress), 1439 February 2013. 1441 [I-D.ietf-core-resource-directory] 1442 Shelby, Z., Koster, M., Bormann, C., and P. Stok, "CoRE 1443 Resource Directory", draft-ietf-core-resource-directory-03 1444 (work in progress), June 2015. 1446 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 1447 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 1448 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 1450 [RFC3040] Cooper, I., Melve, I., and G. Tomlinson, "Internet Web 1451 Replication and Caching Taxonomy", RFC 3040, January 2001. 1453 [RFC4732] Handley, M., Rescorla, E., and IAB, "Internet Denial-of- 1454 Service Considerations", RFC 4732, December 2006. 1456 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 1457 Representation (CBOR)", RFC 7049, October 2013. 1459 [RFC7390] Rahman, A. and E. Dijk, "Group Communication for the 1460 Constrained Application Protocol (CoAP)", RFC 7390, 1461 October 2014. 1463 Appendix A. Change Log 1465 [Note to RFC Editor: Please remove this section before publication.] 1467 Changes from ietf-06 to ietf-07: 1469 o Addressed Ticket #384 - Section 5.4.1 describes briefly 1470 (informative) how to discover CoAP resources from an HTTP client. 1472 o Addressed Ticket #378 - For HTTP media type to CoAP content format 1473 mapping and vice versa: a new draft (TBD) may be proposed in CoRE 1474 which describes an approach for automatic updating of the media 1475 type mapping. This was noted in Section 6.1 but is otherwise 1476 outside the scope of this draft. 1478 o Addressed Ticket #377 - Added IANA section that defines a new HTTP 1479 media type "application/coap-payload" and created new Section 6.2 1480 on how to use it. 1482 o Addressed Ticket #376 - Updated Table 2 (and corresponding note 7) 1483 to indicate that a CoAP 4.05 (Method Not Allowed) Response Code 1484 should be mapped to a HTTP 400 (Bad Request). 1486 o Added note to comply to ABNF when translating CoAP diagnostic 1487 payload to reason-phrase in Section 6.5.3. 1489 Changes from ietf-05 to ietf-06: 1491 o Fully restructured the draft, bringing introductory text more to 1492 the front and allocating main sections to each of the key topics; 1493 addressing Ticket #379; 1495 o Addressed Ticket #382, fix of enhanced form URI template 1496 definition of q in Section 5.3.2; 1498 o Addressed Ticket #381, found a mapping 4.01 to 401 Unauthorized in 1499 Section 7; 1501 o Addressed Ticket #380 (Add IANA registration for "core.hc" 1502 Resource Type) in Section 9; 1504 o Addressed Ticket #376 (CoAP 4.05 response can't be translated to 1505 HTTP 405 by HC proxy) in Section 7 by use of empty 'Allow' header; 1507 o Removed details on the pros and cons of HC proxy placement 1508 options; 1510 o Addressed review comments of Carsten Bormann; 1512 o Clarified failure in mapping of HTTP Accept headers (Section 6.3); 1514 o Clarified detection of CoAP servers not supporting blockwise 1515 (Section 8.3); 1517 o Changed CoAP request timeout min value to MAX_RTT + 1518 MAX_SERVER_RESPONSE_DELAY (Section 8.6); 1520 o Added security section item (Section 10.3) related to use of CoAP 1521 blockwise transfers; 1523 o Many editorial improvements. 1525 Changes from ietf-04 to ietf-05: 1527 o Addressed Ticket #366 (Mapping of CoRE Link Format payloads to be 1528 valid in HTTP Domain?) in Section 6.3.3.2 (Content Transcoding - 1529 CORE Link Format); 1531 o Addressed Ticket #375 (Add requirement on mapping of CoAP 1532 diagnostic payload) in Section 6.3.3.3 (Content Transcoding - 1533 Diagnostic Messages); 1535 o Addressed comment from Yusuke (http://www.ietf.org/mail- 1536 archive/web/core/current/msg05491.html) in Section 6.3.3.1 1537 (Content Transcoding - General); 1539 o Various editorial improvements. 1541 Changes from ietf-03 to ietf-04: 1543 o Expanded use case descriptions in Section 4; 1545 o Fixed/enhanced discovery examples in Section 5.4.1; 1547 o Addressed Ticket #365 (Add text on media type conversion by HTTP- 1548 CoAP proxy) in new Section 6.3.1 (Generalized media type mapping) 1549 and new Section 6.3.2 (Content translation); 1551 o Updated HTTPBis WG draft references to recently published RFC 1552 numbers. 1554 o Various editorial improvements. 1556 Changes from ietf-02 to ietf-03: 1558 o Closed Ticket #351 "Add security implications of proposed default 1559 HTTP-CoAP URI mapping"; 1561 o Closed Ticket #363 "Remove CoAP scheme in default HTTP-CoAP URI 1562 mapping"; 1564 o Closed Ticket #364 "Add discovery of HTTP-CoAP mapping 1565 resource(s)". 1567 Changes from ietf-01 to ietf-02: 1569 o Selection of single default URI mapping proposal as proposed to WG 1570 mailing list 2013-10-09. 1572 Changes from ietf-00 to ietf-01: 1574 o Added URI mapping proposals to Section 4 as per the Email 1575 proposals to WG mailing list from Esko. 1577 Authors' Addresses 1579 Angelo P. Castellani 1580 University of Padova 1581 Via Gradenigo 6/B 1582 Padova 35131 1583 Italy 1585 Email: angelo@castellani.net 1587 Salvatore Loreto 1588 Ericsson 1589 Hirsalantie 11 1590 Jorvas 02420 1591 Finland 1593 Email: salvatore.loreto@ericsson.com 1594 Akbar Rahman 1595 InterDigital Communications, LLC 1596 1000 Sherbrooke Street West 1597 Montreal H3A 3G4 1598 Canada 1600 Phone: +1 514 585 0761 1601 Email: Akbar.Rahman@InterDigital.com 1603 Thomas Fossati 1604 Alcatel-Lucent 1605 3 Ely Road 1606 Milton, Cambridge CB24 6DD 1607 UK 1609 Email: thomas.fossati@alcatel-lucent.com 1611 Esko Dijk 1612 Philips Research 1613 High Tech Campus 34 1614 Eindhoven 5656 AE 1615 The Netherlands 1617 Email: esko.dijk@philips.com