Content deleted Content added
DoktorBlah (talk | contribs) →Implementations: Added RFC 7641, RFC 7959 to the list of implemented standards for node-coap (see the README file on Github) |
ce |
||
(41 intermediate revisions by 27 users not shown) | |||
Line 1:
{{Short description|Specialized Internet application protocol}}
{{IP stack}}
'''Constrained Application Protocol''' ('''CoAP''') is a specialized [[User Datagram Protocol|UDP-based]] Internet application protocol for constrained devices, as defined in [https://datatracker.ietf.org/doc/html/rfc7252 RFC 7252] (published in 2014). It enables those constrained devices called "nodes" to communicate with the wider Internet using similar protocols.
CoAP is designed for use between devices on the same constrained network (e.g., low-power, lossy networks), between devices and general nodes on the Internet, and between devices on different constrained networks both joined by an internet. CoAP is also being used via other mechanisms, such as SMS on mobile communication networks.
CoAP is
The Internet Engineering Task Force ([[IETF]]) Constrained [[RESTful]] Environments Working Group ([https://datatracker.ietf.org/doc/charter-ietf-core/ CoRE]) has done the major standardization work for this protocol. In order to make the protocol suitable to IoT and M2M applications, various new functions have been added.
== Specification ==
The core of the protocol is specified in
* {{IETF RFC|7641}} (2015) Observing Resources in the Constrained Application Protocol
* {{IETF RFC|7959}} (2016) Block-Wise Transfers in the Constrained Application Protocol (CoAP)
Line 16 ⟶ 17:
==Message formats==
The smallest CoAP message is 4 bytes in length, if the token, options and payload fields are omitted, i.e. if it only consists of the CoAP header. The header is followed by the token value (0 to 8 bytes) which may be followed by a list of options in an optimized type–length–value format. Any bytes after the header, token and options (if any) are considered the message payload, which is prefixed by the one-byte "payload marker" (0xFF). The length of the payload is implied by the datagram length.
{| class="wikitable" style="margin: 0 auto; text-align:center"
|+ CoAP
|-
!
|-
! 4 !! 32
| colspan="2" |
|-
! 8 !! 64
| colspan="32" rowspan="2" |
|-
! 12 !! 96
|-
! 16 !! 128
| colspan="32" |
|-
! 20 !! 160
| 1 || 1 || 1 || 1 || 1 || 1 || 1 || 1 || colspan="24" |
|}
=== CoAP fixed-size header ===
The first 4 bytes are mandatory in all CoAP datagrams, they constitute the fixed-size header.
These fields can be
<syntaxhighlight lang="c"> #define COAP_HEADER_VERSION(data) ( (0xC0 & (data)[0]) >> 6 )
#define COAP_HEADER_TYPE(data) ( (0x30 & (data)[0]) >> 4 )
#define COAP_HEADER_TKL(data) ( (0x0F & (data)[0]) >> 0 )
#define COAP_HEADER_CLASS(data) ( ((data)[1] >> 5) & 0x07
#define COAP_HEADER_CODE(data) ( ((data)[1] >> 0) & 0x1F
#define COAP_HEADER_MID(data) ( ((data)[2] << 8) | (data)[3]
</syntaxhighlight>
==== Version (
:Indicates the CoAP version number.
Line 60 ⟶ 62:
:This describes the datagram's message type for the two message type context of Request and Response.
:* Request
:** 0 : Confirmable : This message expects a corresponding
:** 1 : Non-confirmable : This message does not expect a confirmation message.
:* Response
Line 66 ⟶ 68:
:** 3 : Reset : This message indicates that it had received a message but could not process it.
==== Token
:Indicates the length of the variable-length Token field, which may be
==== Request/
{| class="wikitable"
!0
Line 125 ⟶ 127:
| Unsupported Content-Format
}}
* Server
| Internal
| Not
| Bad
| Service
| Gateway
| Proxying
}}
* Signaling Codes: 7.XX {{ordered list|start=0
Line 145 ⟶ 147:
==== Message ID (16 bits) ====
:Used to detect message duplication and to match messages of type
=== Token ===
Matching requests and responses is not done with the message ID because a response may be sent in a different message than the acknowledgement (which uses the message ID for matching). For example, this could be done to prevent retransmissions if obtaining the result takes some time. Such a detached response is called "separate response". In contrast, transmitting the response directly in the acknowledgement is called "piggybacked response" which is expected to be preferred for efficiency reasons.
=== Option ===
{| class="wikitable"
|+Option Format
! colspan="8" |Bit
|-
!0
Line 164 ⟶ 168:
!7
|-
| colspan="4" |Option
| colspan="4" |Option
|-
| colspan="8" |Option
|-
| colspan="8" |Option
|-
| colspan="8" |Option
|}
Option
* 0 to 12: For delta between 0
* 13: For delta from 13 to 268: Option
* 14: For delta from 269 to 65,804: Option
* 15: Reserved for
Option
* 0 to 12: For
* 13: For
* 14: For
* 15: Reserved for future use. It is an error
Option
* Size of
* Semantic and format this field depends on the respective option.
{| class="wikitable sortable"
|-
! Name !! Programming Language !! Implemented CoAP version !! Client/Server !! Implemented CoAP features !! License !! Link
|-
|
|-
|
|-
|
|-
|
|-
|
|-
| Go-CoAP
|-
|
|-
|
|-
|libcoapy
|Python
| colspan="3" |same support as libcoap
|MIT
|{{URL|https://github.com/anyc/libcoapy}}
|-
|
|-
|
|-
|
|-
| Erbium for Contiki || C || RFC 7252 || Client + Server || Observe, Blockwise Transfers || 3-clause BSD || http://www.contiki-os.org/ (er-rest-example)▼
RFC 7641, RFC 7959▼
| Client + Server || Core, Observe, Block || MIT || {{URL|https://github.com/mcollina/node-coap}}▼
|-
|
|-
|
{{URL|https://docs.rs/coap/}}▼
|-
|}
| java-coap || Java || RFC 7252, RFC 7641, RFC 7959, RFC 8323 || Client + Server || || Apache License 2.0 || https://github.com/PelionIoT/java-coap▼
==Proxy implementations==
There exist [[Proxy server|proxy]] implementations which provide [[Forward proxy|forward]] or [[Reverse proxy|reverse]] proxy functionality for the CoAP protocol and also implementations which translate between protocols like HTTP and CoAP.
The following projects provide proxy functionality:
* [http://telecom.dei.unipd.it/pages/read/90/ Squid 3.1.9 with transparent HTTP-CoAP mapping module]▼
* [https://code.google.com/p/jcoap/ jcoap Proxy]▼
* [https://github.com/eclipse/californium/tree/master/californium-proxy2 Californium cf-proxy2]▼
* [https://github.com/Tanganelli/CoAPthon CoAPthon]▼
* [https://github.com/keith-cullen/FreeCoAP FreeCoAP]▼
* [https://github.com/obgm/libcoap libcoap]
==Projects using CoAP==
{| class="wikitable sortable"
|-
! Name !! Programming Language !! Implemented CoAP version !! Client/Server !! Implemented CoAP features !! License !! Link
| jCoAP || Java || RFC 7252 || Client + Server || Observe, Blockwise Transfers || Apache License 2.0 || https://code.google.com/p/jcoap/▼
|-
|
|-
|
|-
|}
| lobaro-coap || C || RFC 7252 || Client + Server ||Observe, Blockwise Transfers || MIT || http://www.lobaro.com/lobaro-coap▼
==Inactive protocol implementations==
{| class="wikitable sortable"
|-
! Name !! Programming Language !! Implemented CoAP version !! Client/Server !! Implemented CoAP features !! License !! Link
| microcoap || C || RFC 7252 || Client + Server || || MIT || https://github.com/1248/microcoap▼
|-
|
|-
|
|-
|
|-
▲|
▲| node-coap || Javascript || RFC 7252,
▲RFC 7641, RFC 7959
▲| Client + Server || Core, Observe, Block || MIT || https://github.com/mcollina/node-coap
|-
|
|-
|
|-
|
|-
|
|-
|
|-
|
|-
|
|-
▲|
|-
| nCoap || Java || RFC 7252|| Client + Server || Observe, Blockwise Transfers, CoRE Link Format, [https://tools.ietf.org/html/draft-kleine-core-coap-endpoint-id-01 Endpoint-ID-Draft] || BSD || https://github.com/okleine/nCoAP
|-
▲|
|-
▲|
|-
| Sensinode Java Device Library || Java SE || RFC 7252|| Client + Server || Core, Observe, Block, RD || Commercial || https://silver.arm.com/browse/SEN00
|-
| Sensinode NanoService Platform || Java SE || RFC 7252|| Cloud Server || Core, Observe, Block, RD || Commercial || https://silver.arm.com/browse/SEN00
|-
▲|
|-
| TinyOS CoapBlip || nesC/C || coap-13 || Client + Server || Observe, Blockwise Transfers || BSD || https://web.archive.org/web/20130312140509/http://docs.tinyos.net/tinywiki/index.php/CoAP
|-
|
▲https://docs.rs/coap/
|-
| YaCoAP || C || || || || MIT || https://github.com/RIOT-Makers/YaCoAP
|-
|}
▲==Proxy implementations==
▲* [http://telecom.dei.unipd.it/pages/read/90/ Squid 3.1.9 with transparent HTTP-CoAP mapping module]
▲* [https://code.google.com/p/jcoap/ jcoap Proxy]
▲* [https://github.com/eclipse/californium/tree/master/californium-proxy2 Californium cf-proxy2]
▲* [https://github.com/Tanganelli/CoAPthon CoAPthon]
▲* [https://github.com/keith-cullen/FreeCoAP FreeCoAP]
==CoAP group communication==
Line 288 ⟶ 322:
== Security ==
CoAP defines four security modes:<ref>
* NoSec, where [[DTLS]] is disabled
* PreSharedKey, where DTLS is enabled, there is a list of pre-shared keys, and each key includes a list of which nodes it can be used to communicate with. Devices must support the AES cipher suite.
Line 294 ⟶ 328:
* Certificate, where DTLS is enabled and the device uses [[X.509]] certificates for validation.
Research has been conducted on optimizing DTLS by implementing security associates as CoAP resources rather than using DTLS as a security wrapper for CoAP traffic. This research has indicated that improvements of up to 6.5 times none optimized implementations.
In addition to DTLS, RFC8613<ref>{{Cite
== Security issues ==
Although the protocol standard includes provisions for mitigating the threat of [[DDoS]] amplification attacks,<ref>[https://blog.cloudflare.com/why-iot-is-insecure/ "TLS 1.3 is going to save us all, and other reasons why IoT is still insecure", Dani Grant, 2017-12-24]</ref> these provisions are not implemented in practice,<ref>[https://i.blackhat.com/eu-18/Thu-Dec-6/eu-18-Maggi-When-Machines-Cant-Talk-wp.pdf "When Machines Can't Talk: Security and Privacy Issues of Machine-to-Machine Data Protocols", Federico Maggi and Rainer Vosseler, 2018-12-06]</ref> resulting in the presence of over 580,000 targets primarily located in China and attacks up to
==See also==
|