idnits 2.17.1 draft-ietf-lpwan-coap-static-context-hc-11.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 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 -- however, there's a paragraph with a matching beginning. Boilerplate error? RFC 2119 keyword, line 141: '... the CoAP header MAY be done in conjun...' RFC 2119 keyword, line 249: '...idirectional and MUST be elided during...' RFC 2119 keyword, line 263: '... The field SHOULD be elided if for i...' RFC 2119 keyword, line 266: '...any case, a rule MUST be defined to ca...' RFC 2119 keyword, line 278: '...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 1044 has weird spacing: '...tkn piv kid...' == Line 1061 has weird spacing: '... mid tkn...' -- The document date (October 09, 2019) is 1660 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 259, but not defined == Missing Reference: 'NON' is mentioned on line 259, but not defined == Missing Reference: 'ACK' is mentioned on line 260, but not defined == Missing Reference: 'RST' is mentioned on line 260, but not defined -- Looks like a reference, but probably isn't: '69' on line 1085 -- Looks like a reference, but probably isn't: '132' on line 1085 == Outdated reference: A later version (-24) exists of draft-ietf-lpwan-ipv6-static-context-hc-21 Summary: 1 error (**), 0 flaws (~~), 8 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 11, 2020 Institut MINES TELECOM; IMT Atlantique 6 R. Andreasen 7 Universidad de Buenos Aires 8 October 09, 2019 10 LPWAN Static Context Header Compression (SCHC) for CoAP 11 draft-ietf-lpwan-coap-static-context-hc-11 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 for CoAP. 23 Status of This Memo 25 This Internet-Draft is submitted in full conformance with the 26 provisions of BCP 78 and BCP 79. 28 Internet-Drafts are working documents of the Internet Engineering 29 Task Force (IETF). Note that other groups may also distribute 30 working documents as Internet-Drafts. The list of current Internet- 31 Drafts is at https://datatracker.ietf.org/drafts/current/. 33 Internet-Drafts are draft documents valid for a maximum of six months 34 and may be updated, replaced, or obsoleted by other documents at any 35 time. It is inappropriate to use Internet-Drafts as reference 36 material or to cite them other than as "work in progress." 38 This Internet-Draft will expire on April 11, 2020. 40 Copyright Notice 42 Copyright (c) 2019 IETF Trust and the persons identified as the 43 document authors. All rights reserved. 45 This document is subject to BCP 78 and the IETF Trust's Legal 46 Provisions Relating to IETF Documents 47 (https://trustee.ietf.org/license-info) in effect on the date of 48 publication of this document. Please review these documents 49 carefully, as they describe your rights and restrictions with respect 50 to this document. Code Components extracted from this document must 51 include Simplified BSD License text as described in Section 4.e of 52 the Trust Legal Provisions and are provided without warranty as 53 described in the Simplified BSD License. 55 Table of Contents 57 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 2 58 1.1. Terminology . . . . . . . . . . . . . . . . . . . . . . . 3 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 . . . . . . . 9 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 . . . . . . . . . . . . . . . . 10 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 1.1. Terminology 132 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 133 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 134 "OPTIONAL" in this document are to be interpreted as described in BCP 135 14 [rfc2119][rfc8174] when, and only when, they appear in all 136 capitals, as shown here. 138 2. SCHC Compression Process 140 The SCHC Compression rules can be applied to CoAP flows. SCHC 141 Compression of the CoAP header MAY be done in conjunction with the 142 lower layers (IPv6/UDP) or independently. The SCHC adaptation layers 143 as described in [I-D.ietf-lpwan-ipv6-static-context-hc] may be used 144 as shown in Figure 1. 146 ^ +------------+ ^ +------------+ ^ +------------+ 147 | | CoAP | | | CoAP | inner | | CoAP | 148 | +------------+ v +------------+ x | OSCORE | 149 | | UDP | | DTLS | outer | +------------+ 150 | +------------+ +------------+ | | UDP | 151 | | IPv6 | | UDP | | +------------+ 152 v +------------+ +------------+ | | IPv6 | 153 | IPv6 | v +------------+ 154 +------------+ 156 Figure 1: rule scope for CoAP 158 Figure 1 shows some examples for CoAP architecture and the SCHC 159 rule's scope. 161 In the first example, a rule compresses the complete header stack 162 from IPv6 to CoAP. In this case, SCHC C/D is performed at the device 163 and at the LPWAN boundary. 165 In the second example, an end-to-end encryption mechanisms is used 166 between the device and the application. The SCHC compression is 167 applied in the CoAP layer compressing the CoAP header independently 168 of the other layers. The rule ID and the compression residue are 169 encrypted using a mechanism such as DTLS. Only the other end can 170 decipher the information. Layers below may also be compressed using 171 other SCHC rules (this is out of the scope of this document) as 172 defined in the SCHC [I-D.ietf-lpwan-ipv6-static-context-hc] document. 174 In the third example, OSCORE [rfc8613] is used. In this case, two 175 rulesets are used to compress the CoAP message. A first ruleset 176 focused on the inner header and is applied end to end by both ends. 177 A second ruleset compresses the outer header and the layers below and 178 is done between the device and the LPWAN boundary. 180 3. CoAP Compression with SCHC 182 CoAP differs from IPv6 and UDP protocols on the following aspects: 184 o IPv6 and UDP are symmetrical protocols. The same fields are found 185 in the request and in the response, with the value of some fields 186 being swapped on the return path (e.g. source and destination 187 fields). A CoAP request is intrinsically different from a 188 response. For example, the URI-path option is mandatory in the 189 request and is not found in the response, a request may contain an 190 Accept option and the response a Content option. 192 [I-D.ietf-lpwan-ipv6-static-context-hc] defines the use of a 193 message direction (DI) in the Field Description, which allows a 194 single Rule to process message headers differently depending of 195 the direction. 197 o Even when a field is "symmetric" (i.e. found in both directions) 198 the values carried in each direction are different. Combined with 199 a matching list in the TV, this allows reducing the range of 200 expected values in a particular direction and therefore reduce the 201 size of the compression residue. For instance, if a client sends 202 only CON request, the type can be elided by compression and the 203 answer may use one single bit to carry either the ACK or RST type. 204 The same behavior can be applied to the CoAP Code field 0.0X code 205 Format is found in the request and Y.ZZ code format in the answer. 206 The direction allows splitting in two parts the possible values 207 for each direction in the same Rule. 209 o In IPv6 and UDP, header fields have a fixed size and it is not 210 sent. In CoAP, some fields in the header have a varying size, for 211 example the Token size may vary from 0 to 8 bytes, the length is 212 given by a field in the header. More systematically, the CoAP 213 options are described using the Type-Length-Value. 215 [I-D.ietf-lpwan-ipv6-static-context-hc] offers the possibility to 216 define a function for the Field Length in the Field Description. 218 o In CoAP headers, a field can appear several times. This is 219 typical for elements of a URI (path or queries). The SCHC 220 specification [I-D.ietf-lpwan-ipv6-static-context-hc] allows a 221 Field ID to appears several times in the rule, and uses the Field 222 Position (FP) to identify the correct instance, and thereby 223 removing the ambiguity of the matching operation. 225 o Field sizes defined in the CoAP protocol can be too large 226 regarding LPWAN traffic constraints. This is particularly true 227 for the Message ID field and the Token field. The MSB MO can be 228 applied to reduce the information carried on LPWANs. 230 o CoAP also obeys the client/server paradigm and the compression 231 ratio can be different if the request is issued from an LPWAN 232 device or from a non LPWAN device. For instance, a Device (Dev) 233 aware of LPWAN constraints can generate a 1-byte token, but a 234 regular CoAP client will certainly send a larger token to the Dev. 235 The SCHC compression-decompression process never modifies the 236 Values it only reduces their sizes. Nevertheless, a proxy placed 237 before the compressor may change some field values to allow SCHC 238 achieving a better compression ratio, while maintaining the 239 necessary context for interoperability with existing CoAP 240 implementations. 242 4. Compression of CoAP header fields 244 This section discusses the compression of the different CoAP header 245 fields. 247 4.1. CoAP version field 249 CoAP version is bidirectional and MUST be elided during the SCHC 250 compression, since it always contains the same value. In the future, 251 if new versions of CoAP are defined, new rules will be needed to 252 avoid ambiguities between versions. 254 4.2. CoAP type field 256 CoAP Protocol [rfc7252] defines 4 types of messages: CON, NON, ACK 257 and RST. ACK and RST are a response to the CON and NON. If the 258 device plays a specific client or server role, a rule can take 259 advantage of these properties with the mapping list: [CON, NON] for 260 one direction and [ACK, RST] for the other direction and so, the 261 compression residue is reduced to 1 bit. 263 The field SHOULD be elided if for instance a client is sending only 264 NON or only CON messages. 266 In any case, a rule MUST be defined to carry RST to a client. 268 4.3. CoAP code field 270 The compression of the CoAP code field follows the same principle as 271 that of the CoAP type field. If the device plays a specific role, 272 the set of code values can be split in two parts, the request codes 273 with the 0 class and the response values. 275 If the device only implements a CoAP client, the request code can be 276 reduced to the set of requests the client is able to process. 278 All the response codes MUST be compressed with a SCHC rule. 280 4.4. CoAP Message ID field 282 The Message ID field is bidirectional and is used to manage 283 acknowledgments. The server memorizes the value for an 284 EXCHANGE_LIFETIME period (by default 247 seconds) for CON messages 285 and a NON_LIFETIME period (by default 145 seconds) for NON messages. 286 During that period, a server receiving the same Message ID value will 287 process the message as a retransmission. After this period, it will 288 be processed as a new message. 290 In case where the Device is a client, the size of the Message ID 291 field may be too large regarding the number of messages sent. The 292 client SHOULD use only small Message ID values, for instance 4 bit 293 long. Therefore, an MSB can be used to limit the size of the 294 compression residue. 296 In case where the Device is a server, the client may be located 297 outside of the LPWAN area and it views the Device as a regular device 298 connected to the Internet. The client will generate Message ID using 299 the 16 bits space offered by this field. A CoAP proxy can be set 300 before the SCHC C/D to reduce the value of the Message ID, to allow 301 its compression with the MSB matching operator and LSB CDA. 303 4.5. CoAP Token fields 305 Token is defined through two CoAP fields, Token Length in the 306 mandatory header and Token Value directly following the mandatory 307 CoAP header. 309 Token Length is processed as any protocol field. If the value 310 remains the same during all the transaction, the size can be stored 311 in the context and elided during the transmission. Otherwise, it 312 will have to be sent as a compression residue. 314 Token Value size cannot be defined directly in the rule in the Field 315 Length (FL). Instead, a specific function designated as "TKL" MUST 316 be used and length does not have to be sent with the residue. During 317 the decompression, this function returns the value contained in the 318 Token Length field. 320 5. CoAP options 322 5.1. CoAP Content and Accept options. 324 These fields are both unidirectional and MUST NOT be set to 325 bidirectional in a rule entry. 327 If a single value is expected by the client, it can be stored in the 328 TV and elided during the transmission. Otherwise, if several 329 possible values are expected by the client, a matching-list SHOULD be 330 used to limit the size of the residue. Otherwise, the value has to 331 be sent as a residue (fixed or variable length). 333 5.2. CoAP option Max-Age, Uri-Host and Uri-Port fields 335 These fields are unidirectional and MUST NOT be set to bidirectional 336 in a rule entry. They are used only by the server to inform of the 337 caching duration and is never found in client requests. 339 If the duration is known by both ends, the value can be elided on the 340 LPWAN. 342 A matching list can be used if some well-known values are defined. 344 Otherwise these options SHOULD be sent as a residue (fixed or 345 variable length). 347 5.3. CoAP option Uri-Path and Uri-Query fields 349 These fields are unidirectional and MUST NOT be set to bidirectional 350 in a rule entry. They are used only by the client to access a 351 specific resource and are never found in server responses. 353 Uri-Path and Uri-Query elements are a repeatable options, the Field 354 Position (FP) gives the position in the path. 356 A Mapping list can be used to reduce the size of variable Paths or 357 Queries. In that case, to optimize the compression, several elements 358 can be regrouped into a single entry. Numbering of elements do not 359 change, MO comparison is set with the first element of the matching. 361 +-------------+--+--+--+--------+---------+-------------+ 362 | Field |FL|FP|DI| Target | Match | CDA | 363 | | | | | Value | Opera. | | 364 +-------------+--+--+--+--------+---------+-------------+ 365 |URI-Path | | 1|up|["/a/b",|equal |not-sent | 366 | | | | |"/c/d"] | | | 367 |URI-Path | | 3|up| |ignore |value-sent | 368 +-------------+--+--+--+--------+---------+-------------+ 370 Figure 2: complex path example 372 In Figure 2 a single bit residue can be used to code one of the 2 373 paths. If regrouping were not allowed, a 2 bits residue would be 374 needed. 376 5.3.1. Variable length Uri-Path and Uri-Query 378 When the length is not known at the rule creation, the Field Length 379 SHOULD be set to variable, and the unit is set to bytes. 381 The MSB MO can be applied to a Uri-Path or Uri-Query element. Since 382 MSB value is given in bit, the size MUST always be a multiple of 8 383 bits. 385 The length sent at the beginning of a variable length residue 386 indicates the size of the LSB in bytes. 388 For instance for a CORECONF path /c/X6?k="eth0" the rule can be set 389 to: 391 +-------------+---+--+--+--------+---------+-------------+ 392 | Field |FL |FP|DI| Target | Match | CDA | 393 | | | | | Value | Opera. | | 394 +-------------+---+--+--+--------+---------+-------------+ 395 |URI-Path | 8| 1|up|"c" |equal |not-sent | 396 |URI-Path |var| 2|up| |ignore |value-sent | 397 |URI-Query |var| 1|up|"k=" |MSB(16) |LSB | 398 +-------------+---+--+--+--------+---------+-------------+ 400 Figure 3: CORECONF URI compression 402 Figure 3 shows the parsing and the compression of the URI, where c is 403 not sent. The second element is sent with the length (i.e. 0x2 X 6) 404 followed by the query option (i.e. 0x05 "eth0"). 406 5.3.2. Variable number of path or query elements 408 The number of Uri-path or Uri-Query elements in a rule is fixed at 409 the rule creation time. If the number varies, several rules SHOULD 410 be created to cover all the possibilities. Another possibility is to 411 define the length of Uri-Path to variable and send a compression 412 residue with a length of 0 to indicate that this Uri-Path is empty. 413 This adds 4 bits to the compression residue. 415 5.4. CoAP option Size1, Size2, Proxy-URI and Proxy-Scheme fields 417 These fields are unidirectional and MUST NOT be set to bidirectional 418 in a rule entry. They are used only by the client to access a 419 specific resource and are never found in server response. 421 If the field value has to be sent, TV is not set, MO is set to 422 "ignore" and CDA is set to "value-sent". A mapping MAY also be used. 424 Otherwise, the TV is set to the value, MO is set to "equal" and CDA 425 is set to "not-sent". 427 5.5. CoAP option ETag, If-Match, If-None-Match, Location-Path and 428 Location-Query fields 430 These fields are unidirectional. 432 These fields values cannot be stored in a rule entry. They MUST 433 always be sent with the compression residues. 435 6. Other RFCs 437 6.1. Block 439 Block [rfc7959] allows a fragmentation at the CoAP level. SCHC also 440 includes a fragmentation protocol. They are compatible. If a block 441 option is used, its content MUST be sent as a compression residue. 443 6.2. Observe 445 The [rfc7641] defines the Observe option. The TV is not set, MO is 446 set to "ignore" and the CDA is set to "value-sent". SCHC does not 447 limit the maximum size for this option (3 bytes). To reduce the 448 transmission size, either the device implementation MAY limit the 449 delta between two consecutive values, or a proxy can modify the 450 increment. 452 Since an RST message may be sent to inform a server that the client 453 does not require Observe response, a rule MUST allow the transmission 454 of this message. 456 6.3. No-Response 458 The [rfc7967] defines a No-Response option limiting the responses 459 made by a server to a request. If the value is known by both ends, 460 then TV is set to this value, MO is set to "equal" and CDA is set to 461 "not-sent". 463 Otherwise, if the value is changing over time, TV is not set, MO is 464 set to "ignore" and CDA to "value-sent". A matching list can also be 465 used to reduce the size. 467 6.4. OSCORE 469 OSCORE [rfc8613] defines end-to-end protection for CoAP messages. 470 This section describes how SCHC rules can be applied to compress 471 OSCORE-protected messages. 473 0 1 2 3 4 5 6 7 <--------- n bytes -------------> 474 +-+-+-+-+-+-+-+-+--------------------------------- 475 |0 0 0|h|k| n | Partial IV (if any) ... 476 +-+-+-+-+-+-+-+-+--------------------------------- 477 | | | 478 |<-- CoAP -->|<------ CoAP OSCORE_piv ------> | 479 OSCORE_flags 481 <- 1 byte -> <------ s bytes -----> 482 +------------+----------------------+-----------------------+ 483 | s (if any) | kid context (if any) | kid (if any) ... | 484 +------------+----------------------+-----------------------+ 485 | | | 486 | <------ CoAP OSCORE_kidctxt ----->|<-- CoAP OSCORE_kid -->| 488 Figure 4: OSCORE Option 490 The encoding of the OSCORE Option Value defined in Section 6.1 of 491 [rfc8613] is repeated in Figure 4. 493 The first byte is used for flags that specify the contents of the 494 OSCORE option. The 3 most significant bits of this byte are reserved 495 and always set to 0. Bit h, when set, indicates the presence of the 496 kid context field in the option. Bit k, when set, indicates the 497 presence of a kid field. The 3 least significant bits n indicate the 498 length of the piv (Partial Initialization Vector) field in bytes. 499 When n = 0, no piv is present. 501 The flag byte is followed by the piv field, kid context field and kid 502 field in this order and if present; the length of the kid context 503 field is encoded in the first byte denoting by s the length of the 504 kid context in bytes. 506 This draft recommends to implement a parser that is able to identify 507 the OSCORE Option and the fields it contains. 509 Conceptually, it discerns up to 4 distinct pieces of information 510 within the OSCORE option: the flag bits, the piv, the kid context, 511 and the kid. It is thus recommended that the parser split the OSCORE 512 option into the 4 subsequent fields: 514 o CoAP OSCORE_flags, 516 o CoAP OSCORE_piv, 518 o CoAP OSCORE_kidctxt, 519 o CoAP OSCORE_kid. 521 These fields are shown superimposed on the OSCORE Option format in 522 Figure 4, the CoAP OSCORE_kidctxt field including the size bits s. 523 Their size SHOULD be reduced using SCHC compression. 525 7. Examples of CoAP header compression 527 7.1. Mandatory header with CON message 529 In this first scenario, the LPWAN compressor at the Network Gateway 530 side receives from an Internet client a POST message, which is 531 immediately acknowledged by the Device. For this simple scenario, 532 the rules are described Figure 5. 534 Rule ID 1 535 +-------------+--+--+--+------+---------+-------------++------------+ 536 | Field |FL|FP|DI|Target| Match | CDA || Sent | 537 | | | | |Value | Opera. | || [bits] | 538 +-------------+--+--+--+------+---------+-------------++------------+ 539 |CoAP version | | |bi| 01 |equal |not-sent || | 540 |CoAP Type | | |dw| CON |equal |not-sent || | 541 |CoAP Type | | |up|[ACK, | | || | 542 | | | | | RST] |match-map|matching-sent|| T | 543 |CoAP TKL | | |bi| 0 |equal |not-sent || | 544 |CoAP Code | | |bi|[0.00,| | || | 545 | | | | | ... | | || | 546 | | | | | 5.05]|match-map|matching-sent|| CC CCC | 547 |CoAP MID | | |bi| 0000 |MSB(7 ) |LSB || M-ID| 548 |CoAP Uri-Path| | |dw| path |equal 1 |not-sent || | 549 +-------------+--+--+--+------+---------+-------------++------------+ 551 Figure 5: CoAP Context to compress header without token 553 The version and Token Length fields are elided. The 26 method and 554 response codes defined in [rfc7252] has been shrunk to 5 bits using a 555 matching list. Uri-Path contains a single element indicated in the 556 matching operator. 558 SCHC Compression reduces the header sending only the Type, a mapped 559 code and the least significant bits of Message ID (9 bits in the 560 example above). 562 Note that a request sent by a client located in an Application Server 563 to a server located in the device, may not be compressed through this 564 rule since the MID will not start with 7 bits equal to 0. A CoAP 565 proxy, before the core SCHC C/D can rewrite the message ID to a value 566 matched by the rule. 568 7.2. OSCORE Compression 570 OSCORE aims to solve the problem of end-to-end encryption for CoAP 571 messages. The goal, therefore, is to hide as much of the message as 572 possible while still enabling proxy operation. 574 Conceptually this is achieved by splitting the CoAP message into an 575 Inner Plaintext and Outer OSCORE Message. The Inner Plaintext 576 contains sensible information which is not necessary for proxy 577 operation. This, in turn, is the part of the message which can be 578 encrypted until it reaches its end destination. The Outer Message 579 acts as a shell matching the format of a regular CoAP message, and 580 includes all Options and information needed for proxy operation and 581 caching. This decomposition is illustrated in Figure 6. 583 CoAP options are sorted into one of 3 classes, each granted a 584 specific type of protection by the protocol: 586 o Class E: Encrypted options moved to the Inner Plaintext, 588 o Class I: Integrity-protected options included in the AAD for the 589 encryption of the Plaintext but otherwise left untouched in the 590 Outer Message, 592 o Class U: Unprotected options left untouched in the Outer Message. 594 Additionally, the OSCORE Option is added as an Outer option, 595 signalling that the message is OSCORE protected. This option carries 596 the information necessary to retrieve the Security Context with which 597 the message was encrypted so that it may be correctly decrypted at 598 the other end-point. 600 Original CoAP Message 601 +-+-+---+-------+---------------+ 602 |v|t|tkl| code | Msg Id. | 603 +-+-+---+-------+---------------+....+ 604 | Token | 605 +-------------------------------.....+ 606 | Options (IEU) | 607 . . 608 . . 609 +------+-------------------+ 610 | 0xFF | 611 +------+------------------------+ 612 | | 613 | Payload | 614 | | 615 +-------------------------------+ 616 / \ 617 / \ 618 / \ 619 / \ 620 Outer Header v v Plaintext 621 +-+-+---+--------+---------------+ +-------+ 622 |v|t|tkl|new code| Msg Id. | | code | 623 +-+-+---+--------+---------------+....+ +-------+-----......+ 624 | Token | | Options (E) | 625 +--------------------------------.....+ +-------+------.....+ 626 | Options (IU) | | OxFF | 627 . . +-------+-----------+ 628 . OSCORE Option . | | 629 +------+-------------------+ | Payload | 630 | 0xFF | | | 631 +------+ +-------------------+ 633 Figure 6: A CoAP message is split into an OSCORE outer and plaintext 635 Figure 6 shows the message format for the OSCORE Message and 636 Plaintext. 638 In the Outer Header, the original message code is hidden and replaced 639 by a default dummy value. As seen in sections 4.1.3.5 and 4.2 of the 640 [rfc8613], the message code is replaced by POST for requests and 641 Changed for responses when Observe is not used. If Observe is used, 642 the message code is replaced by FETCH for requests and Content for 643 responses. 645 The original message code is put into the first byte of the 646 Plaintext. Following the message code, the class E options comes and 647 if present the original message Payload is preceded by its payload 648 marker. 650 The Plaintext is now encrypted by an AEAD algorithm which integrity 651 protects Security Context parameters and eventually any class I 652 options from the Outer Header. Currently no CoAP options are marked 653 class I. The resulting Ciphertext becomes the new Payload of the 654 OSCORE message, as illustrated in Figure 7. 656 This Ciphertext is, as defined in RFC 5116, the concatenation of the 657 encrypted Plaintext and its authentication tag. Note that Inner 658 Compression only affects the Plaintext before encryption, thus we can 659 only aim to reduce this first, variable length component of the 660 Ciphertext. The authentication tag is fixed in length and considered 661 part of the cost of protection. 663 Outer Header 664 +-+-+---+--------+---------------+ 665 |v|t|tkl|new code| Msg Id. | 666 +-+-+---+--------+---------------+....+ 667 | Token | 668 +--------------------------------.....+ 669 | Options (IU) | 670 . . 671 . OSCORE Option . 672 +------+-------------------+ 673 | 0xFF | 674 +------+---------------------------+ 675 | | 676 | Ciphertext: Encrypted Inner | 677 | Header and Payload | 678 | + Authentication Tag | 679 | | 680 +----------------------------------+ 682 Figure 7: OSCORE message 684 The SCHC Compression scheme consists of compressing both the 685 Plaintext before encryption and the resulting OSCORE message after 686 encryption, see Figure 8. 688 This translates into a segmented process where SCHC compression is 689 applied independently in 2 stages, each with its corresponding set of 690 rules, with the Inner SCHC Rules and the Outer SCHC Rules. This way 691 compression is applied to all fields of the original CoAP message. 693 Note that since the Inner part of the message can only be decrypted 694 by the corresponding end-point, this end-point will also have to 695 implement Inner SCHC Compression/Decompression. 697 Outer Message OSCORE Plaintext 698 +-+-+---+--------+---------------+ +-------+ 699 |v|t|tkl|new code| Msg Id. | | code | 700 +-+-+---+--------+---------------+....+ +-------+-----......+ 701 | Token | | Options (E) | 702 +--------------------------------.....+ +-------+------.....+ 703 | Options (IU) | | OxFF | 704 . . +-------+-----------+ 705 . OSCORE Option . | | 706 +------+-------------------+ | Payload | 707 | 0xFF | | | 708 +------+------------+ +-------------------+ 709 | Ciphertext |<---------\ | 710 | | | v 711 +-------------------+ | +-----------------+ 712 | | | Inner SCHC | 713 v | | Compression | 714 +-----------------+ | +-----------------+ 715 | Outer SCHC | | | 716 | Compression | | v 717 +-----------------+ | +-------+ 718 | | |Rule ID| 719 v | +-------+--+ 720 +--------+ +------------+ | Residue | 721 |Rule ID'| | Encryption | <--- +----------+--------+ 722 +--------+--+ +------------+ | | 723 | Residue' | | Payload | 724 +-----------+-------+ | | 725 | Ciphertext | +-------------------+ 726 | | 727 +-------------------+ 729 Figure 8: OSCORE Compression Diagram 731 7.3. Example OSCORE Compression 733 An example is given with a GET Request and its consequent CONTENT 734 Response from a device-based CoAP client to a cloud-based CoAP 735 server. A possible set of rules for the Inner and Outer SCHC 736 Compression is shown. A dump of the results and a contrast between 737 SCHC + OSCORE performance with SCHC + COAP performance is also 738 listed. This gives an approximation to the cost of security with 739 SCHC-OSCORE. 741 Our first example CoAP message is the GET Request in Figure 9 743 Original message: 744 ================= 745 0x4101000182bb74656d7065726174757265 747 Header: 748 0x4101 749 01 Ver 750 00 CON 751 0001 tkl 752 00000001 Request Code 1 "GET" 754 0x0001 = mid 755 0x82 = token 757 Options: 758 0xbb74656d7065726174757265 759 Option 11: URI_PATH 760 Value = temperature 762 Original msg length: 17 bytes. 764 Figure 9: CoAP GET Request 766 Its corresponding response is the CONTENT Response in Figure 10. 768 Original message: 769 ================= 770 0x6145000182ff32332043 772 Header: 773 0x6145 774 01 Ver 775 10 ACK 776 0001 tkl 777 01000101 Successful Response Code 69 "2.05 Content" 779 0x0001 = mid 780 0x82 = token 782 0xFF Payload marker 783 Payload: 784 0x32332043 786 Original msg length: 10 788 Figure 10: CoAP CONTENT Response 790 The SCHC Rules for the Inner Compression include all fields that are 791 already present in a regular CoAP message, what is important is their 792 order and the definition of only those CoAP fields are into 793 Plaintext, Figure 11. 795 Rule ID 0 796 +---------------+--+--+-----------+-----------+-----------++------+ 797 | Field |FP|DI| Target | MO | CDA || Sent | 798 | | | | Value | | ||[bits]| 799 +---------------+--+--+-----------+-----------+-----------++------+ 800 |CoAP Code | |up| 1 | equal |not-sent || | 801 |CoAP Code | |dw|[69,132] | match-map |match-sent || c | 802 |CoAP Uri-Path | |up|temperature| equal |not-sent || | 803 |COAP Option-End| |dw| 0xFF | equal |not-sent || | 804 +---------------+--+--+-----------+-----------+-----------++------+ 806 Figure 11: Inner SCHC Rules 808 Figure 12 shows the Plaintext obtained for our example GET Request 809 and follows the process of Inner Compression and Encryption until we 810 end up with the Payload to be added in the outer OSCORE Message. 812 In this case the original message has no payload and its resulting 813 Plaintext can be compressed up to only 1 byte (size of the Rule ID). 814 The AEAD algorithm preserves this length in its first output, but 815 also yields a fixed-size tag which cannot be compressed and has to be 816 included in the OSCORE message. This translates into an overhead in 817 total message length, which limits the amount of compression that can 818 be achieved and plays into the cost of adding security to the 819 exchange. 821 ________________________________________________________ 822 | | 823 | OSCORE Plaintext | 824 | | 825 | 0x01bb74656d7065726174757265 (13 bytes) | 826 | | 827 | 0x01 Request Code GET | 828 | | 829 | bb74656d7065726174757265 Option 11: URI_PATH | 830 | Value = temperature | 831 |________________________________________________________| 833 | 834 | 835 | Inner SCHC Compression 836 | 837 v 838 _________________________________ 839 | | 840 | Compressed Plaintext | 841 | | 842 | 0x00 | 843 | | 844 | Rule ID = 0x00 (1 byte) | 845 | (No residue) | 846 |_________________________________| 848 | 849 | AEAD Encryption 850 | (piv = 0x04) 851 v 852 _________________________________________________ 853 | | 854 | encrypted_plaintext = 0xa2 (1 byte) | 855 | tag = 0xc54fe1b434297b62 (8 bytes) | 856 | | 857 | ciphertext = 0xa2c54fe1b434297b62 (9 bytes) | 858 |_________________________________________________| 860 Figure 12: Plaintext compression and encryption for GET Request 862 In Figure 13 we repeat the process for the example CONTENT Response. 863 In this case the misalignment produced by the compression residue (1 864 bit) makes it so that 7 bits of padding have to be applied after the 865 payload, resulting in a compressed Plaintext that is the same size as 866 before compression. This misalignment also causes the hexcode from 867 the payload to differ from the original, even though it has not been 868 compressed. On top of this, the overhead from the tag bytes is 869 incurred as before. 871 ________________________________________________________ 872 | | 873 | OSCORE Plaintext | 874 | | 875 | 0x45ff32332043 (6 bytes) | 876 | | 877 | 0x45 Successful Response Code 69 "2.05 Content" | 878 | | 879 | ff Payload marker | 880 | | 881 | 32332043 Payload | 882 |________________________________________________________| 884 | 885 | 886 | Inner SCHC Compression 887 | 888 v 889 __________________________________________ 890 | | 891 | Compressed Plaintext | 892 | | 893 | 0x001919902180 (6 bytes) | 894 | | 895 | 00 Rule ID | 896 | | 897 | 0b0 (1 bit match-map residue) | 898 | 0x32332043 >> 1 (shifted payload) | 899 | 0b0000000 Padding | 900 |__________________________________________| 902 | 903 | AEAD Encryption 904 | (piv = 0x04) 905 v 906 _________________________________________________________ 907 | | 908 | encrypted_plaintext = 0x10c6d7c26cc1 (6 bytes) | 909 | tag = 0xe9aef3f2461e0c29 (8 bytes) | 910 | | 911 | ciphertext = 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) | 912 |_________________________________________________________| 914 Figure 13: Plaintext compression and encryption for CONTENT Response 915 The Outer SCHC Rules (Figure 16) MUST process the OSCORE Options 916 fields. In Figure 14 and Figure 15 we show a dump of the OSCORE 917 Messages generated from our example messages once they have been 918 provided with the Inner Compressed Ciphertext in the payload. These 919 are the messages that have to be compressed by the Outer SCHC 920 Compression. 922 Protected message: 923 ================== 924 0x4102000182d7080904636c69656e74ffa2c54fe1b434297b62 925 (25 bytes) 927 Header: 928 0x4102 929 01 Ver 930 00 CON 931 0001 tkl 932 00000010 Request Code 2 "POST" 934 0x0001 = mid 935 0x82 = token 937 Options: 938 0xd8080904636c69656e74 (10 bytes) 939 Option 21: OBJECT_SECURITY 940 Value = 0x0904636c69656e74 941 09 = 000 0 1 001 Flag byte 942 h k n 943 04 piv 944 636c69656e74 kid 946 0xFF Payload marker 947 Payload: 948 0xa2c54fe1b434297b62 (9 bytes) 950 Figure 14: Protected and Inner SCHC Compressed GET Request 952 Protected message: 953 ================== 954 0x6144000182d008ff10c6d7c26cc1e9aef3f2461e0c29 955 (22 bytes) 957 Header: 958 0x6144 959 01 Ver 960 10 ACK 961 0001 tkl 962 01000100 Successful Response Code 68 "2.04 Changed" 964 0x0001 = mid 965 0x82 = token 967 Options: 968 0xd008 (2 bytes) 969 Option 21: OBJECT_SECURITY 970 Value = b'' 972 0xFF Payload marker 973 Payload: 974 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) 976 Figure 15: Protected and Inner SCHC Compressed CONTENT Response 978 For the flag bits, a number of compression methods has been shown to 979 be useful depending on the application. The simplest alternative is 980 to provide a fixed value for the flags, combining MO equal and CDA 981 not- sent. This saves most bits but could prevent flexibility. 982 Otherwise, match-mapping could be used to choose from an interested 983 number of configurations to the exchange. Otherwise, MSB could be 984 used to mask off the 3 hard-coded most significant bits. 986 Note that fixing a flag bit will limit the choice of CoAP Options 987 that can be used in the exchange, since their values are dependent on 988 certain options. 990 The piv field lends itself to having a number of bits masked off with 991 MO MSB and CDA LSB. This could be useful in applications where the 992 message frequency is low such as that found in LPWAN technologies. 993 Note that compressing the sequence numbers effectively reduces the 994 maximum amount of sequence numbers that can be used in an exchange. 995 Once this amount is exceeded, the SCHC Context would need to be re- 996 established. 998 The size s included in the kid context field MAY be masked off with 999 CDA MSB. The rest of the field could have additional bits masked 1000 off, or have the whole field be fixed with MO equal and CDA not-sent. 1001 The same holds for the kid field. 1003 Figure 16 shows a possible set of Outer Rules to compress the Outer 1004 Header. 1006 Rule ID 0 1007 +-------------------+--+--+--------------+--------+---------++------+ 1008 | Field |FP|DI| Target | MO | CDA || Sent | 1009 | | | | Value | | ||[bits]| 1010 +-------------------+--+--+--------------+--------+---------++------+ 1011 |CoAP version | |bi| 01 |equal |not-sent || | 1012 |CoAP Type | |up| 0 |equal |not-sent || | 1013 |CoAP Type | |dw| 2 |equal |not-sent || | 1014 |CoAP TKL | |bi| 1 |equal |not-sent || | 1015 |CoAP Code | |up| 2 |equal |not-sent || | 1016 |CoAP Code | |dw| 68 |equal |not-sent || | 1017 |CoAP MID | |bi| 0000 |MSB(12) |LSB ||MMMM | 1018 |CoAP Token | |bi| 0x80 |MSB(5) |LSB ||TTT | 1019 |CoAP OSCORE_flags | |up| 0x09 |equal |not-sent || | 1020 |CoAP OSCORE_piv | |up| 0x00 |MSB(4) |LSB ||PPPP | 1021 |COAP OSCORE_kid | |up|0x636c69656e70|MSB(52) |LSB ||KKKK | 1022 |COAP OSCORE_kidctxt| |bi| b'' |equal |not-sent || | 1023 |CoAP OSCORE_flags | |dw| b'' |equal |not-sent || | 1024 |CoAP OSCORE_piv | |dw| b'' |equal |not-sent || | 1025 |CoAP OSCORE_kid | |dw| b'' |equal |not-sent || | 1026 |COAP Option-End | |dw| 0xFF |equal |not-sent || | 1027 +-------------------+--+--+--------------+--------+---------++------+ 1029 Figure 16: Outer SCHC Rules 1031 These Outer Rules are applied to the example GET Request and CONTENT 1032 Response. The resulting messages are shown in Figure 17 and 1033 Figure 18. 1035 Compressed message: 1036 ================== 1037 0x001489458a9fc3686852f6c4 (12 bytes) 1038 0x00 Rule ID 1039 1489 Compression Residue 1040 458a9fc3686852f6c4 Padded payload 1042 Compression residue: 1043 0b 0001 010 0100 0100 (15 bits -> 2 bytes with padding) 1044 mid tkn piv kid 1046 Payload 1047 0xa2c54fe1b434297b62 (9 bytes) 1049 Compressed message length: 12 bytes 1051 Figure 17: SCHC-OSCORE Compressed GET Request 1053 Compressed message: 1054 ================== 1055 0x0014218daf84d983d35de7e48c3c1852 (16 bytes) 1056 0x00 Rule ID 1057 14 Compression residue 1058 218daf84d983d35de7e48c3c1852 Padded payload 1059 Compression residue: 1060 0b0001 010 (7 bits -> 1 byte with padding) 1061 mid tkn 1063 Payload 1064 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) 1066 Compressed msg length: 16 bytes 1068 Figure 18: SCHC-OSCORE Compressed CONTENT Response 1070 For contrast, we compare these results with what would be obtained by 1071 SCHC compressing the original CoAP messages without protecting them 1072 with OSCORE. To do this, we compress the CoAP messages according to 1073 the SCHC rules in Figure 19. 1075 Rule ID 1 1076 +---------------+--+--+-----------+---------+-----------++--------+ 1077 | Field |FP|DI| Target | MO | CDA || Sent | 1078 | | | | Value | | || [bits] | 1079 +---------------+--+--+-----------+---------+-----------++--------+ 1080 |CoAP version | |bi| 01 |equal |not-sent || | 1081 |CoAP Type | |up| 0 |equal |not-sent || | 1082 |CoAP Type | |dw| 2 |equal |not-sent || | 1083 |CoAP TKL | |bi| 1 |equal |not-sent || | 1084 |CoAP Code | |up| 2 |equal |not-sent || | 1085 |CoAP Code | |dw| [69,132] |match-map|map-sent ||C | 1086 |CoAP MID | |bi| 0000 |MSB(12) |LSB ||MMMM | 1087 |CoAP Token | |bi| 0x80 |MSB(5) |LSB ||TTT | 1088 |CoAP Uri-Path | |up|temperature|equal |not-sent || | 1089 |COAP Option-End| |dw| 0xFF |equal |not-sent || | 1090 +---------------+--+--+-----------+---------+-----------++--------+ 1092 Figure 19: SCHC-CoAP Rules (No OSCORE) 1094 This yields the results in Figure 20 for the Request, and Figure 21 1095 for the Response. 1097 Compressed message: 1098 ================== 1099 0x0114 1100 0x01 = Rule ID 1102 Compression residue: 1103 0b00010100 (1 byte) 1105 Compressed msg length: 2 1107 Figure 20: CoAP GET Compressed without OSCORE 1109 Compressed message: 1110 ================== 1111 0x010a32332043 1112 0x01 = Rule ID 1114 Compression residue: 1115 0b00001010 (1 byte) 1117 Payload 1118 0x32332043 1120 Compressed msg length: 6 1122 Figure 21: CoAP CONTENT Compressed without OSCORE 1124 As can be seen, the difference between applying SCHC + OSCORE as 1125 compared to regular SCHC + COAP is about 10 bytes of cost. 1127 8. IANA Considerations 1129 This document has no request to IANA. 1131 9. Security considerations 1133 This document does not have any more Security consideration than the 1134 ones already raised on [I-D.ietf-lpwan-ipv6-static-context-hc] 1136 10. Acknowledgements 1138 The authors would like to thank Dominique Barthel, Carsten Bormann, 1139 Thomas Fossati, Klaus Hartke, Francesca Palombini, Alexander Pelov, 1140 Goran Selander. 1142 11. Normative References 1144 [I-D.ietf-lpwan-ipv6-static-context-hc] 1145 Minaburo, A., Toutain, L., Gomez, C., Barthel, D., and J. 1146 Zuniga, "Static Context Header Compression (SCHC) and 1147 fragmentation for LPWAN, application to UDP/IPv6", draft- 1148 ietf-lpwan-ipv6-static-context-hc-21 (work in progress), 1149 July 2019. 1151 [rfc2119] Bradner, S., "Key words for use in RFCs to Indicate 1152 Requirement Levels", BCP 14, RFC 2119, 1153 DOI 10.17487/RFC2119, March 1997, 1154 . 1156 [rfc7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 1157 Application Protocol (CoAP)", RFC 7252, 1158 DOI 10.17487/RFC7252, June 2014, 1159 . 1161 [rfc7641] Hartke, K., "Observing Resources in the Constrained 1162 Application Protocol (CoAP)", RFC 7641, 1163 DOI 10.17487/RFC7641, September 2015, 1164 . 1166 [rfc7959] Bormann, C. and Z. Shelby, Ed., "Block-Wise Transfers in 1167 the Constrained Application Protocol (CoAP)", RFC 7959, 1168 DOI 10.17487/RFC7959, August 2016, 1169 . 1171 [rfc7967] Bhattacharyya, A., Bandyopadhyay, S., Pal, A., and T. 1172 Bose, "Constrained Application Protocol (CoAP) Option for 1173 No Server Response", RFC 7967, DOI 10.17487/RFC7967, 1174 August 2016, . 1176 [rfc8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 1177 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 1178 May 2017, . 1180 [rfc8613] Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 1181 "Object Security for Constrained RESTful Environments 1182 (OSCORE)", RFC 8613, DOI 10.17487/RFC8613, July 2019, 1183 . 1185 Authors' Addresses 1187 Ana Minaburo 1188 Acklio 1189 1137A avenue des Champs Blancs 1190 35510 Cesson-Sevigne Cedex 1191 France 1193 Email: ana@ackl.io 1195 Laurent Toutain 1196 Institut MINES TELECOM; IMT Atlantique 1197 2 rue de la Chataigneraie 1198 CS 17607 1199 35576 Cesson-Sevigne Cedex 1200 France 1202 Email: Laurent.Toutain@imt-atlantique.fr 1203 Ricardo Andreasen 1204 Universidad de Buenos Aires 1205 Av. Paseo Colon 850 1206 C1063ACV Ciudad Autonoma de Buenos Aires 1207 Argentina 1209 Email: randreasen@fi.uba.ar