idnits 2.17.1 draft-ietf-lpwan-coap-static-context-hc-08.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 128: '... the CoAP header MAY be done in conjun...' RFC 2119 keyword, line 149: '...pplication, CoAP MAY be compressed ind...' RFC 2119 keyword, line 231: '...idirectional and MUST be elided during...' RFC 2119 keyword, line 244: '... The field SHOULD be elided if for i...' RFC 2119 keyword, line 247: '...any case, a rule MUST be defined to ca...' (21 more instances...) Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == Line 344 has weird spacing: '... equal not...' == Line 346 has weird spacing: '... ignore valu...' == Line 371 has weird spacing: '... ignore val...' == Line 1046 has weird spacing: '...tkn piv kid...' == Line 1063 has weird spacing: '... mid tkn...' -- The document date (May 29, 2019) is 1794 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 241, but not defined == Missing Reference: 'NON' is mentioned on line 241, but not defined == Missing Reference: 'ACK' is mentioned on line 241, but not defined == Missing Reference: 'RST' is mentioned on line 241, but not defined -- Looks like a reference, but probably isn't: '69' on line 1087 -- Looks like a reference, but probably isn't: '132' on line 1087 == Outdated reference: A later version (-24) exists of draft-ietf-lpwan-ipv6-static-context-hc-18 ** Downref: Normative reference to an Informational draft: draft-toutain-core-time-scale (ref. 'I-D.toutain-core-time-scale') Summary: 3 errors (**), 0 flaws (~~), 11 warnings (==), 3 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 lpwan Working Group A. Minaburo 3 Internet-Draft Acklio 4 Intended status: Standards Track L. Toutain 5 Expires: November 30, 2019 Institut MINES TELECOM; IMT Atlantique 6 R. Andreasen 7 Universidad de Buenos Aires 8 May 29, 2019 10 LPWAN Static Context Header Compression (SCHC) for CoAP 11 draft-ietf-lpwan-coap-static-context-hc-08 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 18 uses a flexible header with a variable number of options themselves 19 of variable length. The CoAP protocol is asymmetric in its message 20 format, the format of the header packet in the request messages is 21 different from that in the response messages. Most of the 22 compression mechanisms have been introduced in 23 [I-D.ietf-lpwan-ipv6-static-context-hc], this document explains how 24 to use the SCHC compression for CoAP. 26 Status of This Memo 28 This Internet-Draft is submitted in full conformance with the 29 provisions of BCP 78 and BCP 79. 31 Internet-Drafts are working documents of the Internet Engineering 32 Task Force (IETF). Note that other groups may also distribute 33 working documents as Internet-Drafts. The list of current Internet- 34 Drafts is at https://datatracker.ietf.org/drafts/current/. 36 Internet-Drafts are draft documents valid for a maximum of six months 37 and may be updated, replaced, or obsoleted by other documents at any 38 time. It is inappropriate to use Internet-Drafts as reference 39 material or to cite them other than as "work in progress." 41 This Internet-Draft will expire on November 30, 2019. 43 Copyright Notice 45 Copyright (c) 2019 IETF Trust and the persons identified as the 46 document authors. All rights reserved. 48 This document is subject to BCP 78 and the IETF Trust's Legal 49 Provisions Relating to IETF Documents 50 (https://trustee.ietf.org/license-info) in effect on the date of 51 publication of this document. Please review these documents 52 carefully, as they describe your rights and restrictions with respect 53 to this document. Code Components extracted from this document must 54 include Simplified BSD License text as described in Section 4.e of 55 the Trust Legal Provisions and are provided without warranty as 56 described in the Simplified BSD License. 58 Table of Contents 60 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 61 2. SCHC Compression Process . . . . . . . . . . . . . . . . . . 3 62 3. CoAP Compression with SCHC . . . . . . . . . . . . . . . . . 4 63 4. Compression of CoAP header fields . . . . . . . . . . . . . . 6 64 4.1. CoAP version field . . . . . . . . . . . . . . . . . . . 6 65 4.2. CoAP type field . . . . . . . . . . . . . . . . . . . . . 6 66 4.3. CoAP code field . . . . . . . . . . . . . . . . . . . . . 6 67 4.4. CoAP Message ID field . . . . . . . . . . . . . . . . . . 6 68 4.5. CoAP Token fields . . . . . . . . . . . . . . . . . . . . 7 69 5. CoAP options . . . . . . . . . . . . . . . . . . . . . . . . 7 70 5.1. CoAP Content and Accept options. . . . . . . . . . . . . 7 71 5.2. CoAP option Max-Age field, CoAP option Uri-Host and Uri- 72 Port fields . . . . . . . . . . . . . . . . . . . . . . . 8 73 5.3. CoAP option Uri-Path and Uri-Query fields . . . . . . . . 8 74 5.3.1. Variable length Uri-Path and Uri-Query . . . . . . . 8 75 5.3.2. Variable number of path or query elements . . . . . . 9 76 5.4. CoAP option Size1, Size2, Proxy-URI and Proxy-Scheme 77 fields . . . . . . . . . . . . . . . . . . . . . . . . . 9 78 5.5. CoAP option ETag, If-Match, If-None-Match, Location-Path 79 and Location-Query fields . . . . . . . . . . . . . . . . 9 80 6. Other RFCs . . . . . . . . . . . . . . . . . . . . . . . . . 10 81 6.1. Block . . . . . . . . . . . . . . . . . . . . . . . . . . 10 82 6.2. Observe . . . . . . . . . . . . . . . . . . . . . . . . . 10 83 6.3. No-Response . . . . . . . . . . . . . . . . . . . . . . . 10 84 6.4. Time Scale . . . . . . . . . . . . . . . . . . . . . . . 10 85 6.5. OSCORE . . . . . . . . . . . . . . . . . . . . . . . . . 11 86 7. Examples of CoAP header compression . . . . . . . . . . . . . 12 87 7.1. Mandatory header with CON message . . . . . . . . . . . . 12 88 7.2. OSCORE Compression . . . . . . . . . . . . . . . . . . . 13 89 7.3. Example OSCORE Compression . . . . . . . . . . . . . . . 17 90 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 27 91 9. Security considerations . . . . . . . . . . . . . . . . . . . 27 92 10. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 27 93 11. Normative References . . . . . . . . . . . . . . . . . . . . 27 94 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 28 96 1. Introduction 98 CoAP [rfc7252] is an implementation of the REST architecture for 99 constrained devices. Although CoAP was designed for constrained 100 devices, the size of a CoAP header may still be too large for LPWAN 101 constraints and some compression may be needed to reduce the header 102 size. 104 [I-D.ietf-lpwan-ipv6-static-context-hc] defines a header compression 105 mechanism for LPWAN network based on a static context. The context 106 is said static since the field description composing the Rules are 107 not learned during the packet exchanges but are previously defined. 108 The context(s) is(are) known by both ends before transmission. 110 A context is composed of a set of rules that are referenced by Rule 111 IDs (identifiers). A rule contains an ordered list of the fields 112 descriptions containing a field ID (FID), its length (FL) and its 113 position (FP), a direction indicator (DI) (upstream, downstream and 114 bidirectional) and some associated Target Values (TV). Target Value 115 indicates the value that can be expected. TV can also be a list of 116 values. A Matching Operator (MO) is associated to each header field 117 description. The rule is selected if all the MOs fit the TVs for all 118 fields. In that case, a Compression/Decompression Action (CDA) 119 associated to each field defines the link between the compressed and 120 decompressed value for each of the header fields. Compression 121 results mainly in 4 actions: send the field value, send nothing, send 122 less significant bits of a field, send an index. Values sent are 123 called Compression Residues and follows the rule ID. 125 2. SCHC Compression Process 127 The SCHC Compression rules can be applied to CoAP flows. SCHC 128 Compression of the CoAP header MAY be done in conjunction with the 129 above layers (IPv6/UDP) or independently. The SCHC adaptation layers 130 as described in [I-D.ietf-lpwan-ipv6-static-context-hc] may be used 131 as shown in Figure 1. 133 ^ +------------+ ^ +------------+ ^ +------------+ 134 | | CoAP | | | CoAP | inner | | CoAP | 135 | +------------+ v +------------+ x | OSCORE | 136 | | UDP | | DTLS | outer | +------------+ 137 | +------------+ +------------+ | | UDP | 138 | | IPv6 | | UDP | | +------------+ 139 v +------------+ +------------+ | | IPv6 | 140 | IPv6 | v +------------+ 141 +------------+ 143 Figure 1: rule scope for CoAP 145 Figure 1 shows some examples for CoAP architecture and the SCHC 146 rule's scope. A rule can cover all headers from IPv6 to CoAP, in 147 which case SCHC C/D is performed at the device and at the LPWAN 148 boundary. If an end-to-end encryption mechanisms is used between the 149 device and the application, CoAP MAY be compressed independently of 150 the other layers. The rule ID and the compression residue are 151 encrypted using a mechanism such as DTLS. Only the other end can 152 decipher the information. 153 Layers below may also be compressed using other SCHC rules (this is 154 out of the scope of this document). OSCORE 155 [I-D.ietf-core-object-security] can also define 2 rules to compress 156 the CoAP message. A first rule focuses on the inner header and is 157 end to end, a second rule may compress the outer header and the 158 layers below. SCHC C/D for inner header is done by both ends, SCHC 159 C/D for outer header and other headers is done between the device and 160 the LPWAN boundary. 162 3. CoAP Compression with SCHC 164 CoAP differs from IPv6 and UDP protocols on the following aspects: 166 o IPv6 and UDP are symmetrical protocols. The same fields are found 167 in the request and in the response, only the location in the 168 header may vary (e.g. source and destination fields). A CoAP 169 request is different from a response. For example, the URI-path 170 option is mandatory in the request and is not found in the 171 response, a request may contain an Accept option and the response 172 a Content option. 174 [I-D.ietf-lpwan-ipv6-static-context-hc] defines the use of a 175 message direction (DI) in the Field Description, which allows a 176 single Rule to process message headers differently in both 177 directions. 179 o Even when a field is "symmetric" (i.e. found in both directions) 180 the values carried in each direction are different. Combined with 181 a matching list in the TV, this allows reducing the range of 182 expected values in a particular direction and therefore reduce the 183 size of the compression residue. For instance, if a client sends 184 only CON request, the type can be elided by compression and the 185 answer may use one single bit to carry either the ACK or RST type. 186 The same behavior can be applied to the CoAP Code field (0.0X code 187 are present in the request and Y.ZZ in the answer). The direction 188 allows splitting in two parts the possible values for each 189 direction. 191 o In IPv6 and UDP, header fields have a fixed size. In CoAP, Token 192 size may vary from 0 to 8 bytes, the length being given by a field 193 in the header. More systematically, the CoAP options are 194 described using the Type-Length-Value. 196 [I-D.ietf-lpwan-ipv6-static-context-hc] offers the possibility to 197 define a function for the Field Length in the Field Description. 199 o In CoAP headers, a field can be present several times. This is 200 typical for elements of an URI (path or queries). The position 201 defined in a rule, associated to a Field ID, can be used to 202 identify the proper instance. 204 [I-D.ietf-lpwan-ipv6-static-context-hc] allows a Field ID to 205 appears several times in the rule, the Field Position (FP) removes 206 ambiguities for the matching operation. 208 o Field sizes defined in the CoAP protocol can be too large 209 regarding LPWAN traffic constraints. This is particularly true 210 for the message ID field or Token field. The MSB MO can be used 211 to reduce the information carried on LPWANs. 213 o CoAP also obeys the client/server paradigm and the compression 214 ratio can be different if the request is issued from an LPWAN 215 device or from an non LPWAN device. For instance a Device (Dev) 216 aware of LPWAN constraints can generate a 1 byte token, but a 217 regular CoAP client will certainly send a larger token to the Dev. 218 SCHC compression will not modify the values to offer a better 219 compression rate. Nevertheless, a proxy placed before the 220 compressor may change some field values to offer a better 221 compression ratio and maintain the necessary context for 222 interoperability with existing CoAP implementations. 224 4. Compression of CoAP header fields 226 This section discusses the compression of the different CoAP header 227 fields. 229 4.1. CoAP version field 231 This field is bidirectional and MUST be elided during the SCHC 232 compression, since it always contains the same value. In the future, 233 if new versions of CoAP are defined, new rules will be defined to 234 avoid ambiguities between versions. 236 4.2. CoAP type field 238 [rfc7252] defines 4 types of messages: CON, NON, ACK and RST. The 239 last two are a response to the first two. If the device plays a 240 specific role, a rule can exploit these properties with the mapping 241 list: [CON, NON] for one direction and [ACK, RST] for the other 242 direction. Compression residue is reduced to 1 bit. 244 The field SHOULD be elided if for instance a client is sending only 245 NON or CON messages. 247 In any case, a rule MUST be defined to carry RST to a client. 249 4.3. CoAP code field 251 The compression of the CoAP code field follows the same principle as 252 for the CoAP type field. If the device plays a specific role, the 253 set of code values can be split in two parts, the request codes with 254 the 0 class and the response values. 256 If the device only implements a CoAP client, the request code can be 257 reduced to the set of requests the client is able to process. 259 All the response codes MUST be compressed with a SCHC rule. 261 4.4. CoAP Message ID field 263 This field is bidirectional and is used to manage acknowledgments. 264 The server memorizes the value for a EXCHANGE_LIFETIME period (by 265 default 247 seconds) for CON messages and a NON_LIFETIME period (by 266 default 145 seconds) for NON messages. During that period, a server 267 receiving the same Message ID value will process the message as a 268 retransmission. After this period, it will be processed as a new 269 message. 271 In case the Device is a client, the size of the message ID field may 272 be too large regarding the number of messages sent. The client 273 SHOULD use only small message ID values, for instance 4 bit long. 274 Therefore, a MSB can be used to limit the size of the compression 275 residue. 277 In case the Device is a server, the client may be located outside of 278 the LPWAN area and view the Device as a regular device connected to 279 the internet. The client will generate Message ID using the 16 bits 280 space offered by this field. A CoAP proxy can be set before the SCHC 281 C/D to reduce the value of the Message ID, to allow its compression 282 with the MSB matching operator and LSB CDA. 284 4.5. CoAP Token fields 286 Token is defined through two CoAP fields, Token Length in the 287 mandatory header and Token Value directly following the mandatory 288 CoAP header. 290 Token Length is processed as any protocol field. If the value 291 remains the same during all the transaction, the size can be stored 292 in the context and elided during the transmission. Otherwise, it 293 will have to the sent as a compression residue. 295 Token Value size cannot be defined directly in the rule in the Field 296 Length (FL). Instead, a specific function designated as "TKL" MUST 297 be used and length does not have to the sent with the residue. 298 During the decompression, this function returns the value contained 299 in the Token Length field. 301 5. CoAP options 303 5.1. CoAP Content and Accept options. 305 These fields are both unidirectional and MUST NOT be set to 306 bidirectional in a rule entry. 308 If a single value is expected by the client, it can be stored in the 309 TV and elided during the transmission. Otherwise, if several 310 possible values are expected by the client, a matching-list SHOULD be 311 used to limit the size of the residue. If is not possible, the value 312 has to be sent as a residue (fixed or variable length). 314 5.2. CoAP option Max-Age field, CoAP option Uri-Host and Uri-Port 315 fields 317 These fields is unidirectional and MUST NOT be set to bidirectional 318 in a rule entry. It is used only by the server to inform of the 319 caching duration and is never found in client requests. 321 If the duration is known by both ends, the value can be elided on the 322 LPWAN. 324 A matching list can be used if some well-known values are defined. 326 Otherwise these options SHOULD be sent as a residue (fixed or 327 variable length). 329 5.3. CoAP option Uri-Path and Uri-Query fields 331 These fields are unidirectional and MUST NOT be set to bidirectional 332 in a rule entry. They are used only by the client to access a 333 specific resource and are never found in server responses. 335 Uri-Path and Uri-Query elements are a repeatable options, the Field 336 Position (FP) gives the position in the path. 338 A Mapping list can be used to reduce the size of variable Paths or 339 Queries. In that case, to optimize the compression, several elements 340 can be regrouped into a single entry. Numbering of elements do not 341 change, MO comparison is set with the first element of the matching. 343 FID FL FP DI TV MO CDA 344 URI-Path 1 up ["/a/b", equal not-sent 345 "/c/d"] 346 URI-Path 3 up ignore value-sent 348 Figure 2: complex path example 350 In Figure 2 a single bit residue can be used to code one of the 2 351 paths. If regrouping were not allowed, a 2 bits residue would be 352 needed. 354 5.3.1. Variable length Uri-Path and Uri-Query 356 When the length is not known at the rule creation, the Field Length 357 SHOULD be set to variable, and the unit is set to bytes. 359 The MSB MO can be applied to a Uri-Path or Uri-Query element. Since 360 MSB value is given in bit, the size MUST always be a multiple of 8 361 bits. 363 The length sent at the beginning of a variable length residue 364 indicates the size of the LSB in bytes. 366 For instance for a CORECONF path /c/X6?k="eth0" the rule can be set 367 to: 369 FID FL FP DI TV MO CDA 370 URI-Path 1 up "c" equal not-sent 371 URI-Path 2 up ignore value-sent 372 URI-Query 1 up "k=" MSB (16) LSB 374 Figure 3: CORECONF URI compression 376 Figure 3 shows the parsing and the compression of the URI, where c is 377 not sent. The second element is sent with the length (i.e. 0x2 X 6) 378 followed by the query option (i.e. 0x05 "eth0"). 380 5.3.2. Variable number of path or query elements 382 The number of Uri-path or Uri-Query elements in a rule is fixed at 383 the rule creation time. If the number varies, several rules SHOULD 384 be created to cover all the possibilities. Another possibility is to 385 define the length of Uri-Path to variable and send a compression 386 residue with a length of 0 to indicate that this Uri-Path is empty. 387 This adds 4 bits to the compression residue. 389 5.4. CoAP option Size1, Size2, Proxy-URI and Proxy-Scheme fields 391 These fields are unidirectional and MUST NOT be set to bidirectional 392 in a rule entry. They are used only by the client to access a 393 specific resource and are never found in server response. 395 If the field value has to be sent, TV is not set, MO is set to 396 "ignore" and CDA is set to "value-sent". A mapping MAY also be used. 398 Otherwise, the TV is set to the value, MO is set to "equal" and CDA 399 is set to "not-sent". 401 5.5. CoAP option ETag, If-Match, If-None-Match, Location-Path and 402 Location-Query fields 404 These fields are unidirectional. 406 These fields values cannot be stored in a rule entry. They MUST 407 always be sent with the compression residues. 409 6. Other RFCs 411 6.1. Block 413 Block [rfc7959] allows a fragmentation at the CoAP level. SCHC also 414 includes a fragmentation protocol. They are compatible. If a block 415 option is used, its content MUST be sent as a compression residue. 417 6.2. Observe 419 [rfc7641] defines the Observe option. The TV is not set, MO is set 420 to "ignore" and the CDA is set to "value-sent". SCHC does not limit 421 the maximum size for this option (3 bytes). To reduce the 422 transmission size, either the device implementation MAY limit the 423 delta between two consecutive values, or a proxy can modify the 424 increment. 426 Since an RST message may be sent to inform a server that the client 427 does not require Observe response, a rule MUST allow the transmission 428 of this message. 430 6.3. No-Response 432 [rfc7967] defines a No-Response option limiting the responses made by 433 a server to a request. If the value is known by both ends, then TV 434 is set to this value, MO is set to "equal" and CDA is set to "not- 435 sent". 437 Otherwise, if the value is changing over time, TV is not set, MO is 438 set to "ignore" and CDA to "value-sent". A matching list can also be 439 used to reduce the size. 441 6.4. Time Scale 443 The time scale [I-D.toutain-core-time-scale] option allows a client 444 to inform the server that it is in a constrained network and that 445 message ID MUST be kept for a duration given by the option. 447 If the value is known by both ends, then TV is set to this value, MO 448 is set to "equal" and CDA is set to "not-sent". 450 Otherwise, if the value is changing over time, TV is not set, MO is 451 set to "ignore" and CDA to "value-sent". A matching list can also be 452 used to reduce the size. 454 6.5. OSCORE 456 OSCORE [I-D.ietf-core-object-security] defines end-to-end protection 457 for CoAP messages. This section describes how SCHC rules can be 458 applied to compress OSCORE-protected messages. 460 0 1 2 3 4 5 6 7 <--------- n bytes -------------> 461 +-+-+-+-+-+-+-+-+--------------------------------- 462 |0 0 0|h|k| n | Partial IV (if any) ... 463 +-+-+-+-+-+-+-+-+--------------------------------- 464 | | | 465 |<-- CoAP -->|<------ CoAP OSCORE_piv ------> | 466 OSCORE_flags 468 <- 1 byte -> <------ s bytes -----> 469 +------------+----------------------+-----------------------+ 470 | s (if any) | kid context (if any) | kid (if any) ... | 471 +------------+----------------------+-----------------------+ 472 | | | 473 | <------ CoAP OSCORE_kidctxt ----->|<-- CoAP OSCORE_kid -->| 475 Figure 4: OSCORE Option 477 The encoding of the OSCORE Option Value defined in Section 6.1 of 478 [I-D.ietf-core-object-security] is repeated in Figure 4. 480 The first byte is used for flags that specify the contents of the 481 OSCORE option. The 3 most significant bits are reserved and always 482 set to 0. Bit h, when set, indicates the presence of the kid context 483 field in the option. Bit k, when set, indicates the presence of a 484 kid field. The 3 least significant bits n indicate the length of the 485 piv field in bytes. When n = 0, no piv is present. 487 After the flag byte follow the piv field, kid context field and kid 488 field in order and if present; the length of the kid context field is 489 encoded in the first byte denoting by s the length of the kid context 490 in bytes. 492 This draft recommends to implement a parser that is able to identify 493 the OSCORE Option and the fields it contains. 495 Conceptually, it discerns up to 4 distinct pieces of information 496 within the OSCORE option: the flag bits, the piv, the kid context, 497 and the kid. It is thus recommended that the parser split the OSCORE 498 option into the 4 subsequent fields: 500 o CoAP OSCORE_flags, 501 o CoAP OSCORE_piv, 503 o CoAP OSCORE_kidctxt, 505 o CoAP OSCORE_kid. 507 These fields are shown superimposed on the OSCORE Option format in 508 Figure 4, the CoAP OSCORE_kidctxt field including the size bits s. 509 Their size SHOULD be reduced using the MSB matching operator. 511 7. Examples of CoAP header compression 513 7.1. Mandatory header with CON message 515 In this first scenario, the LPWAN compressor at the Network Gateway 516 side receives from a client on the Internet a POST message, which is 517 immediately acknowledged by the Device. For this simple scenario, 518 the rules are described Figure 5. 520 Rule ID 1 521 +-------------+--+--+--+------+---------+-------------++------------+ 522 | Field |FL|FP|DI|Target| Match | CDA || Sent | 523 | | | | |Value | Opera. | || [bits] | 524 +-------------+--+--+--+------+---------+-------------++------------+ 525 |CoAP version | | |bi| 01 |equal |not-sent || | 526 |CoAP version | | |bi| 01 |equal |not-sent || | 527 |CoAP Type | | |dw| CON |equal |not-sent || | 528 |CoAP Type | | |up|[ACK, | | || | 529 | | | | | RST] |match-map|matching-sent|| T | 530 |CoAP TKL | | |bi| 0 |equal |not-sent || | 531 |CoAP Code | | |bi| ML1 |match-map|matching-sent|| CC CCC | 532 |CoAP MID | | |bi| 0000 |MSB(7 ) |LSB(9) || M-ID| 533 |CoAP Uri-Path| | |dw| path |equal 1 |not-sent || | 534 +-------------+--+--+--+------+---------+-------------++------------+ 536 Figure 5: CoAP Context to compress header without token 538 The version and Token Length fields are elided. Code has shrunk to 5 539 bits using a matching list. Uri-Path contains a single element 540 indicated in the matching operator. 542 Figure 6 shows the time diagram of the exchange. A client in the 543 Application Server sends a CON request. It can go through a proxy 544 which reduces the message ID to a smallest value, with at least the 9 545 most significant bits equal to 0. SCHC Compression reduces the 546 header sending only the Type, a mapped code and the least 9 547 significant bits of Message ID. 549 Device LPWAN SCHC C/D 550 | | 551 | rule id=1 |<-------------------- 552 |<-------------------| +-+-+--+----+------+ 553 <------------------- | CCCCCMMMMMMMMM | |1|0| 4|0.01|0x0034| 554 +-+-+--+----+-------+ | 00001000110100 | | 0xb4 p a t| 555 |1|0| 1|0.01|0x0034 | | | | h | 556 | 0xb4 p a t | | | +------+ 557 | h | | | 558 +------+ | | 559 | | 560 | | 561 ---------------------->| rule id=1 | 562 +-+-+--+----+--------+ |------------------->| 563 |1|2| 0|2.05| 0x0034 | | TCCCCCMMMMMMMMM |---------------------> 564 +-+-+--+----+--------+ | 001100000110100 | +-+-+--+----+------+ 565 | | |1|2| 0|2.05|0x0034| 566 v v +-+-+--+----+------+ 568 Figure 6: Compression with global addresses 570 7.2. OSCORE Compression 572 OSCORE aims to solve the problem of end-to-end encryption for CoAP 573 messages. The goal, therefore, is to hide as much of the message as 574 possible while still enabling proxy operation. 576 Conceptually this is achieved by splitting the CoAP message into an 577 Inner Plaintext and Outer OSCORE Message. The Inner Plaintext 578 contains sensible information which is not necessary for proxy 579 operation. This, in turn, is the part of the message which can be 580 encrypted until it reaches its end destination. The Outer Message 581 acts as a shell matching the format of a regular CoAP message, and 582 includes all Options and information needed for proxy operation and 583 caching. This decomposition is illustrated in Figure 7. 585 CoAP options are sorted into one of 3 classes, each granted a 586 specific type of protection by the protocol: 588 o Class E: Encrypted options moved to the Inner Plaintext, 590 o Class I: Integrity-protected options included in the AAD for the 591 encryption of the Plaintext but otherwise left untouched in the 592 Outer Message, 594 o Class U: Unprotected options left untouched in the Outer Message. 596 Additionally, the OSCORE Option is added as an Outer option, 597 signaling that the message is OSCORE protected. This option carries 598 the information necessary to retrieve the Security Context with which 599 the message was encrypted so that it may be correctly decrypted at 600 the other end-point. 602 Original CoAP Message 603 +-+-+---+-------+---------------+ 604 |v|t|tkl| code | Msg Id. | 605 +-+-+---+-------+---------------+....+ 606 | Token | 607 +-------------------------------.....+ 608 | Options (IEU) | 609 . . 610 . . 611 +------+-------------------+ 612 | 0xFF | 613 +------+------------------------+ 614 | | 615 | Payload | 616 | | 617 +-------------------------------+ 618 / \ 619 / \ 620 / \ 621 / \ 622 Outer Header v v Plaintext 623 +-+-+---+--------+---------------+ +-------+ 624 |v|t|tkl|new code| Msg Id. | | code | 625 +-+-+---+--------+---------------+....+ +-------+-----......+ 626 | Token | | Options (E) | 627 +--------------------------------.....+ +-------+------.....+ 628 | Options (IU) | | OxFF | 629 . . +-------+-----------+ 630 . OSCORE Option . | | 631 +------+-------------------+ | Payload | 632 | 0xFF | | | 633 +------+ +-------------------+ 635 Figure 7: OSCORE inner and outer header form a CoAP message 637 Figure 7 shows the message format for the OSCORE Message and 638 Plaintext. 640 In the Outer Header, the original message code is hidden and replaced 641 by a default dummy value. As seen in sections 4.1.3.5 and 4.2 of 643 [I-D.ietf-core-object-security], the message code is replaced by POST 644 for requests and Changed for responses when Observe is not used. If 645 Observe is used, the message code is replaced by FETCH for requests 646 and Content for responses. 648 The original message code is put into the first byte of the 649 Plaintext. Following the message code, the class E options comes and 650 if present the original message Payload is preceded by its payload 651 marker. 653 The Plaintext is now encrypted by an AEAD algorithm which integrity 654 protects Security Context parameters and eventually any class I 655 options from the Outer Header. Currently no CoAP options are marked 656 class I. The resulting Ciphertext becomes the new Payload of the 657 OSCORE message, as illustrated in Figure 8. 659 This Ciphertext is, as defined in RFC 5116, the concatenation of the 660 encrypted Plaintext and its authentication tag. Note that Inner 661 Compression only affects the Plaintext before encryption, thus we can 662 only aim to reduce this first, variable length component of the 663 Ciphertext. The authentication tag is fixed in length and considered 664 part of the cost of protection. 666 Outer Header 667 +-+-+---+--------+---------------+ 668 |v|t|tkl|new code| Msg Id. | 669 +-+-+---+--------+---------------+....+ 670 | Token | 671 +--------------------------------.....+ 672 | Options (IU) | 673 . . 674 . OSCORE Option . 675 +------+-------------------+ 676 | 0xFF | 677 +------+-------------------------+ 678 | | 679 | Encrypted Inner Header and | 680 | Payload | 681 | | 682 +--------------------------------+ 684 Figure 8: OSCORE message 686 The SCHC Compression scheme consists of compressing both the 687 Plaintext before encryption and the resulting OSCORE message after 688 encryption, see Figure 9. 690 This translates into a segmented process where SCHC compression is 691 applied independently in 2 stages, each with its corresponding set of 692 rules, with the Inner SCHC Rules and the Outer SCHC Rules. This way 693 compression is applied to all fields of the original CoAP message. 695 Note that since the Inner part of the message can only be decrypted 696 by the corresponding end-point, this end-point will also have to 697 implement Inner SCHC Compression/Decompression. 699 Outer Message OSCORE Plaintext 700 +-+-+---+--------+---------------+ +-------+ 701 |v|t|tkl|new code| Msg Id. | | code | 702 +-+-+---+--------+---------------+....+ +-------+-----......+ 703 | Token | | Options (E) | 704 +--------------------------------.....+ +-------+------.....+ 705 | Options (IU) | | OxFF | 706 . . +-------+-----------+ 707 . OSCORE Option . | | 708 +------+-------------------+ | Payload | 709 | 0xFF | | | 710 +------+------------+ +-------------------+ 711 | Ciphertext |<---------\ | 712 | | | v 713 +-------------------+ | +-----------------+ 714 | | | Inner SCHC | 715 v | | Compression | 716 +-----------------+ | +-----------------+ 717 | Outer SCHC | | | 718 | Compression | | v 719 +-----------------+ | +-------+ 720 | | |Rule ID| 721 v | +-------+--+ 722 +--------+ +------------+ | Residue | 723 |Rule ID'| | Encryption | <--- +----------+--------+ 724 +--------+--+ +------------+ | | 725 | Residue' | | Payload | 726 +-----------+-------+ | | 727 | Ciphertext | +-------------------+ 728 | | 729 +-------------------+ 731 Figure 9: OSCORE Compression Diagram 733 7.3. Example OSCORE Compression 735 An example is given with a GET Request and its consequent CONTENT 736 Response. A possible set of rules for the Inner and Outer SCHC 737 Compression is shown. A dump of the results and a contrast between 738 SCHC + OSCORE performance with SCHC + COAP performance is also 739 listed. This gives an approximation to the cost of security with 740 SCHC-OSCORE. 742 Our first example CoAP message is the GET Request in Figure 10 744 Original message: 745 ================= 746 0x4101000182bb74656d7065726174757265 748 Header: 749 0x4101 750 01 Ver 751 00 CON 752 0001 tkl 753 00000001 Request Code 1 "GET" 755 0x0001 = mid 756 0x82 = token 758 Options: 759 0xbb74656d7065726174757265 760 Option 11: URI_PATH 761 Value = temperature 763 Original msg length: 17 bytes. 765 Figure 10: CoAP GET Request 767 Its corresponding response is the CONTENT Response in Figure 11. 769 Original message: 770 ================= 771 0x6145000182ff32332043 773 Header: 774 0x6145 775 01 Ver 776 10 ACK 777 0001 tkl 778 01000101 Successful Response Code 69 "2.05 Content" 780 0x0001 = mid 781 0x82 = token 783 0xFF Payload marker 784 Payload: 785 0x32332043 787 Original msg length: 10 789 Figure 11: CoAP CONTENT Response 791 The SCHC Rules for the Inner Compression include all fields that are 792 already present in a regular CoAP message, what is important is the 793 order of appearance and inclusion of only those CoAP fields that go 794 into the Plaintext, Figure 12. 796 Rule ID 0 797 +---------------+--+--+-----------+-----------+-----------++------+ 798 | Field |FP|DI| Target | MO | CDA || Sent | 799 | | | | Value | | ||[bits]| 800 +---------------+--+--+-----------+-----------+-----------++------+ 801 |CoAP Code | |up| 1 | equal |not-sent || | 802 |CoAP Code | |dw|[69,132] | match-map |match-sent || c | 803 |CoAP Uri-Path | |up|temperature| equal |not-sent || | 804 |COAP Option-End| |dw| 0xFF | equal |not-sent || | 805 +---------------+--+--+-----------+-----------+-----------++------+ 807 Figure 12: Inner SCHC Rules 809 Figure 13 shows the Plaintext obtained for our example GET Request 810 and follows the process of Inner Compression and Encryption until we 811 end up with the Payload to be added in the outer OSCORE Message. 813 In this case the original message has no payload and its resulting 814 Plaintext can be compressed up to only 1 byte (size of the Rule ID). 815 The AEAD algorithm preserves this length in its first output, but 816 also yields a fixed-size tag which cannot be compressed and has to be 817 included in the OSCORE message. This translates into an overhead in 818 total message length, which limits the amount of compression that can 819 be achieved and plays into the cost of adding security to the 820 exchange. 822 ________________________________________________________ 823 | | 824 | OSCORE Plaintext | 825 | | 826 | 0x01bb74656d7065726174757265 (13 bytes) | 827 | | 828 | 0x01 Request Code GET | 829 | | 830 | bb74656d7065726174757265 Option 11: URI_PATH | 831 | Value = temperature | 832 |________________________________________________________| 834 | 835 | 836 | Inner SCHC Compression 837 | 838 v 839 _________________________________ 840 | | 841 | Compressed Plaintext | 842 | | 843 | 0x00 | 844 | | 845 | Rule ID = 0x00 (1 byte) | 846 | (No residue) | 847 |_________________________________| 849 | 850 | AEAD Encryption 851 | (piv = 0x04) 852 v 853 _________________________________________________ 854 | | 855 | encrypted_plaintext = 0xa2 (1 byte) | 856 | tag = 0xc54fe1b434297b62 (8 bytes) | 857 | | 858 | ciphertext = 0xa2c54fe1b434297b62 (9 bytes) | 859 |_________________________________________________| 861 Figure 13: Plaintext compression and encryption for GET Request 863 In Figure 14 we repeat the process for the example CONTENT Response. 864 In this case the misalignment produced by the compression residue (1 865 bit) makes it so that 7 bits of padding have to be applied after the 866 payload, resulting in a compressed Plaintext that is the same size as 867 before compression. This misalignment also causes the hexcode from 868 the payload to differ from the original, even though it has not been 869 compressed. On top of this, the overhead from the tag bytes is 870 incurred as before. 872 ________________________________________________________ 873 | | 874 | OSCORE Plaintext | 875 | | 876 | 0x45ff32332043 (6 bytes) | 877 | | 878 | 0x45 Successful Response Code 69 "2.05 Content" | 879 | | 880 | ff Payload marker | 881 | | 882 | 32332043 Payload | 883 |________________________________________________________| 885 | 886 | 887 | Inner SCHC Compression 888 | 889 v 890 __________________________________________ 891 | | 892 | Compressed Plaintext | 893 | | 894 | 0x001919902180 (6 bytes) | 895 | | 896 | 00 Rule ID | 897 | | 898 | 0b0 (1 bit match-map residue) | 899 | 0x32332043 >> 1 (shifted payload) | 900 | 0b0000000 Padding | 901 |__________________________________________| 903 | 904 | AEAD Encryption 905 | (piv = 0x04) 906 v 907 _________________________________________________________ 908 | | 909 | encrypted_plaintext = 0x10c6d7c26cc1 (6 bytes) | 910 | tag = 0xe9aef3f2461e0c29 (8 bytes) | 911 | | 912 | ciphertext = 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) | 913 |_________________________________________________________| 915 Figure 14: Plaintext compression and encryption for CONTENT Response 917 The Outer SCHC Rules (Figure 17) MUST process the OSCORE Options 918 fields. In Figure 15 and Figure 16 we show a dump of the OSCORE 919 Messages generated from our example messages once they have been 920 provided with the Inner Compressed Ciphertext in the payload. These 921 are the messages that are to go through Outer SCHC Compression. 923 Protected message: 924 ================== 925 0x4102000182d7080904636c69656e74ffa2c54fe1b434297b62 926 (25 bytes) 928 Header: 929 0x4102 930 01 Ver 931 00 CON 932 0001 tkl 933 00000010 Request Code 2 "POST" 935 0x0001 = mid 936 0x82 = token 938 Options: 939 0xd7080904636c69656e74 (10 bytes) 940 Option 21: OBJECT_SECURITY 941 Value = 0x0904636c69656e74 942 09 = 000 0 1 001 Flag byte 943 h k n 944 04 piv 945 636c69656e74 kid 947 0xFF Payload marker 948 Payload: 949 0xa2c54fe1b434297b62 (9 bytes) 951 Figure 15: Protected and Inner SCHC Compressed GET Request 953 Protected message: 954 ================== 955 0x6144000182d008ff10c6d7c26cc1e9aef3f2461e0c29 956 (22 bytes) 958 Header: 959 0x6144 960 01 Ver 961 10 ACK 962 0001 tkl 963 01000100 Successful Response Code 68 "2.04 Changed" 965 0x0001 = mid 966 0x82 = token 968 Options: 969 0xd008 (2 bytes) 970 Option 21: OBJECT_SECURITY 971 Value = b'' 973 0xFF Payload marker 974 Payload: 975 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) 977 Figure 16: Protected and Inner SCHC Compressed CONTENT Response 979 For the flag bits, a number of compression methods could prove to be 980 useful depending on the application. The simplest alternative is to 981 provide a fixed value for the flags, combining MO equal and CDA not- 982 sent. This saves most bits but could hinder flexibility. Otherwise, 983 match-mapping could allow to choose from a number of configurations 984 of interest to the exchange. If neither of these alternatives is 985 desirable, MSB could be used to mask off the 3 hard-coded most 986 significant bits. 988 Note that fixing a flag bit will limit the choice of CoAP Options 989 that can be used in the exchange, since their values are dependent on 990 certain options. 992 The piv field lends itself to having a number of bits masked off with 993 MO MSB and CDA LSB. This could prove useful in applications where 994 the message frequency is low such as that found in LPWAN 995 technologies. Note that compressing the sequence numbers effectively 996 reduces the maximum amount of sequence numbers that can be used in an 997 exchange. Once this amount is exceeded, the SCHC Context would need 998 to be re-established. 1000 The size s included in the kid context field MAY be masked off with 1001 CDA MSB. The rest of the field could have additional bits masked 1002 off, or have the whole field be fixed with MO equal and CDA not-sent. 1003 The same holds for the kid field. 1005 Figure 17 shows a possible set of Outer Rules to compress the Outer 1006 Header. 1008 Rule ID 0 1009 +-------------------+--+--+--------------+--------+---------++------+ 1010 | Field |FP|DI| Target | MO | CDA || Sent | 1011 | | | | Value | | ||[bits]| 1012 +-------------------+--+--+--------------+--------+---------++------+ 1013 |CoAP version | |bi| 01 |equal |not-sent || | 1014 |CoAP Type | |up| 0 |equal |not-sent || | 1015 |CoAP Type | |dw| 2 |equal |not-sent || | 1016 |CoAP TKL | |bi| 1 |equal |not-sent || | 1017 |CoAP Code | |up| 2 |equal |not-sent || | 1018 |CoAP Code | |dw| 68 |equal |not-sent || | 1019 |CoAP MID | |bi| 0000 |MSB(12) |LSB ||MMMM | 1020 |CoAP Token | |bi| 0x80 |MSB(5) |LSB ||TTT | 1021 |CoAP OSCORE_flags | |up| 0x09 |equal |not-sent || | 1022 |CoAP OSCORE_piv | |up| 0x00 |MSB(4) |LSB ||PPPP | 1023 |COAP OSCORE_kid | |up|0x636c69656e70|MSB(52) |LSB ||KKKK | 1024 |COAP OSCORE_kidctxt| |bi| b'' |equal |not-sent || | 1025 |CoAP OSCORE_flags | |dw| b'' |equal |not-sent || | 1026 |CoAP OSCORE_piv | |dw| b'' |equal |not-sent || | 1027 |CoAP OSCORE_kid | |dw| b'' |equal |not-sent || | 1028 |COAP Option-End | |dw| 0xFF |equal |not-sent || | 1029 +-------------------+--+--+--------------+--------+---------++------+ 1031 Figure 17: Outer SCHC Rules 1033 These Outer Rules are applied to the example GET Request and CONTENT 1034 Response. The resulting messages are shown in Figure 18 and 1035 Figure 19. 1037 Compressed message: 1038 ================== 1039 0x001489458a9fc3686852f6c4 (12 bytes) 1040 0x00 Rule ID 1041 1489 Compression Residue 1042 458a9fc3686852f6c4 Padded payload 1044 Compression residue: 1045 0b 0001 010 0100 0100 (15 bits -> 2 bytes with padding) 1046 mid tkn piv kid 1048 Payload 1049 0xa2c54fe1b434297b62 (9 bytes) 1051 Compressed message length: 12 bytes 1053 Figure 18: SCHC-OSCORE Compressed GET Request 1055 Compressed message: 1056 ================== 1057 0x0014218daf84d983d35de7e48c3c1852 (16 bytes) 1058 0x00 Rule ID 1059 14 Compression residue 1060 218daf84d983d35de7e48c3c1852 Padded payload 1061 Compression residue: 1062 0b0001 010 (7 bits -> 1 byte with padding) 1063 mid tkn 1065 Payload 1066 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) 1068 Compressed msg length: 16 bytes 1070 Figure 19: SCHC-OSCORE Compressed CONTENT Response 1072 For contrast, we compare these results with what would be obtained by 1073 SCHC compressing the original CoAP messages without protecting them 1074 with OSCORE. To do this, we compress the CoAP messages according to 1075 the SCHC rules in Figure 20. 1077 Rule ID 1 1078 +---------------+--+--+-----------+---------+-----------++--------+ 1079 | Field |FP|DI| Target | MO | CDA || Sent | 1080 | | | | Value | | || [bits] | 1081 +---------------+--+--+-----------+---------+-----------++--------+ 1082 |CoAP version | |bi| 01 |equal |not-sent || | 1083 |CoAP Type | |up| 0 |equal |not-sent || | 1084 |CoAP Type | |dw| 2 |equal |not-sent || | 1085 |CoAP TKL | |bi| 1 |equal |not-sent || | 1086 |CoAP Code | |up| 2 |equal |not-sent || | 1087 |CoAP Code | |dw| [69,132] |equal |not-sent || | 1088 |CoAP MID | |bi| 0000 |MSB(12) |LSB ||MMMM | 1089 |CoAP Token | |bi| 0x80 |MSB(5) |LSB ||TTT | 1090 |CoAP Uri-Path | |up|temperature|equal |not-sent || | 1091 |COAP Option-End| |dw| 0xFF |equal |not-sent || | 1092 +---------------+--+--+-----------+---------+-----------++--------+ 1094 Figure 20: SCHC-CoAP Rules (No OSCORE) 1096 This yields the results in Figure 21 for the Request, and Figure 22 1097 for the Response. 1099 Compressed message: 1100 ================== 1101 0x0114 1102 0x01 = Rule ID 1104 Compression residue: 1105 0b00010100 (1 byte) 1107 Compressed msg length: 2 1109 Figure 21: CoAP GET Compressed without OSCORE 1111 Compressed message: 1112 ================== 1113 0x010a32332043 1114 0x01 = Rule ID 1116 Compression residue: 1117 0b00001010 (1 byte) 1119 Payload 1120 0x32332043 1122 Compressed msg length: 6 1124 Figure 22: CoAP CONTENT Compressed without OSCORE 1126 As can be seen, the difference between applying SCHC + OSCORE as 1127 compared to regular SCHC + COAP is about 10 bytes of cost. 1129 8. IANA Considerations 1131 This document has no request to IANA. 1133 9. Security considerations 1135 This document does not have any more Security consideration than the 1136 ones already raised on [I-D.ietf-lpwan-ipv6-static-context-hc] 1138 10. Acknowledgements 1140 Thanks to all the persons that have give us feedback 1142 11. Normative References 1144 [I-D.ietf-core-object-security] 1145 Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 1146 "Object Security for Constrained RESTful Environments 1147 (OSCORE)", draft-ietf-core-object-security-16 (work in 1148 progress), March 2019. 1150 [I-D.ietf-lpwan-ipv6-static-context-hc] 1151 Minaburo, A., Toutain, L., Gomez, C., Barthel, D., and J. 1152 Zuniga, "LPWAN Static Context Header Compression (SCHC) 1153 and fragmentation for IPv6 and UDP", draft-ietf-lpwan- 1154 ipv6-static-context-hc-18 (work in progress), December 1155 2018. 1157 [I-D.toutain-core-time-scale] 1158 Minaburo, A. and L. Toutain, "CoAP Time Scale Option", 1159 draft-toutain-core-time-scale-00 (work in progress), 1160 October 2017. 1162 [rfc7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 1163 Application Protocol (CoAP)", RFC 7252, 1164 DOI 10.17487/RFC7252, June 2014, 1165 . 1167 [rfc7641] Hartke, K., "Observing Resources in the Constrained 1168 Application Protocol (CoAP)", RFC 7641, 1169 DOI 10.17487/RFC7641, September 2015, 1170 . 1172 [rfc7959] Bormann, C. and Z. Shelby, Ed., "Block-Wise Transfers in 1173 the Constrained Application Protocol (CoAP)", RFC 7959, 1174 DOI 10.17487/RFC7959, August 2016, 1175 . 1177 [rfc7967] Bhattacharyya, A., Bandyopadhyay, S., Pal, A., and T. 1178 Bose, "Constrained Application Protocol (CoAP) Option for 1179 No Server Response", RFC 7967, DOI 10.17487/RFC7967, 1180 August 2016, . 1182 Authors' Addresses 1184 Ana Minaburo 1185 Acklio 1186 1137A avenue des Champs Blancs 1187 35510 Cesson-Sevigne Cedex 1188 France 1190 Email: ana@ackl.io 1192 Laurent Toutain 1193 Institut MINES TELECOM; IMT Atlantique 1194 2 rue de la Chataigneraie 1195 CS 17607 1196 35576 Cesson-Sevigne Cedex 1197 France 1199 Email: Laurent.Toutain@imt-atlantique.fr 1200 Ricardo Andreasen 1201 Universidad de Buenos Aires 1202 Av. Paseo Colon 850 1203 C1063ACV Ciudad Autonoma de Buenos Aires 1204 Argentina 1206 Email: randreasen@fi.uba.ar