CoRE Working Group | A. Castellani |
Internet-Draft | University of Padova |
Intended status: Informational | S. Loreto |
Expires: January 21, 2017 | Ericsson |
A. Rahman | |
InterDigital Communications, LLC | |
T. Fossati | |
Nokia | |
E. Dijk | |
Philips Lighting | |
July 20, 2016 |
Guidelines for HTTP-to-CoAP Mapping Implementations
draft-ietf-core-http-mapping-13
This document provides reference information for implementing a cross-protocol network proxy that performs translation from the HTTP protocol to the CoAP protocol. This will enable a HTTP client to access resources on a CoAP server through the proxy. This document describes how a HTTP request is mapped to a CoAP request, and then how a CoAP response is mapped back to a HTTP response. This includes guidelines for URI mapping, media type mapping and additional proxy implementation issues. This document covers the Reverse, Forward and Interception cross-protocol proxy cases.
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 January 21, 2017.
Copyright (c) 2016 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 (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.
CoAP [RFC7252] has been designed with the twofold aim to be an application protocol specialized for constrained environments and to be easily used in Representational State Transfer (REST) based architectures such as the Web. The latter goal has led to defining CoAP to easily interoperate with HTTP [RFC7230] through an intermediary proxy which performs cross-protocol conversion.
Section 10 of [RFC7252] describes the fundamentals of the CoAP-to-HTTP and the HTTP-to-CoAP cross-protocol mapping process. However, [RFC7252] focuses on the basic mapping of request methods and simple response code mapping between HTTP and CoAP, and it leaves many details of the cross-protocol proxy for future definition. Therefore, a primary goal of this informational document is to define a consistent set of guidelines that an HTTP-to-CoAP proxy implementation should adhere to. The key benefit to adhering to such guidelines is to reduce variation between proxy implementations, thereby increasing interoperability between an HTTP client and a CoAP server independent of the proxy that implements the cross-protocol mapping. (For example, 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 document describes HTTP mappings that apply to protocol elements defined in the base CoAP specification [RFC7252]. It is up to CoAP protocol extensions (new methods, response codes, options, content-formats) to describe their own HTTP mappings, if applicable.
This document is organized as follows:
The keywords "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].
HC Proxy: a proxy performing a cross-protocol mapping, in the context of this document an HTTP-to-CoAP (HC) mapping. Specifically, the HC proxy acts as an HTTP server and a CoAP client. The HC Proxy can take on the role of a Forward, Reverse or Interception Proxy.
Forward Proxy (or Forward HC Proxy): a message forwarding agent that is selected by the HTTP 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/de-referencing agent for a predefined subset of the URI space. In [RFC7230] this is called a Proxy. [RFC7252] defines Forward-Proxy similarly.
Reverse Proxy (or Reverse HC Proxy): as in [RFC7230], a receiving agent that acts as a layer above some other server(s) and translates the received requests to the underlying server's protocol. A Reverse HC Proxy behaves as an origin (HTTP) server on its connection from the HTTP client. The HTTP client uses the "origin-form" (Section 5.3.1 of [RFC7230]) as a request-target URI.
Interception Proxy (or Interception HC Proxy) [RFC3040]: a proxy that receives inbound HTTP traffic flows through the process of traffic redirection; transparent to the HTTP client.
Note that a Reverse Proxy appears to an HTTP client as an origin server while a Forward Proxy does not. So, when communicating with a Reverse Proxy a client may be unaware it is communicating with a proxy at all.
A HC proxy is accessed by an HTTP client which wants to access a resource on a CoAP server. The HC proxy handles the HTTP request by mapping it to the equivalent CoAP request, which is then forwarded to the appropriate CoAP server. The received CoAP response is then mapped to an appropriate HTTP response and finally sent back to the originating HTTP client.
See Figure 1 for an example deployment scenario. Here a HC proxy is located at the boundary of the Constrained Network domain, to avoid sending any HTTP traffic into the Constrained Network and to avoid any (unsecured) CoAP multicast traffic outside the Constrained Network. A DNS server (not shown) is used by the HTTP Client to resolve the IP address of the HC proxy and optionally also used by the HC proxy to resolve IP addresses of CoAP servers.
Constrained Network .-------------------. / .------. \ / | CoAP | \ / |server| \ || '------' || || || .--------. HTTP Request .------------. CoAP Req .------. || | HTTP |---------------->|HTTP-to-CoAP|----------->| CoAP | || | Client |<----------------| Proxy |<-----------|Server| || '--------' HTTP Response '------------' CoAP Resp '------' || || || || .------. || || | CoAP | || \ |server| .------. / \ '------' | CoAP | / \ |server| / \ '------' / '-----------------'
Figure 1: HTTP-To-CoAP Proxy Deployment Scenario
Normative requirements on the translation of HTTP requests to CoAP requests and of the CoAP responses back to HTTP responses are defined in Section 10.2 of [RFC7252]. However, [RFC7252] focuses on the basic mapping of request methods and simple response code mapping between HTTP and CoAP, and leaves many details of the cross-protocol HC proxy for future definition. This document provides additional guidelines and more details for the implementation of a HC Proxy, which should be followed in addition to the normative requirements. Note that the guidelines apply to all forms of an HC proxy (i.e. Reverse, Forward, Intercepting) unless explicitly otherwise noted.
To illustrate the situations HTTP to CoAP protocol translation may be used, three use cases are described below.
1. Legacy building control application without CoAP: A building control application that uses HTTP but not CoAP can check the status of CoAP sensors and/or control actuators via a HC proxy.
2. Making sensor data available to 3rd parties on the Web: For demonstration or public interest purposes, a HC proxy may be configured to expose the contents of a CoAP sensor to the world via the web (HTTP and/or HTTPS). Some sensors may only accept secure 'coaps' requests, therefore the proxy is configured to translate request to those devices accordingly. The HC proxy is furthermore configured to only pass through GET requests in order to protect the constrained network.
3. Smartphone and home sensor: A smartphone can access directly a CoAP home sensor using a mutually authenticated 'https' request, provided its home router runs a HC proxy and is configured with the appropriate certificate. An HTML5 application on the smartphone can provide a friendly UI using the standard (HTTP) networking functions of HTML5.
A key point in the above use cases is the expected nature of the URI to be used by the HTTP client initiating the HTTP request to the HC proxy. Specifically, in use case #1, there will be no "coap" or "coaps" related information embedded in the HTTP URI as it is a legacy HTTP client sending the request. Use case #2 is also expected to be similar. In contrast, in use case #3, it is expected that the HTTP client will specifically embed "coap" or "coaps" related information in the HTTP URI of the HTTP request to the HC proxy.
Though, in principle, a CoAP URI could be directly used by a HTTP client to de-reference a CoAP resource through a HC proxy, the reality is that all major web browsers, networking libraries and command line tools do not allow making HTTP requests using URIs with a scheme "coap" or "coaps".
Thus, there is a need for web applications to embed or "pack" a CoAP URI into a HTTP URI so that it can be (non-destructively) transported from the HTTP client to the HC proxy. The HC proxy can then "unpack" the CoAP URI and finally de-reference it via a CoAP request to the target Server.
URI Mapping is the term used in the document to describe the process through which the URI of a CoAP resource is transformed into an HTTP URI so that:
To this end, the remainder of this section will identify:
In the remainder of this section, the following terms will be used with a distinctive meaning:
The null mapping is the case where there is no Target CoAP URI appended to the HC Proxy URI. In other words, it is a "pure" HTTP URI that is sent to the HC Proxy. This would typically occur in situations like Use Case #1 described in Section 4, and the Proxy would typically be a Reverse Proxy. In this scenario, the HC Proxy will determine through its own proprietary algorithms what the Target CoAP URI should be.
The default mapping is for the Target CoAP URI to be appended as-is to the HC Proxy URI, to form the Hosting HTTP URI. This is the URI that will then be sent by the HTTP client in the HTTP request to the HC proxy.
For example: given a HC Proxy 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 unambiguously from the Hosting HTTP URI. Also, it is 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 HC Proxy URI. Therefore, it is either known in advance, e.g. as a configuration preset, or dynamically discovered using the mechanism described in Section 5.5.
The default URI mapping function SHOULD 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.
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.
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.
This section defines a format for the URI template [RFC6570] used by a HC proxy to inform its clients about the expected syntax for the Hosting HTTP URI. This will then be used by the HTTP client to construct the URI to be sent in the HTTP request to the HC proxy.
When instantiated, an URI Mapping Template is always concatenated to a HC Proxy URI provided by the HC proxy via discovery (see Section 5.5), or by other means.
A simple form (Section 5.4.1) and an enhanced form (Section 5.4.2) are provided to fit different users' requirements.
Both forms are expressed as level 2 URI templates [RFC6570] to take care of the expansion of values that are allowed to include reserved URI characters. The syntax of all URI formats is specified in this section in Augmented Backus-Naur Form (ABNF) [RFC5234].
The simple form MUST be used for mappings where the Target CoAP URI is going to be copied (using rules of Section 5.3.2) at some fixed position into the Hosting HTTP URI.
tu = coap-URI / coaps-URI ; from [RFC7252], Section 6.1 and 6.2
The "tu" template variable is intended to be used in a template definition to represent a Target CoAP URI: Section 5.3.1 apply, in that the CoAP scheme may be omitted from the Hosting HTTP URI.
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 HC Proxy URI. Note that these examples all define mapping templates that deviate from the default template of Section 5.3 to be able to illustrate the use of the above template variables.
?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
forward/{+tu} coap://s.example.com/light http://p.example.com/hc/forward/coap://s.example.com/light or coaps://s.example.com/light http://p.example.com/hc/forward/coaps://s.example.com/light
?coap_uri={+tu} coap://s.example.com/light http://p.example.com/hc/?coap_uri=s.example.com/light
The enhanced form can be used to express more sophisticated mappings of the Target CoAP URI into the Hosting HTTP URI, i.e., mappings that do not fit into the simple form.
s = "coap" / "coaps" ; from [RFC7252], 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 qq = [ "?" query ] ; qq is empty if and only if 'query' is empty
There MUST be at most one instance of each of the following template variables in a template definition:
The qq form is used when the path and the (optional) query components are to be copied verbatim from the Target CoAP URI into the Hosting HTTP URI, i.e. as "{+p}{+qq}". Instead, the q form is used when the query and path are mapped as separate entities, e.g. as in "coap_path={+p}&coap_query={+q}".
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 HC Proxy URI.
{+s}/{+hp}{+p}{+qq} 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
?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 http://p.example.com/hc/?s=coaps&hp=s.example.com&p=/light&q=on
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 defined in this document. It can be used as the value for the "rt" attribute in a query to the /.well-known/core in order to locate the URI where the HC proxy function is anchored, i.e. the HC Proxy URI.
Along with it, the new target attribute "hct" is defined in this document. This attribute MAY be returned in a "core.hc" link to provide the URI Mapping Template associated to the mapping resource. The default template given in Section 5.3, i.e., {+tu}, MUST be assumed if no "hct" attribute is found in the returned link. If a "hct" attribute is present in the returned link, then a client MUST use it to create the Hosting HTTP URI.
The URI mapping SHOULD be discoverable (as specified in [RFC6690]) 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 needs an explicit anchor referring to the HTTP origin, while on the HTTP interface the link context is already the HTTP origin carried in the request's Host header, and doesn't have to be made explicit.
Req: GET coap://[ff02::1]/.well-known/core?rt=core.hc Res: 2.05 Content </hc/>;anchor="http://p.example.com";rt="core.hc"
Req: GET coap://[ff02::1]/.well-known/core?rt=core.hc Res: 2.05 Content </hc/>;anchor="http://p.example.com"; rt="core.hc";hct="?uri={+tu}"
Req: GET /.well-known/core?rt=core.hc HTTP/1.1 Host: p.example.com Res: HTTP/1.1 200 OK Content-Type: application/link-format Content-Length: 18 </hc/>;rt="core.hc"
Req: GET /.well-known/core?rt=core.hc HTTP/1.1 Host: p.example.com Res: HTTP/1.1 200 OK Content-Type: application/link-format+json Content-Length: 31 [{"href":"/hc/","rt":"core.hc"}]
Req: GET /.well-known/core?rt=core.hc HTTP/1.1 Host: p.example.com Res: HTTP/1.1 200 OK Link: </hc/>;rt="core.hc"
On the HTTP side, link information can be serialized in more than one way:
A HC proxy needs to translate HTTP media types (Section 3.1.1.1 of [RFC7231]) and content encodings (Section 3.1.2.2 of [RFC7231]) into CoAP content formats (Section 12.3 of [RFC7252]) and vice versa.
Media type translation can happen in GET, PUT or POST requests going from HTTP to CoAP, and in 2.xx (i.e., successful) responses going from CoAP to HTTP. Specifically, PUT and POST need to map both the Content-Type and Content-Encoding HTTP headers into a single CoAP Content-Format option, whereas GET needs to map Accept and Accept-Encoding HTTP headers into a single CoAP Accept option. To generate the HTTP response, the CoAP Content-Format option is mapped back to a suitable HTTP Content-Type and Content-Encoding combination.
An HTTP request carrying a Content-Type and Content-Encoding combination which the HC proxy is unable to map to an equivalent CoAP Content-Format, SHALL elicit a 415 (Unsupported Media Type) response by the HC proxy.
On the content negotiation side, failure to map Accept and Accept-* headers SHOULD be silently ignored: the HC proxy SHOULD therefore forward as a CoAP request with no Accept option. The HC proxy thus disregards the Accept/Accept-* header fields by treating the response as if it is not subject to content negotiation, as mentioned in Sections 5.3.* of [RFC7231]. However, a HC proxy implementation is free to attempt mapping a single Accept header in a GET request to multiple CoAP GET requests, each with a single Accept option, which are then tried in sequence until one succeeds. Note that an HTTP Accept */* MUST be mapped to a CoAP request without Accept option.
While the CoAP to HTTP direction has always a well defined mapping (with the exception examined in Section 6.2), the HTTP to CoAP direction is more problematic because the source set, i.e., potentially 1000+ IANA registered media types, is much bigger than the destination set, i.e., the mere 6 values initially defined in Section 12.3 of [RFC7252].
Depending on the tight/loose coupling with the application(s) for which it proxies, the HC proxy could implement different media type mappings.
When tightly coupled, the HC proxy knows exactly which content formats are supported by the applications, and can be strict when enforcing its forwarding policies in general, and the media type mapping in particular.
On the other side, when the HC proxy is a general purpose application layer gateway, being too strict could significantly reduce the amount of traffic that it would be able to successfully forward. In this case, the "loose" media type mapping detailed in Section 6.3 MAY be implemented.
The latter grants more evolution of the surrounding ecosystem, at the cost of allowing more attack surface. In fact, as a result of such strategy, payloads would be forwarded more liberally across the unconstrained/constrained network boundary of the communication path. Therefore, when applied, other forms of access control must be set in place to avoid unauthorized users to deplete or abuse systems and network resources.
If the HC proxy receives a CoAP response with a Content-Format that it does not recognize (e.g. because the value has been registered after the proxy has been deployed, or the CoAP server uses an experimental value which is not registered), then the HC proxy SHALL return a generic "application/coap-payload" media type with numeric parameter "cf" as defined in Section 9.2.
For example, the CoAP content format '60' ("application/cbor") would be represented by "application/coap-payload;cf=60", if the HC Proxy doesn't recognize the content format '60'.
A HTTP client may use the media type "application/coap-payload" as a means to send a specific content format to a CoAP server via a HC Proxy if the client has determined that the HC Proxy does not directly support the type mapping it needs. This case may happen when dealing for example with newly registered, yet to be registered, or experimental CoAP content formats.
By structuring the type information in a super-class (e.g. "text") followed by a finer grained sub-class (e.g. "html"), and optional parameters (e.g. "charset=utf-8"), Internet media types provide a rich and scalable framework for encoding the type of any given entity.
This approach is not applicable to CoAP, where Content Formats conflate an Internet media type (potentially with specific parameters) and a content encoding into one small integer value.
To remedy this loss of flexibility, we introduce the concept of a "loose" media type mapping, where media types that are specializations of a more generic media type can be aliased to their super-class and then mapped (if possible) to one of the CoAP content formats. For example, "application/soap+xml" can be aliased to "application/xml", which has a known conversion to CoAP. In the context of this "loose" media type mapping, "application/octet-stream" can be used as a fallback when no better alias is found for a specific media type.
Table 1 defines the default lookup table for the "loose" media type mapping. Given an input media type, the table returns its best generalized media type using the most specific match i.e. the table entries are compared to the input in top to bottom order until an entry matches.
Internet media type | Generalized media type |
---|---|
application/*+xml | application/xml |
application/*+json | application/json |
text/xml | application/xml |
text/* | text/plain |
*/* | application/octet-stream |
The "loose" media type mapping is an OPTIONAL feature. Implementations supporting this kind of mapping should provide a flexible way to define the set of media type generalizations allowed.
This section defines the algorithm used to map an HTTP Internet media type to its correspondent CoAP content format.
The algorithm uses the mapping table defined in Section 12.3 of [RFC7252] plus, possibly, any locally defined extension of it. Optionally, the table and lookup mechanism described in Section 6.3 can be used if the implementation chooses so.
Note that the algorithm may have side effects on the associated representation (see also Section 6.5).
In the following:
INPUT: C-T and C-E OUTPUT: C-F or Fail 1. if no C-T: return Fail 2. C-F = MAP[C-T, C-E] 3. if C-F is not None: return C-F 4. if C-E is not "identity": 5. if C-E is supported (e.g. gzip): 6. decode the representation accordingly 7. set C-E to "identity" 8. else: 9. return Fail 10. repeat steps 2. and 3. 11. if C-T allows a non-lossy transformation into \ 12. one of the supported C-F: 13. transcode the representation accordingly 14. return C-F 15. if GMAP is defined: 16. C-F = GMAP[C-T] 17. if C-F is not None: return C-F 18. return Fail
Figure 2
Payload content transcoding (e.g. see steps 11-14 of Figure 2) is an OPTIONAL feature. Implementations supporting this feature should provide a flexible way to define the set of transcodings allowed.
As noted in Section 6.4, the process of mapping the media type can have side effects on the forwarded entity body. This may be caused by the removal or addition of a specific content encoding, or because the HC proxy decides to transcode the representation to a different (compatible) format. The latter proves useful when an optimized version of a specific format exists. For example an XML-encoded resource could be transcoded to Efficient XML Interchange (EXI) format, or a JSON-encoded resource into CBOR [RFC7049], effectively achieving compression without losing any information.
However, it should be noted that in certain cases, transcoding can lose information in a non-obvious manner. For example, encoding an XML document using schema-informed EXI encoding leads to a loss of information when the destination does not know the exact schema version used by the encoder, which means that whenever the HC proxy transcodes an application/XML to application/EXI in-band metadata could be lost. Therefore, the implementer should always carefully verify such lossy payload transformations before triggering the transcoding.
The CoRE Link Format [RFC6690] is a set of links (i.e., URIs and their formal relationships) which is carried as content payload in a CoAP response. These links usually include CoAP URIs that might be translated by the HC proxy to the correspondent HTTP URIs using the implemented URI mapping function (see Section 5). Such a process would inspect the forwarded traffic and attempt to re-write the body of resources with an application/link-format media type, mapping the embedded CoAP URIs to their HTTP counterparts. Some potential issues with this approach are:
Therefore, CoRE Link Format payload should only be transcoded at the risk and discretion of the proxy implementer.
CoAP responses may, in certain error cases, contain a diagnostic message in the payload explaining the error situation, as described in Section 5.5.2 of [RFC7252]. If present, the CoAP response diagnostic payload SHOULD be copied in the HTTP response body. The CoAP diagnostic message MUST NOT be copied into the HTTP reason-phrase, since it potentially contains CR-LF characters which are incompatible with HTTP reason-phrase syntax.
Table 2 defines the HTTP response status codes to which each CoAP response code SHOULD be mapped. Multiple appearances of a HTTP status code in the second column indicates multiple equivalent HTTP responses are possible based on the same CoAP response code, depending on the conditions cited in the Notes (third column and text below table).
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 | 403 Forbidden | 5 |
4.02 Bad Option | 400 Bad Request | 6 |
4.02 Bad Option | 500 Internal Server Error | 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 Ent. Too Large | 413 Request Repr. Too Large | |
4.15 Unsupported Media Type | 415 Unsupported Media 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 Supported | 502 Bad Gateway | 9 |
Notes:
A HC proxy should cache CoAP responses, and reply whenever applicable with a cached representation of the requested resource.
If the HTTP client drops the connection after the HTTP request was made, a HC proxy should wait for the associated CoAP response and cache it if possible. Subsequent requests to the HC 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 request.
According to [RFC7252], a proxy must limit the number of outstanding requests to a given CoAP server to NSTART. To limit the amount of aggregate traffic to a constrained network, the HC proxy should also put a limit on 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.
Highly volatile resources that are being frequently requested may be observed [RFC7641] by the HC proxy to keep their cached representation fresh while minimizing the amount of CoAP traffic in the constrained network. See Section 8.2.
There are cases where using the CoAP observe protocol [RFC7641] to handle proxy cache refresh is preferable to the validation mechanism based on ETag as defined in [RFC7252]. Such scenarios include, but are not limited to, sleepy CoAP nodes -- with possibly high variance in requests' distribution -- which would greatly benefit from a server driven cache update mechanism. Ideal candidates for CoAP observe are also 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 refreshing 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 T_C be the mean time between two representation changes of R, and let M_R be the mean number of CoAP messages per second exchanged to and from resource R. If we assume that the initial cost for establishing the observation is negligible, an observation on R reduces M_R if and only if T_R < 2*T_C with respect to using ETag validation, that is if and only if the mean arrival rate of requests for resource R is greater than half the change rate of R.
When observing the resource R, M_R is always upper bounded by 2/T_C.
A HC 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 constrained networks, and to cope with small datagram buffers in CoAP end-points as described in [RFC7252] Section 4.6.
A HC 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 HC proxy SHOULD attempt to use blockwise transfer when sending a CoAP PUT or POST request message that is larger than BLOCKWISE_THRESHOLD bytes. The value of BLOCKWISE_THRESHOLD is implementation-specific, for example it can be:
The value BLOCKWISE_THRESHOLD, or the parameters from which it is calculated, should be configurable in a proxy implementation. The maximum block size the proxy will attempt to use in CoAP requests should also be configurable.
The HC proxy SHOULD detect CoAP end-points not supporting blockwise transfers. This can be done by checking for a 4.02 (Bad Option) response returned by an end-point in response to a CoAP request with a Block* Option, and subsequent absence of the 4.02 in response to the same request without Block* Options. This allows the HC proxy to be more efficient, not attempting repeated blockwise transfers to CoAP servers that do not support it.
A HC proxy MAY support CoAP multicast. If it does, the HC proxy sends out a multicast CoAP request if the Target CoAP URI's authority is a multicast IP literal or resolves to a multicast IP address. If the HC proxy does not support CoAP multicast, it SHOULD respond 403 (Forbidden) to any valid HTTP request that maps to a CoAP multicast request.
Details related to supporting CoAP multicast are currently out of scope of this document since in a proxy scenario a HTTP client typically expects to receive a single response, not multiple. However, a HC proxy that implements CoAP multicast may include application-specific functions to aggregate multiple CoAP responses into a single HTTP response. We suggest using the "application/http" internet media type (Section 8.3.2 of [RFC7230]) to enclose a set of one or more HTTP response messages, each representing the mapping of one CoAP response.
For further considerations related to the handling of multicast requests, see Section 10.1.
If the CoAP server takes a long time in responding, 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 [RFC7230].
A HC proxy MUST define an internal timeout for each pending CoAP request, because the CoAP server may silently die before completing the request. Assuming the Proxy uses confirmable CoAP requests, such timeout value T SHOULD be at least
T = MAX_RTT + MAX_SERVER_RESPONSE_DELAY
where MAX_RTT is defined in [RFC7252] and MAX_SERVER_RESPONSE_DELAY is defined in [RFC7390].
This document registers a new Resource Type (rt=) Link Target Attribute, 'core.hc', in the "Resource Type (rt=) Link Target Attribute Values" subregistry under the "Constrained RESTful Environments (CoRE) Parameters" registry.
Attribute Value: core.hc
Description: HTTP to CoAP mapping base resource.
Reference: See Section 5.5.
This document defines the "application/coap-payload" media type with a single parameter "cf". This media type represents any payload that a CoAP message can carry, having a content format that can be identified by an integer in range 0-65535 corresponding to a CoAP Content-Format parameter ([RFC7252], Section 12.2). The parameter "cf" is the integer defining the CoAP content format.
Type name: application
Subtype name: coap-payload
Required parameters:
cf - CoAP Content-Format integer in range 0-65535 denoting the content format of the CoAP payload carried.
Optional parameters: None
Encoding considerations:
The specific CoAP content format encoding considerations for the selected Content-Format (cf parameter) apply.
Security considerations:
The specific CoAP content format security considerations for the selected Content-Format (cf parameter) apply.
Interoperability considerations:
Published specification: (this I-D - TBD)
Applications that use this media type:
HTTP-to-CoAP Proxies.
Fragment identifier considerations: N/A
Additional information:
Person and email address to contact for further information:
Intended usage: COMMON
Restrictions on usage:
An application (or user) can only use this media type if it has to represent a CoAP payload of which the specified CoAP Content-Format is an unrecognized number; such that a proper translation directly to the equivalent HTTP media type is not possible.
Author: CoRE WG
Change controller: IETF
Provisional registration? (standards tree only): N/A
The security concerns raised in Section 9.2 of [RFC7230] also apply to the HC proxy scenario.
A HC proxy deployed at the boundary of a constrained network is an easy single point of failure for reducing availability. As such, special care should be taken in designing, developing and operating it, keeping in mind that, in most cases, it has fewer limitations than the constrained devices it is serving.
The following sub paragraphs categorize and discuss a set of specific security issues related to the translation, caching and forwarding functionality exposed by a HC proxy.
Multicast requests impose a non trivial cost on the constrained network and endpoints, and might be exploited as a DoS attack vector (see also Section 10.2). From a privacy perspective, they can be used to gather detailed information about the resources hosted in the constrained network. For these reasons, it is RECOMMENDED that requests to multicast resources are access controlled with a default-deny policy. It is RECOMMENDED that the requestor of a multicast resource is strongly authenticated. If privacy is a concern, for example whenever the HTTP request transits through the public Internet, the request SHOULD be transported over a mutually authenticated and encrypted TLS connection.
Due to the typically constrained nature of CoAP nodes, particular attention should be given to the implementation of traffic reduction mechanisms (see Section 8.1), because inefficient proxy 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 which is mapped to a CoAP multicast resource, as discussed in Section 11.3 of [RFC7252].
The risk likelihood 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 which disrupts availability of the targeted CoAP server can be limited by access controlling the exposed multicast resources, so that only known/authorized users can access such URIs.
An HTTP request can be sent to the HC proxy over a secured connection. However, there may not always exist a secure connection mapping to CoAP. For example, a secure distribution method for multicast traffic is complex and may not be implemented (see [RFC7390]).
A HC proxy should implement rules for security context translations. For example all "https" unicast requests are translated to "coaps" requests, or "https" requests are translated to unsecured "coap" requests. 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 the HC proxy operates. These rules should be configurable.
It is RECOMMENDED that, by default, accessing a "coaps" URI is only allowed from a corresponding "https" URI.
By default, a HC 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 means. Assuming that CoAP nodes are isolated behind a firewall as in the HC proxy deployment shown in Figure 1, the HC proxy may be configured to translate the incoming HTTPS request using plain CoAP (NoSec mode).
The following risks related to the URI mapping described in Section 5 and its use by HC proxies have been identified:
An initial version of Table 2 in Section 7 has been provided in revision -05 of the CoRE CoAP I-D. 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 Abhijan Bhattacharyya, Brian Frank, Carsten Bormann, Christian Amsuess, Christian Groves, Cullen Jennings, Dorothy Gellert, Francesco Corazza, Hannes Tschofenig, Jaime Jimenez, Kepeng Li, Kerry Lynn, Klaus Hartke, Linyi Tian, Michele Rossi, Michele Zorzi, Nicola Bui, Peter Saint-Andre, Zach Shelby 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.
[I-D.ietf-core-links-json] | Li, K., Rahman, A. and C. Bormann, "Representing CoRE Formats in JSON and CBOR", Internet-Draft draft-ietf-core-links-json-06, July 2016. |
[I-D.ietf-core-resource-directory] | Shelby, Z., Koster, M., Bormann, C. and P. Stok, "CoRE Resource Directory", Internet-Draft draft-ietf-core-resource-directory-08, July 2016. |
[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, DOI 10.17487/RFC2616, June 1999. |
[RFC3040] | Cooper, I., Melve, I. and G. Tomlinson, "Internet Web Replication and Caching Taxonomy", RFC 3040, DOI 10.17487/RFC3040, January 2001. |
[RFC4732] | Handley, M., Rescorla, E. and IAB, "Internet Denial-of-Service Considerations", RFC 4732, DOI 10.17487/RFC4732, December 2006. |
[RFC7049] | Bormann, C. and P. Hoffman, "Concise Binary Object Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, October 2013. |
[RFC7390] | Rahman, A. and E. Dijk, "Group Communication for the Constrained Application Protocol (CoAP)", RFC 7390, DOI 10.17487/RFC7390, October 2014. |
[Note to RFC Editor: Please remove this section before publication.]
Changes from ietf-12 to ietf-13 (Christian Amsuss' comments):
Changes from ietf-11 to ietf-12 (2nd WGLC):
Changes from ietf-10 to ietf-11 (Chair review):
Changes from ietf-09 to ietf-10:
Changes from ietf-08 to ietf-09:
Changes from ietf-07 to ietf-08:
Changes from ietf-06 to ietf-07:
Changes from ietf-05 to ietf-06:
Changes from ietf-04 to ietf-05:
Changes from ietf-03 to ietf-04:
Changes from ietf-02 to ietf-03:
Changes from ietf-01 to ietf-02:
Changes from ietf-00 to ietf-01: