idnits 2.17.1 draft-ietf-core-http-mapping-06.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (March 9, 2015) is 3335 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: 'RFC5234' is mentioned on line 395, but not defined == Missing Reference: 'C-T' is mentioned on line 778, but not defined == Missing Reference: 'C-E' is mentioned on line 764, but not defined == Missing Reference: 'RFC7232' is mentioned on line 906, but not defined ** Obsolete undefined reference: RFC 7232 (Obsoleted by RFC 9110) -- Looks like a reference, but probably isn't: '251557' on line 1281 == Outdated reference: A later version (-21) exists of draft-ietf-core-block-16 ** Obsolete normative reference: RFC 7230 (Obsoleted by RFC 9110, RFC 9112) ** Obsolete normative reference: RFC 7231 (Obsoleted by RFC 9110) ** Obsolete normative reference: RFC 7235 (Obsoleted by RFC 9110) -- 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 (==), 5 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: September 10, 2015 Ericsson 6 A. Rahman 7 InterDigital Communications, LLC 8 T. Fossati 9 Alcatel-Lucent 10 E. Dijk 11 Philips Research 12 March 9, 2015 14 Guidelines for HTTP-CoAP Mapping Implementations 15 draft-ietf-core-http-mapping-06 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 September 10, 2015. 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 . . . . . . . . . . . . . . . . . . . . . . . . . 6 66 5.1. URI Terminology . . . . . . . . . . . . . . . . . . . . . 7 67 5.2. Default Mapping . . . . . . . . . . . . . . . . . . . . . 7 68 5.2.1. Optional Scheme Omission . . . . . . . . . . . . . . 8 69 5.2.2. Encoding Caveats . . . . . . . . . . . . . . . . . . 8 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 . . . . . . . . . . . . . . . . . . . . . . . . 12 74 5.4.1. Examples . . . . . . . . . . . . . . . . . . . . . . 12 75 6. Media Type Mapping . . . . . . . . . . . . . . . . . . . . . 14 76 6.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . 14 77 6.2. Loose Media Type Mapping . . . . . . . . . . . . . . . . 15 78 6.3. Media Type to Content Format Mapping Algorithm . . . . . 16 79 6.4. Content Transcoding . . . . . . . . . . . . . . . . . . . 17 80 6.4.1. General . . . . . . . . . . . . . . . . . . . . . . . 17 81 6.4.2. CoRE Link Format . . . . . . . . . . . . . . . . . . 18 82 6.4.3. Diagnostic Messages . . . . . . . . . . . . . . . . . 18 83 7. Response Code Mapping . . . . . . . . . . . . . . . . . . . . 19 84 8. Additional Mapping Guidelines . . . . . . . . . . . . . . . . 21 85 8.1. Caching and Congestion Control . . . . . . . . . . . . . 21 86 8.2. Cache Refresh via Observe . . . . . . . . . . . . . . . . 22 87 8.3. Use of CoAP Blockwise Transfer . . . . . . . . . . . . . 22 88 8.4. Security Translation . . . . . . . . . . . . . . . . . . 23 89 8.5. CoAP Multicast . . . . . . . . . . . . . . . . . . . . . 23 90 8.6. Timeouts . . . . . . . . . . . . . . . . . . . . . . . . 24 91 8.7. Miscellaneous . . . . . . . . . . . . . . . . . . . . . . 24 92 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 25 93 10. Security Considerations . . . . . . . . . . . . . . . . . . . 25 94 10.1. Traffic Overflow . . . . . . . . . . . . . . . . . . . . 25 95 10.2. Handling Secured Exchanges . . . . . . . . . . . . . . . 26 96 10.3. Proxy and CoAP Server Resource Exhaustion . . . . . . . 27 97 10.4. URI Mapping . . . . . . . . . . . . . . . . . . . . . . 27 98 11. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 28 99 12. References . . . . . . . . . . . . . . . . . . . . . . . . . 28 100 12.1. Normative References . . . . . . . . . . . . . . . . . . 28 101 12.2. Informative References . . . . . . . . . . . . . . . . . 29 102 Appendix A. Change Log . . . . . . . . . . . . . . . . . . . . . 29 103 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 31 105 1. Introduction 107 CoAP [RFC7252] has been designed with the twofold aim to be an 108 application protocol specialized for constrained environments and to 109 be easily used in REST architectures such as the Web. The latter 110 goal has led to define CoAP to easily interoperate with HTTP 111 [RFC7230] through an intermediary proxy which performs cross-protocol 112 conversion. 114 Section 10 of [RFC7252] describes the fundamentals of the CoAP-to- 115 HTTP and the HTTP-to-CoAP cross-protocol mapping process. However, 116 implementing such a cross-protocol proxy can be complex, and many 117 details regarding its internal procedures and design choices require 118 further elaboration. Therefore a first goal of this document is to 119 provide more detailed information to proxy designers and 120 implementers, to help build proxies that correctly inter-work with 121 existing CoAP and HTTP implementations. 123 The second goal of this informational document is to define a 124 consistent set of guidelines that a HTTP-to-CoAP proxy implementation 125 MAY adhere to. The main reason for adhering to such guidelines is to 126 reduce variation between proxy implementations, thereby increasing 127 interoperability. (For example, a proxy conforming to these 128 guidelines made by vendor A can be easily replaced by a proxy from 129 vendor B that also conforms to the guidelines.) 131 This document is organized as follows: 133 o Section 2 describes terminology to identify proxy types, mapping 134 approaches and proxy deployments; 136 o Section 3 introduces the reverse HTTP-CoAP proxy; 138 o Section 4 lists use cases in which HTTP clients need to contact 139 CoAP servers; 141 o Section 5 introduces a default HTTP-to-CoAP URI mapping syntax; 143 o Section 6 describes how to map HTTP media types to CoAP content 144 formats and vice versa; 146 o Section 7 describes how to map CoAP responses to HTTP responses; 148 o Section 8 describes additional mapping guidelines related to 149 caching, congestion, timeouts and CoAP blockwise 150 [I-D.ietf-core-block] transfers; 152 o Section 10 discusses possible security impact of HTTP-CoAP 153 protocol mapping. 155 2. Terminology 157 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 158 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 159 "OPTIONAL" in this document are to be interpreted as described in 160 [RFC2119]. 162 HC Proxy: a proxy performing a cross-protocol mapping, in the context 163 of this document a HTTP-CoAP mapping. A Cross-Protocol Proxy can 164 behave as a Forward Proxy, Reverse Proxy or Interception Proxy. In 165 this document we focus on the Reverse Proxy case. 167 Forward Proxy: a message forwarding agent that is selected by the 168 client, usually via local configuration rules, to receive requests 169 for some type(s) of absolute URI and to attempt to satisfy those 170 requests via translation to the protocol indicated by the absolute 171 URI. The user decides (is willing to) use the proxy as the 172 forwarding/dereferencing agent for a predefined subset of the URI 173 space. In [RFC7230] this is called a Proxy. [RFC7252] defines 174 Forward-Proxy similarly. 176 Reverse Proxy: as in [RFC7230], a receiving agent that acts as a 177 layer above some other server(s) and translates the received requests 178 to the underlying server's protocol. A Reverse HC Proxy behaves as 179 an origin (HTTP) server on its connection towards the (HTTP) client 180 and as a (CoAP) client on its connection towards the (CoAP) origin 181 server. The (HTTP) client uses the "origin-form" (Section 5.3.1 of 182 [RFC7230]) as a request-target URI. 184 Interception Proxy [RFC3040]: a proxy that receives inbound traffic 185 flows through the process of traffic redirection; transparent to the 186 client. 188 Placement terms: a Server-Side proxy is placed in the same network 189 domain as the server; conversely a Client-Side proxy is placed in the 190 same network domain as the client. In any other case, the proxy is 191 said to be External. 193 Note that a Reverse Proxy appears to a client as an origin server 194 while a Forward Proxy does not. So when communicating with a Reverse 195 Proxy a client may be unaware it is communicating with a proxy at 196 all. 198 3. HTTP-CoAP Reverse Proxy 200 A Reverse HTTP-CoAP Proxy (HC proxy) is accessed by clients only 201 supporting HTTP, and handles their HTTP requests by mapping these to 202 CoAP requests, which are forwarded to CoAP servers; mapping back 203 received CoAP responses to HTTP responses. This mechanism is 204 transparent to the client, which may assume that it is communicating 205 with the intended target HTTP server. In other words, the client 206 accesses the proxy as an origin server using the "origin-form" 207 (Section 5.3.1 of [RFC7230]) as a request target. 209 See Figure 1 for an example deployment scenario. Here an HC Proxy is 210 placed server-side, at the boundary of the Constrained Network 211 domain, to avoid any HTTP traffic on the Constrained Network and to 212 avoid any (unsecured) CoAP multicast traffic outside the Constrained 213 Network. The DNS server is used by the HTTP Client to resolve the IP 214 address of the HC Proxy and optionally also by the HC Proxy to 215 resolve IP addresses of CoAP servers. 217 Constrained Network 218 .-------------------. 219 / .------. \ 220 / | CoAP | \ 221 / |server| \ 222 || '------' || 223 || || 224 .--------. HTTP Request .-----------. CoAP Req .------. || 225 | HTTP |----------------->| HTTP-CoAP |----------->| CoAP | || 226 | Client |<-----------------| Proxy |<-----------|Server| || 227 '--------' HTTP Response '-----------' CoAP Resp '------' || 228 || || 229 || .------. || 230 || | CoAP | || 231 \ |server| .------. / 232 \ '------' | CoAP | / 233 \ |server| / 234 \ '------' / 235 '-----------------' 237 Figure 1: Reverse Cross-Protocol Proxy Deployment Scenario 239 Other placement options for the HC Proxy (not shown) are client-side, 240 which is in the same domain as the HTTP Client; or external, which is 241 both outside the HTTP Client's domain and the CoAP servers' domain. 243 Normative requirements on the translation of HTTP requests to CoAP 244 requests and of the CoAP responses back to HTTP responses are defined 245 in Section 10.2 of [RFC7252]. However, that section only considers 246 the case of a Forward HC Proxy in which a client explicitly indicates 247 it targets a request to a CoAP server, and does not cover all aspects 248 of proxy implementation in detail. This document provides guidelines 249 and more details for the implementation of a Reverse HC Proxy, which 250 MAY be followed in addition to the normative requirements. Note that 251 most of the guidelines also apply to an Intercepting HC Proxy. 253 4. Use Cases 255 To illustrate in which situations HTTP to CoAP protocol translation 256 may be used, three use cases are described below. 258 1. Smartphone and home sensor: A smartphone can access directly a 259 CoAP home sensor using an authenticated 'https' request, if its home 260 router contains an HC proxy. An HTML5 application on the smartphone 261 can provide a friendly UI to the user using standard (HTTP) 262 networking functions of HTML5. 264 2. Legacy building control application without CoAP: A building 265 control application that uses HTTP but not CoAP, can check the status 266 of CoAP sensors and/or actuators via an HC proxy. 268 3. Making sensor data available to 3rd parties: For demonstration or 269 public interest purposes, a HC proxy may be configured to expose the 270 contents of a CoAP sensor to the world via the web (HTTP and/or 271 HTTPS). Some sensors might only handle secure 'coaps' requests, 272 therefore the proxy is configured to translate any request to a 273 'coaps' secured request. The HC proxy is furthermore configured to 274 only pass through GET requests in order to protect the constrained 275 network. In this way even unattended HTTP clients, such as web 276 crawlers, may index sensor data as regular web pages. 278 5. URI Mapping 280 Though, in principle, a CoAP URI could be directly used by a HTTP 281 user agent to de-reference a CoAP resource through an HC proxy, the 282 reality is that all major web browsers, networking libraries and 283 command line tools do not allow making HTTP requests using URIs with 284 a scheme "coap" or "coaps". 286 Thus, there is a need for web applications to "pack" a CoAP URI into 287 a HTTP URI so that it can be (non-destructively) transported from the 288 user agent to the HC proxy. The HC proxy can then "unpack" the CoAP 289 URI and finally de-reference it via a CoAP request to the target 290 Server. 292 URI Mapping is the process through which the URI of a CoAP resource 293 is transformed into an HTTP URI so that: 295 o the requesting HTTP user agent can handle it; 297 o the receiving HC proxy can extract the intended CoAP URI 298 unambiguously. 300 To this end, the remainder of this section will identify: 302 o the default mechanism to map a CoAP URI into a HTTP URI; 304 o the URI template format to express a class of CoAP-HTTP URI 305 mapping functions; 307 o the discovery mechanism based on CoRE Link Format [RFC6690] 308 through which clients of an HC proxy can dynamically discover 309 information about the supported URI Mapping Template(s), as well 310 as the base URI where the HC proxy function is anchored. 312 5.1. URI Terminology 314 In the remainder of this section, the following terms will be used 315 with a distinctive meaning: 317 Target CoAP URI: 318 URI which refers to the (final) CoAP resource that has to be 319 de-referenced. It conforms to syntax defined in Section 6 of 320 [RFC7252]. Specifically, its scheme is either "coap" or 321 "coaps". 323 Hosting HTTP URI: 324 URI that conforms to syntax in Section 2.7 of [RFC7230]. Its 325 authority component refers to an HC proxy, whereas path (and 326 query) component(s) embed the information used by an HC proxy 327 to extract the Target CoAP URI. 329 5.2. Default Mapping 331 The default mapping is for the Target CoAP URI to be appended as-is 332 to a base URI provided by the HC proxy, to form the Hosting HTTP URI. 334 For example: given a base URI http://p.example.com/hc and a Target 335 CoAP URI coap://s.example.com/light, the resulting Hosting HTTP URI 336 would be http://p.example.com/hc/coap://s.example.com/light. 338 Provided a correct Target CoAP URI, the Hosting HTTP URI resulting 339 from the default mapping is always syntactically correct. 340 Furthermore, the Target CoAP URI can always be extracted in an 341 unambiguous way from the Hosting HTTP URI. Also it is worth noting 342 that, using the default mapping, a query component in the target CoAP 343 resource URI is naturally encoded into the query component of the 344 Hosting URI, e.g.: coap://s.example.com/light?dim=5 becomes 345 http://p.example.com/hc/coap://s.example.com/light?dim=5. 347 There is no default for the base URI. Therefore it is either known 348 in advance, e.g. as a configuration preset, or dynamically discovered 349 using the mechanism described in Section 5.4. 351 The default URI mapping function is RECOMMENDED to be implemented and 352 activated by default in an HC proxy, unless there are valid reasons, 353 e.g. application specific, to use a different mapping function. 355 5.2.1. Optional Scheme Omission 357 When found in a Hosting HTTP URI, the scheme (i.e., "coap" or 358 "coaps"), the scheme component delimiter (":"), and the double slash 359 ("//") preceding the authority MAY be omitted. In such case, a local 360 default - not defined by this document - applies. 362 So, http://p.example.com/hc/s.coap.example.com/foo could either 363 represent the target coap://s.coap.example.com/foo or 364 coaps://s.coap.example.com/foo depending on application specific 365 presets. 367 5.2.2. Encoding Caveats 369 When the authority of the Target CoAP URI is given as an IPv6address, 370 then the surrounding square brackets MUST be percent-encoded in the 371 Hosting HTTP URI, in order to comply with the syntax defined in 372 Section 3.3. of [RFC3986] for a URI path segment. E.g.: 373 coap://[2001:db8::1]/light?on becomes 374 http://p.example.com/hc/coap://%5B2001:db8::1%5D/light?on. 376 Everything else can be safely copied verbatim from the Target CoAP 377 URI to the Hosting HTTP URI. 379 5.3. URI Mapping Template 381 This section defines a format for the URI template [RFC6570] used by 382 an HC proxy to inform its clients about the expected syntax for the 383 Hosting HTTP URI. 385 When instantiated, an URI Mapping Template is always concatenated to 386 a base URI provided by the HC proxy via discovery (see Section 5.4), 387 or by other means. 389 A simple form (Section 5.3.1) and an enhanced form (Section 5.3.2) 390 are provided to fit different users' requirements. 392 Both forms are expressed as level 2 URI templates [RFC6570] to take 393 care of the expansion of values that are allowed to include reserved 394 URI characters. The syntax of all URI formats is specified in this 395 section in Augmented Backus-Naur Form (ABNF) [RFC5234]. 397 5.3.1. Simple Form 399 The simple form MUST be used for mappings where the Target CoAP URI 400 is going to be copied (using rules of Section 5.2.2) at some fixed 401 position into the Hosting HTTP URI. 403 The following template variables MUST be used in mutual exclusion in 404 a template definition: 406 cu = coap-URI ; from [RFC7252], Section 6.1 407 su = coaps-URI ; from [RFC7252], Section 6.2 408 tu = cu / su 410 The same considerations as in Section 5.2.1 apply, in that the CoAP 411 scheme may be omitted from the Hosting HTTP URI. 413 5.3.1.1. Examples 415 All the following examples (given as a specific URI mapping template, 416 a Target CoAP URI, and the produced Hosting HTTP URI) use 417 http://p.example.com/hc as the base URI. Note that these examples 418 all define mapping templates that deviate from the default template 419 of Section 5.2 to be able to illustrate the use of the above template 420 variables. 422 1. "coap" URI is a query argument of the Hosting HTTP URI: 424 ?coap_target_uri={+cu} 426 coap://s.example.com/light 428 http://p.example.com/hc?coap_target_uri=coap://s.example.com/light 430 2. "coaps" URI is a query argument of the Hosting HTTP URI: 432 ?coaps_target_uri={+su} 434 coaps://s.example.com/light 436 http://p.example.com/hc?coaps_target_uri=coaps://s.example.com/light 438 3. Target CoAP URI as a query argument of the Hosting HTTP URI: 440 ?target_uri={+tu} 442 coap://s.example.com/light 444 http://p.example.com/hc?target_uri=coap://s.example.com/light 446 or 448 coaps://s.example.com/light 450 http://p.example.com/hc?target_uri=coaps://s.example.com/light 452 4. Target CoAP URI in the path component of the Hosting HTTP URI 453 (i.e., the default URI Mapping template): 455 /{+tu} 457 coap://s.example.com/light 459 http://p.example.com/hc/coap://s.example.com/light 461 or 463 coaps://s.example.com/light 465 http://p.example.com/hc/coaps://s.example.com/light 467 5. "coap" URI is a query argument of the Hosting HTTP URI; client 468 decides to omit scheme because a default scheme is agreed 469 beforehand between client and proxy: 471 ?coap_uri={+cu} 473 coap://s.example.com/light 475 http://p.example.com/hc?coap_uri=s.example.com/light 477 5.3.2. Enhanced Form 479 The enhanced form can be used to express more sophisticated mappings, 480 i.e., those that do not fit into the simple form. 482 There MUST be at most one instance of each of the following template 483 variables in a template definition: 485 s = "coap" / "coaps" ; from [RFC7252], Sections 6.1 and 6.2 486 hp = host [":" port] ; from [RFC3986] Sections 3.2.2 and 3.2.3 487 p = path-abempty ; from [RFC3986] Section 3.3 488 q = query ; from [RFC3986] Section 3.4 489 qq = [ "?" query ] ; qq is empty iff 'query' is empty 491 5.3.2.1. Examples 493 All the following examples (given as a specific URI mapping template, 494 a Target CoAP URI, and the produced Hosting HTTP URI) use 495 http://p.example.com/hc as the base URI. 497 1. Target CoAP URI components in path segments, and optional query 498 in query component: 500 {+s}{+hp}{+p}{+qq} 502 coap://s.example.com/light 504 http://p.example.com/hc/coap/s.example.com/light 506 or 508 coap://s.example.com/light?on 510 http://p.example.com/hc/coap/s.example.com/light?on 512 2. Target CoAP URI components split in individual query arguments: 514 ?s={+s}&hp={+hp}&p={+p}&q={+q} 516 coap://s.example.com/light 518 http://p.example.com/hc?s=coap&hp=s.example.com&p=/light&q= 520 or 522 coaps://s.example.com/light?on 524 http://p.example.com/hc?s=coaps&hp=s.example.com&p=/light&q=on 526 5.4. Discovery 528 In order to accommodate site specific needs while allowing third 529 parties to discover the proxy function, the HC proxy SHOULD publish 530 information related to the location and syntax of the HC proxy 531 function using the CoRE Link Format [RFC6690] interface. 533 To this aim a new Resource Type, "core.hc", is defined in this 534 document. It is associated with a base URI, and can be used as the 535 value for the "rt" attribute in a query to the /.well-known/core in 536 order to locate the base URI where the HC proxy function is anchored. 538 Along with it, the new target attribute "hct" is defined in this 539 document. This attribute MAY be returned in a "core.hc" link to 540 provide the URI Mapping Template associated to the mapping resource. 541 The default template given in Section 5.2, i.e., {+tu}, MUST be 542 assumed if no "hct" attribute is found in the returned link. If an 543 "hct" attribute is present in the returned link, then a compliant 544 client MUST use it to create the Hosting HTTP URI. 546 Discovery as specified in [RFC6690] SHOULD be available on both the 547 HTTP and the CoAP side of the HC proxy, with one important 548 difference: on the CoAP side the link associated to the "core.hc" 549 resource needs an explicit anchor referring to the HTTP origin, while 550 on the HTTP interface the link context is already the HTTP origin 551 carried in the request's Host header, and doesn't have to be made 552 explicit. 554 5.4.1. Examples 556 o The first example exercises the CoAP interface, and assumes that 557 the default template, {+tu}, is used: 559 Req: GET coap://[ff02::1]/.well-known/core?rt=core.hc 561 Res: 2.05 Content 562 ;anchor="http://p.example.com";rt="core.hc" 564 o The second example - also on the CoAP side of the HC proxy - uses 565 a custom template, i.e., one where the CoAP URI is carried inside 566 the query component, thus the returned link carries the URI 567 template to be used in an explicit "hct" attribute: 569 Req: GET coap://[ff02::1]/.well-known/core?rt=core.hc 571 Res: 2.05 Content 572 ;anchor="http://p.example.com"; 573 rt="core.hc";hct="?uri={+tu}" 575 On the HTTP side link information can be serialised in more than one 576 way: 578 o using the 'application/link-format' content type: 580 Req: GET /.well-known/core?rt=core.hc HTTP/1.1 581 Host: p.example.com 583 Res: HTTP/1.1 200 OK 584 Content-Type: application/link-format 585 Content-Length: 18 587 ;rt="core.hc" 589 o using the 'application/link-format+json' content type as defined 590 in [I-D.bormann-core-links-json]: 592 Req: GET /.well-known/core?rt=core.hc HTTP/1.1 593 Host: p.example.com 595 Res: HTTP/1.1 200 OK 596 Content-Type: application/link-format+json 597 Content-Length: 31 599 [{"href":"/hc","rt":"core.hc"}] 601 o using the Link header: 603 Req: GET /.well-known/core?rt=core.hc HTTP/1.1 604 Host: p.example.com 606 Res: HTTP/1.1 200 OK 607 Link: ;rt="core.hc" 609 o An HC proxy may expose two different base URIs to differentiate 610 between Target CoAP resources in the "coap" and "coaps" scheme: 612 Req: GET /.well-known/core?rt=core.hc 613 Host: p.example.com 615 Res: HTTP/1.1 200 OK 616 Content-Type: application/link-format+json 617 Content-Length: 111 619 [ 620 {"href":"/hc/plaintext","rt":"core.hc","hct":"{+cu}"}, 621 {"href":"/hc/secure","rt":"core.hc","hct":"{+su}"} 622 ] 624 6. Media Type Mapping 626 6.1. Overview 628 An HC proxy needs to translate HTTP media types (Section 3.1.1.1 of 629 [RFC7231]) and content encodings (Section 3.1.2.2 of [RFC7231]) into 630 CoAP content formats (Section 12.3 of [RFC7252]) and vice versa. 632 Media type translation can happen in GET, PUT or POST requests going 633 from HTTP to CoAP, and in 2.xx (i.e., successful) responses going 634 from CoAP to HTTP. Specifically, PUT and POST need to map both the 635 Content-Type and Content-Encoding HTTP headers into a single CoAP 636 Content-Format option, whereas GET needs to map Accept and Accept- 637 Encoding HTTP headers into a single CoAP Accept option. To generate 638 the HTTP response, the CoAP Content-Format option is mapped back to a 639 suitable HTTP Content-Type and Content-Encoding combination. 641 An HTTP request carrying a Content-Type and Content-Encoding 642 combination which the HC proxy is unable to map to an equivalent CoAP 643 Content-Format, SHALL elicit a 415 (Unsupported Media Type) response 644 by the HC proxy. 646 If the HC proxy receives a CoAP response with a Content-Format that 647 it does not recognise (for example because the value has been 648 registered after the proxy has been implemented), then it is allowed 649 to either return a HTTP entity without a Content-Type header, or 650 examine the data to determine its type on the fly. 652 On the content negotiation side, failure to map Accept and Accept-* 653 headers SHOULD be silently ignored: the HC proxy SHOULD therefore 654 forward as a CoAP request with no Accept option. The HC proxy thus 655 disregards the Accept/Accept-* header fields by treating the response 656 as if it is not subject to content negotiation, as mentioned in 657 Sections 5.3.* of [RFC7231]. However, an HC proxy implementation is 658 free to attempt mapping a single Accept header in a GET request to 659 multiple CoAP GET requests, each with a single Accept option, which 660 are then tried in sequence until one succeeds. Note that an HTTP 661 Accept */* MUST be mapped to a CoAP request without Accept option. 663 While the CoAP to HTTP direction has always a well defined mapping, 664 the HTTP to CoAP direction is more problematic because the source 665 set, i.e., potentially 1000+ IANA registered media types, is much 666 bigger than the destination set, i.e., the mere 6 values initially 667 defined in Section 12.3 of [RFC7252]. 669 Depending on the tight/loose coupling with the application(s) for 670 which it proxies, the HC proxy could implement different media type 671 mappings. 673 When tightly coupled, the HC proxy knows exactly which content 674 formats are supported by the applications, and can be strict when 675 enforcing its forwarding policies in general, and the media type 676 mapping in particular. 678 On the other side, when the HC proxy is a general purpose application 679 layer gateway, being too strict could significantly reduce the amount 680 of traffic that it'd be able to successfully forward. In this cases, 681 the "loose" media type mapping detailed in Section 6.2 MAY be 682 implemented. 684 The latter grants more evolution of the surrounding ecosystem, at the 685 cost of allowing more attack surface. In fact, as a result of such 686 strategy, payloads would be forwarded more liberally across the 687 unconstrained/constrained network boundary of the communication path. 688 Therefore, when applied, other forms of access control must be set in 689 place to avoid unauthorised users to deplete or abuse systems and 690 network resources. 692 6.2. Loose Media Type Mapping 694 By structuring the type information in a super-class (e.g. "text") 695 followed by a finer grained sub-class (e.g. "html"), and optional 696 parameters (e.g. "charset=utf-8"), Internet media types provide a 697 rich and scalable framework for encoding the type of any given 698 entity. 700 This approach is not applicable to CoAP, where Content Formats 701 conflate an Internet media type (potentially with specific 702 parameters) and a content encoding into one small integer value. 704 To remedy this loss of flexibility, we introduce the concept of a 705 "loose" media type mapping, where media types that are 706 specialisations of a more generic media type can be aliased to their 707 super-class and then mapped (if possible) to one of the CoAP content 708 formats. For example, "application/soap+xml" can be aliased to 709 "application/xml", which has a known conversion to CoAP. In the 710 context of this "loose" media type mapping, "application/octet- 711 stream" can be used as a fallback when no better alias is found for a 712 specific media type. 714 Table 1 defines the default lookup table for the "loose" media type 715 mapping. Given an input media type, the table returns its best 716 generalised media type using the most specific match i.e. the table 717 entries are compared to the input in top to bottom order until an 718 entry matches. 720 +---------------------+--------------------------+ 721 | Internet media type | Generalised media type | 722 +---------------------+--------------------------+ 723 | application/*+xml | application/xml | 724 | application/*+json | application/json | 725 | text/xml | application/xml | 726 | text/* | text/plain | 727 | */* | application/octet-stream | 728 +---------------------+--------------------------+ 730 Table 1: Media type generalisation lookup table 732 The "loose" media type mapping is an OPTIONAL feature. 733 Implementations supporting this kind of mapping SHOULD provide a 734 flexible way to define the set of media type generalisations allowed. 736 6.3. Media Type to Content Format Mapping Algorithm 738 This section defines the algorithm used to map an HTTP Internet media 739 type to its correspondent CoAP content format. 741 The algorithm uses the mapping table Table 9 defined in Section 12.3 742 of [RFC7252] plus, possibly, any locally defined extension of it. 743 Optionally, the table and lookup mechanism described in Section 6.2 744 can be used if the implementation chooses so. 746 Note that the algorithm may have side effects on the associated 747 representation (see also Section 6.4). 749 In the following: 751 o C-T, C-E, and C-F stand for the values of the Content-Type (or 752 Accept) HTTP header, Content-Encoding (or Accept-Encoding) HTTP 753 header, and Content-Format CoAP option respectively. 755 o If C-E is not given it is assumed to be "identity". 757 o MAP is the mandatory lookup table, GMAP is the optional 758 generalised table. 760 INPUT: C-T and C-E 761 OUTPUT: C-F or Fail 763 1. if no C-T: return Fail 764 2. C-F = MAP[C-T, C-E] 765 3. if C-F is not None: return C-F 766 4. if C-E is not "identity": 767 5. if C-E is supported (e.g. gzip): 768 6. decode the representation accordingly 769 7. set C-E to "identity" 770 8. else: 771 9. return Fail 772 10. repeat steps 2. and 3. 773 11. if C-T allows a non-lossy transformation into \ 774 12. one of the supported C-F: 775 13. transcode the representation accordingly 776 14. return C-F 777 15. if GMAP is defined: 778 16. C-F = GMAP[C-T] 779 17. if C-F is not None: return C-F 780 18. return Fail 782 Figure 2 784 6.4. Content Transcoding 786 6.4.1. General 788 Payload content transcoding (e.g. see steps 11-14 of Figure 2) is an 789 OPTIONAL feature. Implementations supporting this feature should 790 provide a flexible way to define the set of transcodings allowed. 792 As noted in Section 6.3, the process of mapping the media type can 793 have side effects on the forwarded entity body. This may be caused 794 by the removal or addition of a specific content encoding, or because 795 the HC proxy decides to transcode the representation to a different 796 (compatible) format. The latter proves useful when an optimised 797 version of a specific format exists. For example an XML-encoded 798 resource could be transcoded to Efficient XML Interchange (EXI) 799 format, or a JSON-encoded resource into CBOR [RFC7049], effectively 800 achieving compression without losing any information. 802 However, it should be noted that in certain cases, transcoding can 803 lose information in a non-obvious manner. For example, encoding an 804 XML document using schema-informed EXI encoding leads to a loss of 805 information when the destination does not know the exact schema 806 version used by the encoder. So whenever the HC proxy transcodes an 807 application/XML to application/EXI in-band meta data could be lost. 808 Therefore, the implementer should always carefully verify such lossy 809 payload transformations before triggering the transcoding. 811 6.4.2. CoRE Link Format 813 The CoRE Link Format [RFC6690] is a set of links (i.e., URIs and 814 their formal relationships) which is carried as content payload in a 815 CoAP response. These links usually include CoAP URIs that might be 816 translated by the HC proxy to the correspondent HTTP URIs using the 817 implemented URI mapping function (see Section 5). Such a process 818 would inspect the forwarded traffic and attempt to re-write the body 819 of resources with an application/link-format media type, mapping the 820 embedded CoAP URIs to their HTTP counterparts. Some potential issues 821 with this approach are: 823 1. The client may be interested to retrieve original (unaltered) 824 CoAP payloads through the HC proxy, not modified versions. 826 2. Tampering with payloads is incompatible with resources that are 827 integrity protected (although this is a problem with transcoding 828 in general). 830 3. The HC proxy needs to fully understand [RFC6690] syntax and 831 semantics, otherwise there is an inherent risk to corrupt the 832 payloads. 834 Therefore, CoRE Link Format payload should only be transcoded at the 835 risk and discretion of the proxy implementer. 837 6.4.3. Diagnostic Messages 839 CoAP responses may, in certain error cases, contain a diagnostic 840 message in the payload explaining the error situation, as described 841 in Section 5.5.2 of [RFC7252]. In this scenario, the CoAP response 842 diagnostic payload MUST NOT be returned as the regular HTTP payload 843 (message body). Instead, the CoAP diagnostic payload must be used as 844 the HTTP reason-phrase of the HTTP status line, as defined in 845 Section 3.1.2 of [RFC7230], without any alterations. 847 7. Response Code Mapping 849 Table 2 defines the HTTP response status codes to which each CoAP 850 response code SHOULD be mapped. This table complies with the 851 requirements in Section 10.2 of [RFC7252] and is intended to cover 852 all possible cases. Multiple appearances of a HTTP status code in 853 the second column indicates multiple equivalent HTTP responses are 854 possible based on the same CoAP response code, depending on the 855 conditions cited in the Notes (third column and text below table). 857 +-----------------------------+-----------------------------+-------+ 858 | CoAP Response Code | HTTP Status Code | Notes | 859 +-----------------------------+-----------------------------+-------+ 860 | 2.01 Created | 201 Created | 1 | 861 | 2.02 Deleted | 200 OK | 2 | 862 | | 204 No Content | 2 | 863 | 2.03 Valid | 304 Not Modified | 3 | 864 | | 200 OK | 4 | 865 | 2.04 Changed | 200 OK | 2 | 866 | | 204 No Content | 2 | 867 | 2.05 Content | 200 OK | | 868 | 4.00 Bad Request | 400 Bad Request | | 869 | 4.01 Unauthorized | 401 Unauthorized | 5 | 870 | 4.02 Bad Option | 400 Bad Request | 6 | 871 | 4.03 Forbidden | 403 Forbidden | | 872 | 4.04 Not Found | 404 Not Found | | 873 | 4.05 Method Not Allowed | 405 Method Not Allowed | 7 | 874 | 4.06 Not Acceptable | 406 Not Acceptable | | 875 | 4.12 Precondition Failed | 412 Precondition Failed | | 876 | 4.13 Request Ent. Too Large | 413 Request Repr. Too Large | | 877 | 4.15 Unsupported Media Type | 415 Unsupported Media Type | | 878 | 5.00 Internal Server Error | 500 Internal Server Error | | 879 | 5.01 Not Implemented | 501 Not Implemented | | 880 | 5.02 Bad Gateway | 502 Bad Gateway | | 881 | 5.03 Service Unavailable | 503 Service Unavailable | 8 | 882 | 5.04 Gateway Timeout | 504 Gateway Timeout | | 883 | 5.05 Proxying Not Supported | 502 Bad Gateway | 9 | 884 +-----------------------------+-----------------------------+-------+ 886 Table 2: CoAP-HTTP Response Code Mappings 888 Notes: 890 1. A CoAP server may return an arbitrary format payload along with 891 this response. This payload SHOULD be returned as entity in the 892 HTTP 201 response. Section 7.3.2 of [RFC7231] does not put any 893 requirement on the format of the entity. (In the past, [RFC2616] 894 did.) 896 2. The HTTP code is 200 or 204 respectively for the case that a CoAP 897 server returns a payload or not. [RFC7231] Section 5.3 requires 898 code 200 in case a representation of the action result is 899 returned for DELETE/POST/PUT, and code 204 if not. Hence, a 900 proxy SHOULD transfer any CoAP payload contained in a CoAP 2.02 901 response to the HTTP client using a 200 OK response. 903 3. HTTP code 304 (Not Modified) is sent if the HTTP client performed 904 a conditional HTTP request and the CoAP server responded with 905 2.03 (Valid) to the corresponding CoAP validation request. Note 906 that Section 4.1 of [RFC7232] puts some requirements on header 907 fields that must be present in the HTTP 304 response. 909 4. A 200 response to a CoAP 2.03 occurs only when the HC proxy, for 910 efficiency reasons, is caching resources and translated a HTTP 911 request (without conditional request) to a CoAP request that 912 includes ETag validation. The proxy receiving 2.03 updates the 913 freshness of its cached representation and returns the entire 914 representation to the HTTP client. 916 5. A HTTP 401 Unauthorized (Section 3.1 of [RFC7235]) response MUST 917 include a WWW-Authenticate header. Since there is no CoAP 918 equivalent of WWW-Authenticate, the HC proxy must generate this 919 header itself including at least one challenge (Section 4.1 of 920 [RFC7235]). If the HC proxy does not implement a proper 921 authentication method that can be used to gain access to the 922 target CoAP resource, it can include a 'dummy' challenge for 923 example "WWW-Authenticate: None". 925 6. A proxy receiving 4.02 may first retry the request with less CoAP 926 Options in the hope that the CoAP server will understand the 927 newly formulated request. For example, if the proxy tried using 928 a Block Option [I-D.ietf-core-block] which was not recognised by 929 the CoAP server it may retry without that Block Option. Note 930 that HTTP 402 MUST NOT be returned because it is reserved for 931 future use [RFC7231]. 933 7. HTTP code 405 (Method Not Allowed) MUST include an "Allow" 934 response-header field (Section 7.4.1 of [RFC7231]). However, a 935 CoAP response does not include information about which methods 936 are allowed on the resource. Therefore, if the proxy does not 937 have further information about which methods are allowed on the 938 resource it SHOULD include an empty field value in the Allow 939 header field. The intended interpretation of an empty Allow in 940 this case is "resource temporarily allows no methods" which 941 complies fully to [RFC7231]. 943 8. The value of the HTTP "Retry-After" response-header field is 944 taken from the value of the CoAP Max-Age Option, if present. 946 9. This CoAP response can only happen if the proxy itself is 947 configured to use a CoAP forward-proxy (Section 5.7 of [RFC7252]) 948 to execute some, or all, of its CoAP requests. 950 8. Additional Mapping Guidelines 952 8.1. Caching and Congestion Control 954 An HC proxy SHOULD limit the number of requests to CoAP servers by 955 responding, where applicable, with a cached representation of the 956 resource. 958 Duplicate idempotent pending requests by an HC proxy to the same CoAP 959 resource SHOULD in general be avoided, by using the same response for 960 multiple requesting HTTP clients without duplicating the CoAP 961 request. 963 If the HTTP client times out and drops the HTTP session to the HC 964 proxy (closing the TCP connection) after the HTTP request was made, 965 an HC proxy SHOULD wait for the associated CoAP response and cache it 966 if possible. Further requests to the HC proxy for the same resource 967 can use the result present in cache, or, if a response has still to 968 come, the HTTP requests will wait on the open CoAP request. 970 According to [RFC7252], a proxy MUST limit the number of outstanding 971 interactions to a given CoAP server to NSTART. To limit the amount 972 of aggregate traffic to a constrained network, the HC proxy SHOULD 973 also pose a limit to the number of concurrent CoAP requests pending 974 on the same constrained network; further incoming requests MAY either 975 be queued or dropped (returning 503 Service Unavailable). This limit 976 and the proxy queueing/dropping behavior SHOULD be configurable. In 977 order to effectively apply above congestion control, the HC proxy 978 should be server-side placed. 980 Resources experiencing a high access rate coupled with high 981 volatility MAY be observed [I-D.ietf-core-observe] by the HC proxy to 982 keep their cached representation fresh while minimizing the number of 983 CoAP traffic in the constrained network. See Section 8.2. 985 8.2. Cache Refresh via Observe 987 There are cases where using the CoAP observe protocol 988 [I-D.ietf-core-observe] to handle proxy cache refresh is preferable 989 to the validation mechanism based on ETag as defined in [RFC7252]. 990 Such scenarios include, but are not limited to, sleepy CoAP nodes -- 991 with possibly high variance in requests' distribution -- which would 992 greatly benefit from a server driven cache update mechanism. Ideal 993 candidates for CoAP observe are also crowded or very low throughput 994 networks, where reduction of the total number of exchanged messages 995 is an important requirement. 997 This subsection aims at providing a practical evaluation method to 998 decide whether the refresh of a cached resource R is more efficiently 999 handled via ETag validation or by establishing an observation on R. 1001 Let T_R be the mean time between two client requests to resource R, 1002 let T_C be the mean time between two representation changes of R, and 1003 let M_R be the mean number of CoAP messages per second exchanged to 1004 and from resource R. If we assume that the initial cost for 1005 establishing the observation is negligible, an observation on R 1006 reduces M_R iff T_R < 2*T_C with respect to using ETag validation, 1007 that is iff the mean arrival rate of requests for resource R is 1008 greater than half the change rate of R. 1010 When observing the resource R, M_R is always upper bounded by 2/T_C. 1012 8.3. Use of CoAP Blockwise Transfer 1014 An HC proxy SHOULD support CoAP blockwise transfers 1015 [I-D.ietf-core-block] to allow transport of large CoAP payloads while 1016 avoiding excessive link-layer fragmentation in constrained networks, 1017 and to cope with small datagram buffers in CoAP end-points as 1018 described in [RFC7252] Section 4.6. 1020 An HC proxy SHOULD attempt to retry a payload-carrying CoAP PUT or 1021 POST request with blockwise transfer if the destination CoAP server 1022 responded with 4.13 (Request Entity Too Large) to the original 1023 request. An HC proxy SHOULD attempt to use blockwise transfer when 1024 sending a CoAP PUT or POST request message that is larger than 1025 BLOCKWISE_THRESHOLD bytes. The value of BLOCKWISE_THRESHOLD is 1026 implementation-specific, for example it can be: 1028 o calculated based on a known or typical UDP datagram buffer size 1029 for CoAP end-points, or 1031 o set to N times the known size of a link-layer frame in a 1032 constrained network where e.g. N=5, or 1034 o preset to a known IP MTU value, or 1036 o set to a known Path MTU value. 1038 The value BLOCKWISE_THRESHOLD, or the parameters from which it is 1039 calculated, should be configurable in a proxy implementation. The 1040 maximum block size the proxy will attempt to use in CoAP requests 1041 should also be configurable. 1043 The HC proxy SHOULD detect CoAP end-points not supporting blockwise 1044 transfers by checking for a 4.02 (Bad Option) response returned by an 1045 end-point in response to a CoAP request with a Block* Option, and 1046 subsequent absence of the 4.02 in response to the same request 1047 without Block* Options. This allows the HC proxy to be more 1048 efficient, not attempting repeated blockwise transfers to CoAP 1049 servers that do not support it. However if a request payload is too 1050 large to be sent as a single CoAP request and blockwise transfer 1051 would be unavoidable, the proxy still SHOULD attempt blockwise 1052 transfer on such an end-point before returning the response 413 1053 (Request Entity Too Large) to the HTTP client. 1055 For improved latency an HC proxy MAY initiate a blockwise CoAP 1056 request triggered by an incoming HTTP request even when the HTTP 1057 request message has not yet been fully received, but enough data has 1058 been received to send one or more data blocks to a CoAP server 1059 already. This is particularly useful on slow client-to-proxy 1060 connections. 1062 8.4. Security Translation 1064 For the guidelines on security context translations for an HC proxy, 1065 see Section 10.2. A translation may involve e.g. applying a rule 1066 that any "https" request is translated to a "coaps" request, or e.g. 1067 applying a rule that a "https" request is translated to an unsecured 1068 "coap" request. 1070 8.5. CoAP Multicast 1072 An HC proxy MAY support CoAP multicast. If it does, the HC proxy 1073 sends out a multicast CoAP request if the Target CoAP URI's authority 1074 is a multicast IP literal or resolves to a multicast IP address; 1075 assuming the proper security measures are in place to mitigate 1076 security risks of CoAP multicast (Section 10). If the security 1077 policies do not allow the specific CoAP multicast request to be made, 1078 the HC proxy SHOULD respond 403 (Forbidden). 1080 If an HC proxy does not support CoAP multicast, it SHOULD respond 403 1081 (Forbidden) to any valid HTTP request that maps to a CoAP multicast 1082 request. 1084 However, details of supporting CoAP multicast are currently out of 1085 scope of this document since in a reverse proxy scenario a HTTP 1086 client typically expects to receive a single response, not multiple. 1087 However an HC proxy supporting CoAP multicast MAY include 1088 application-specific functions to aggregate multiple CoAP responses 1089 into a single HTTP response. We suggest using the "application/http" 1090 internet media type (Section 8.3.2 of [RFC7230]) to enclose a set of 1091 one or more HTTP response messages, each representing the mapping of 1092 one CoAP response. 1094 8.6. Timeouts 1096 When facing long delays of a CoAP server in responding, the HTTP 1097 client or any other proxy in between MAY timeout. Further discussion 1098 of timeouts in HTTP is available in Section 6.2.4 of [RFC7230]. 1100 An HC proxy MUST define an internal timeout for each pending CoAP 1101 request, because the CoAP server may silently die before completing 1102 the request. Assuming the Proxy may use confirmable CoAP requests, 1103 such timeout value T SHOULD be at least 1105 T = MAX_RTT + MAX_SERVER_RESPONSE_DELAY 1107 where MAX_RTT is defined in [RFC7252] and MAX_SERVER_RESPONSE_DELAY 1108 is defined in [RFC7390]. An exception to this rule occurs when the 1109 HC proxy is configured with a HTTP response timeout value that is 1110 lower than above value T; then the lower value should be also used as 1111 the CoAP request timeout. 1113 8.7. Miscellaneous 1115 In certain use cases, constrained CoAP nodes do not make use of the 1116 DNS protocol. However even when the DNS protocol is not used in a 1117 constrained network, defining valid FQDN (i.e., DNS entries) for 1118 constrained CoAP servers, where possible, may help HTTP clients to 1119 access the resources offered by these servers via an HC proxy. 1121 HTTP connection pipelining (section 6.3.2 of [RFC7230]) may be 1122 supported by an HC proxy. This is transparent to the CoAP servers: 1123 the HC proxy will serve the pipelined requests by issuing different 1124 CoAP requests. The HC proxy in this case needs to respect the NSTART 1125 limit of Section 4.7 of [RFC7252]. 1127 9. IANA Considerations 1129 This document registers a new Resource Type (rt=) Link Target 1130 Attribute, 'core.hc', in the "Resource Type (rt=) Link Target 1131 Attribute Values" subregistry under the "Constrained RESTful 1132 Environments (CoRE) Parameters" registry. 1134 Attribute Value: core.hc 1136 Description: HTTP to CoAP mapping base resource. 1138 Reference: See Section 5.4. 1140 10. Security Considerations 1142 The security concerns raised in Section 9.2 of [RFC7230] also apply 1143 to the HC proxy scenario. In fact, the HC proxy is a trusted (not 1144 rarely a transparently trusted) component in the network path. 1146 The trustworthiness assumption on the HC proxy cannot be dropped, 1147 because the protocol translation function is the core duty of the HC 1148 proxy: it is a necessarily trusted, impossible to bypass, component 1149 in the communication path. 1151 A reverse proxy deployed at the boundary of a constrained network is 1152 an easy single point of failure for reducing availability. As such, 1153 special care should be taken in designing, developing and operating 1154 it, keeping in mind that, in most cases, it has fewer limitations 1155 than the constrained devices it is serving. 1157 The following sub paragraphs categorize and discuss a set of specific 1158 security issues related to the translation, caching and forwarding 1159 functionality exposed by an HC proxy. 1161 10.1. Traffic Overflow 1163 Due to the typically constrained nature of CoAP nodes, particular 1164 attention SHOULD be given to the implementation of traffic reduction 1165 mechanisms (see Section 8.1), because inefficient proxy 1166 implementations can be targeted by unconstrained Internet attackers. 1167 Bandwidth or complexity involved in such attacks is very low. 1169 An amplification attack to the constrained network may be triggered 1170 by a multicast request generated by a single HTTP request which is 1171 mapped to a CoAP multicast resource, as considered in Section 11.3 of 1172 [RFC7252]. 1174 The risk likelihood of this amplification technique is higher than an 1175 amplification attack carried out by a malicious constrained device 1176 (e.g. ICMPv6 flooding, like Packet Too Big, or Parameter Problem on 1177 a multicast destination [RFC4732]), since it does not require direct 1178 access to the constrained network. 1180 The feasibility of this attack, disruptive in terms of CoAP server 1181 availability, can be limited by access controlling the exposed HTTP 1182 multicast resources, so that only known/authorized users access such 1183 URIs. 1185 10.2. Handling Secured Exchanges 1187 An HTTP request can be sent to the HC proxy over a secured 1188 connection. However, there may not always exist a secure connection 1189 mapping to CoAP. For example, a secure distribution method for 1190 multicast traffic is complex and MAY not be implemented (see 1191 [RFC7390]). 1193 An HC proxy SHOULD implement explicit rules for security context 1194 translations. A translation may involve e.g. applying a rule that 1195 any "https" unicast request is translated to a "coaps" request, or 1196 e.g. applying a rule that a "https" request is translated to an 1197 unsecured "coap" request. Another rule could specify the security 1198 policy and parameters used for DTLS connections. Such rules will 1199 largely depend on the application and network context in which a 1200 proxy operates. These rules SHOULD be configurable in an HC proxy. 1202 If a policy for access to 'coaps' URIs is configurable in an HC 1203 proxy, it is RECOMMENDED that the policy is by default configured to 1204 disallow access to any 'coaps' URI by a HTTP client using an 1205 unsecured (non-TLS) connection. Naturally, a user MAY reconfigure 1206 the policy to allow such access in specific cases. 1208 By default, an HC proxy SHOULD reject any secured client request if 1209 there is no configured security policy mapping. This recommendation 1210 MAY be relaxed in case the destination network is believed to be 1211 secured by other, complementary, means. E.g.: assumed that CoAP 1212 nodes are isolated behind a firewall (e.g. as in the SS HC proxy 1213 deployment shown in Figure 1), the HC proxy may be configured to 1214 translate the incoming HTTPS request using plain CoAP (NoSec mode). 1216 The HTTP-CoAP URI mapping (defined in Section 5) MUST NOT map to HTTP 1217 a CoAP resource intended to be accessed exclusively in a secure 1218 manner. 1220 A secured connection that is terminated at the HC proxy, i.e., the 1221 proxy decrypts secured data locally, raises an ambiguity about the 1222 cacheability of the requested resource. The HC proxy SHOULD NOT 1223 cache any secured content to avoid any leak of secured information. 1224 However in some specific scenario, a security/efficiency trade-off 1225 could motivate caching secured information; in that case the caching 1226 behavior MAY be tuned to some extent on a per-resource basis. 1228 10.3. Proxy and CoAP Server Resource Exhaustion 1230 If the HC proxy implements the low-latency optimization of 1231 Section 8.3 intended for slow client-to-proxy connections, the Proxy 1232 may become vulnerable to a resource exhaustion attack. In this case 1233 an attacking client could initiate multiple requests using a 1234 relatively large message body which is (after an initial fast 1235 transfer) transferred very slowly to the Proxy. This would trigger 1236 the HC proxy to create state for a blockwise CoAP request per HTTP 1237 request, waiting for the arrival of more data over the HTTP/TCP 1238 connection. Such attacks can be mitigated in the usual ways for HTTP 1239 servers using for example a connection time limit along with a limit 1240 on the number of open TCP connections per IP address. 1242 10.4. URI Mapping 1244 The following risks related to the URI mapping described in Section 5 1245 and its use by HC proxies have been identified: 1247 DoS attack on the constrained/CoAP network. 1248 To mitigate, by default deny any Target CoAP URI whose authority 1249 is (or maps to) a multicast address. Then explicitly whitelist 1250 multicast resources/authorities that are allowed to be de- 1251 referenced. See also Section 8.5. 1253 Leaking information on the constrained/CoAP network resources and 1254 topology. 1255 To mitigate, by default deny any Target CoAP URI (especially 1256 /.well-known/core is a resource to be protected), and then 1257 explicit whitelist resources that are allowed to be seen from 1258 outside. 1260 Reduced privacy due to the mechanics of the URI mapping. 1261 The internal CoAP Target resource is totally transparent from 1262 outside. An HC proxy can mitigate by implementing a HTTPS-only 1263 interface, making the Target CoAP URI totally opaque to a passive 1264 attacker. 1266 11. Acknowledgements 1268 An initial version of Table 2 in Section 7 has been provided in 1269 revision -05 of [RFC7252]. Special thanks to Peter van der Stok for 1270 countless comments and discussions on this document, that contributed 1271 to its current structure and text. 1273 Thanks to Carsten Bormann, Zach Shelby, Michele Rossi, Nicola Bui, 1274 Michele Zorzi, Klaus Hartke, Cullen Jennings, Kepeng Li, Brian Frank, 1275 Peter Saint-Andre, Kerry Lynn, Linyi Tian, Dorothy Gellert, Francesco 1276 Corazza for helpful comments and discussions that have shaped the 1277 document. 1279 The research leading to these results has received funding from the 1280 European Community's Seventh Framework Programme [FP7/2007-2013] 1281 under grant agreement n. [251557]. 1283 12. References 1285 12.1. Normative References 1287 [I-D.ietf-core-block] 1288 Bormann, C. and Z. Shelby, "Blockwise transfers in CoAP", 1289 draft-ietf-core-block-16 (work in progress), October 2014. 1291 [I-D.ietf-core-observe] 1292 Hartke, K., "Observing Resources in CoAP", draft-ietf- 1293 core-observe-16 (work in progress), December 2014. 1295 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1296 Requirement Levels", BCP 14, RFC 2119, March 1997. 1298 [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform 1299 Resource Identifier (URI): Generic Syntax", STD 66, RFC 1300 3986, January 2005. 1302 [RFC6570] Gregorio, J., Fielding, R., Hadley, M., Nottingham, M., 1303 and D. Orchard, "URI Template", RFC 6570, March 2012. 1305 [RFC6690] Shelby, Z., "Constrained RESTful Environments (CoRE) Link 1306 Format", RFC 6690, August 2012. 1308 [RFC7230] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol 1309 (HTTP/1.1): Message Syntax and Routing", RFC 7230, June 1310 2014. 1312 [RFC7231] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol 1313 (HTTP/1.1): Semantics and Content", RFC 7231, June 2014. 1315 [RFC7235] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol 1316 (HTTP/1.1): Authentication", RFC 7235, June 2014. 1318 [RFC7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 1319 Application Protocol (CoAP)", RFC 7252, June 2014. 1321 12.2. Informative References 1323 [I-D.bormann-core-links-json] 1324 Bormann, C., "Representing CoRE Link Collections in JSON", 1325 draft-bormann-core-links-json-02 (work in progress), 1326 February 2013. 1328 [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., 1329 Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext 1330 Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. 1332 [RFC3040] Cooper, I., Melve, I., and G. Tomlinson, "Internet Web 1333 Replication and Caching Taxonomy", RFC 3040, January 2001. 1335 [RFC4732] Handley, M., Rescorla, E., and IAB, "Internet Denial-of- 1336 Service Considerations", RFC 4732, December 2006. 1338 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 1339 Representation (CBOR)", RFC 7049, October 2013. 1341 [RFC7390] Rahman, A. and E. Dijk, "Group Communication for the 1342 Constrained Application Protocol (CoAP)", RFC 7390, 1343 October 2014. 1345 Appendix A. Change Log 1347 [Note to RFC Editor: Please remove this section before publication.] 1349 Changes from ietf-05 to ietf-06: 1351 o Fully restructured the draft, bringing introductory text more to 1352 the front and allocating main sections to each of the key topics; 1353 addressing Ticket #379; 1355 o Addressed Ticket #382, fix of enhanced form URI template 1356 definition of q in Section 5.3.2; 1358 o Addressed Ticket #381, found a mapping 4.01 to 401 Unauthorized in 1359 Section 7; 1361 o Addressed Ticket #380 (Add IANA registration for "core.hc" 1362 Resource Type) in Section 9; 1364 o Addressed Ticket #376 (CoAP 4.05 response can't be translated to 1365 HTTP 405 by HC proxy) in Section 7 by use of empty 'Allow' header; 1367 o Removed details on the pros and cons of HC proxy placement 1368 options; 1370 o Addressed review comments of Carsten Bormann; 1372 o Clarified failure in mapping of HTTP Accept headers (Section 6.3); 1374 o Clarified detection of CoAP servers not supporting blockwise 1375 (Section 8.3); 1377 o Changed CoAP request timeout min value to MAX_RTT + 1378 MAX_SERVER_RESPONSE_DELAY (Section 8.6); 1380 o Added security section item (Section 10.3) related to use of CoAP 1381 blockwise transfers; 1383 o Many editorial improvements. 1385 Changes from ietf-04 to ietf-05: 1387 o Addressed Ticket #366 (Mapping of CoRE Link Format payloads to be 1388 valid in HTTP Domain?) in Section 6.3.3.2 (Content Transcoding - 1389 CORE Link Format); 1391 o Addressed Ticket #375 (Add requirement on mapping of CoAP 1392 diagnostic payload) in Section 6.3.3.3 (Content Transcoding - 1393 Diagnostic Messages); 1395 o Addressed comment from Yusuke (http://www.ietf.org/mail- 1396 archive/web/core/current/msg05491.html) in Section 6.3.3.1 1397 (Content Transcoding - General); 1399 o Various editorial improvements. 1401 Changes from ietf-03 to ietf-04: 1403 o Expanded use case descriptions in Section 4; 1405 o Fixed/enhanced discovery examples in Section 5.4.1; 1407 o Addressed Ticket #365 (Add text on media type conversion by HTTP- 1408 CoAP proxy) in new Section 6.3.1 (Generalized media type mapping) 1409 and new Section 6.3.2 (Content translation); 1411 o Updated HTTPBis WG draft references to recently published RFC 1412 numbers. 1414 o Various editorial improvements. 1416 Changes from ietf-02 to ietf-03: 1418 o Closed Ticket #351 "Add security implications of proposed default 1419 HTTP-CoAP URI mapping"; 1421 o Closed Ticket #363 "Remove CoAP scheme in default HTTP-CoAP URI 1422 mapping"; 1424 o Closed Ticket #364 "Add discovery of HTTP-CoAP mapping 1425 resource(s)". 1427 Changes from ietf-01 to ietf-02: 1429 o Selection of single default URI mapping proposal as proposed to WG 1430 mailing list 2013-10-09. 1432 Changes from ietf-00 to ietf-01: 1434 o Added URI mapping proposals to Section 4 as per the Email 1435 proposals to WG mailing list from Esko. 1437 Authors' Addresses 1439 Angelo P. Castellani 1440 University of Padova 1441 Via Gradenigo 6/B 1442 Padova 35131 1443 Italy 1445 Email: angelo@castellani.net 1447 Salvatore Loreto 1448 Ericsson 1449 Hirsalantie 11 1450 Jorvas 02420 1451 Finland 1453 Email: salvatore.loreto@ericsson.com 1454 Akbar Rahman 1455 InterDigital Communications, LLC 1456 1000 Sherbrooke Street West 1457 Montreal H3A 3G4 1458 Canada 1460 Phone: +1 514 585 0761 1461 Email: Akbar.Rahman@InterDigital.com 1463 Thomas Fossati 1464 Alcatel-Lucent 1465 3 Ely Road 1466 Milton, Cambridge CB24 6DD 1467 UK 1469 Email: thomas.fossati@alcatel-lucent.com 1471 Esko Dijk 1472 Philips Research 1473 High Tech Campus 34 1474 Eindhoven 5656 AE 1475 The Netherlands 1477 Email: esko.dijk@philips.com