Constrained Application Protocol: Difference between revisions

Content deleted Content added
DrTobbe (talk | contribs)
Message formats: Clarify message ID usage for acknowledgement/reset matching and token usage for request-response-matching
ce
 
(33 intermediate revisions by 22 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 a [[servicean application-layer]] protocol that is intended for use in resource-constrained internetInternet devices, such as [[wireless sensor network]] nodes. CoAP is designed to easily translate to [[HTTP]] for simplified integration with the web, while also meeting specialized requirements such as [[multicast]] support, very low overhead, and simplicity.<ref>[https://tools.ietf.org/html/rfc7252 RFC 7252, Constrained Application Protocol (CoAP)]</ref><ref>"[http://hinrg.cs.jhu.edu/joomla/images/stories/IPSN_2011_koliti.pdf Integrating Wireless Sensor Networks with the Web] {{Webarchive|url=https://web.archive.org/web/20170830060917/http://hinrg.cs.jhu.edu/joomla/images/stories/IPSN_2011_koliti.pdf |date=2017-08-30 }}" , Walter, Colitti 2011</ref> Multicast, low overhead, and simplicity are important for [[Internet of things]] (IoT) and [[machine-to-machine]] (M2M) communication, which tend to be deeply [[Embedded system|embedded]] and have much less memory and power supply than traditional internetInternet devices have. Therefore, efficiency is very important. CoAP can run on most devices that support [[User Datagram Protocol|UDP]] or a UDP analogue.
 
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.
Line 40 ⟶ 41:
|}
 
=== CoAP Fixedfixed-Sizesize Headerheader ===
The first 4 bytes are mandatory in all CoAP datagrams, they constitute the fixed-size header.
 
These fields can be extracted from these 4 bytes in C via these macros:
<syntaxhighlight lang="c">
#define COAP_HEADER_VERSION(data) ( (0xC0 & (data)[0]) >> 6 )
#define COAP_HEADER_TYPE(data) ( (0x30 & (data)[0]) >> 4 )
Line 150 ⟶ 152:
Every request carries a token (but it may be zero length) whose value was generated by the client. The server must echo every token value without any modification back to the client in the corresponding response. It is intended for use as a client-local identifier to match requests and responses, especially for concurrent requests.
 
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 ===
Line 177 ⟶ 179:
Option delta:
 
* 0 to 12: For delta between 0 toand 12: Represents the exact delta value between the last option ID and the desired option ID, with no option delta extended value
* 13: For delta from 13 to 268: Option delta extended is an 8-bit value that represents the option delta value minus 13
* 14: For delta from 269 to 65,804: Option delta extended is a 16-bit value that represents the option delta value minus 269
Line 184 ⟶ 186:
Option length:
 
* 0 to 12: For option length between 0 toand 12: Represents the exact length value, with no option length extended value
* 13: For option length from 13 to 268: Option length extended is an 8-bit value that represents the option length value minus 13
* 14: For option length from 269 to 65,804: Option length extended is a 16-bit value that represents the option length value minus 269
* 15: Reserved for future use. It is an error for the option length field to be set to 0xFF.
 
Option value:
Line 194 ⟶ 196:
* Semantic and format this field depends on the respective option.
 
==ProxyActive protocol implementations==
==Implementations==
{| class="wikitable sortable"
|-
! Name !! Programming Language !! Implemented CoAP version !! Client/Server !! Implemented CoAP features !! License !! Link
|-
| coap || Dart || RFC 7252 || Client || Blockwise Transfers, Observe, Multicast, Proxying (partial) || MIT || https://github.com/shamblett/coap
|-
| aiocoap || Python 3 || RFC 7252, RFC 7641, RFC 7959, RFC 8323, RFC 7967, RFC 8132, RFC 9176, RFC 8613, RFC 9528|| Client + Server || Blockwise Transfers, Observe (partial) || MIT || {{URL|https://pypi.python.org/pypi/aiocoap}}
|-
| Californium || Java || RFC 7252, RFC 7641, RFC 7959 || Client + Server || Observe, Blockwise Transfers, Multicast (since 2.x), DTLS (+ DTLS 1.2 Connection ID) || EPL+EDL || {{URL|https://www.eclipse.org/californium}} {{URL|https://github.com/eclipse/californium}}
|-
| cantcoapCoAPSharp || C++/C#, .NET || RFC 7252 || Client + Server || Core, Observe, Block, RD || BSDMIT || {{URL|http://www.coapsharp.com https://github.com/staropramFemtomaxInc/cantcoapcoapsharp}}
|-
| CanopusFreeCoAP || [[Go (programming language)|Go]]C || RFC 7252 || Client + Server ||+ CoreHTTP/CoAP Proxy ||Core, ApacheDTLS, LicenseBlockwise 2.0Transfers || BSD || {{URL|https://github.com/zubairhamedkeith-cullen/canopusFreeCoAP}}
|-
| Go-CoAP || [[Go (programming language)|Go]] || RFC 7252, RFC 8232, RFC 7641, RFC 7959 || Client + Server || Core, Observe, Blockwise, Multicast, TCP/TLS || Apache License 2.0 || {{URL|https://github.com/goplgd-ocfdev/go-coap}}
|-
| CoAPjava-coap implementation for|| GoJava || RFC [[Go7252, (programmingRFC language)|Go]] ||7641, RFC 72527959, RFC 8323|| Client + Server || Core + Draft Subscribe || MITApache License 2.0 || {{URL|https://github.com/dustinPelionIoT/gojava-coap}}
|-
| CoAP.NETlibcoap || C# || RFC 7252, coap-13RFC 7390, coap-08RFC 7641, coap-03RFC 7959, RFC 7967, RFC 8132, RFC 8323, RFC 8516, RFC 8613, RFC 8768, RFC 8974, RFC 9175, RFC 9177|| Client + Server || Core, Observe, Multicast, Blockwise Transfers, Patch/Fetch, OSCORE, (D)TLS || 3-clause BSD/GPL || https://github.com/smeshlinkobgm/CoAP.NETlibcoap
|-
|libcoapy
| CoAPSharp || C#, .NET || RFC 7252 || Client + Server || Core, Observe, Block, RD || LGPL || http://www.coapsharp.com
|Python
| colspan="3" |same support as libcoap
|MIT
|{{URL|https://github.com/anyc/libcoapy}}
|-
| CoAPthonlobaro-coap || PythonC || RFC 7252 || Client + Server + Forward Proxy + Reverse Proxy || Observe, MulticastBlockwise server discovery, CoRE Link Format parsing, Block-wiseTransfers || MIT || https{{URL|http://githubwww.lobaro.com/Tanganelli/CoAPthonlobaro-coap}}
|-
| CoAP ShellmicroCoAPy || JavaMicroPython || RFC 7252 || Client + Server || Observe, Blockwise Transfers, DTLSCore || Apache License 2.0 || {{URL|https://github.com/tzolovinsighio/coap-shell microCoAPy}}
|-
| CoppernanoCoAP || JavaScript (Browser Plugin)C || RFC 7252 || Client + Server || ObserveCore, Blockwise Transfers, DTLS || 3-clause BSDLGPL || {{URL|https://githubapi.com/mkovatsc/Copper https://addons.mozillariot-os.org/firefox/addon/copper-270430/{{Dead link|date=July 2019 |bot=InternetArchiveBot |fix-attempted=yes group__net__nanocoap.html}}
|-
| node-coap || JavascriptJavaScript || RFC 7252,
| eCoAP || C || RFC 7252 || Client + Server || Core || MIT || https://gitlab.com/jobol/ecoap
RFC 7641, RFC 7959
| Client + Server || Core, Observe, Block || MIT || {{URL|https://github.com/mcollina/node-coap}}
|-
| ErbiumQt for ContikiCoAP || C++ || RFC 7252 || Client + Server || Core, Observe, Blockwise Transfers || 3-clauseGPL, BSDCommercial || httphttps://wwwdoc.contiki-osqt.orgio/ (erqt-rest6/qtcoap-example)index.html
|-
| FreeCoAPcoap-rs || CRust || RFC 7252 || Client + Server + HTTP/CoAP Proxy || Core, DTLSMulticast, BlockwiseObserve Transfersoption, ''Too Many Requests'' Response Code || BSDMIT || {{URL|https://github.com/keith-cullenCovertness/FreeCoAPcoap-rs}}
{{URL|https://docs.rs/coap/}}
|-
|}
| iCoAP || Objective-C || RFC 7252 || Client || Core, Observe, Blockwise Transfers || MIT || https://github.com/stuffrabbit/iCoAP
 
==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
| java-coap || Java || RFC 7252, RFC 7641, RFC 7959, RFC 8323 || Client + Server || || Apache License 2.0 || https://github.com/PelionIoT/java-coap
|-
| jCoAPCoAP Shell || Java || RFC 7252 || Client + Server || Observe, Blockwise Transfers, DTLS || Apache License 2.0 || https://code.googlegithub.com/p/jcoaptzolov/coap-shell
|-
| libcoapCopper || CJavaScript (browser plugin) || RFC 7252 || Client + Server || Observe, Blockwise Transfers, DTLS || 3-clause BSD/GPL || https://github.com/obgmmkovatsc/libcoapCopper https://addons.mozilla.org/firefox/addon/copper-270430/{{Dead link|date=July 2019 |bot=InternetArchiveBot |fix-attempted=yes }}
|-
|}
| LibNyoci || C || RFC 7252 || Client + Server || Core, Observe, Block, DTLS || MIT || https://github.com/darconeous/libnyoci
 
==Inactive protocol implementations==
{| class="wikitable sortable"
|-
! Name !! Programming Language !! Implemented CoAP version !! Client/Server !! Implemented CoAP features !! License !! Link
| lobaro-coap || C || RFC 7252 || Client + Server ||Observe, Blockwise Transfers || MIT || http://www.lobaro.com/lobaro-coap
|-
| microcoapcantcoap || C++/C || RFC 7252 || Client + Server || || MITBSD || https://github.com/1248staropram/microcoapcantcoap
|-
| microCoAPyCanopus || MicroPython[[Go (programming language)|Go]] || RFC 7252 || Client + Server || Core || Apache License 2.0 || https://github.com/insighiozubairhamed/microCoAPycanopus
|-
| nanocoapCoAP implementation for Go || C[[Go (programming language)|Go]] || RFC 7252 || Client + Server || Core, Blockwise+ TransfersDraft Subscribe || LGPLMIT || https://apigithub.riotcom/dustin/go-os.org/group__net__nanocoap.htmlcoap
|-
| nCoapCoAP.NET || JavaC# || RFC 7252, coap-13, coap-08, coap-03 || Client + Server || Core, Observe, Blockwise Transfers, CoRE|| Link Format, [https://tools.ietf.org/html/draft3-kleine-core-coap-endpoint-id-01 Endpoint-ID-Draft] ||clause BSD || https://github.com/okleinesmeshlink/nCoAPCoAP.NET
|-
| CoAPthon || Python || RFC 7252|| Client + Server + Forward Proxy + Reverse Proxy || Observe, Multicast server discovery, CoRE Link Format parsing, Block-wise || MIT || https://github.com/Tanganelli/CoAPthon
| node-coap || Javascript || RFC 7252,
RFC 7641, RFC 7959
| Client + Server || Core, Observe, Block || MIT || https://github.com/mcollina/node-coap
|-
| Ruby coapeCoAP || RubyC || RFC 7252 || Client + Server (david) || Core, Observe, Block, RD || MIT, GPL || https://github.com/nning/coap<br/>https://githubgitlab.com/nningjobol/davidecoap
|-
| SensinodeErbium Cfor Device LibraryContiki || C || RFC 7252 || Client + Server || Core, Observe, Block,Blockwise RDTransfers || Commercial3-clause BSD || httpshttp://silverwww.armcontiki-os.comorg/browse/SEN00 (er-rest-example)
|-
| Sensinode Java Device Libraryguile-coap || Java SEGuile || RFC 7252, RFC 8323 || Client + Server || Core, Observe, Block, RD || CommercialGPL-3.0-or-later || https://silver.armcodeberg.comorg/browseeris/SEN00guile-coap
|-
| Sensinode NanoService PlatformiCoAP || Java SEObjective-C || RFC 7252 || Cloud ServerClient || Core, Observe, Block,Blockwise RDTransfers || CommercialMIT || https://silver.armgithub.com/browsestuffrabbit/SEN00iCoAP
|-
| SwiftCoAPjCoAP || SwiftJava || RFC 7252 || Client + Server || Core, Observe, Blockwise Transfers || MITApache License 2.0 || https://githubcode.google.com/stuffrabbitp/jcoap/SwiftCoAP
|-
| TinyOS CoapBlipLibNyoci || nesC/C || coap-13RFC 7252|| Client + Server || Core, Observe, BlockwiseBlock, TransfersDTLS || BSDMIT || https://webgithub.archive.orgcom/web/20130312140509/http://docs.tinyos.net/tinywiki/index.phpdarconeous/CoAPlibnyoci
|-
| txThingsmicrocoap || Python (Twisted)C || RFC 7252 || Client + Server || Blockwise Transfers, Observe (partial) || MIT || https://github.com/mwasilak/txThings1248/microcoap
|-
| coap-rsnCoap || RustJava || RFC 7252 || Client + Server || CoreObserve, Multicast,Blockwise Observe optionTransfers, ''TooCoRE ManyLink Requests''Format, Response[https://tools.ietf.org/html/draft-kleine-core-coap-endpoint-id-01 CodeEndpoint-ID-Draft] || MITBSD || https://github.com/Covertnessokleine/coap-rsnCoAP
|-
https://docs.rs/coap/
| LibNyociRuby coap || CRuby || RFC 7252 || Client + Server (david) || Core, Observe, Block, DTLSRD || MIT, GPL || https://github.com/darconeousnning/coap<br/>https://github.com/nning/libnyocidavid
|-
| CoAPSharpSensinode C Device Library || C#, .NET || RFC 7252 || Client + Server || Core, Observe, Block, RD || LGPLCommercial || httphttps://wwwsilver.coapsharparm.com/browse/SEN00
|-
| 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
|-
| eCoAPSwiftCoAP || CSwift || RFC 7252 || Client + Server || Core, Observe, Blockwise Transfers || MIT || https://gitlabgithub.com/jobolstuffrabbit/ecoapSwiftCoAP
|-
| lobaro-coapTinyOS CoapBlip || nesC/C || RFC 7252coap-13 || Client + Server || Observe, Blockwise Transfers || MITBSD || https://web.archive.org/web/20130312140509/http://wwwdocs.lobarotinyos.comnet/lobaro-coaptinywiki/index.php/CoAP
|-
| iCoAPtxThings || Objective-CPython (Twisted) || RFC 7252 || Client + Server || CoreBlockwise Transfers, Observe, Blockwise Transfers(partial) || MIT || https://github.com/stuffrabbitmwasilak/txThings/iCoAP
|-
| 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 292 ⟶ 322:
 
== Security ==
CoAP defines four security modes:<ref> [https://tools.ietf.org/html/rfc7252 RFC 7252, Constrained Application Protocol (CoAP)]</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 298 ⟶ 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. <ref name="Security as a CoAP resource: An optimized DTLS implementation for the IoT">{{cite journalbook |lastlast1=Capossele |firstfirst1=Angelo |last2=Cervo |first2=Valerio |last3=De Cicco |first3=Gianluca |last4=Petrioli |first4=Chiara |datetitle=June 2015 IEEE International Conference on Communications (ICC) |titlechapter=Security as a CoAP resource: An optimized DTLS implementation for the IoT |journalauthor4-link= Chiara Petrioli |date=June 2015 |publisher=IEEE |pages=529–554 |doi= 10.1109/ICC.2015.7248379|isbn=978-1-4673-6432-4 |s2cid=12568959 }}</ref>
 
In addition to DTLS, RFC8613<ref>{{Cite webjournal|lastlast1=Palombini|firstfirst1=Francesca|last2=Seitz|first2=Ludwig|last3=Selander|first3=Goeran|last4=Mattsson|first4=John|title=Object Security for Constrained RESTful Environments (OSCORE)|url=https://tools.ietf.org/html/rfc8613.html|access-date=2021-05-07|website=tools.ietf.org|year=2019 |doi=10.17487/RFC8613 |s2cid=58380874 |language=en}}</ref> defines the Object Security for Constrained RESTful Environments ([[OSCORE]]) protocol which provides security for CoAP at the application layer.
 
== 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 320&nbsp;GbpsGbit/s.<ref>[https://www.zdnet.com/article/the-coap-protocol-is-the-next-big-thing-for-ddos-attacks/ "The CoAP protocol is the next big thing for DDoS attacks", Catalin Cimpanu, 2018-12-05]</ref>
 
==See also==