idnits 2.17.1 draft-ietf-lpwan-coap-static-context-hc-09.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 239: '...idirectional and MUST be elided during...' RFC 2119 keyword, line 253: '... The field SHOULD be elided if for i...' RFC 2119 keyword, line 256: '...any case, a rule MUST be defined to ca...' RFC 2119 keyword, line 268: '...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 352 has weird spacing: '... equal not...' == Line 354 has weird spacing: '... ignore valu...' == Line 379 has weird spacing: '... ignore val...' == Line 1026 has weird spacing: '...tkn piv kid...' == Line 1043 has weird spacing: '... mid tkn...' -- The document date (July 06, 2019) is 1746 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 249, but not defined == Missing Reference: 'NON' is mentioned on line 249, but not defined == Missing Reference: 'ACK' is mentioned on line 249, but not defined == Missing Reference: 'RST' is mentioned on line 249, but not defined -- Looks like a reference, but probably isn't: '69' on line 1067 -- Looks like a reference, but probably isn't: '132' on line 1067 == Unused Reference: 'I-D.toutain-core-time-scale' is defined on line 1139, but no explicit reference was found in the text == Outdated reference: A later version (-24) exists of draft-ietf-lpwan-ipv6-static-context-hc-19 ** Downref: Normative reference to an Informational draft: draft-toutain-core-time-scale (ref. 'I-D.toutain-core-time-scale') Summary: 3 errors (**), 0 flaws (~~), 12 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: January 7, 2020 Institut MINES TELECOM; IMT Atlantique 6 R. Andreasen 7 Universidad de Buenos Aires 8 July 06, 2019 10 LPWAN Static Context Header Compression (SCHC) for CoAP 11 draft-ietf-lpwan-coap-static-context-hc-09 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 is 19 asymmetric in its message format: the format of the packet header in 20 the request messages is different from that in the response messages. 21 Most of the compression mechanisms have been introduced in 22 [I-D.ietf-lpwan-ipv6-static-context-hc], this document explains how 23 to use the SCHC compression for CoAP. 25 Status of This Memo 27 This Internet-Draft is submitted in full conformance with the 28 provisions of BCP 78 and BCP 79. 30 Internet-Drafts are working documents of the Internet Engineering 31 Task Force (IETF). Note that other groups may also distribute 32 working documents as Internet-Drafts. The list of current Internet- 33 Drafts is at https://datatracker.ietf.org/drafts/current/. 35 Internet-Drafts are draft documents valid for a maximum of six months 36 and may be updated, replaced, or obsoleted by other documents at any 37 time. It is inappropriate to use Internet-Drafts as reference 38 material or to cite them other than as "work in progress." 40 This Internet-Draft will expire on January 7, 2020. 42 Copyright Notice 44 Copyright (c) 2019 IETF Trust and the persons identified as the 45 document authors. All rights reserved. 47 This document is subject to BCP 78 and the IETF Trust's Legal 48 Provisions Relating to IETF Documents 49 (https://trustee.ietf.org/license-info) in effect on the date of 50 publication of this document. Please review these documents 51 carefully, as they describe your rights and restrictions with respect 52 to this document. Code Components extracted from this document must 53 include Simplified BSD License text as described in Section 4.e of 54 the Trust Legal Provisions and are provided without warranty as 55 described in the Simplified BSD License. 57 Table of Contents 59 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 60 2. SCHC Compression Process . . . . . . . . . . . . . . . . . . 3 61 3. CoAP Compression with SCHC . . . . . . . . . . . . . . . . . 4 62 4. Compression of CoAP header fields . . . . . . . . . . . . . . 6 63 4.1. CoAP version field . . . . . . . . . . . . . . . . . . . 6 64 4.2. CoAP type field . . . . . . . . . . . . . . . . . . . . . 6 65 4.3. CoAP code field . . . . . . . . . . . . . . . . . . . . . 6 66 4.4. CoAP Message ID field . . . . . . . . . . . . . . . . . . 6 67 4.5. CoAP Token fields . . . . . . . . . . . . . . . . . . . . 7 68 5. CoAP options . . . . . . . . . . . . . . . . . . . . . . . . 7 69 5.1. CoAP Content and Accept options. . . . . . . . . . . . . 7 70 5.2. CoAP option Max-Age, Uri-Host and Uri-Port fields . . . . 7 71 5.3. CoAP option Uri-Path and Uri-Query fields . . . . . . . . 8 72 5.3.1. Variable length Uri-Path and Uri-Query . . . . . . . 8 73 5.3.2. Variable number of path or query elements . . . . . . 9 74 5.4. CoAP option Size1, Size2, Proxy-URI and Proxy-Scheme 75 fields . . . . . . . . . . . . . . . . . . . . . . . . . 9 76 5.5. CoAP option ETag, If-Match, If-None-Match, Location-Path 77 and Location-Query fields . . . . . . . . . . . . . . . . 9 78 6. Other RFCs . . . . . . . . . . . . . . . . . . . . . . . . . 9 79 6.1. Block . . . . . . . . . . . . . . . . . . . . . . . . . . 9 80 6.2. Observe . . . . . . . . . . . . . . . . . . . . . . . . . 10 81 6.3. No-Response . . . . . . . . . . . . . . . . . . . . . . . 10 82 6.4. OSCORE . . . . . . . . . . . . . . . . . . . . . . . . . 10 83 7. Examples of CoAP header compression . . . . . . . . . . . . . 11 84 7.1. Mandatory header with CON message . . . . . . . . . . . . 11 85 7.2. OSCORE Compression . . . . . . . . . . . . . . . . . . . 12 86 7.3. Example OSCORE Compression . . . . . . . . . . . . . . . 16 87 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 26 88 9. Security considerations . . . . . . . . . . . . . . . . . . . 26 89 10. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 26 90 11. Normative References . . . . . . . . . . . . . . . . . . . . 26 91 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 27 93 1. Introduction 95 CoAP [rfc7252] is an implementation of the REST architecture for 96 constrained devices. Although CoAP was designed for constrained 97 devices, the size of a CoAP header may still be too large for the 98 constraints of Low Power Wide Area Networks (LPWAN) and some 99 compression may be needed to reduce the header size. 101 [I-D.ietf-lpwan-ipv6-static-context-hc] defines a header compression 102 mechanism for LPWAN network based on a static context. The context 103 is said static since the field description composing the Rules are 104 not learned during the packet exchanges but are previously defined. 105 The context(s) is(are) known by both ends before transmission. 107 A context is composed of a set of rules that are referenced by Rule 108 IDs (identifiers). A rule contains an ordered list of the fields 109 descriptions containing a field ID (FID), its length (FL) and its 110 position (FP), a direction indicator (DI) (upstream, downstream and 111 bidirectional) and some associated Target Values (TV). Target Value 112 indicates the value that can be expected. TV can also be a list of 113 values. A Matching Operator (MO) is associated to each header field 114 description. The rule is selected if all the MOs fit the TVs for all 115 fields of the incoming packet. In that case, a Compression/ 116 Decompression Action (CDA) associated to each field defines how the 117 compressed and the decompressed values are computed out of each 118 other, for each of the header fields. Compression mainly results in 119 one of 4 actions: send the field value, send nothing, send some least 120 significant bits of the field or send an index. Values sent are 121 called Compression Residues and follow the rule ID in the transmitted 122 message. 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 all headers from IPv6 to 154 CoAP. In this case, SCHC C/D is performed at the device and at the 155 LPWAN boundary. 157 In the second example, an end-to-end encryption mechanisms is used 158 between the device and the application. CoAP is compressed 159 independently of the other layers. The rule ID and the compression 160 residue are encrypted using a mechanism such as DTLS. Only the other 161 end can decipher the information. 162 Layers below may also be compressed using other SCHC rules (this is 163 out of the scope of this document). 165 In the third example, OSCORE [I-D.ietf-core-object-security] is used. 166 2 rulesets are used to compress the CoAP message. A first ruleset 167 focuses on the inner header and is end to end, a second ruleset 168 compresses the outer header and the layers below. SCHC C/D for inner 169 header is done by both ends, and SCHC C/D for outer header and other 170 headers 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 are present in the request and Y.ZZ in the answer). The direction 198 allows splitting in two parts the possible values for each 199 direction. 201 o In IPv6 and UDP, header fields have a fixed size. In CoAP, Token 202 size may vary from 0 to 8 bytes, the length being given by a field 203 in the header. More systematically, the CoAP options are 204 described using the Type-Length-Value. 206 [I-D.ietf-lpwan-ipv6-static-context-hc] offers the possibility to 207 define a function for the Field Length in the Field Description. 209 o In CoAP headers, a field can appear several times. This is 210 typical for elements of a URI (path or queries). 211 [I-D.ietf-lpwan-ipv6-static-context-hc] allows a Field ID to 212 appears several times in the rule, the Field Position (FP) 213 identifies the proper instance, thereby removing the ambiguity of 214 the matching operation. 216 o Field sizes defined in the CoAP protocol can be too large 217 regarding LPWAN traffic constraints. This is particularly true 218 for the message ID field or Token field. The MSB MO can be used 219 to reduce the information carried on LPWANs. 221 o CoAP also obeys the client/server paradigm and the compression 222 ratio can be different if the request is issued from an LPWAN 223 device or from a non LPWAN device. For instance a Device (Dev) 224 aware of LPWAN constraints can generate a 1 byte token, but a 225 regular CoAP client will certainly send a larger token to the Dev. 226 The SCHC compression-decompression process does not modify the 227 values. Nevertheless, a proxy placed before the compressor may 228 change some field values to allow SCHC achieving a better 229 compression ratio, while maintaining the necessary context for 230 interoperability with existing CoAP implementations. 232 4. Compression of CoAP header fields 234 This section discusses the compression of the different CoAP header 235 fields. 237 4.1. CoAP version field 239 This field is bidirectional and MUST be elided during the SCHC 240 compression, since it always contains the same value. In the future, 241 if new versions of CoAP are defined, new rules will be defined to 242 avoid ambiguities between versions. 244 4.2. CoAP type field 246 [rfc7252] defines 4 types of messages: CON, NON, ACK and RST. The 247 last two are a response to the first two. If the device plays a 248 specific client or server role, a rule can exploit these properties 249 with the mapping list: [CON, NON] for one direction and [ACK, RST] 250 for the other direction. The compression residue is reduced to 1 251 bit. 253 The field SHOULD be elided if for instance a client is sending only 254 NON or only CON messages. 256 In any case, a rule MUST be defined to carry RST to a client. 258 4.3. CoAP code field 260 The compression of the CoAP code field follows the same principle as 261 that of the CoAP type field. If the device plays a specific role, 262 the set of code values can be split in two parts, the request codes 263 with the 0 class and the response values. 265 If the device only implements a CoAP client, the request code can be 266 reduced to the set of requests the client is able to process. 268 All the response codes MUST be compressed with a SCHC rule. 270 4.4. CoAP Message ID field 272 This field is bidirectional and is used to manage acknowledgments. 273 The server memorizes the value for a EXCHANGE_LIFETIME period (by 274 default 247 seconds) for CON messages and a NON_LIFETIME period (by 275 default 145 seconds) for NON messages. During that period, a server 276 receiving the same Message ID value will process the message as a 277 retransmission. After this period, it will be processed as a new 278 message. 280 In case the Device is a client, the size of the message ID field may 281 be too large regarding the number of messages sent. The client 282 SHOULD use only small message ID values, for instance 4 bit long. 283 Therefore, a MSB can be used to limit the size of the compression 284 residue. 286 In case the Device is a server, the client may be located outside of 287 the LPWAN area and view the Device as a regular device connected to 288 the internet. The client will generate Message ID using the 16 bits 289 space offered by this field. A CoAP proxy can be set before the SCHC 290 C/D to reduce the value of the Message ID, to allow its compression 291 with the MSB matching operator and LSB CDA. 293 4.5. CoAP Token fields 295 Token is defined through two CoAP fields, Token Length in the 296 mandatory header and Token Value directly following the mandatory 297 CoAP header. 299 Token Length is processed as any protocol field. If the value 300 remains the same during all the transaction, the size can be stored 301 in the context and elided during the transmission. Otherwise, it 302 will have to the sent as a compression residue. 304 Token Value size cannot be defined directly in the rule in the Field 305 Length (FL). Instead, a specific function designated as "TKL" MUST 306 be used and length does not have to the sent with the residue. 307 During the decompression, this function returns the value contained 308 in the Token Length field. 310 5. CoAP options 312 5.1. CoAP Content and Accept options. 314 These fields are both unidirectional and MUST NOT be set to 315 bidirectional in a rule entry. 317 If a single value is expected by the client, it can be stored in the 318 TV and elided during the transmission. Otherwise, if several 319 possible values are expected by the client, a matching-list SHOULD be 320 used to limit the size of the residue. If is not possible, the value 321 has to be sent as a residue (fixed or variable length). 323 5.2. CoAP option Max-Age, Uri-Host and Uri-Port fields 325 These fields are unidirectional and MUST NOT be set to bidirectional 326 in a rule entry. They are used only by the server to inform of the 327 caching duration and is never found in client requests. 329 If the duration is known by both ends, the value can be elided on the 330 LPWAN. 332 A matching list can be used if some well-known values are defined. 334 Otherwise these options SHOULD be sent as a residue (fixed or 335 variable length). 337 5.3. CoAP option Uri-Path and Uri-Query fields 339 These fields are unidirectional and MUST NOT be set to bidirectional 340 in a rule entry. They are used only by the client to access a 341 specific resource and are never found in server responses. 343 Uri-Path and Uri-Query elements are a repeatable options, the Field 344 Position (FP) gives the position in the path. 346 A Mapping list can be used to reduce the size of variable Paths or 347 Queries. In that case, to optimize the compression, several elements 348 can be regrouped into a single entry. Numbering of elements do not 349 change, MO comparison is set with the first element of the matching. 351 FID FL FP DI TV MO CDA 352 URI-Path 1 up ["/a/b", equal not-sent 353 "/c/d"] 354 URI-Path 3 up ignore value-sent 356 Figure 2: complex path example 358 In Figure 2 a single bit residue can be used to code one of the 2 359 paths. If regrouping were not allowed, a 2 bits residue would be 360 needed. 362 5.3.1. Variable length Uri-Path and Uri-Query 364 When the length is not known at the rule creation, the Field Length 365 SHOULD be set to variable, and the unit is set to bytes. 367 The MSB MO can be applied to a Uri-Path or Uri-Query element. Since 368 MSB value is given in bit, the size MUST always be a multiple of 8 369 bits. 371 The length sent at the beginning of a variable length residue 372 indicates the size of the LSB in bytes. 374 For instance for a CORECONF path /c/X6?k="eth0" the rule can be set 375 to: 377 FID FL FP DI TV MO CDA 378 URI-Path 1 up "c" equal not-sent 379 URI-Path 2 up ignore value-sent 380 URI-Query 1 up "k=" MSB (16) LSB 382 Figure 3: CORECONF URI compression 384 Figure 3 shows the parsing and the compression of the URI, where c is 385 not sent. The second element is sent with the length (i.e. 0x2 X 6) 386 followed by the query option (i.e. 0x05 "eth0"). 388 5.3.2. Variable number of path or query elements 390 The number of Uri-path or Uri-Query elements in a rule is fixed at 391 the rule creation time. If the number varies, several rules SHOULD 392 be created to cover all the possibilities. Another possibility is to 393 define the length of Uri-Path to variable and send a compression 394 residue with a length of 0 to indicate that this Uri-Path is empty. 395 This adds 4 bits to the compression residue. 397 5.4. CoAP option Size1, Size2, Proxy-URI and Proxy-Scheme fields 399 These fields are unidirectional and MUST NOT be set to bidirectional 400 in a rule entry. They are used only by the client to access a 401 specific resource and are never found in server response. 403 If the field value has to be sent, TV is not set, MO is set to 404 "ignore" and CDA is set to "value-sent". A mapping MAY also be used. 406 Otherwise, the TV is set to the value, MO is set to "equal" and CDA 407 is set to "not-sent". 409 5.5. CoAP option ETag, If-Match, If-None-Match, Location-Path and 410 Location-Query fields 412 These fields are unidirectional. 414 These fields values cannot be stored in a rule entry. They MUST 415 always be sent with the compression residues. 417 6. Other RFCs 419 6.1. Block 421 Block [rfc7959] allows a fragmentation at the CoAP level. SCHC also 422 includes a fragmentation protocol. They are compatible. If a block 423 option is used, its content MUST be sent as a compression residue. 425 6.2. Observe 427 [rfc7641] defines the Observe option. The TV is not set, MO is set 428 to "ignore" and the CDA is set to "value-sent". SCHC does not limit 429 the maximum size for this option (3 bytes). To reduce the 430 transmission size, either the device implementation MAY limit the 431 delta between two consecutive values, or a proxy can modify the 432 increment. 434 Since an RST message may be sent to inform a server that the client 435 does not require Observe response, a rule MUST allow the transmission 436 of this message. 438 6.3. No-Response 440 [rfc7967] defines a No-Response option limiting the responses made by 441 a server to a request. If the value is known by both ends, then TV 442 is set to this value, MO is set to "equal" and CDA is set to "not- 443 sent". 445 Otherwise, if the value is changing over time, TV is not set, MO is 446 set to "ignore" and CDA to "value-sent". A matching list can also be 447 used to reduce the size. 449 6.4. OSCORE 451 OSCORE [I-D.ietf-core-object-security] defines end-to-end protection 452 for CoAP messages. This section describes how SCHC rules can be 453 applied to compress OSCORE-protected messages. 455 0 1 2 3 4 5 6 7 <--------- n bytes -------------> 456 +-+-+-+-+-+-+-+-+--------------------------------- 457 |0 0 0|h|k| n | Partial IV (if any) ... 458 +-+-+-+-+-+-+-+-+--------------------------------- 459 | | | 460 |<-- CoAP -->|<------ CoAP OSCORE_piv ------> | 461 OSCORE_flags 463 <- 1 byte -> <------ s bytes -----> 464 +------------+----------------------+-----------------------+ 465 | s (if any) | kid context (if any) | kid (if any) ... | 466 +------------+----------------------+-----------------------+ 467 | | | 468 | <------ CoAP OSCORE_kidctxt ----->|<-- CoAP OSCORE_kid -->| 470 Figure 4: OSCORE Option 472 The encoding of the OSCORE Option Value defined in Section 6.1 of 473 [I-D.ietf-core-object-security] is repeated in Figure 4. 475 The first byte is used for flags that specify the contents of the 476 OSCORE option. The 3 most significant bits are reserved and always 477 set to 0. Bit h, when set, indicates the presence of the kid context 478 field in the option. Bit k, when set, indicates the presence of a 479 kid field. The 3 least significant bits n indicate the length of the 480 piv field in bytes. When n = 0, no piv is present. 482 After the flag byte follow the piv field, kid context field and kid 483 field in order and if present; the length of the kid context field is 484 encoded in the first byte denoting by s the length of the kid context 485 in bytes. 487 This draft recommends to implement a parser that is able to identify 488 the OSCORE Option and the fields it contains. 490 Conceptually, it discerns up to 4 distinct pieces of information 491 within the OSCORE option: the flag bits, the piv, the kid context, 492 and the kid. It is thus recommended that the parser split the OSCORE 493 option into the 4 subsequent fields: 495 o CoAP OSCORE_flags, 497 o CoAP OSCORE_piv, 499 o CoAP OSCORE_kidctxt, 501 o CoAP OSCORE_kid. 503 These fields are shown superimposed on the OSCORE Option format in 504 Figure 4, the CoAP OSCORE_kidctxt field including the size bits s. 505 Their size SHOULD be reduced using SCHC compression. 507 7. Examples of CoAP header compression 509 7.1. Mandatory header with CON message 511 In this first scenario, the LPWAN compressor at the Network Gateway 512 side receives from a client on the Internet a POST message, which is 513 immediately acknowledged by the Device. For this simple scenario, 514 the rules are described Figure 5. 516 Rule ID 1 517 +-------------+--+--+--+------+---------+-------------++------------+ 518 | Field |FL|FP|DI|Target| Match | CDA || Sent | 519 | | | | |Value | Opera. | || [bits] | 520 +-------------+--+--+--+------+---------+-------------++------------+ 521 |CoAP version | | |bi| 01 |equal |not-sent || | 522 |CoAP Type | | |dw| CON |equal |not-sent || | 523 |CoAP Type | | |up|[ACK, | | || | 524 | | | | | RST] |match-map|matching-sent|| T | 525 |CoAP TKL | | |bi| 0 |equal |not-sent || | 526 |CoAP Code | | |bi|[0.00,| | || | 527 | | | | | ... | | || | 528 | | | | | 5.05]|match-map|matching-sent|| CC CCC | 529 |CoAP MID | | |bi| 0000 |MSB(7 ) |LSB || M-ID| 530 |CoAP Uri-Path| | |dw| path |equal 1 |not-sent || | 531 +-------------+--+--+--+------+---------+-------------++------------+ 533 Figure 5: CoAP Context to compress header without token 535 The version and Token Length fields are elided. The 26 method and 536 response codes defined in [rfc7252] has been shrunk to 5 bits using a 537 matching list. Uri-Path contains a single element indicated in the 538 matching operator. 540 SCHC Compression reduces the header sending only the Type, a mapped 541 code and the least significant bits of Message ID (9 bits in the 542 example above). 544 Note that a request sent by a client located an Application Server to 545 a server in the device, may not be compressed through this rule since 546 the MID will not start with 7 bits equal to 0. A CoAP proxy, before 547 the core SCHC C/D can rewrite the message ID to a value matched by 548 the rule. 550 7.2. OSCORE Compression 552 OSCORE aims to solve the problem of end-to-end encryption for CoAP 553 messages. The goal, therefore, is to hide as much of the message as 554 possible while still enabling proxy operation. 556 Conceptually this is achieved by splitting the CoAP message into an 557 Inner Plaintext and Outer OSCORE Message. The Inner Plaintext 558 contains sensible information which is not necessary for proxy 559 operation. This, in turn, is the part of the message which can be 560 encrypted until it reaches its end destination. The Outer Message 561 acts as a shell matching the format of a regular CoAP message, and 562 includes all Options and information needed for proxy operation and 563 caching. This decomposition is illustrated in Figure 6. 565 CoAP options are sorted into one of 3 classes, each granted a 566 specific type of protection by the protocol: 568 o Class E: Encrypted options moved to the Inner Plaintext, 570 o Class I: Integrity-protected options included in the AAD for the 571 encryption of the Plaintext but otherwise left untouched in the 572 Outer Message, 574 o Class U: Unprotected options left untouched in the Outer Message. 576 Additionally, the OSCORE Option is added as an Outer option, 577 signaling that the message is OSCORE protected. This option carries 578 the information necessary to retrieve the Security Context with which 579 the message was encrypted so that it may be correctly decrypted at 580 the other end-point. 582 Original CoAP Message 583 +-+-+---+-------+---------------+ 584 |v|t|tkl| code | Msg Id. | 585 +-+-+---+-------+---------------+....+ 586 | Token | 587 +-------------------------------.....+ 588 | Options (IEU) | 589 . . 590 . . 591 +------+-------------------+ 592 | 0xFF | 593 +------+------------------------+ 594 | | 595 | Payload | 596 | | 597 +-------------------------------+ 598 / \ 599 / \ 600 / \ 601 / \ 602 Outer Header v v Plaintext 603 +-+-+---+--------+---------------+ +-------+ 604 |v|t|tkl|new code| Msg Id. | | code | 605 +-+-+---+--------+---------------+....+ +-------+-----......+ 606 | Token | | Options (E) | 607 +--------------------------------.....+ +-------+------.....+ 608 | Options (IU) | | OxFF | 609 . . +-------+-----------+ 610 . OSCORE Option . | | 611 +------+-------------------+ | Payload | 612 | 0xFF | | | 613 +------+ +-------------------+ 615 Figure 6: A CoAP message is split into an OSCORE outer and plaintext 617 Figure 6 shows the message format for the OSCORE Message and 618 Plaintext. 620 In the Outer Header, the original message code is hidden and replaced 621 by a default dummy value. As seen in sections 4.1.3.5 and 4.2 of 622 [I-D.ietf-core-object-security], the message code is replaced by POST 623 for requests and Changed for responses when Observe is not used. If 624 Observe is used, the message code is replaced by FETCH for requests 625 and Content for responses. 627 The original message code is put into the first byte of the 628 Plaintext. Following the message code, the class E options comes and 629 if present the original message Payload is preceded by its payload 630 marker. 632 The Plaintext is now encrypted by an AEAD algorithm which integrity 633 protects Security Context parameters and eventually any class I 634 options from the Outer Header. Currently no CoAP options are marked 635 class I. The resulting Ciphertext becomes the new Payload of the 636 OSCORE message, as illustrated in Figure 7. 638 This Ciphertext is, as defined in RFC 5116, the concatenation of the 639 encrypted Plaintext and its authentication tag. Note that Inner 640 Compression only affects the Plaintext before encryption, thus we can 641 only aim to reduce this first, variable length component of the 642 Ciphertext. The authentication tag is fixed in length and considered 643 part of the cost of protection. 645 Outer Header 646 +-+-+---+--------+---------------+ 647 |v|t|tkl|new code| Msg Id. | 648 +-+-+---+--------+---------------+....+ 649 | Token | 650 +--------------------------------.....+ 651 | Options (IU) | 652 . . 653 . OSCORE Option . 654 +------+-------------------+ 655 | 0xFF | 656 +------+---------------------------+ 657 | | 658 | Ciphertext: Encrypted Inner | 659 | Header and Payload | 660 | + Authentication Tag | 661 | | 662 +----------------------------------+ 664 Figure 7: OSCORE message 666 The SCHC Compression scheme consists of compressing both the 667 Plaintext before encryption and the resulting OSCORE message after 668 encryption, see Figure 8. 670 This translates into a segmented process where SCHC compression is 671 applied independently in 2 stages, each with its corresponding set of 672 rules, with the Inner SCHC Rules and the Outer SCHC Rules. This way 673 compression is applied to all fields of the original CoAP message. 675 Note that since the Inner part of the message can only be decrypted 676 by the corresponding end-point, this end-point will also have to 677 implement Inner SCHC Compression/Decompression. 679 Outer Message OSCORE Plaintext 680 +-+-+---+--------+---------------+ +-------+ 681 |v|t|tkl|new code| Msg Id. | | code | 682 +-+-+---+--------+---------------+....+ +-------+-----......+ 683 | Token | | Options (E) | 684 +--------------------------------.....+ +-------+------.....+ 685 | Options (IU) | | OxFF | 686 . . +-------+-----------+ 687 . OSCORE Option . | | 688 +------+-------------------+ | Payload | 689 | 0xFF | | | 690 +------+------------+ +-------------------+ 691 | Ciphertext |<---------\ | 692 | | | v 693 +-------------------+ | +-----------------+ 694 | | | Inner SCHC | 695 v | | Compression | 696 +-----------------+ | +-----------------+ 697 | Outer SCHC | | | 698 | Compression | | v 699 +-----------------+ | +-------+ 700 | | |Rule ID| 701 v | +-------+--+ 702 +--------+ +------------+ | Residue | 703 |Rule ID'| | Encryption | <--- +----------+--------+ 704 +--------+--+ +------------+ | | 705 | Residue' | | Payload | 706 +-----------+-------+ | | 707 | Ciphertext | +-------------------+ 708 | | 709 +-------------------+ 711 Figure 8: OSCORE Compression Diagram 713 7.3. Example OSCORE Compression 715 An example is given with a GET Request and its consequent CONTENT 716 Response from a device-based CoAP client to a cloud-based CoAP 717 server. A possible set of rules for the Inner and Outer SCHC 718 Compression is shown. A dump of the results and a contrast between 719 SCHC + OSCORE performance with SCHC + COAP performance is also 720 listed. This gives an approximation to the cost of security with 721 SCHC-OSCORE. 723 Our first example CoAP message is the GET Request in Figure 9 725 Original message: 726 ================= 727 0x4101000182bb74656d7065726174757265 729 Header: 730 0x4101 731 01 Ver 732 00 CON 733 0001 tkl 734 00000001 Request Code 1 "GET" 736 0x0001 = mid 737 0x82 = token 739 Options: 740 0xbb74656d7065726174757265 741 Option 11: URI_PATH 742 Value = temperature 744 Original msg length: 17 bytes. 746 Figure 9: CoAP GET Request 748 Its corresponding response is the CONTENT Response in Figure 10. 750 Original message: 751 ================= 752 0x6145000182ff32332043 754 Header: 755 0x6145 756 01 Ver 757 10 ACK 758 0001 tkl 759 01000101 Successful Response Code 69 "2.05 Content" 761 0x0001 = mid 762 0x82 = token 764 0xFF Payload marker 765 Payload: 766 0x32332043 768 Original msg length: 10 770 Figure 10: CoAP CONTENT Response 772 The SCHC Rules for the Inner Compression include all fields that are 773 already present in a regular CoAP message, what is important is the 774 order of appearance and inclusion of only those CoAP fields that go 775 into the Plaintext, Figure 11. 777 Rule ID 0 778 +---------------+--+--+-----------+-----------+-----------++------+ 779 | Field |FP|DI| Target | MO | CDA || Sent | 780 | | | | Value | | ||[bits]| 781 +---------------+--+--+-----------+-----------+-----------++------+ 782 |CoAP Code | |up| 1 | equal |not-sent || | 783 |CoAP Code | |dw|[69,132] | match-map |match-sent || c | 784 |CoAP Uri-Path | |up|temperature| equal |not-sent || | 785 |COAP Option-End| |dw| 0xFF | equal |not-sent || | 786 +---------------+--+--+-----------+-----------+-----------++------+ 788 Figure 11: Inner SCHC Rules 790 Figure 12 shows the Plaintext obtained for our example GET Request 791 and follows the process of Inner Compression and Encryption until we 792 end up with the Payload to be added in the outer OSCORE Message. 794 In this case the original message has no payload and its resulting 795 Plaintext can be compressed up to only 1 byte (size of the Rule ID). 796 The AEAD algorithm preserves this length in its first output, but 797 also yields a fixed-size tag which cannot be compressed and has to be 798 included in the OSCORE message. This translates into an overhead in 799 total message length, which limits the amount of compression that can 800 be achieved and plays into the cost of adding security to the 801 exchange. 803 ________________________________________________________ 804 | | 805 | OSCORE Plaintext | 806 | | 807 | 0x01bb74656d7065726174757265 (13 bytes) | 808 | | 809 | 0x01 Request Code GET | 810 | | 811 | bb74656d7065726174757265 Option 11: URI_PATH | 812 | Value = temperature | 813 |________________________________________________________| 815 | 816 | 817 | Inner SCHC Compression 818 | 819 v 820 _________________________________ 821 | | 822 | Compressed Plaintext | 823 | | 824 | 0x00 | 825 | | 826 | Rule ID = 0x00 (1 byte) | 827 | (No residue) | 828 |_________________________________| 830 | 831 | AEAD Encryption 832 | (piv = 0x04) 833 v 834 _________________________________________________ 835 | | 836 | encrypted_plaintext = 0xa2 (1 byte) | 837 | tag = 0xc54fe1b434297b62 (8 bytes) | 838 | | 839 | ciphertext = 0xa2c54fe1b434297b62 (9 bytes) | 840 |_________________________________________________| 842 Figure 12: Plaintext compression and encryption for GET Request 844 In Figure 13 we repeat the process for the example CONTENT Response. 845 In this case the misalignment produced by the compression residue (1 846 bit) makes it so that 7 bits of padding have to be applied after the 847 payload, resulting in a compressed Plaintext that is the same size as 848 before compression. This misalignment also causes the hexcode from 849 the payload to differ from the original, even though it has not been 850 compressed. On top of this, the overhead from the tag bytes is 851 incurred as before. 853 ________________________________________________________ 854 | | 855 | OSCORE Plaintext | 856 | | 857 | 0x45ff32332043 (6 bytes) | 858 | | 859 | 0x45 Successful Response Code 69 "2.05 Content" | 860 | | 861 | ff Payload marker | 862 | | 863 | 32332043 Payload | 864 |________________________________________________________| 866 | 867 | 868 | Inner SCHC Compression 869 | 870 v 871 __________________________________________ 872 | | 873 | Compressed Plaintext | 874 | | 875 | 0x001919902180 (6 bytes) | 876 | | 877 | 00 Rule ID | 878 | | 879 | 0b0 (1 bit match-map residue) | 880 | 0x32332043 >> 1 (shifted payload) | 881 | 0b0000000 Padding | 882 |__________________________________________| 884 | 885 | AEAD Encryption 886 | (piv = 0x04) 887 v 888 _________________________________________________________ 889 | | 890 | encrypted_plaintext = 0x10c6d7c26cc1 (6 bytes) | 891 | tag = 0xe9aef3f2461e0c29 (8 bytes) | 892 | | 893 | ciphertext = 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) | 894 |_________________________________________________________| 896 Figure 13: Plaintext compression and encryption for CONTENT Response 897 The Outer SCHC Rules (Figure 16) MUST process the OSCORE Options 898 fields. In Figure 14 and Figure 15 we show a dump of the OSCORE 899 Messages generated from our example messages once they have been 900 provided with the Inner Compressed Ciphertext in the payload. These 901 are the messages that are to go through Outer SCHC Compression. 903 Protected message: 904 ================== 905 0x4102000182d7080904636c69656e74ffa2c54fe1b434297b62 906 (25 bytes) 908 Header: 909 0x4102 910 01 Ver 911 00 CON 912 0001 tkl 913 00000010 Request Code 2 "POST" 915 0x0001 = mid 916 0x82 = token 918 Options: 919 0xd8080904636c69656e74 (10 bytes) 920 Option 21: OBJECT_SECURITY 921 Value = 0x0904636c69656e74 922 09 = 000 0 1 001 Flag byte 923 h k n 924 04 piv 925 636c69656e74 kid 927 0xFF Payload marker 928 Payload: 929 0xa2c54fe1b434297b62 (9 bytes) 931 Figure 14: Protected and Inner SCHC Compressed GET Request 933 Protected message: 934 ================== 935 0x6144000182d008ff10c6d7c26cc1e9aef3f2461e0c29 936 (22 bytes) 938 Header: 939 0x6144 940 01 Ver 941 10 ACK 942 0001 tkl 943 01000100 Successful Response Code 68 "2.04 Changed" 945 0x0001 = mid 946 0x82 = token 948 Options: 949 0xd008 (2 bytes) 950 Option 21: OBJECT_SECURITY 951 Value = b'' 953 0xFF Payload marker 954 Payload: 955 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) 957 Figure 15: Protected and Inner SCHC Compressed CONTENT Response 959 For the flag bits, a number of compression methods could prove to be 960 useful depending on the application. The simplest alternative is to 961 provide a fixed value for the flags, combining MO equal and CDA not- 962 sent. This saves most bits but could hinder flexibility. Otherwise, 963 match-mapping could allow to choose from a number of configurations 964 of interest to the exchange. If neither of these alternatives is 965 desirable, MSB could be used to mask off the 3 hard-coded most 966 significant bits. 968 Note that fixing a flag bit will limit the choice of CoAP Options 969 that can be used in the exchange, since their values are dependent on 970 certain options. 972 The piv field lends itself to having a number of bits masked off with 973 MO MSB and CDA LSB. This could prove useful in applications where 974 the message frequency is low such as that found in LPWAN 975 technologies. Note that compressing the sequence numbers effectively 976 reduces the maximum amount of sequence numbers that can be used in an 977 exchange. Once this amount is exceeded, the SCHC Context would need 978 to be re-established. 980 The size s included in the kid context field MAY be masked off with 981 CDA MSB. The rest of the field could have additional bits masked 982 off, or have the whole field be fixed with MO equal and CDA not-sent. 983 The same holds for the kid field. 985 Figure 16 shows a possible set of Outer Rules to compress the Outer 986 Header. 988 Rule ID 0 989 +-------------------+--+--+--------------+--------+---------++------+ 990 | Field |FP|DI| Target | MO | CDA || Sent | 991 | | | | Value | | ||[bits]| 992 +-------------------+--+--+--------------+--------+---------++------+ 993 |CoAP version | |bi| 01 |equal |not-sent || | 994 |CoAP Type | |up| 0 |equal |not-sent || | 995 |CoAP Type | |dw| 2 |equal |not-sent || | 996 |CoAP TKL | |bi| 1 |equal |not-sent || | 997 |CoAP Code | |up| 2 |equal |not-sent || | 998 |CoAP Code | |dw| 68 |equal |not-sent || | 999 |CoAP MID | |bi| 0000 |MSB(12) |LSB ||MMMM | 1000 |CoAP Token | |bi| 0x80 |MSB(5) |LSB ||TTT | 1001 |CoAP OSCORE_flags | |up| 0x09 |equal |not-sent || | 1002 |CoAP OSCORE_piv | |up| 0x00 |MSB(4) |LSB ||PPPP | 1003 |COAP OSCORE_kid | |up|0x636c69656e70|MSB(52) |LSB ||KKKK | 1004 |COAP OSCORE_kidctxt| |bi| b'' |equal |not-sent || | 1005 |CoAP OSCORE_flags | |dw| b'' |equal |not-sent || | 1006 |CoAP OSCORE_piv | |dw| b'' |equal |not-sent || | 1007 |CoAP OSCORE_kid | |dw| b'' |equal |not-sent || | 1008 |COAP Option-End | |dw| 0xFF |equal |not-sent || | 1009 +-------------------+--+--+--------------+--------+---------++------+ 1011 Figure 16: Outer SCHC Rules 1013 These Outer Rules are applied to the example GET Request and CONTENT 1014 Response. The resulting messages are shown in Figure 17 and 1015 Figure 18. 1017 Compressed message: 1018 ================== 1019 0x001489458a9fc3686852f6c4 (12 bytes) 1020 0x00 Rule ID 1021 1489 Compression Residue 1022 458a9fc3686852f6c4 Padded payload 1024 Compression residue: 1025 0b 0001 010 0100 0100 (15 bits -> 2 bytes with padding) 1026 mid tkn piv kid 1028 Payload 1029 0xa2c54fe1b434297b62 (9 bytes) 1031 Compressed message length: 12 bytes 1033 Figure 17: SCHC-OSCORE Compressed GET Request 1035 Compressed message: 1036 ================== 1037 0x0014218daf84d983d35de7e48c3c1852 (16 bytes) 1038 0x00 Rule ID 1039 14 Compression residue 1040 218daf84d983d35de7e48c3c1852 Padded payload 1041 Compression residue: 1042 0b0001 010 (7 bits -> 1 byte with padding) 1043 mid tkn 1045 Payload 1046 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) 1048 Compressed msg length: 16 bytes 1050 Figure 18: SCHC-OSCORE Compressed CONTENT Response 1052 For contrast, we compare these results with what would be obtained by 1053 SCHC compressing the original CoAP messages without protecting them 1054 with OSCORE. To do this, we compress the CoAP messages according to 1055 the SCHC rules in Figure 19. 1057 Rule ID 1 1058 +---------------+--+--+-----------+---------+-----------++--------+ 1059 | Field |FP|DI| Target | MO | CDA || Sent | 1060 | | | | Value | | || [bits] | 1061 +---------------+--+--+-----------+---------+-----------++--------+ 1062 |CoAP version | |bi| 01 |equal |not-sent || | 1063 |CoAP Type | |up| 0 |equal |not-sent || | 1064 |CoAP Type | |dw| 2 |equal |not-sent || | 1065 |CoAP TKL | |bi| 1 |equal |not-sent || | 1066 |CoAP Code | |up| 2 |equal |not-sent || | 1067 |CoAP Code | |dw| [69,132] |match-map|map-sent ||C | 1068 |CoAP MID | |bi| 0000 |MSB(12) |LSB ||MMMM | 1069 |CoAP Token | |bi| 0x80 |MSB(5) |LSB ||TTT | 1070 |CoAP Uri-Path | |up|temperature|equal |not-sent || | 1071 |COAP Option-End| |dw| 0xFF |equal |not-sent || | 1072 +---------------+--+--+-----------+---------+-----------++--------+ 1074 Figure 19: SCHC-CoAP Rules (No OSCORE) 1076 This yields the results in Figure 20 for the Request, and Figure 21 1077 for the Response. 1079 Compressed message: 1080 ================== 1081 0x0114 1082 0x01 = Rule ID 1084 Compression residue: 1085 0b00010100 (1 byte) 1087 Compressed msg length: 2 1089 Figure 20: CoAP GET Compressed without OSCORE 1091 Compressed message: 1092 ================== 1093 0x010a32332043 1094 0x01 = Rule ID 1096 Compression residue: 1097 0b00001010 (1 byte) 1099 Payload 1100 0x32332043 1102 Compressed msg length: 6 1104 Figure 21: CoAP CONTENT Compressed without OSCORE 1106 As can be seen, the difference between applying SCHC + OSCORE as 1107 compared to regular SCHC + COAP is about 10 bytes of cost. 1109 8. IANA Considerations 1111 This document has no request to IANA. 1113 9. Security considerations 1115 This document does not have any more Security consideration than the 1116 ones already raised on [I-D.ietf-lpwan-ipv6-static-context-hc] 1118 10. Acknowledgements 1120 The authors would like to thank Dominique Barthel, Carsten Bormann, 1121 Thomas Fossati, Klaus Hartke, Francesca Palombini, Alexander Pelov, 1122 Goran Selander. 1124 11. Normative References 1126 [I-D.ietf-core-object-security] 1127 Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 1128 "Object Security for Constrained RESTful Environments 1129 (OSCORE)", draft-ietf-core-object-security-16 (work in 1130 progress), March 2019. 1132 [I-D.ietf-lpwan-ipv6-static-context-hc] 1133 Minaburo, A., Toutain, L., Gomez, C., Barthel, D., and J. 1134 Zuniga, "Static Context Header Compression (SCHC) and 1135 fragmentation for LPWAN, application to UDP/IPv6", draft- 1136 ietf-lpwan-ipv6-static-context-hc-19 (work in progress), 1137 July 2019. 1139 [I-D.toutain-core-time-scale] 1140 Minaburo, A. and L. Toutain, "CoAP Time Scale Option", 1141 draft-toutain-core-time-scale-00 (work in progress), 1142 October 2017. 1144 [rfc7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 1145 Application Protocol (CoAP)", RFC 7252, 1146 DOI 10.17487/RFC7252, June 2014, 1147 . 1149 [rfc7641] Hartke, K., "Observing Resources in the Constrained 1150 Application Protocol (CoAP)", RFC 7641, 1151 DOI 10.17487/RFC7641, September 2015, 1152 . 1154 [rfc7959] Bormann, C. and Z. Shelby, Ed., "Block-Wise Transfers in 1155 the Constrained Application Protocol (CoAP)", RFC 7959, 1156 DOI 10.17487/RFC7959, August 2016, 1157 . 1159 [rfc7967] Bhattacharyya, A., Bandyopadhyay, S., Pal, A., and T. 1160 Bose, "Constrained Application Protocol (CoAP) Option for 1161 No Server Response", RFC 7967, DOI 10.17487/RFC7967, 1162 August 2016, . 1164 Authors' Addresses 1166 Ana Minaburo 1167 Acklio 1168 1137A avenue des Champs Blancs 1169 35510 Cesson-Sevigne Cedex 1170 France 1172 Email: ana@ackl.io 1173 Laurent Toutain 1174 Institut MINES TELECOM; IMT Atlantique 1175 2 rue de la Chataigneraie 1176 CS 17607 1177 35576 Cesson-Sevigne Cedex 1178 France 1180 Email: Laurent.Toutain@imt-atlantique.fr 1182 Ricardo Andreasen 1183 Universidad de Buenos Aires 1184 Av. Paseo Colon 850 1185 C1063ACV Ciudad Autonoma de Buenos Aires 1186 Argentina 1188 Email: randreasen@fi.uba.ar