idnits 2.17.1 draft-ietf-lpwan-coap-static-context-hc-10.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The abstract seems to contain references ([I-D.ietf-lpwan-ipv6-static-context-hc]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. ** The document seems to lack a both a reference to RFC 2119 and the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. RFC 2119 keyword, line 133: '... the CoAP header MAY be done in conjun...' RFC 2119 keyword, line 241: '...idirectional and MUST be elided during...' RFC 2119 keyword, line 255: '... The field SHOULD be elided if for i...' RFC 2119 keyword, line 258: '...any case, a rule MUST be defined to ca...' RFC 2119 keyword, line 270: '...e response codes MUST be compressed wi...' (19 more instances...) Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == Line 354 has weird spacing: '... equal not...' == Line 356 has weird spacing: '... ignore valu...' == Line 381 has weird spacing: '... ignore val...' == Line 1028 has weird spacing: '...tkn piv kid...' == Line 1045 has weird spacing: '... mid tkn...' -- The document date (October 08, 2019) is 1661 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: 'CON' is mentioned on line 251, but not defined == Missing Reference: 'NON' is mentioned on line 251, but not defined == Missing Reference: 'ACK' is mentioned on line 252, but not defined == Missing Reference: 'RST' is mentioned on line 252, but not defined -- Looks like a reference, but probably isn't: '69' on line 1069 -- Looks like a reference, but probably isn't: '132' on line 1069 == Outdated reference: A later version (-24) exists of draft-ietf-lpwan-ipv6-static-context-hc-21 Summary: 2 errors (**), 0 flaws (~~), 11 warnings (==), 3 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 lpwan Working Group A. Minaburo 3 Internet-Draft Acklio 4 Intended status: Standards Track L. Toutain 5 Expires: April 10, 2020 Institut MINES TELECOM; IMT Atlantique 6 R. Andreasen 7 Universidad de Buenos Aires 8 October 08, 2019 10 LPWAN Static Context Header Compression (SCHC) for CoAP 11 draft-ietf-lpwan-coap-static-context-hc-10 13 Abstract 15 This draft defines the way SCHC header compression can be applied to 16 CoAP headers. The CoAP header structure differs from IPv6 and UDP 17 protocols since CoAP uses a flexible header with a variable number of 18 options, themselves of variable length. The CoAP protocol messages 19 format is asymmetric: the request messages have a header format 20 different from the one in the response messages. This document 21 explains how to use the SCHC compression mechanism described in 22 [I-D.ietf-lpwan-ipv6-static-context-hc] for CoAP. 24 Status of This Memo 26 This Internet-Draft is submitted in full conformance with the 27 provisions of BCP 78 and BCP 79. 29 Internet-Drafts are working documents of the Internet Engineering 30 Task Force (IETF). Note that other groups may also distribute 31 working documents as Internet-Drafts. The list of current Internet- 32 Drafts is at https://datatracker.ietf.org/drafts/current/. 34 Internet-Drafts are draft documents valid for a maximum of six months 35 and may be updated, replaced, or obsoleted by other documents at any 36 time. It is inappropriate to use Internet-Drafts as reference 37 material or to cite them other than as "work in progress." 39 This Internet-Draft will expire on April 10, 2020. 41 Copyright Notice 43 Copyright (c) 2019 IETF Trust and the persons identified as the 44 document authors. All rights reserved. 46 This document is subject to BCP 78 and the IETF Trust's Legal 47 Provisions Relating to IETF Documents 48 (https://trustee.ietf.org/license-info) in effect on the date of 49 publication of this document. Please review these documents 50 carefully, as they describe your rights and restrictions with respect 51 to this document. Code Components extracted from this document must 52 include Simplified BSD License text as described in Section 4.e of 53 the Trust Legal Provisions and are provided without warranty as 54 described in the Simplified BSD License. 56 Table of Contents 58 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 59 2. SCHC Compression Process . . . . . . . . . . . . . . . . . . 3 60 3. CoAP Compression with SCHC . . . . . . . . . . . . . . . . . 4 61 4. Compression of CoAP header fields . . . . . . . . . . . . . . 6 62 4.1. CoAP version field . . . . . . . . . . . . . . . . . . . 6 63 4.2. CoAP type field . . . . . . . . . . . . . . . . . . . . . 6 64 4.3. CoAP code field . . . . . . . . . . . . . . . . . . . . . 6 65 4.4. CoAP Message ID field . . . . . . . . . . . . . . . . . . 6 66 4.5. CoAP Token fields . . . . . . . . . . . . . . . . . . . . 7 67 5. CoAP options . . . . . . . . . . . . . . . . . . . . . . . . 7 68 5.1. CoAP Content and Accept options. . . . . . . . . . . . . 7 69 5.2. CoAP option Max-Age, Uri-Host and Uri-Port fields . . . . 8 70 5.3. CoAP option Uri-Path and Uri-Query fields . . . . . . . . 8 71 5.3.1. Variable length Uri-Path and Uri-Query . . . . . . . 8 72 5.3.2. Variable number of path or query elements . . . . . . 9 73 5.4. CoAP option Size1, Size2, Proxy-URI and Proxy-Scheme 74 fields . . . . . . . . . . . . . . . . . . . . . . . . . 9 75 5.5. CoAP option ETag, If-Match, If-None-Match, Location-Path 76 and Location-Query fields . . . . . . . . . . . . . . . . 9 77 6. Other RFCs . . . . . . . . . . . . . . . . . . . . . . . . . 10 78 6.1. Block . . . . . . . . . . . . . . . . . . . . . . . . . . 10 79 6.2. Observe . . . . . . . . . . . . . . . . . . . . . . . . . 10 80 6.3. No-Response . . . . . . . . . . . . . . . . . . . . . . . 10 81 6.4. OSCORE . . . . . . . . . . . . . . . . . . . . . . . . . 10 82 7. Examples of CoAP header compression . . . . . . . . . . . . . 12 83 7.1. Mandatory header with CON message . . . . . . . . . . . . 12 84 7.2. OSCORE Compression . . . . . . . . . . . . . . . . . . . 13 85 7.3. Example OSCORE Compression . . . . . . . . . . . . . . . 16 86 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 26 87 9. Security considerations . . . . . . . . . . . . . . . . . . . 26 88 10. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 26 89 11. Normative References . . . . . . . . . . . . . . . . . . . . 26 90 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 27 92 1. Introduction 94 CoAP [rfc7252] is an implementation of the REST architecture for 95 constrained devices. Although CoAP was designed for constrained 96 devices, the size of a CoAP header still is too large for the 97 constraints of Low Power Wide Area Networks (LPWAN) and some 98 compression is needed to reduce the header size. 100 [I-D.ietf-lpwan-ipv6-static-context-hc] defines a header compression 101 mechanism for LPWAN network based on a static context. The context 102 is said static since the field description composing the Rules are 103 not learned during the packet exchanges but are previously defined. 104 The context(s) is(are) known by both ends before transmission. 106 A context is composed of a set of rules that are referenced by Rule 107 IDs (identifiers). A rule contains an ordered list of the fields 108 descriptions containing a field ID (FID), its length (FL) and its 109 position (FP), a direction indicator (DI) (upstream, downstream and 110 bidirectional) and some associated Target Values (TV). Target Value 111 indicates the value that can be expected. TV can also be a list of 112 values. A Matching Operator (MO) is associated to each header field 113 description. The rule is selected if all the MOs fit the TVs for all 114 fields of the incoming packet. In that case, a Compression/ 115 Decompression Action (CDA) associated to each field defines how the 116 compressed and the decompressed values are computed out of each 117 other, for each of the header fields. Compression mainly results in 118 one of 4 actions: send the field value, send nothing, send some least 119 significant bits of the field or send an index. After applying the 120 compression there may be some bits to be sent, these values are 121 called Compression Residues and are transmitted after the Rule ID in 122 the compressed messages. 124 The compression rules define a generic way to compress and decompress 125 the fields. If the device is modified, for example, to introduce new 126 functionalities or new CoAP options, the rules must be updated to 127 reflect the evolution. There is no risk to lock a device in a 128 particular version of CoAP. 130 2. SCHC Compression Process 132 The SCHC Compression rules can be applied to CoAP flows. SCHC 133 Compression of the CoAP header MAY be done in conjunction with the 134 lower layers (IPv6/UDP) or independently. The SCHC adaptation layers 135 as described in [I-D.ietf-lpwan-ipv6-static-context-hc] may be used 136 as shown in Figure 1. 138 ^ +------------+ ^ +------------+ ^ +------------+ 139 | | CoAP | | | CoAP | inner | | CoAP | 140 | +------------+ v +------------+ x | OSCORE | 141 | | UDP | | DTLS | outer | +------------+ 142 | +------------+ +------------+ | | UDP | 143 | | IPv6 | | UDP | | +------------+ 144 v +------------+ +------------+ | | IPv6 | 145 | IPv6 | v +------------+ 146 +------------+ 148 Figure 1: rule scope for CoAP 150 Figure 1 shows some examples for CoAP architecture and the SCHC 151 rule's scope. 153 In the first example, a rule compresses the complete header stack 154 from IPv6 to CoAP. In this case, SCHC C/D is performed at the device 155 and at the LPWAN boundary. 157 In the second example, an end-to-end encryption mechanisms is used 158 between the device and the application. The SCHC compression is 159 applied in the CoAP layer compressing the CoAP header independently 160 of the other layers. The rule ID and the compression residue are 161 encrypted using a mechanism such as DTLS. Only the other end can 162 decipher the information. Layers below may also be compressed using 163 other SCHC rules (this is out of the scope of this document) as 164 defined in the SCHC [I-D.ietf-lpwan-ipv6-static-context-hc] document. 166 In the third example, OSCORE [rfc8613] is used. In this case, two 167 rulesets are used to compress the CoAP message. A first ruleset 168 focused on the inner header and is applied end to end by both ends. 169 A second ruleset compresses the outer header and the layers below and 170 is done between the device and the LPWAN boundary. 172 3. CoAP Compression with SCHC 174 CoAP differs from IPv6 and UDP protocols on the following aspects: 176 o IPv6 and UDP are symmetrical protocols. The same fields are found 177 in the request and in the response, with the value of some fields 178 being swapped on the return path (e.g. source and destination 179 fields). A CoAP request is intrinsically different from a 180 response. For example, the URI-path option is mandatory in the 181 request and is not found in the response, a request may contain an 182 Accept option and the response a Content option. 184 [I-D.ietf-lpwan-ipv6-static-context-hc] defines the use of a 185 message direction (DI) in the Field Description, which allows a 186 single Rule to process message headers differently depending of 187 the direction. 189 o Even when a field is "symmetric" (i.e. found in both directions) 190 the values carried in each direction are different. Combined with 191 a matching list in the TV, this allows reducing the range of 192 expected values in a particular direction and therefore reduce the 193 size of the compression residue. For instance, if a client sends 194 only CON request, the type can be elided by compression and the 195 answer may use one single bit to carry either the ACK or RST type. 196 The same behavior can be applied to the CoAP Code field 0.0X code 197 Format is found in the request and Y.ZZ code format in the answer. 198 The direction allows splitting in two parts the possible values 199 for each direction in the same Rule. 201 o In IPv6 and UDP, header fields have a fixed size and it is not 202 sent. In CoAP, some fields in the header have a varying size, for 203 example the Token size may vary from 0 to 8 bytes, the length is 204 given by a field in the header. More systematically, the CoAP 205 options are described using the Type-Length-Value. 207 [I-D.ietf-lpwan-ipv6-static-context-hc] offers the possibility to 208 define a function for the Field Length in the Field Description. 210 o In CoAP headers, a field can appear several times. This is 211 typical for elements of a URI (path or queries). The SCHC 212 specification [I-D.ietf-lpwan-ipv6-static-context-hc] allows a 213 Field ID to appears several times in the rule, and uses the Field 214 Position (FP) to identify the correct instance, and thereby 215 removing the ambiguity of the matching operation. 217 o Field sizes defined in the CoAP protocol can be too large 218 regarding LPWAN traffic constraints. This is particularly true 219 for the Message ID field and the Token field. The MSB MO can be 220 applied to reduce the information carried on LPWANs. 222 o CoAP also obeys the client/server paradigm and the compression 223 ratio can be different if the request is issued from an LPWAN 224 device or from a non LPWAN device. For instance, a Device (Dev) 225 aware of LPWAN constraints can generate a 1-byte token, but a 226 regular CoAP client will certainly send a larger token to the Dev. 227 The SCHC compression-decompression process never modifies the 228 Values it only reduces their sizes. Nevertheless, a proxy placed 229 before the compressor may change some field values to allow SCHC 230 achieving a better compression ratio, while maintaining the 231 necessary context for interoperability with existing CoAP 232 implementations. 234 4. Compression of CoAP header fields 236 This section discusses the compression of the different CoAP header 237 fields. 239 4.1. CoAP version field 241 CoAP version is bidirectional and MUST be elided during the SCHC 242 compression, since it always contains the same value. In the future, 243 if new versions of CoAP are defined, new rules will be needed to 244 avoid ambiguities between versions. 246 4.2. CoAP type field 248 CoAP Protocol [rfc7252] defines 4 types of messages: CON, NON, ACK 249 and RST. ACK and RST are a response to the CON and NON. If the 250 device plays a specific client or server role, a rule can take 251 advantage of these properties with the mapping list: [CON, NON] for 252 one direction and [ACK, RST] for the other direction and so, the 253 compression residue is reduced to 1 bit. 255 The field SHOULD be elided if for instance a client is sending only 256 NON or only CON messages. 258 In any case, a rule MUST be defined to carry RST to a client. 260 4.3. CoAP code field 262 The compression of the CoAP code field follows the same principle as 263 that of the CoAP type field. If the device plays a specific role, 264 the set of code values can be split in two parts, the request codes 265 with the 0 class and the response values. 267 If the device only implements a CoAP client, the request code can be 268 reduced to the set of requests the client is able to process. 270 All the response codes MUST be compressed with a SCHC rule. 272 4.4. CoAP Message ID field 274 The Message ID field is bidirectional and is used to manage 275 acknowledgments. The server memorizes the value for an 276 EXCHANGE_LIFETIME period (by default 247 seconds) for CON messages 277 and a NON_LIFETIME period (by default 145 seconds) for NON messages. 278 During that period, a server receiving the same Message ID value will 279 process the message as a retransmission. After this period, it will 280 be processed as a new message. 282 In case where the Device is a client, the size of the Message ID 283 field may be too large regarding the number of messages sent. The 284 client SHOULD use only small Message ID values, for instance 4 bit 285 long. Therefore, an MSB can be used to limit the size of the 286 compression residue. 288 In case where the Device is a server, the client may be located 289 outside of the LPWAN area and it views the Device as a regular device 290 connected to the Internet. The client will generate Message ID using 291 the 16 bits space offered by this field. A CoAP proxy can be set 292 before the SCHC C/D to reduce the value of the Message ID, to allow 293 its compression with the MSB matching operator and LSB CDA. 295 4.5. CoAP Token fields 297 Token is defined through two CoAP fields, Token Length in the 298 mandatory header and Token Value directly following the mandatory 299 CoAP header. 301 Token Length is processed as any protocol field. If the value 302 remains the same during all the transaction, the size can be stored 303 in the context and elided during the transmission. Otherwise, it 304 will have to be sent as a compression residue. 306 Token Value size cannot be defined directly in the rule in the Field 307 Length (FL). Instead, a specific function designated as "TKL" MUST 308 be used and length does not have to be sent with the residue. During 309 the decompression, this function returns the value contained in the 310 Token Length field. 312 5. CoAP options 314 5.1. CoAP Content and Accept options. 316 These fields are both unidirectional and MUST NOT be set to 317 bidirectional in a rule entry. 319 If a single value is expected by the client, it can be stored in the 320 TV and elided during the transmission. Otherwise, if several 321 possible values are expected by the client, a matching-list SHOULD be 322 used to limit the size of the residue. Otherwise, the value has to 323 be sent as a residue (fixed or variable length). 325 5.2. CoAP option Max-Age, Uri-Host and Uri-Port fields 327 These fields are unidirectional and MUST NOT be set to bidirectional 328 in a rule entry. They are used only by the server to inform of the 329 caching duration and is never found in client requests. 331 If the duration is known by both ends, the value can be elided on the 332 LPWAN. 334 A matching list can be used if some well-known values are defined. 336 Otherwise these options SHOULD be sent as a residue (fixed or 337 variable length). 339 5.3. CoAP option Uri-Path and Uri-Query fields 341 These fields are unidirectional and MUST NOT be set to bidirectional 342 in a rule entry. They are used only by the client to access a 343 specific resource and are never found in server responses. 345 Uri-Path and Uri-Query elements are a repeatable options, the Field 346 Position (FP) gives the position in the path. 348 A Mapping list can be used to reduce the size of variable Paths or 349 Queries. In that case, to optimize the compression, several elements 350 can be regrouped into a single entry. Numbering of elements do not 351 change, MO comparison is set with the first element of the matching. 353 FID FL FP DI TV MO CDA 354 URI-Path 1 up ["/a/b", equal not-sent 355 "/c/d"] 356 URI-Path 3 up ignore value-sent 358 Figure 2: complex path example 360 In Figure 2 a single bit residue can be used to code one of the 2 361 paths. If regrouping were not allowed, a 2 bits residue would be 362 needed. 364 5.3.1. Variable length Uri-Path and Uri-Query 366 When the length is not known at the rule creation, the Field Length 367 SHOULD be set to variable, and the unit is set to bytes. 369 The MSB MO can be applied to a Uri-Path or Uri-Query element. Since 370 MSB value is given in bit, the size MUST always be a multiple of 8 371 bits. 373 The length sent at the beginning of a variable length residue 374 indicates the size of the LSB in bytes. 376 For instance for a CORECONF path /c/X6?k="eth0" the rule can be set 377 to: 379 FID FL FP DI TV MO CDA 380 URI-Path 1 up "c" equal not-sent 381 URI-Path 2 up ignore value-sent 382 URI-Query 1 up "k=" MSB (16) LSB 384 Figure 3: CORECONF URI compression 386 Figure 3 shows the parsing and the compression of the URI, where c is 387 not sent. The second element is sent with the length (i.e. 0x2 X 6) 388 followed by the query option (i.e. 0x05 "eth0"). 390 5.3.2. Variable number of path or query elements 392 The number of Uri-path or Uri-Query elements in a rule is fixed at 393 the rule creation time. If the number varies, several rules SHOULD 394 be created to cover all the possibilities. Another possibility is to 395 define the length of Uri-Path to variable and send a compression 396 residue with a length of 0 to indicate that this Uri-Path is empty. 397 This adds 4 bits to the compression residue. 399 5.4. CoAP option Size1, Size2, Proxy-URI and Proxy-Scheme fields 401 These fields are unidirectional and MUST NOT be set to bidirectional 402 in a rule entry. They are used only by the client to access a 403 specific resource and are never found in server response. 405 If the field value has to be sent, TV is not set, MO is set to 406 "ignore" and CDA is set to "value-sent". A mapping MAY also be used. 408 Otherwise, the TV is set to the value, MO is set to "equal" and CDA 409 is set to "not-sent". 411 5.5. CoAP option ETag, If-Match, If-None-Match, Location-Path and 412 Location-Query fields 414 These fields are unidirectional. 416 These fields values cannot be stored in a rule entry. They MUST 417 always be sent with the compression residues. 419 6. Other RFCs 421 6.1. Block 423 Block [rfc7959] allows a fragmentation at the CoAP level. SCHC also 424 includes a fragmentation protocol. They are compatible. If a block 425 option is used, its content MUST be sent as a compression residue. 427 6.2. Observe 429 The [rfc7641] defines the Observe option. The TV is not set, MO is 430 set to "ignore" and the CDA is set to "value-sent". SCHC does not 431 limit the maximum size for this option (3 bytes). To reduce the 432 transmission size, either the device implementation MAY limit the 433 delta between two consecutive values, or a proxy can modify the 434 increment. 436 Since an RST message may be sent to inform a server that the client 437 does not require Observe response, a rule MUST allow the transmission 438 of this message. 440 6.3. No-Response 442 The [rfc7967] defines a No-Response option limiting the responses 443 made by a server to a request. If the value is known by both ends, 444 then TV is set to this value, MO is set to "equal" and CDA is set to 445 "not-sent". 447 Otherwise, if the value is changing over time, TV is not set, MO is 448 set to "ignore" and CDA to "value-sent". A matching list can also be 449 used to reduce the size. 451 6.4. OSCORE 453 OSCORE [rfc8613] defines end-to-end protection for CoAP messages. 454 This section describes how SCHC rules can be applied to compress 455 OSCORE-protected messages. 457 0 1 2 3 4 5 6 7 <--------- n bytes -------------> 458 +-+-+-+-+-+-+-+-+--------------------------------- 459 |0 0 0|h|k| n | Partial IV (if any) ... 460 +-+-+-+-+-+-+-+-+--------------------------------- 461 | | | 462 |<-- CoAP -->|<------ CoAP OSCORE_piv ------> | 463 OSCORE_flags 465 <- 1 byte -> <------ s bytes -----> 466 +------------+----------------------+-----------------------+ 467 | s (if any) | kid context (if any) | kid (if any) ... | 468 +------------+----------------------+-----------------------+ 469 | | | 470 | <------ CoAP OSCORE_kidctxt ----->|<-- CoAP OSCORE_kid -->| 472 Figure 4: OSCORE Option 474 The encoding of the OSCORE Option Value defined in Section 6.1 of 475 [rfc8613] is repeated in Figure 4. 477 The first byte is used for flags that specify the contents of the 478 OSCORE option. The 3 most significant bits of this byte are reserved 479 and always set to 0. Bit h, when set, indicates the presence of the 480 kid context field in the option. Bit k, when set, indicates the 481 presence of a kid field. The 3 least significant bits n indicate the 482 length of the piv (Partial Initialization Vector) field in bytes. 483 When n = 0, no piv is present. 485 The flag byte is followed by the piv field, kid context field and kid 486 field in this order and if present; the length of the kid context 487 field is encoded in the first byte denoting by s the length of the 488 kid context in bytes. 490 This draft recommends to implement a parser that is able to identify 491 the OSCORE Option and the fields it contains. 493 Conceptually, it discerns up to 4 distinct pieces of information 494 within the OSCORE option: the flag bits, the piv, the kid context, 495 and the kid. It is thus recommended that the parser split the OSCORE 496 option into the 4 subsequent fields: 498 o CoAP OSCORE_flags, 500 o CoAP OSCORE_piv, 502 o CoAP OSCORE_kidctxt, 503 o CoAP OSCORE_kid. 505 These fields are shown superimposed on the OSCORE Option format in 506 Figure 4, the CoAP OSCORE_kidctxt field including the size bits s. 507 Their size SHOULD be reduced using SCHC compression. 509 7. Examples of CoAP header compression 511 7.1. Mandatory header with CON message 513 In this first scenario, the LPWAN compressor at the Network Gateway 514 side receives from an Internet client a POST message, which is 515 immediately acknowledged by the Device. For this simple scenario, 516 the rules are described Figure 5. 518 Rule ID 1 519 +-------------+--+--+--+------+---------+-------------++------------+ 520 | Field |FL|FP|DI|Target| Match | CDA || Sent | 521 | | | | |Value | Opera. | || [bits] | 522 +-------------+--+--+--+------+---------+-------------++------------+ 523 |CoAP version | | |bi| 01 |equal |not-sent || | 524 |CoAP Type | | |dw| CON |equal |not-sent || | 525 |CoAP Type | | |up|[ACK, | | || | 526 | | | | | RST] |match-map|matching-sent|| T | 527 |CoAP TKL | | |bi| 0 |equal |not-sent || | 528 |CoAP Code | | |bi|[0.00,| | || | 529 | | | | | ... | | || | 530 | | | | | 5.05]|match-map|matching-sent|| CC CCC | 531 |CoAP MID | | |bi| 0000 |MSB(7 ) |LSB || M-ID| 532 |CoAP Uri-Path| | |dw| path |equal 1 |not-sent || | 533 +-------------+--+--+--+------+---------+-------------++------------+ 535 Figure 5: CoAP Context to compress header without token 537 The version and Token Length fields are elided. The 26 method and 538 response codes defined in [rfc7252] has been shrunk to 5 bits using a 539 matching list. Uri-Path contains a single element indicated in the 540 matching operator. 542 SCHC Compression reduces the header sending only the Type, a mapped 543 code and the least significant bits of Message ID (9 bits in the 544 example above). 546 Note that a request sent by a client located in an Application Server 547 to a server located in the device, may not be compressed through this 548 rule since the MID will not start with 7 bits equal to 0. A CoAP 549 proxy, before the core SCHC C/D can rewrite the message ID to a value 550 matched by the rule. 552 7.2. OSCORE Compression 554 OSCORE aims to solve the problem of end-to-end encryption for CoAP 555 messages. The goal, therefore, is to hide as much of the message as 556 possible while still enabling proxy operation. 558 Conceptually this is achieved by splitting the CoAP message into an 559 Inner Plaintext and Outer OSCORE Message. The Inner Plaintext 560 contains sensible information which is not necessary for proxy 561 operation. This, in turn, is the part of the message which can be 562 encrypted until it reaches its end destination. The Outer Message 563 acts as a shell matching the format of a regular CoAP message, and 564 includes all Options and information needed for proxy operation and 565 caching. This decomposition is illustrated in Figure 6. 567 CoAP options are sorted into one of 3 classes, each granted a 568 specific type of protection by the protocol: 570 o Class E: Encrypted options moved to the Inner Plaintext, 572 o Class I: Integrity-protected options included in the AAD for the 573 encryption of the Plaintext but otherwise left untouched in the 574 Outer Message, 576 o Class U: Unprotected options left untouched in the Outer Message. 578 Additionally, the OSCORE Option is added as an Outer option, 579 signalling that the message is OSCORE protected. This option carries 580 the information necessary to retrieve the Security Context with which 581 the message was encrypted so that it may be correctly decrypted at 582 the other end-point. 584 Original CoAP Message 585 +-+-+---+-------+---------------+ 586 |v|t|tkl| code | Msg Id. | 587 +-+-+---+-------+---------------+....+ 588 | Token | 589 +-------------------------------.....+ 590 | Options (IEU) | 591 . . 592 . . 593 +------+-------------------+ 594 | 0xFF | 595 +------+------------------------+ 596 | | 597 | Payload | 598 | | 599 +-------------------------------+ 600 / \ 601 / \ 602 / \ 603 / \ 604 Outer Header v v Plaintext 605 +-+-+---+--------+---------------+ +-------+ 606 |v|t|tkl|new code| Msg Id. | | code | 607 +-+-+---+--------+---------------+....+ +-------+-----......+ 608 | Token | | Options (E) | 609 +--------------------------------.....+ +-------+------.....+ 610 | Options (IU) | | OxFF | 611 . . +-------+-----------+ 612 . OSCORE Option . | | 613 +------+-------------------+ | Payload | 614 | 0xFF | | | 615 +------+ +-------------------+ 617 Figure 6: A CoAP message is split into an OSCORE outer and plaintext 619 Figure 6 shows the message format for the OSCORE Message and 620 Plaintext. 622 In the Outer Header, the original message code is hidden and replaced 623 by a default dummy value. As seen in sections 4.1.3.5 and 4.2 of the 624 [rfc8613], the message code is replaced by POST for requests and 625 Changed for responses when Observe is not used. If Observe is used, 626 the message code is replaced by FETCH for requests and Content for 627 responses. 629 The original message code is put into the first byte of the 630 Plaintext. Following the message code, the class E options comes and 631 if present the original message Payload is preceded by its payload 632 marker. 634 The Plaintext is now encrypted by an AEAD algorithm which integrity 635 protects Security Context parameters and eventually any class I 636 options from the Outer Header. Currently no CoAP options are marked 637 class I. The resulting Ciphertext becomes the new Payload of the 638 OSCORE message, as illustrated in Figure 7. 640 This Ciphertext is, as defined in RFC 5116, the concatenation of the 641 encrypted Plaintext and its authentication tag. Note that Inner 642 Compression only affects the Plaintext before encryption, thus we can 643 only aim to reduce this first, variable length component of the 644 Ciphertext. The authentication tag is fixed in length and considered 645 part of the cost of protection. 647 Outer Header 648 +-+-+---+--------+---------------+ 649 |v|t|tkl|new code| Msg Id. | 650 +-+-+---+--------+---------------+....+ 651 | Token | 652 +--------------------------------.....+ 653 | Options (IU) | 654 . . 655 . OSCORE Option . 656 +------+-------------------+ 657 | 0xFF | 658 +------+---------------------------+ 659 | | 660 | Ciphertext: Encrypted Inner | 661 | Header and Payload | 662 | + Authentication Tag | 663 | | 664 +----------------------------------+ 666 Figure 7: OSCORE message 668 The SCHC Compression scheme consists of compressing both the 669 Plaintext before encryption and the resulting OSCORE message after 670 encryption, see Figure 8. 672 This translates into a segmented process where SCHC compression is 673 applied independently in 2 stages, each with its corresponding set of 674 rules, with the Inner SCHC Rules and the Outer SCHC Rules. This way 675 compression is applied to all fields of the original CoAP message. 677 Note that since the Inner part of the message can only be decrypted 678 by the corresponding end-point, this end-point will also have to 679 implement Inner SCHC Compression/Decompression. 681 Outer Message OSCORE Plaintext 682 +-+-+---+--------+---------------+ +-------+ 683 |v|t|tkl|new code| Msg Id. | | code | 684 +-+-+---+--------+---------------+....+ +-------+-----......+ 685 | Token | | Options (E) | 686 +--------------------------------.....+ +-------+------.....+ 687 | Options (IU) | | OxFF | 688 . . +-------+-----------+ 689 . OSCORE Option . | | 690 +------+-------------------+ | Payload | 691 | 0xFF | | | 692 +------+------------+ +-------------------+ 693 | Ciphertext |<---------\ | 694 | | | v 695 +-------------------+ | +-----------------+ 696 | | | Inner SCHC | 697 v | | Compression | 698 +-----------------+ | +-----------------+ 699 | Outer SCHC | | | 700 | Compression | | v 701 +-----------------+ | +-------+ 702 | | |Rule ID| 703 v | +-------+--+ 704 +--------+ +------------+ | Residue | 705 |Rule ID'| | Encryption | <--- +----------+--------+ 706 +--------+--+ +------------+ | | 707 | Residue' | | Payload | 708 +-----------+-------+ | | 709 | Ciphertext | +-------------------+ 710 | | 711 +-------------------+ 713 Figure 8: OSCORE Compression Diagram 715 7.3. Example OSCORE Compression 717 An example is given with a GET Request and its consequent CONTENT 718 Response from a device-based CoAP client to a cloud-based CoAP 719 server. A possible set of rules for the Inner and Outer SCHC 720 Compression is shown. A dump of the results and a contrast between 721 SCHC + OSCORE performance with SCHC + COAP performance is also 722 listed. This gives an approximation to the cost of security with 723 SCHC-OSCORE. 725 Our first example CoAP message is the GET Request in Figure 9 727 Original message: 728 ================= 729 0x4101000182bb74656d7065726174757265 731 Header: 732 0x4101 733 01 Ver 734 00 CON 735 0001 tkl 736 00000001 Request Code 1 "GET" 738 0x0001 = mid 739 0x82 = token 741 Options: 742 0xbb74656d7065726174757265 743 Option 11: URI_PATH 744 Value = temperature 746 Original msg length: 17 bytes. 748 Figure 9: CoAP GET Request 750 Its corresponding response is the CONTENT Response in Figure 10. 752 Original message: 753 ================= 754 0x6145000182ff32332043 756 Header: 757 0x6145 758 01 Ver 759 10 ACK 760 0001 tkl 761 01000101 Successful Response Code 69 "2.05 Content" 763 0x0001 = mid 764 0x82 = token 766 0xFF Payload marker 767 Payload: 768 0x32332043 770 Original msg length: 10 772 Figure 10: CoAP CONTENT Response 774 The SCHC Rules for the Inner Compression include all fields that are 775 already present in a regular CoAP message, what is important is their 776 order and the definition of only those CoAP fields are into 777 Plaintext, Figure 11. 779 Rule ID 0 780 +---------------+--+--+-----------+-----------+-----------++------+ 781 | Field |FP|DI| Target | MO | CDA || Sent | 782 | | | | Value | | ||[bits]| 783 +---------------+--+--+-----------+-----------+-----------++------+ 784 |CoAP Code | |up| 1 | equal |not-sent || | 785 |CoAP Code | |dw|[69,132] | match-map |match-sent || c | 786 |CoAP Uri-Path | |up|temperature| equal |not-sent || | 787 |COAP Option-End| |dw| 0xFF | equal |not-sent || | 788 +---------------+--+--+-----------+-----------+-----------++------+ 790 Figure 11: Inner SCHC Rules 792 Figure 12 shows the Plaintext obtained for our example GET Request 793 and follows the process of Inner Compression and Encryption until we 794 end up with the Payload to be added in the outer OSCORE Message. 796 In this case the original message has no payload and its resulting 797 Plaintext can be compressed up to only 1 byte (size of the Rule ID). 798 The AEAD algorithm preserves this length in its first output, but 799 also yields a fixed-size tag which cannot be compressed and has to be 800 included in the OSCORE message. This translates into an overhead in 801 total message length, which limits the amount of compression that can 802 be achieved and plays into the cost of adding security to the 803 exchange. 805 ________________________________________________________ 806 | | 807 | OSCORE Plaintext | 808 | | 809 | 0x01bb74656d7065726174757265 (13 bytes) | 810 | | 811 | 0x01 Request Code GET | 812 | | 813 | bb74656d7065726174757265 Option 11: URI_PATH | 814 | Value = temperature | 815 |________________________________________________________| 817 | 818 | 819 | Inner SCHC Compression 820 | 821 v 822 _________________________________ 823 | | 824 | Compressed Plaintext | 825 | | 826 | 0x00 | 827 | | 828 | Rule ID = 0x00 (1 byte) | 829 | (No residue) | 830 |_________________________________| 832 | 833 | AEAD Encryption 834 | (piv = 0x04) 835 v 836 _________________________________________________ 837 | | 838 | encrypted_plaintext = 0xa2 (1 byte) | 839 | tag = 0xc54fe1b434297b62 (8 bytes) | 840 | | 841 | ciphertext = 0xa2c54fe1b434297b62 (9 bytes) | 842 |_________________________________________________| 844 Figure 12: Plaintext compression and encryption for GET Request 846 In Figure 13 we repeat the process for the example CONTENT Response. 847 In this case the misalignment produced by the compression residue (1 848 bit) makes it so that 7 bits of padding have to be applied after the 849 payload, resulting in a compressed Plaintext that is the same size as 850 before compression. This misalignment also causes the hexcode from 851 the payload to differ from the original, even though it has not been 852 compressed. On top of this, the overhead from the tag bytes is 853 incurred as before. 855 ________________________________________________________ 856 | | 857 | OSCORE Plaintext | 858 | | 859 | 0x45ff32332043 (6 bytes) | 860 | | 861 | 0x45 Successful Response Code 69 "2.05 Content" | 862 | | 863 | ff Payload marker | 864 | | 865 | 32332043 Payload | 866 |________________________________________________________| 868 | 869 | 870 | Inner SCHC Compression 871 | 872 v 873 __________________________________________ 874 | | 875 | Compressed Plaintext | 876 | | 877 | 0x001919902180 (6 bytes) | 878 | | 879 | 00 Rule ID | 880 | | 881 | 0b0 (1 bit match-map residue) | 882 | 0x32332043 >> 1 (shifted payload) | 883 | 0b0000000 Padding | 884 |__________________________________________| 886 | 887 | AEAD Encryption 888 | (piv = 0x04) 889 v 890 _________________________________________________________ 891 | | 892 | encrypted_plaintext = 0x10c6d7c26cc1 (6 bytes) | 893 | tag = 0xe9aef3f2461e0c29 (8 bytes) | 894 | | 895 | ciphertext = 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) | 896 |_________________________________________________________| 898 Figure 13: Plaintext compression and encryption for CONTENT Response 899 The Outer SCHC Rules (Figure 16) MUST process the OSCORE Options 900 fields. In Figure 14 and Figure 15 we show a dump of the OSCORE 901 Messages generated from our example messages once they have been 902 provided with the Inner Compressed Ciphertext in the payload. These 903 are the messages that have to be compressed by the Outer SCHC 904 Compression. 906 Protected message: 907 ================== 908 0x4102000182d7080904636c69656e74ffa2c54fe1b434297b62 909 (25 bytes) 911 Header: 912 0x4102 913 01 Ver 914 00 CON 915 0001 tkl 916 00000010 Request Code 2 "POST" 918 0x0001 = mid 919 0x82 = token 921 Options: 922 0xd8080904636c69656e74 (10 bytes) 923 Option 21: OBJECT_SECURITY 924 Value = 0x0904636c69656e74 925 09 = 000 0 1 001 Flag byte 926 h k n 927 04 piv 928 636c69656e74 kid 930 0xFF Payload marker 931 Payload: 932 0xa2c54fe1b434297b62 (9 bytes) 934 Figure 14: Protected and Inner SCHC Compressed GET Request 936 Protected message: 937 ================== 938 0x6144000182d008ff10c6d7c26cc1e9aef3f2461e0c29 939 (22 bytes) 941 Header: 942 0x6144 943 01 Ver 944 10 ACK 945 0001 tkl 946 01000100 Successful Response Code 68 "2.04 Changed" 948 0x0001 = mid 949 0x82 = token 951 Options: 952 0xd008 (2 bytes) 953 Option 21: OBJECT_SECURITY 954 Value = b'' 956 0xFF Payload marker 957 Payload: 958 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) 960 Figure 15: Protected and Inner SCHC Compressed CONTENT Response 962 For the flag bits, a number of compression methods has been shown to 963 be useful depending on the application. The simplest alternative is 964 to provide a fixed value for the flags, combining MO equal and CDA 965 not- sent. This saves most bits but could prevent flexibility. 966 Otherwise, match-mapping could be used to choose from an interested 967 number of configurations to the exchange. Otherwise, MSB could be 968 used to mask off the 3 hard-coded most significant bits. 970 Note that fixing a flag bit will limit the choice of CoAP Options 971 that can be used in the exchange, since their values are dependent on 972 certain options. 974 The piv field lends itself to having a number of bits masked off with 975 MO MSB and CDA LSB. This could be useful in applications where the 976 message frequency is low such as that found in LPWAN technologies. 977 Note that compressing the sequence numbers effectively reduces the 978 maximum amount of sequence numbers that can be used in an exchange. 979 Once this amount is exceeded, the SCHC Context would need to be re- 980 established. 982 The size s included in the kid context field MAY be masked off with 983 CDA MSB. The rest of the field could have additional bits masked 984 off, or have the whole field be fixed with MO equal and CDA not-sent. 985 The same holds for the kid field. 987 Figure 16 shows a possible set of Outer Rules to compress the Outer 988 Header. 990 Rule ID 0 991 +-------------------+--+--+--------------+--------+---------++------+ 992 | Field |FP|DI| Target | MO | CDA || Sent | 993 | | | | Value | | ||[bits]| 994 +-------------------+--+--+--------------+--------+---------++------+ 995 |CoAP version | |bi| 01 |equal |not-sent || | 996 |CoAP Type | |up| 0 |equal |not-sent || | 997 |CoAP Type | |dw| 2 |equal |not-sent || | 998 |CoAP TKL | |bi| 1 |equal |not-sent || | 999 |CoAP Code | |up| 2 |equal |not-sent || | 1000 |CoAP Code | |dw| 68 |equal |not-sent || | 1001 |CoAP MID | |bi| 0000 |MSB(12) |LSB ||MMMM | 1002 |CoAP Token | |bi| 0x80 |MSB(5) |LSB ||TTT | 1003 |CoAP OSCORE_flags | |up| 0x09 |equal |not-sent || | 1004 |CoAP OSCORE_piv | |up| 0x00 |MSB(4) |LSB ||PPPP | 1005 |COAP OSCORE_kid | |up|0x636c69656e70|MSB(52) |LSB ||KKKK | 1006 |COAP OSCORE_kidctxt| |bi| b'' |equal |not-sent || | 1007 |CoAP OSCORE_flags | |dw| b'' |equal |not-sent || | 1008 |CoAP OSCORE_piv | |dw| b'' |equal |not-sent || | 1009 |CoAP OSCORE_kid | |dw| b'' |equal |not-sent || | 1010 |COAP Option-End | |dw| 0xFF |equal |not-sent || | 1011 +-------------------+--+--+--------------+--------+---------++------+ 1013 Figure 16: Outer SCHC Rules 1015 These Outer Rules are applied to the example GET Request and CONTENT 1016 Response. The resulting messages are shown in Figure 17 and 1017 Figure 18. 1019 Compressed message: 1020 ================== 1021 0x001489458a9fc3686852f6c4 (12 bytes) 1022 0x00 Rule ID 1023 1489 Compression Residue 1024 458a9fc3686852f6c4 Padded payload 1026 Compression residue: 1027 0b 0001 010 0100 0100 (15 bits -> 2 bytes with padding) 1028 mid tkn piv kid 1030 Payload 1031 0xa2c54fe1b434297b62 (9 bytes) 1033 Compressed message length: 12 bytes 1035 Figure 17: SCHC-OSCORE Compressed GET Request 1037 Compressed message: 1038 ================== 1039 0x0014218daf84d983d35de7e48c3c1852 (16 bytes) 1040 0x00 Rule ID 1041 14 Compression residue 1042 218daf84d983d35de7e48c3c1852 Padded payload 1043 Compression residue: 1044 0b0001 010 (7 bits -> 1 byte with padding) 1045 mid tkn 1047 Payload 1048 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) 1050 Compressed msg length: 16 bytes 1052 Figure 18: SCHC-OSCORE Compressed CONTENT Response 1054 For contrast, we compare these results with what would be obtained by 1055 SCHC compressing the original CoAP messages without protecting them 1056 with OSCORE. To do this, we compress the CoAP messages according to 1057 the SCHC rules in Figure 19. 1059 Rule ID 1 1060 +---------------+--+--+-----------+---------+-----------++--------+ 1061 | Field |FP|DI| Target | MO | CDA || Sent | 1062 | | | | Value | | || [bits] | 1063 +---------------+--+--+-----------+---------+-----------++--------+ 1064 |CoAP version | |bi| 01 |equal |not-sent || | 1065 |CoAP Type | |up| 0 |equal |not-sent || | 1066 |CoAP Type | |dw| 2 |equal |not-sent || | 1067 |CoAP TKL | |bi| 1 |equal |not-sent || | 1068 |CoAP Code | |up| 2 |equal |not-sent || | 1069 |CoAP Code | |dw| [69,132] |match-map|map-sent ||C | 1070 |CoAP MID | |bi| 0000 |MSB(12) |LSB ||MMMM | 1071 |CoAP Token | |bi| 0x80 |MSB(5) |LSB ||TTT | 1072 |CoAP Uri-Path | |up|temperature|equal |not-sent || | 1073 |COAP Option-End| |dw| 0xFF |equal |not-sent || | 1074 +---------------+--+--+-----------+---------+-----------++--------+ 1076 Figure 19: SCHC-CoAP Rules (No OSCORE) 1078 This yields the results in Figure 20 for the Request, and Figure 21 1079 for the Response. 1081 Compressed message: 1082 ================== 1083 0x0114 1084 0x01 = Rule ID 1086 Compression residue: 1087 0b00010100 (1 byte) 1089 Compressed msg length: 2 1091 Figure 20: CoAP GET Compressed without OSCORE 1093 Compressed message: 1094 ================== 1095 0x010a32332043 1096 0x01 = Rule ID 1098 Compression residue: 1099 0b00001010 (1 byte) 1101 Payload 1102 0x32332043 1104 Compressed msg length: 6 1106 Figure 21: CoAP CONTENT Compressed without OSCORE 1108 As can be seen, the difference between applying SCHC + OSCORE as 1109 compared to regular SCHC + COAP is about 10 bytes of cost. 1111 8. IANA Considerations 1113 This document has no request to IANA. 1115 9. Security considerations 1117 This document does not have any more Security consideration than the 1118 ones already raised on [I-D.ietf-lpwan-ipv6-static-context-hc] 1120 10. Acknowledgements 1122 The authors would like to thank Dominique Barthel, Carsten Bormann, 1123 Thomas Fossati, Klaus Hartke, Francesca Palombini, Alexander Pelov, 1124 Goran Selander. 1126 11. Normative References 1128 [I-D.ietf-lpwan-ipv6-static-context-hc] 1129 Minaburo, A., Toutain, L., Gomez, C., Barthel, D., and J. 1130 Zuniga, "Static Context Header Compression (SCHC) and 1131 fragmentation for LPWAN, application to UDP/IPv6", draft- 1132 ietf-lpwan-ipv6-static-context-hc-21 (work in progress), 1133 July 2019. 1135 [rfc7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 1136 Application Protocol (CoAP)", RFC 7252, 1137 DOI 10.17487/RFC7252, June 2014, 1138 . 1140 [rfc7641] Hartke, K., "Observing Resources in the Constrained 1141 Application Protocol (CoAP)", RFC 7641, 1142 DOI 10.17487/RFC7641, September 2015, 1143 . 1145 [rfc7959] Bormann, C. and Z. Shelby, Ed., "Block-Wise Transfers in 1146 the Constrained Application Protocol (CoAP)", RFC 7959, 1147 DOI 10.17487/RFC7959, August 2016, 1148 . 1150 [rfc7967] Bhattacharyya, A., Bandyopadhyay, S., Pal, A., and T. 1151 Bose, "Constrained Application Protocol (CoAP) Option for 1152 No Server Response", RFC 7967, DOI 10.17487/RFC7967, 1153 August 2016, . 1155 [rfc8613] Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 1156 "Object Security for Constrained RESTful Environments 1157 (OSCORE)", RFC 8613, DOI 10.17487/RFC8613, July 2019, 1158 . 1160 Authors' Addresses 1162 Ana Minaburo 1163 Acklio 1164 1137A avenue des Champs Blancs 1165 35510 Cesson-Sevigne Cedex 1166 France 1168 Email: ana@ackl.io 1170 Laurent Toutain 1171 Institut MINES TELECOM; IMT Atlantique 1172 2 rue de la Chataigneraie 1173 CS 17607 1174 35576 Cesson-Sevigne Cedex 1175 France 1177 Email: Laurent.Toutain@imt-atlantique.fr 1179 Ricardo Andreasen 1180 Universidad de Buenos Aires 1181 Av. Paseo Colon 850 1182 C1063ACV Ciudad Autonoma de Buenos Aires 1183 Argentina 1185 Email: randreasen@fi.uba.ar