CoRE Working Group A. Castellani Internet-Draft University of Padova Intended status: Informational S. Loreto Expires: August 16, 2014 Ericsson A. Rahman InterDigital Communications, LLC T. Fossati Alcatel-Lucent E. Dijk Philips Research February 12, 2014 Guidelines for HTTP-CoAP Mapping Implementations draft-ietf-core-http-mapping-03 Abstract This draft provides reference information for HTTP-CoAP protocol translation proxy implementors, focusing primarily on the reverse proxy case. It details deployment options, defines a safe method for URI mapping, and provides a set of guidelines and considerations related to protocol translation. Status of This Memo This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet- Drafts is at http://datatracker.ietf.org/drafts/current/. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." This Internet-Draft will expire on August 16, 2014. Copyright Notice Copyright (c) 2014 IETF Trust and the persons identified as the document authors. All rights reserved. This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents Castellani, et al. Expires August 16, 2014 [Page 1] Internet-Draft HTTP-CoAP Mapping February 2014 (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Table of Contents 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 3 3. Cross-Protocol Usage of URIs . . . . . . . . . . . . . . . . 4 4. Use Cases . . . . . . . . . . . . . . . . . . . . . . . . . . 5 5. URI Mapping . . . . . . . . . . . . . . . . . . . . . . . . . 5 5.1. Terminology . . . . . . . . . . . . . . . . . . . . . . . 6 5.2. Default Mapping . . . . . . . . . . . . . . . . . . . . . 6 5.2.1. Optional scheme . . . . . . . . . . . . . . . . . . . 7 5.2.2. Encoding Caveats . . . . . . . . . . . . . . . . . . 7 5.3. URI Mapping Template . . . . . . . . . . . . . . . . . . 7 5.3.1. Simple Form . . . . . . . . . . . . . . . . . . . . . 8 5.3.2. Enhanced Form . . . . . . . . . . . . . . . . . . . . 10 5.4. Discovery . . . . . . . . . . . . . . . . . . . . . . . . 11 5.4.1. Examples . . . . . . . . . . . . . . . . . . . . . . 11 6. HTTP-CoAP Reverse Proxy . . . . . . . . . . . . . . . . . . . 12 6.1. Proxy Placement . . . . . . . . . . . . . . . . . . . . . 13 6.2. Response Code Translations . . . . . . . . . . . . . . . 14 6.3. Media Type Translations . . . . . . . . . . . . . . . . . 16 6.4. Caching and Congestion Control . . . . . . . . . . . . . 17 6.5. Cache Refresh via Observe . . . . . . . . . . . . . . . . 18 6.6. Use of CoAP Blockwise Transfer . . . . . . . . . . . . . 18 6.7. Security Translation . . . . . . . . . . . . . . . . . . 19 6.8. Other guidelines . . . . . . . . . . . . . . . . . . . . 19 7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 20 8. Security Considerations . . . . . . . . . . . . . . . . . . . 20 8.1. Traffic overflow . . . . . . . . . . . . . . . . . . . . 21 8.2. Handling Secured Exchanges . . . . . . . . . . . . . . . 21 8.3. URI Mapping . . . . . . . . . . . . . . . . . . . . . . . 22 9. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 22 10. References . . . . . . . . . . . . . . . . . . . . . . . . . 22 10.1. Normative References . . . . . . . . . . . . . . . . . . 23 10.2. Informative References . . . . . . . . . . . . . . . . . 24 Appendix A. Change Log . . . . . . . . . . . . . . . . . . . . . 24 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 24 1. Introduction Castellani, et al. Expires August 16, 2014 [Page 2] Internet-Draft HTTP-CoAP Mapping February 2014 CoAP [I-D.ietf-core-coap] has been designed with the twofold aim to be an application protocol specialized for constrained environments and to be easily used in REST architectures such as the Web. The latter goal has led to define CoAP to easily interoperate with HTTP [RFC2616] through an intermediary proxy which performs cross-protocol conversion. Section 10 of [I-D.ietf-core-coap] describes the fundamentals of the CoAP-to-HTTP and the HTTP-to-CoAP cross-protocol mapping process. However, implementing such a cross-protocol proxy can be complex, and many details regarding its internal procedures and design choices require further elaboration. Therefore a first goal of this document is to provide more detailed information to proxy designers and implementers, to help implement proxies that correctly inter-work with other CoAP and HTTP client/server implementations that adhere to the HTTP and CoAP specifications. The second goal of this informational document is to define a consistent set of guidelines that a HTTP-to-CoAP proxy implementation MAY adhere to. The main reason of adhering to such guidelines is to reduce variation between proxy implementations, thereby increasing interoperability. (As an example use case, a proxy conforming to these guidelines made by vendor A can be easily replaced by a proxy from vendor B that also conforms to the guidelines.) This draft is organized as follows: o Section 2 describes terminology to identify proxy types, mapping approaches and proxy deployments; o Section 3 discusses how URIs refer to resources independent of access protocols; o Section 4 briefly lists use cases in which HTTP clients need to contact CoAP servers; o Section 5 introduces a default HTTP-to-CoAP URI mapping syntax; o Section 6 analyzes the mapping that allows HTTP clients to contact CoAP servers; o Section 8 discusses possible security impact related to HTTP-CoAP cross-protocol mapping. 2. Terminology This document assumes readers are familiar with the terms Reverse Proxy as defined in [I-D.ietf-httpbis-p1-messaging] and Interception Castellani, et al. Expires August 16, 2014 [Page 3] Internet-Draft HTTP-CoAP Mapping February 2014 Proxy as defined in [RFC3040]. In addition, the following terms are defined: Cross-Protocol Proxy (or Cross Proxy): is a proxy performing a cross- protocol mapping, in the context of this document a HTTP-CoAP (HC) mapping. A Cross-Protocol Proxy can behave as a Forward Proxy, Reverse Proxy or Interception Proxy. Note: In this document we focus on the Reverse Proxy mode of the Cross-Protocol Proxy. Forward Proxy: a message forwarding agent that is selected by the client, usually via local configuration rules, to receive requests for some type(s) of absolute URI and to attempt to satisfy those requests via translation to the protocol indicated by the absolute URI. The user decides (is willing to) use the proxy as the forwarding/dereferencing agent for a predefined subset of the URI space. Reverse Proxy: a receiving agent that acts as a layer above some other server(s) and translates the received requests to the underlying server's protocol. It behaves as an origin (HTTP) server on its connection towards the (HTTP) client and as a (CoAP) client on its connection towards the (CoAP) origin server. The (HTTP) client uses the "origin-form" [I-D.ietf-httpbis-p1-messaging] as a request- target URI. Reverse and Forward proxies are technically very similar, with main differences being that the former appears to a client as an origin server while the latter does not, and that clients may be unaware they are communicating with a proxy. Placement terms: a server-side (SS) proxy is placed in the same network domain as the server; conversely a client-side (CS) proxy is in the same network domain as the client. In any other case than SS or CS, the proxy is said to be External (E). The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119]. 3. Cross-Protocol Usage of URIs A Uniform Resource Identifier (URI) provides a simple and extensible method for identifying a resource. It enables uniform identification of resources via a separately defined extensible set of naming schemes [RFC3986]. Castellani, et al. Expires August 16, 2014 [Page 4] Internet-Draft HTTP-CoAP Mapping February 2014 URIs are formed of at least three components: scheme, authority and path. The scheme often corresponds to the protocol used to access the resource. However, as noted in Section 1.2.2 of [RFC3986] the scheme does not imply that a particular protocol is used to access the resource. So, we can define the same resource to be accessible by different protocols i.e. the resource can have cross-protocol URIs referring to it. HTTP clients typically only support 'http' and 'https' schemes. Therefore, they cannot directly access CoAP servers (which support 'coap' and/or 'coaps'). In this situation, communication is enabled by a Cross-Protocol Proxy, as shown in Figure 1, supporting URI mapping features. Such features are discussed in Section 5. 4. Use Cases To illustrate in which situations HTTP to CoAP request mapping may be used, three use cases are briefly described. 1. Smartphone and home sensor: A smartphone, when at home, can perform 'coap' requests directly to a home sensor via WiFi. When the smartphone is away from home, the same request is done by an authenticated 'https' request over an external IP network to the home router. The home router contains a HTTP-CoAP proxy. 2. Legacy building control application without CoAP: A building control application can use HTTP, but not CoAP. It checks the status of sensors or actuators via a HTTP-CoAP proxy. 3. Making sensor data available to 3rd parties: For demonstration or public interest purposes, a HTTP-CoAP proxy may be configured to expose the contents of a sensor to the world via the web (HTTP and/or HTTPS). The sensor can only handle secure 'coaps' requests, therefore the proxy is configured to translate any request to a 'coaps' secured request. The proxy is furthermore configured to only pass through GET requests. 5. URI Mapping Though, in principle, a CoAP URI could be directly used by a HTTP user agent to de-reference a CoAP resource through a HC Proxy, the reality is that all major web browsers and command line tools do not allow making HTTP requests using URIs with a scheme different from "http" or "https". Thus, there is a need for web applications to "pack" a CoAP URI into a HTTP URI so that it can be (non-destructively) transported from the user agent to the HC Proxy. The HC Proxy can then "unpack" the CoAP Castellani, et al. Expires August 16, 2014 [Page 5] Internet-Draft HTTP-CoAP Mapping February 2014 URI and finally de-reference it via a CoAP request to the target Server. URI Mapping is the process through which the URI of a CoAP resource is transformed in to an HTTP URI so that: o the requesting HTTP user agent can handle it; o the receiving HC Proxy can extract the intended CoAP URI unambiguously. To this end, the remainder of this section will identify: o the default mechanism to map a CoAP URI into a HTTP URI; o the URI template format to express a class of CoAP-HTTP URI mapping functions; o the discovery mechanism based on [RFC6690] through which clients of a HC Proxy can dynamically discover information about the supported URI Mapping Template(s), as well as the base URI where the HC Proxy function is anchored. 5.1. Terminology In the remainder, the following terms will be used with a distinctive meaning: Target CoAP URI: URI which refers to the (final) CoAP resource that has to be de-referenced. It conforms to syntax defined in section 6. of [I-D.ietf-core-coap]. Specifically, it has a scheme of "coap" or "coaps". Hosting HTTP URI: URI that conforms to syntax in section 2.7 of [I-D.ietf-httpbis-p1-messaging]. Its authority component refers to an HC Proxy, whereas path (and query) component(s) embed the information used by an HC Proxy to extract the Target CoAP URI. 5.2. Default Mapping The default is for the Target CoAP URI to be appended as-is to a base URI provided by the HC Proxy to form the Hosting HTTP URI. Castellani, et al. Expires August 16, 2014 [Page 6] Internet-Draft HTTP-CoAP Mapping February 2014 For example: given a base URI http://p.example.com/hc and a Target CoAP URI coap://s.example.com/light, the resulting Hosting HTTP URI would be http://p.example.com/hc/coap://s.example.com/light. Provided a correct Target CoAP URI, the Hosting HTTP URI resulting from the default mapping is always syntactically correct. Furthermore, the Target CoAP URI can always be extracted in an unambiguous way from the Hosting HTTP URI. Also worth noting that, using the default mapping, a query component in the target CoAP resource URI is naturally encoded into the query component of the Hosting URI, e.g.: coap://s.example.com/light?dim=5 becomes http:// p.example.com/hc/coap://s.example.com/light?dim=5. There is no default for the base URI. Therefore it is either known in advance, e.g. as a configuration preset, or dynamically discovered using the mechanism described in Section 5.4. The default URI mapping function is RECOMMENDED to be implemented and activated by default in a HC Proxy, unless there are valid reasons, e.g. application specific, to use a different mapping function. 5.2.1. Optional scheme When found in a Hosting HTTP URI, the scheme (i.e. "coap" or "coaps"), the scheme component delimiter (":"), and the double slash ("//") preceding the authority MAY be omitted. In such case, a local default - not defined by this document - applies. So, http://p.example.com/hc/s.coap.example.com/foo could either represent the target coap://s.coap.example.com/foo or coaps:// s.coap.example.com/foo depending on application specific presets. 5.2.2. Encoding Caveats When the authority of the Target CoAP URI is given as an IPv6address, then the surrounding square brackets MUST be percent-encoded in the Hosting HTTP URI, in order to comply with the syntax defined in Section 3.3. of [RFC3986] for a URI path segment. E.g.: coap:// [2001:db8::1]/light?on becomes http://p.example.com/hc/coap:// %5B2001:db8::1%5D/light?on. Everything else can be safely copied verbatim from the Target CoAP URI to the Hosting HTTP URI. 5.3. URI Mapping Template Castellani, et al. Expires August 16, 2014 [Page 7] Internet-Draft HTTP-CoAP Mapping February 2014 This section defines a format for the URI template used by a HC Proxy to inform its clients about the expected syntax for the Hosting HTTP URI. When instantiated, an URI Mapping Template is always concatenated to a base URI provided by the HC Proxy via discovery (see Section 5.4), or by other means. A simple form (Section 5.3.1) and an enhanced form (Section 5.3.2) are provided to fit different users' requirements. Both forms are expressed as level 2 URI template's to take care of the expansion of values that are allowed to include reserved URI characters. 5.3.1. Simple Form The simple form MUST be used for mappings where the Target CoAP URI is going to be copied verbatim at some fixed position into the Hosting HTTP URI. The following template variables MUST be used in mutual exclusion in a template definition: cu = coap-URI ; from [I-D.ietf-core-coap], Section 6.1 su = coaps-URI ; from [I-D.ietf-core-coap], Section 6.2 tu = cu / su The same considerations done in Section 5.2.1 apply. 5.3.1.1. Examples All the following examples (given as a specific URI mapping template, a Target CoAP URI, and the produced Hosting HTTP URI) use http:// p.example.com/hc as the base URI. 1. "coap" URI is a query argument of the Hosting HTTP URI: ?coap_target_uri={+cu} coap://s.example.com/light http://p.example.com/hc?coap_target_uri=coap://s.example.com/light 2. "coaps" URI is a query argument of the Hosting HTTP URI: Castellani, et al. Expires August 16, 2014 [Page 8] Internet-Draft HTTP-CoAP Mapping February 2014 ?coaps_target_uri={+su} coaps://s.example.com/light http://p.example.com/hc?coaps_target_uri=coaps://s.example.com/light 3. Target CoAP URI as a query argument of the Hosting HTTP URI: ?target_uri={+tu} coap://s.example.com/light http://p.example.com/hc?target_uri=coap://s.example.com/light or coaps://s.example.com/light http://p.example.com/hc?target_uri=coaps://s.example.com/light 4. Target CoAP URI in the path component of the Hosting HTTP URI (i.e. the default URI Mapping template): /{+tu} coap://s.example.com/light http://p.example.com/hc/coap://s.example.com/light or coaps://s.example.com/light http://p.example.com/hc/coaps://s.example.com/light Castellani, et al. Expires August 16, 2014 [Page 9] Internet-Draft HTTP-CoAP Mapping February 2014 5.3.2. Enhanced Form The enhanced form can be used to express more sophisticated mappings, i.e. those that do not fit into the simple form. There MUST be at most one instance of each of the following template variables in a template definition: s = "coap" / "coaps" ; from [I-D.ietf-core-coap], Sections 6.1 and 6.2 hp = host [":" port] ; from [RFC3986] Sections 3.2.2 and 3.2.3 p = path-abempty ; from [RFC3986] Section 3.3. q = [ "?" query ] ; from [RFC3986] Section 3.4 5.3.2.1. Examples All the following examples (given as a specific URI mapping template, a Target CoAP URI, and the produced Hosting HTTP URI) use http:// p.example.com/hc as the base URI. 1. Target CoAP URI components in path segments, and optional query in query component: {+s}{+hp}{+p}{+q} coap://s.example.com/light http://p.example.com/hc/coap/s.example.com/light or coap://s.example.com/light?on http://p.example.com/hc/coap/s.example.com/light?on 2. Target CoAP URI components split in individual query arguments: ?s={+s}&hp={+hp}&p={+p}&q={+q} coap://s.example.com/light http://p.example.com/hc?s=coap&hp=s.example.com&p=/light&q or coaps://s.example.com/light?on Castellani, et al. Expires August 16, 2014 [Page 10] Internet-Draft HTTP-CoAP Mapping February 2014 http://p.example.com/hc?s=coaps&hp=s.example.com&p=/light&q=on 5.4. Discovery In order to accommodate site specific needs while allowing third parties to discover the proxy function, the HC Proxy SHOULD publish information related to the location and syntax of the HC Proxy function using the CoRE Link Format [RFC6690] interface. To this aim a new Resource Type, "core.hc", is associated with a base URI, and can be used as the value for the "rt" attribute in a query to the /.well-known/core in order to locate the base URI where the HC Proxy function is anchored. Along with it, the new target attribute "hct" MAY be returned in a "core.hc" link to provide the associated URI Mapping Template. The default template given in Section 5.2, i.e. {+tu}, MUST be assumed if no "hct" attribute is found in the returned link. If an "htc" attribute is present in the returned link, then a compliant client MUST use it to create the Hosting HTTP URI. Discovery SHOULD be available on both the HTTP and the CoAP side of the HC proxy, with one important difference: on the CoAP side the link associated to the "core.hc" resource is returned as an absolute- URI referencing the HTTP interface, while on the HTTP interface it is returned as a reference relative to the HC Proxy origin. 5.4.1. Examples o The first example exercises the CoAP interface, and assumes that the default template, {+tu}, is used: Req: GET coap://[ff02::1]/.well-known/core?rt=core.hc Res: 2.05 Content ;rt="core.hc" o The second example - also on the CoAP side of the HC Proxy - uses a custom template, i.e. one where the CoAP URI is carried inside the query component, thus the returned link carries the URI template to be used in an explicit "hct" attribute: Castellani, et al. Expires August 16, 2014 [Page 11] Internet-Draft HTTP-CoAP Mapping February 2014 Req: GET coap://[ff02::1]/.well-known/core?rt=core.hc Res: 2.05 Content ;rt="core.hc";hct="?uri={+tu}" On the HTTP side there exist two alternatives to transport the link information: o one uses the 'application/link-format' content type and returning the link in the response body: Req: GET http://p.example.com/.well-known/core?rt=core.hc Res: 200 OK Content-Type: application/link-format Content-Length: 18 ;rt="core.hc" o the other uses the Link header to encode the link information: Req: GET http://p.example.com/.well-known/core?rt=core.hc Res: 200 OK Link: ;rt="core.hc" o An HC Proxy may expose two different base URIs to differentiate between Target CoAP resources in the "coap" and "coaps" scheme: Req: GET http://p.example.com/.well-known/core?rt=core.hc Res: 200 OK Link: ;rt="core.hc";htc="{+cu}" Link: ;rt="core.hc";htc="{+su}" 6. HTTP-CoAP Reverse Proxy Castellani, et al. Expires August 16, 2014 [Page 12] Internet-Draft HTTP-CoAP Mapping February 2014 A HTTP-CoAP Reverse Cross-Protocol Proxy is accessed by web clients only supporting HTTP, and handles their requests by mapping these to CoAP requests, which are forwarded to CoAP servers; and mapping back the received CoAP responses to HTTP. This mechanism is transparent to the client, which may assume that it is communicating with the intended target HTTP server. In other words, the client accesses the proxy as an origin server using the "origin-form" [I-D.ietf-httpbis-p1-messaging] as a Request Target. Normative requirements on the translation of HTTP requests to CoAP and of the CoAP responses back to HTTP responses are defined in Section 10.2 of [I-D.ietf-core-coap]. However, that section only considers the case of a HTTP-CoAP Forward Cross-Protocol Proxy in which a client explicitly indicates it targets a request to a CoAP server, and does not cover all aspects of proxy implementation in detail. The present section provides guidelines and more details for the implementation of a Reverse Cross-Protocol Proxy, which MAY be followed in addition to the normative requirements. Translation of unicast HTTP requests into multicast CoAP requests is currently out of scope since in a reverse proxy scenario a HTTP client typically expects to receive a single response, not multiple. However a Cross-Protocol Proxy MAY include custom application- specific functions to generate a multicast CoAP request based on a unicast HTTP request and aggregate multiple CoAP responses into a single HTTP response. Note that the guidelines in this section also apply to an HTTP-CoAP Intercepting Cross-Protocol Proxy. 6.1. Proxy Placement Typically, a Cross-Protocol Proxy is located at the edge of the constrained network. See Figure 1. The arguments supporting server- side (SS) placement are the following: Caching: Efficient caching requires that all request traffic to a CoAP server is handled by the same proxy which receives HTTP requests from multiple source locations. This maximally reduces the load on (constrained) CoAP servers. Multicast: To support CoAPs use of local-multicast functionality available in a constrained network, the Cross-Protocol Proxy requires a network interface directly attached to the constrained network. TCP/UDP: Translation between HTTP and CoAP requires also TCP/UDP translation; TCP may be the preferred way for communicating with Castellani, et al. Expires August 16, 2014 [Page 13] Internet-Draft HTTP-CoAP Mapping February 2014 the constrained network due to its reliability or due to intermediate gateways configured to block UDP traffic. Arguments against SS placement, in favor of client-side (CS), are: Scalability: A solution where a single SS proxy has to manage numerous open TCP/IP connections to a large number of HTTP clients is not scalable. (Unless multiple SS proxies are employed with a load-balancing mechanism, which adds complexity.) +------+ | | | DNS | | | +------+ Constrained Network -------------------- / \ / /-----\ /-----\ \ / CoAP CoAP \ / server server \ || \-----/ \-----/ || +------+ HTTP Request +----------+ || |HTTP |------------------------>| HTTP-CoAP| Req /-----\ || |Client| | Cross- |------->| CoAP || | |<------------------------| Proxy |<-------|server || +------+ HTTP Response +----------+ Resp \-----/ || || || || /-----\ || || CoAP || \ server / \ \-----/ / \ /-----\ / \ CoAP / \ server / \ \-----/ / ---------------- Figure 1: Reverse Cross-Protocol Proxy Deployment Scenario 6.2. Response Code Translations Table 1 defines all possible CoAP responses along with the HTTP response to which each CoAP response SHOULD be translated. This table complies with the Section 10.2 requirements of [I-D.ietf-core-coap] and is intended to cover all possible cases. Multiple appearances of a HTTP status code in the second column Castellani, et al. Expires August 16, 2014 [Page 14] Internet-Draft HTTP-CoAP Mapping February 2014 indicates multiple equivalent HTTP responses are possible, depending on the conditions cited in the Notes (third column). +----------------------------+----------------------------+---------+ | CoAP Response Code | HTTP Status Code | Notes | +----------------------------+----------------------------+---------+ | 2.01 Created | 201 Created | 1 | | 2.02 Deleted | 200 OK | 2 | | | 204 No Content | 2 | | 2.03 Valid | 304 Not Modified | 3 | | | 200 OK | 4 | | 2.04 Changed | 200 OK | 2 | | | 204 No Content | 2 | | 2.05 Content | 200 OK | | | 4.00 Bad Request | 400 Bad Request | | | 4.01 Unauthorized | 400 Bad Request | 5 | | 4.02 Bad Option | 400 Bad Request | 6 | | 4.03 Forbidden | 403 Forbidden | | | 4.04 Not Found | 404 Not Found | | | 4.05 Method Not Allowed | 400 Bad Request | 7 | | 4.06 Not Acceptable | 406 Not Acceptable | | | 4.12 Precondition Failed | 412 Precondition Failed | | | 4.13 Request Entity Too | 413 Request Repr. Too | | | Large | Large | | | 4.15 Unsupported Media | 415 Unsupported Media Type | | | Type | | | | 5.00 Internal Server Error | 500 Internal Server Error | | | 5.01 Not Implemented | 501 Not Implemented | | | 5.02 Bad Gateway | 502 Bad Gateway | | | 5.03 Service Unavailable | 503 Service Unavailable | 8 | | 5.04 Gateway Timeout | 504 Gateway Timeout | | | 5.05 Proxying Not | 502 Bad Gateway | 9 | | Supported | | | +----------------------------+----------------------------+---------+ Table 1: HTTP-CoAP Response Mapping Notes: 1. A CoAP server may return an arbitrary format payload along with this response. This payload SHOULD be returned as entity in the HTTP 201 response. Section 7.3.2 of [I-D.ietf-httpbis-p2-semantics] does not put any requirement on the format of the payload. (In the past, [RFC2616] did.) 2. The HTTP code is 200 or 204 respectively for the case that a CoAP server returns a payload or not. [I-D.ietf-httpbis-p2-semantics] Section 5.3 requires code 200 in case a representation of the Castellani, et al. Expires August 16, 2014 [Page 15] Internet-Draft HTTP-CoAP Mapping February 2014 action result is returned for DELETE, POST and PUT and code 204 if not. Hence, a proxy SHOULD transfer any CoAP payload contained in a 2.02 response to the HTTP client in a 200 OK response. 3. A CoAP 2.03 (Valid) response only (1) confirms that the request ETag is valid and (2) provides a new Max-Age value. HTTP 304 (Not Modified) also updates some header fields of a stored response. A non-caching proxy may not have enough information to fill in the required values in the HTTP 304 (Not Modified) response, so it may not be advisable for a non-caching proxy to provoke the 2.03 (Valid) response by forwarding an ETag. A caching proxy will fill the information out of the cache. 4. A 200 response to a CoAP 2.03 occurs only when the proxy is caching and translated a HTTP request (without validation request) to a CoAP request that includes validation, for efficiency. The proxy receiving 2.03 updates the freshness of the cached representation and returns the entire representation to the HTTP client. 5. The HTTP code 401 Unauthorized MUST NOT be used, as long as in CoAP there is no equivalent defined of the required WWW- Authenticate header (Section 3.1 of [I-D.ietf-httpbis-p7-auth]). 6. In some cases a proxy receiving 4.02 may retry the request with less CoAP Options in the hope that the server will understand the newly formulated request. For example, if the proxy tried using a Block Option which was not recognized by the CoAP server it may retry without that Block Option. 7. The HTTP code "405 Method Not Allowed" MUST NOT be used since CoAP does not provide enough information to determine a value for the required "Allow" response-header field. 8. The value of the HTTP "Retry-After" response-header field is taken from the value of the CoAP Max-Age Option, if present. 9. This CoAP response can only happen if the proxy itself is configured to use a CoAP Forward Proxy to execute some, or all, of its CoAP requests. 6.3. Media Type Translations A Cross-Protocol Proxy translates a media type string, carried in a HTTP Content-Type header in a request, to a CoAP Content-Format Option with the equivalent numeric value. The media types supported by CoAP are defined in the CoAP Content-Format Registry. Any HTTP Castellani, et al. Expires August 16, 2014 [Page 16] Internet-Draft HTTP-CoAP Mapping February 2014 request with a Content-Type for which the proxy does not know an equivalent CoAP Content-Format number, MUST lead to HTTP response 415 (Unsupported Media Type). Also, a CoAP Content-Format value in a response is translated back to the equivalent HTTP Content-Type. If a proxy receives a CoAP Content-Format value that it does not recognize (e.g. because the value is IANA-registered after the proxy software was deployed), and is unable to look up the equivalent HTTP Content-Type on the fly, the proxy SHOULD return an HTTP entity (payload) without Content-Type header (complying to Section 3.1.1.5 of [I-D.ietf-httpbis-p2-semantics]). 6.4. Caching and Congestion Control A Cross-Protocol Proxy SHOULD limit the number of requests to CoAP servers by responding, where applicable, with a cached representation of the resource. Duplicate idempotent pending requests by a Cross-Protocol Proxy to the same CoAP resource SHOULD in general be avoided, by duplexing the response to the requesting HTTP clients without duplicating the CoAP request. If the HTTP client times out and drops the HTTP session to the Cross- Protocol Proxy (closing the TCP connection) after the HTTP request was made, a Cross-Protocol Proxy SHOULD wait for the associated CoAP response and cache it if possible. Further requests to the Cross- Protocol Proxy for the same resource can use the result present in cache, or, if a response has still to come, the HTTP requests will wait on the open CoAP session. According to [I-D.ietf-core-coap], a proxy MUST limit the number of outstanding interactions to a given CoAP server to NSTART. To limit the amount of aggregate traffic to a constrained network, the Cross- Protocol Proxy SHOULD also pose a limit to the number of concurrent CoAP requests pending on the same constrained network; further incoming requests MAY either be queued or dropped (returning 503 Service Unavailable). This limit and the proxy queueing/dropping behavior SHOULD be configurable. In order to efficiently apply this congestion control, the Cross-Protocol Proxy SHOULD be SS placed. Resources experiencing a high access rate coupled with high volatility MAY be observed [I-D.ietf-core-observe] by the Cross- Protocol Proxy to keep their cached representation fresh while minimizing the number CoAP messages. See Section 6.5. Castellani, et al. Expires August 16, 2014 [Page 17] Internet-Draft HTTP-CoAP Mapping February 2014 6.5. Cache Refresh via Observe There are cases where using the CoAP observe protocol [I-D.ietf-core-observe] to handle proxy cache refresh is preferable to the validation mechanism based on ETag as defined in [I-D.ietf-core-coap]. Such scenarios include, but are not limited to, sleepy nodes -- with possibly high variance in requests' distribution -- which would greatly benefit from a server driven cache update mechanism. Ideal candidates would also be crowded or very low throughput networks, where reduction of the total number of exchanged messages is an important requirement. This subsection aims at providing a practical evaluation method to decide whether the refresh of a cached resource R is more efficiently handled via ETag validation or by establishing an observation on R. Let T_R be the mean time between two client requests to resource R, let F_R be the freshness lifetime of R representation, and let M_R be the total number of messages exchanged towards resource R. If we assume that the initial cost for establishing the observation is negligible, an observation on R reduces M_R iff T_R < 2*F_R with respect to using ETag validation, that is iff the mean arrival time of requests for resource R is greater than half the refresh rate of R. When using observations M_R is always upper bounded by 2*F_R: in the constrained network no more than 2*F_R messages will be generated towards resource R. 6.6. Use of CoAP Blockwise Transfer A Cross-Protocol Proxy SHOULD support CoAP blockwise transfers [I-D.ietf-core-block] to allow transport of large CoAP payloads while avoiding excessive link-layer fragmentation in LLNs, and to cope with small datagram buffers in CoAP end-points as described in [I-D.ietf-core-coap] Section 4.6. A Cross-Protocol Proxy SHOULD attempt to retry a payload-carrying CoAP PUT or POST request with blockwise transfer if the destination CoAP server responded with 4.13 (Request Entity Too Large) to the original request. A Cross-Protocol Proxy SHOULD attempt to use blockwise transfer when sending a CoAP PUT or POST request message that is larger than a value BLOCKWISE_THRESHOLD. The value of BLOCKWISE_THRESHOLD MAY be implementation-specific, for example calculated based on a known or typical UDP datagram buffer size for CoAP end-points, or set to N times the size of a link-layer frame where e.g. N=5, or preset to a known IP MTU value, or set to a known Path MTU value. The value BLOCKWISE_THRESHOLD or parameters from Castellani, et al. Expires August 16, 2014 [Page 18] Internet-Draft HTTP-CoAP Mapping February 2014 which it is calculated SHOULD be configurable in a proxy implementation. The Cross-Protocol Proxy SHOULD detect CoAP end-points not supporting blockwise transfers by checking for a 4.02 (Bad Option) response returned by an end-point in response to a CoAP request with a Block* Option. This allows the Cross-Protocol Proxy to be more efficient, not attempting repeated blockwise transfers to CoAP servers that do not support it. However if a request payload is too large to be sent as a single CoAP request and blockwise transfer would be unavoidable, the proxy still SHOULD attempt blockwise transfer on such an end- point before returning 413 (Request Entity Too Large) to the HTTP client. For improved latency a cross proxy MAY initiate a blockwise CoAP request triggered by an incoming HTTP request even when the HTTP request message has not yet been fully received, but enough data has been received to send one or more data blocks to a CoAP server already. This is particularly useful on slow client-to-proxy connections. 6.7. Security Translation A HC proxy SHOULD implement explicit rules for security context translations. A translation may involve e.g. applying a rule that any "https" request is translated to a "coaps" request, or e.g. applying a rule that a "https" request is translated to an unsecured "coap" request. Another rule could specify the security policy and parameters used for DTLS connections. Such rules will largely depend on the application and network context in which a proxy is applied. To enable widest possible use of a proxy implementation, these rules SHOULD be configurable in a HC proxy. If a policy for access to 'coaps' URIs is configurable in a HC proxy, it is RECOMMENDED that the policy is by default configured to disallow access to any 'coaps' URI by a HTTP client using an unsecured (non-TLS) connection. Naturally, a user MAY reconfigure the policy to allow such access in specific cases. 6.8. Other guidelines For long delays of a CoAP server, the HTTP client or any other proxy in between MAY timeout. Further discussion of timeouts in HTTP is available in Section 6.2.4 of [I-D.ietf-httpbis-p1-messaging]. Castellani, et al. Expires August 16, 2014 [Page 19] Internet-Draft HTTP-CoAP Mapping February 2014 A cross proxy MUST define an internal timeout for each pending CoAP request, because the CoAP server may silently die before completing the request. The timeout value SHOULD be approximately less than or equal to MAX_RTT defined in [I-D.ietf-core-coap]. When the DNS protocol is not used between CoAP nodes in a constrained network, defining valid FQDN (i.e., DNS entries) for constrained CoAP servers, where possible, MAY help HTTP clients to access the resources offered by these servers via a HC proxy. HTTP connection pipelining (section 6.2.2.1 of [I-D.ietf-httpbis-p1-messaging]) MAY be supported by the proxy and is transparent to the CoAP network: the HC cross proxy will sequentially serve the pipelined requests by issuing different CoAP requests. It is expected that the HC function will often be implemented in software on the proxy. Many different software approaches are possible, including using CGI [RFC3875] as an interface between the HTTP layer and the protocol translation engine. 7. IANA Considerations This memo includes no request to IANA. 8. Security Considerations The security concerns raised in Section 15.7 of [RFC2616] also apply to the cross proxy scenario. In fact, the cross proxy is a trusted (not rarely a transparently trusted) component in the network path. The trustworthiness assumption on the cross proxy cannot be dropped. Even if we had a blind, bi-directional, end-to-end, tunneling facility like the one provided by the CONNECT method in HTTP, and also assuming the existence of a DTLS-TLS transparent mapping, the two tunneled ends should be speaking the same application protocol, which is not the case. Basically, the protocol translation function is a core duty of the cross proxy that can't be removed, and makes it a necessarily trusted, impossible to bypass, component in the communication path. A reverse proxy deployed at the boundary of a constrained network is an easy single point of failure for reducing availability. As such, a special care should be taken in designing, developing and operating it, keeping in mind that, in most cases, it could have fewer limitations than the constrained devices it is serving. Castellani, et al. Expires August 16, 2014 [Page 20] Internet-Draft HTTP-CoAP Mapping February 2014 The following sub paragraphs categorize and argue about a set of specific security issues related to the translation, caching and forwarding functionality exposed by a cross proxy module. 8.1. Traffic overflow Due to the typically constrained nature of CoAP nodes, particular attention SHOULD be posed in the implementation of traffic reduction mechanisms (see Section 6.4), because inefficient implementations can be targeted by unconstrained Internet attackers. Bandwidth or complexity involved in such attacks is very low. An amplification attack to the constrained network may be triggered by a multicast request generated by a single HTTP request mapped to a CoAP multicast resource, as considered in Section TBD of [I-D.ietf-core-coap]. The impact of this amplification technique is higher than an amplification attack carried out by a malicious constrained device (e.g. ICMPv6 flooding, like Packet Too Big, or Parameter Problem on a multicast destination [RFC4732]), since it does not require direct access to the constrained network. The feasibility of this attack, disruptive in terms of CoAP server availability, can be limited by access controlling the exposed HTTP multicast resource, so that only known/authorized users access such URIs. 8.2. Handling Secured Exchanges It is possible that the request from the client to the cross proxy is sent over a secured connection. However, there may or may not exist a secure connection mapping to the other protocol. For example, a secure distribution method for multicast traffic is complex and MAY not be implemented (see [I-D.ietf-core-groupcomm]). By default, a cross proxy SHOULD reject any secured client request if there is no configured security policy mapping. This recommendation MAY be relaxed in case the destination network is believed to be secured by other, complementary, means. E.g.: assumed that CoAP nodes are isolated behind a firewall (e.g. as the SS cross proxy deployment shown in Figure 1), the cross proxy may be configured to translate the incoming HTTPS request using plain CoAP (i.e. NoSec mode.) The HC URI mapping MUST NOT map to HTTP (see Section 5) a CoAP resource intended to be accessed only using HTTPS. Castellani, et al. Expires August 16, 2014 [Page 21] Internet-Draft HTTP-CoAP Mapping February 2014 A secured connection that is terminated at the cross proxy, i.e. the proxy decrypts secured data locally, raises an ambiguity about the cacheability of the requested resource. The cross proxy SHOULD NOT cache any secured content to avoid any leak of secured information. However in some specific scenario, a security/efficiency trade-off could motivate caching secured information; in that case the caching behavior MAY be tuned to some extent on a per-resource basis. 8.3. URI Mapping The following risks related to the URI mapping described in Section 5 have been identified: DoS attack on the internal network. Default deny any Target CoAP URI whose authority is (or maps to) a multicast address. Then explicitly whitelist multicast resources that are allowed to be de-referenced. Leaking information on the internal network resources and topology. Default deny any Target CoAP URI (especially /.well-known/core is the resource to be protected), and then explicit whitelist resources that are allowed to be seen from outside. Reduced privacy due to the mechanics of the URI mapping. The internal CoAP Target resource is totally transparent from outside: an HC Proxy implementing a HTTPS-only interface makes the Target CoAP URI totally opaque to a passive attacker. 9. Acknowledgements An initial version of the table found in Section 6.2 has been provided in revision -05 of [I-D.ietf-core-coap]. Special thanks to Peter van der Stok for countless comments and discussions on this document, that contributed to its current structure and text. Thanks to Carsten Bormann, Zach Shelby, Michele Rossi, Nicola Bui, Michele Zorzi, Klaus Hartke, Cullen Jennings, Kepeng Li, Brian Frank, Peter Saint-Andre, Kerry Lynn, Linyi Tian, Dorothy Gellert, Francesco Corazza for helpful comments and discussions that have shaped the document. The research leading to these results has received funding from the European Community's Seventh Framework Programme [FP7/2007-2013] under grant agreement n. [251557]. 10. References Castellani, et al. Expires August 16, 2014 [Page 22] Internet-Draft HTTP-CoAP Mapping February 2014 10.1. Normative References [I-D.ietf-core-block] Bormann, C. and Z. Shelby, "Blockwise transfers in CoAP", draft-ietf-core-block-12 (work in progress), June 2013. [I-D.ietf-core-coap] Shelby, Z., Hartke, K., and C. Bormann, "Constrained Application Protocol (CoAP)", draft-ietf-core-coap-18 (work in progress), June 2013. [I-D.ietf-core-observe] Hartke, K., "Observing Resources in CoAP", draft-ietf- core-observe-10 (work in progress), September 2013. [I-D.ietf-httpbis-p1-messaging] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing", draft-ietf- httpbis-p1-messaging-24 (work in progress), September 2013. [I-D.ietf-httpbis-p2-semantics] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content", draft-ietf- httpbis-p2-semantics-24 (work in progress), September 2013. [I-D.ietf-httpbis-p7-auth] Fielding, R. and J. Reschke, "Hypertext Transfer Protocol (HTTP/1.1): Authentication", draft-ietf-httpbis-p7-auth-24 (work in progress), September 2013. [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997. [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext Transfer Protocol -- HTTP/1.1", RFC 2616, June 1999. [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform Resource Identifier (URI): Generic Syntax", STD 66, RFC 3986, January 2005. [RFC6570] Gregorio, J., Fielding, R., Hadley, M., Nottingham, M., and D. Orchard, "URI Template", RFC 6570, March 2012. [RFC6690] Shelby, Z., "Constrained RESTful Environments (CoRE) Link Format", RFC 6690, August 2012. Castellani, et al. Expires August 16, 2014 [Page 23] Internet-Draft HTTP-CoAP Mapping February 2014 10.2. Informative References [I-D.ietf-core-groupcomm] Rahman, A. and E. Dijk, "Group Communication for CoAP", draft-ietf-core-groupcomm-16 (work in progress), October 2013. [RFC3040] Cooper, I., Melve, I., and G. Tomlinson, "Internet Web Replication and Caching Taxonomy", RFC 3040, January 2001. [RFC3875] Robinson, D. and K. Coar, "The Common Gateway Interface (CGI) Version 1.1", RFC 3875, October 2004. [RFC4732] Handley, M., Rescorla, E., IAB, "Internet Denial-of- Service Considerations", RFC 4732, December 2006. Appendix A. Change Log Changes from ietf-02 to ietf-03: o Closed Ticket #351 [1] "Add security implications of proposed default HC URI mapping"; o Closed Ticket #363 [2] "Remove CoAP scheme in default HTTP-CoAP URI mapping"; o Closed Ticket #364 [3] "Add discovery of HTTP-CoAP mapping resource(s)". Changes from ietf-01 to ietf-02: o Selection of single default URI mapping proposal as proposed to WG mailing list 2013-10-09. Changes from ietf-00 to ietf-01: o Added URI mapping proposals to Section 4 as per the Email proposals to WG mailing list from Esko. Authors' Addresses Angelo P. Castellani University of Padova Via Gradenigo 6/B Padova 35131 Italy Email: angelo@castellani.net Castellani, et al. Expires August 16, 2014 [Page 24] Internet-Draft HTTP-CoAP Mapping February 2014 Salvatore Loreto Ericsson Hirsalantie 11 Jorvas 02420 Finland Email: salvatore.loreto@ericsson.com Akbar Rahman InterDigital Communications, LLC 1000 Sherbrooke Street West Montreal H3A 3G4 Canada Phone: +1 514 585 0761 Email: Akbar.Rahman@InterDigital.com Thomas Fossati Alcatel-Lucent 3 Ely Road Milton, Cambridge CB24 6DD UK Email: thomas.fossati@alcatel-lucent.com Esko Dijk Philips Research High Tech Campus 34 Eindhoven 5656 AE The Netherlands Email: esko.dijk@philips.com Castellani, et al. Expires August 16, 2014 [Page 25]