idnits 2.17.1 draft-ietf-lpwan-coap-static-context-hc-05.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack a Security Considerations section. ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** There are 21 instances of too long lines in the document, the longest one being 2 characters in excess of 72. ** 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. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year == Line 338 has weird spacing: '... equal not...' == Line 340 has weird spacing: '... ignore valu...' == Line 363 has weird spacing: '... ignore val...' == Line 1039 has weird spacing: '...tkn piv kid...' == Line 1056 has weird spacing: '... mid tkn...' -- The document date (October 22, 2018) is 2013 days in the past. Is this intentional? Checking references for intended status: Informational ---------------------------------------------------------------------------- == Missing Reference: 'CON' is mentioned on line 236, but not defined == Missing Reference: 'NON' is mentioned on line 236, but not defined == Missing Reference: 'ACK' is mentioned on line 236, but not defined == Missing Reference: 'RST' is mentioned on line 236, but not defined -- Looks like a reference, but probably isn't: '69' on line 1080 -- Looks like a reference, but probably isn't: '132' on line 1080 == Outdated reference: A later version (-16) exists of draft-ietf-core-object-security-15 == Outdated reference: A later version (-24) exists of draft-ietf-lpwan-ipv6-static-context-hc-16 Summary: 4 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: Informational L. Toutain 5 Expires: April 25, 2019 Institut MINES TELECOM; IMT Atlantique 6 R. Andreasen 7 Universidad de Buenos Aires 8 October 22, 2018 10 LPWAN Static Context Header Compression (SCHC) for CoAP 11 draft-ietf-lpwan-coap-static-context-hc-05 13 Abstract 15 This draft defines the way SCHC header compression can be applied to 16 CoAP headers. CoAP header structure differs from IPv6 and UDP 17 protocols since the CoAP 18 use a flexible header with a variable number of options themselves of 19 a variable length. Another important difference is the asymmetry in 20 the header format used in request and response messages. Most of the 21 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 April 25, 2019. 42 Copyright Notice 44 Copyright (c) 2018 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 . . . . . . . . . . . . . . . . . . . . . . . . 2 60 2. SCHC Compression Process . . . . . . . . . . . . . . . . . . 3 61 3. CoAP Compression with SCHC . . . . . . . . . . . . . . . . . 4 62 4. Compression of CoAP header fields . . . . . . . . . . . . . . 5 63 4.1. CoAP version field . . . . . . . . . . . . . . . . . . . 5 64 4.2. CoAP type field . . . . . . . . . . . . . . . . . . . . . 5 65 4.3. CoAP code field . . . . . . . . . . . . . . . . . . . . . 6 66 4.4. CoAP Message ID field . . . . . . . . . . . . . . . . . . 6 67 4.5. CoAP Token fields . . . . . . . . . . . . . . . . . . . . 6 68 5. CoAP options . . . . . . . . . . . . . . . . . . . . . . . . 7 69 5.1. CoAP Content and Accept options. . . . . . . . . . . . . 7 70 5.2. CoAP option Max-Age field, CoAP option Uri-Host and Uri- 71 Port fields . . . . . . . . . . . . . . . . . . . . . . . 7 72 5.3. CoAP option Uri-Path and Uri-Query fields . . . . . . . . 7 73 5.3.1. Variable length Uri-Path and Uri-Query . . . . . . . 8 74 5.3.2. Variable number of path or query elements . . . . . . 8 75 5.4. CoAP option Size1, Size2, Proxy-URI and Proxy-Scheme 76 fields . . . . . . . . . . . . . . . . . . . . . . . . . 9 77 5.5. CoAP option ETag, If-Match, If-None-Match, Location-Path 78 and Location-Query fields . . . . . . . . . . . . . . . . 9 79 6. Other RFCs . . . . . . . . . . . . . . . . . . . . . . . . . 9 80 6.1. Block . . . . . . . . . . . . . . . . . . . . . . . . . . 9 81 6.2. Observe . . . . . . . . . . . . . . . . . . . . . . . . . 9 82 6.3. No-Response . . . . . . . . . . . . . . . . . . . . . . . 9 83 6.4. Time Scale . . . . . . . . . . . . . . . . . . . . . . . 10 84 6.5. OSCORE . . . . . . . . . . . . . . . . . . . . . . . . . 10 85 7. Examples of CoAP header compression . . . . . . . . . . . . . 11 86 7.1. Mandatory header with CON message . . . . . . . . . . . . 11 87 7.2. OSCORE Compression . . . . . . . . . . . . . . . . . . . 13 88 7.3. Example OSCORE Compression . . . . . . . . . . . . . . . 17 89 8. Normative References . . . . . . . . . . . . . . . . . . . . 27 90 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 27 92 1. Introduction 94 CoAP [rfc7252] is an implementation of the REST architecture for 95 constrained devices. Nevertheless, if limited, the size of a CoAP 96 header may be too large for LPWAN constraints and some compression 97 may be needed to reduce the header size. 99 [I-D.ietf-lpwan-ipv6-static-context-hc] defines a header compression 100 mechanism for LPWAN network based on a static context. The context 101 is said static since the field description composing the Rules and 102 the context are not learned during the packet exchanges but are 103 previously defined. The context(s) is(are) known by both ends before 104 transmission. 106 A context is composed of a set of rules that are referenced by Rule 107 IDs (identifiers). A rule contains an ordered list of the fields 108 descriptions containing a field ID (FID), its length (FL) and its 109 position (FP), a direction indicator (DI) (upstream, downstream and 110 bidirectional) and some associated Target Values (TV). Target Value 111 indicates the value that can be expected. TV can also be a list of 112 values. A Matching Operator (MO) is associated to each header field 113 description. The rule is selected if all the MOs fit the TVs for all 114 fields. In that case, a Compression/Decompression Action (CDA) 115 associated to each field defines the link between the compressed and 116 decompressed value for each of the header fields. Compression 117 results mainly in 4 actions: send the field value, send nothing, send 118 less significant bits of a field, send an index. Values sent are 119 called Compression Residues and follows the rule ID. 121 2. SCHC Compression Process 123 The SCHC Compression rules can be applied to CoAP flows. SCHC 124 Compression of the CoAP header may be done in conjunction with the 125 above layers (IPv6/UDP) or independently. The SCHC adaptation layers 126 as described in [I-D.ietf-lpwan-ipv6-static-context-hc] may be used 127 as as shown in the Figure 1. 129 ^ +------------+ ^ +------------+ ^ +------------+ 130 | | CoAP | | | CoAP | inner | | CoAP | 131 | +------------+ v +------------+ x | OSCORE | 132 | | UDP | | DTLS | outer | +------------+ 133 | +------------+ +------------+ | | UDP | 134 | | IPv6 | | UDP | | +------------+ 135 v +------------+ +------------+ | | IPv6 | 136 | IPv6 | v +------------+ 137 +------------+ 139 Figure 1: rule scope for CoAP 141 Figure 1 shows some examples for CoAP architecture and the SCHC 142 rule's scope. A rule can covers all headers from IPv6 to CoAP, SCHC 143 C/D is done in the device and at the LPWAN boundary. If an end-to- 144 end encryption mechanisms is used between the device and the 145 application. CoAP must be compressed independently of the other 146 layers. The rule ID and the compression residue are encrypted using 147 a mechanism such as DTLS. Only the other end can decipher the 148 information. 149 Layers below may also be compressed using other SCHC rules (this is 150 out of the scope of this document). OSCORE 151 [I-D.ietf-core-object-security] can also define 2 rules to compress 152 the CoAP message. A first rule focuses on the inner header and is 153 end to end, a second rule may compress the outer header and the layer 154 above. SCHC C/D for inner header is done by both ends, SCHC C/D for 155 outer header and other headers is done between the device and the 156 LPWAN boundary. 158 3. CoAP Compression with SCHC 160 CoAP differs from IPv6 and UDP protocols on the following aspects: 162 o IPv6 and UDP are symmetrical protocols. The same fields are found 163 in the request and in the response, only the location in the 164 header may vary (e.g. source and destination fields). A CoAP 165 request is different from a response. For example, the URI-path 166 option is mandatory in the request and is not found in the 167 response, a request may contain an Accept option and the response 168 a Content option. 170 [I-D.ietf-lpwan-ipv6-static-context-hc] defines the use of a 171 message direction (DI) when processing the rule which allows the 172 description of message header format in both directions. 174 o Even when a field is "symmetric" (i.e. found in both directions) 175 the values carried in each direction are different. Combined with 176 a matching list in the TV, this will allow to reduce the range of 177 expected values in a particular direction and therefore reduce the 178 size of a compression residue. For instance, if a client sends 179 only CON request, the type can be elided by compression and the 180 answer may use one bit to carry either the ACK or RST type. Same 181 behavior can be applied to the CoAP Code field (0.0X code are 182 present in the request and Y.ZZ in the answer). The direction 183 allows to split in two parts the possible values for each 184 direction. 186 o In IPv6 and UDP header fields have a fixed size. In CoAP, Token 187 size may vary from 0 to 8 bytes, length is given by a field in the 188 header. More systematically, the CoAP options are described using 189 the Type-Length-Value. 191 [I-D.ietf-lpwan-ipv6-static-context-hc] offers the possibility to 192 define a function for the Field Length in the Field Description. 194 o In CoAP headers, a field can be duplicated several times, for 195 instances, elements of an URI (path or queries). The position 196 defined in a rule, associated to a Field ID, can be used to 197 identify the proper element. 199 [I-D.ietf-lpwan-ipv6-static-context-hc] allows a Field id to 200 appears several times in the rule, the Field Position (FP) removes 201 ambiguities for the matching operation. 203 o Field size defined in the CoAP protocol can be too large regarding 204 LPWAN traffic constraints. This is particularly true for the 205 message ID field or Token field. The use of MSB MO can be used to 206 reduce the information carried on LPWANs. 208 o CoAP also obeys to the client/server paradigm and the compression 209 rate can be different if the request is issued from an LPWAN node 210 or from an non LPWAN device. For instance a Device (Dev) aware of 211 LPWAN constraints can generate a 1 byte token, but a regular CoAP 212 client will certainly send a larger token to the Thing. SCHC 213 compression will not modify the values to offer a better 214 compression rate. Nevertheless a proxy placed before the 215 compressor may change some field values to offer a better 216 compression rate and maintain the necessary context for 217 interoperability with existing CoAP implementations. 219 4. Compression of CoAP header fields 221 This section discusses of the compression of the different CoAP 222 header fields. 224 4.1. CoAP version field 226 This field is bidirectional and must be elided during the SCHC 227 compression, since it always contains the same value. In the future, 228 if new version of CoAP are defined, new rules ID will be defined 229 avoiding ambiguities between versions. 231 4.2. CoAP type field 233 [rfc7252] defines 4 types of messages: CON, NON, ACK and RST. The 234 latter two ones are a response of the two first ones. If the device 235 plays a specific role, a rule can exploit these property with the 236 mapping list: [CON, NON] for one direction and [ACK, RST] for the 237 other direction. Compression residue is reduced to 1 bit. 239 The field must be elided if for instance a client is sending only NON 240 or CON messages. 242 In any case, a rule must be defined to carry RST to a client. 244 4.3. CoAP code field 246 The compression of the CoAP code field follows the same principle as 247 for the CoAP type field. If the device plays a specific role, the 248 set of code values can be split in two parts, the request codes with 249 the 0 class and the response values. 251 If the device implement only a CoAP client, the request code can be 252 reduced to the set of request the client is able to process. 254 All the response codes should be compressed with a SCHC rule. 256 4.4. CoAP Message ID field 258 This field is bidirectional and is used to manage acknowledgments. 259 Server memorizes the value for a EXCHANGE_LIFETIME period (by default 260 247 seconds) for CON messages and a NON_LIFETIME period (by default 261 145 seconds) for NON messages. During that period, a server 262 receiving the same Message ID value will process the message as a 263 retransmission. After this period, it will be processed as a new 264 messages. 266 In case the Device is a client, the size of the message ID field may 267 the too large regarding the number of messages sent. Client may use 268 only small message ID values, for instance 4 bit long. Therefore a 269 MSB can be used to limit the size of the compression residue. 271 In case the Device is a server, client may be located outside of the 272 LPWAN area and view the device as a regular device connected to the 273 internet. The client will generate Message ID using the 16 bits 274 space offered by this field. A CoAP proxy can be set before the SCHC 275 C/D to reduce the value of the Message ID, to allow its compression 276 with the MSB matching operator and LSB CDA. 278 4.5. CoAP Token fields 280 Token is defined through two CoAP fields, Token Length in the 281 mandatory header and Token Value directly following the mandatory 282 CoAP header. 284 Token Length is processed as any protocol field. If the value 285 remains the same during all the transaction, the size can be stored 286 in the context and elided during the transmission. Otherwise it will 287 have to the send as a compression residue. 289 Token Value size should not be defined directly in the rule in the 290 Field Length (FL). Instead a specific function designed as "TKL" 291 must be used and length do not have to the sent with the residue. 292 During the decompression, this function returns the value contained 293 in the Token Length field. 295 5. CoAP options 297 5.1. CoAP Content and Accept options. 299 These field are both unidirectional and must not be set to 300 bidirectional in a rule entry. 302 If single value is expected by the client, it can be stored in the TV 303 and elided during the transmission. Otherwise, if several possible 304 values are expected by the client, a matching-list should be used to 305 limit the size of the residue. If is not possible, the value has to 306 be sent as a residue (fixed or variable length). 308 5.2. CoAP option Max-Age field, CoAP option Uri-Host and Uri-Port 309 fields 311 This field is unidirectional and must not be set to bidirectional in 312 a rule entry. It is used only by the server to inform of the caching 313 duration and is never found in client requests. 315 If the duration is known by both ends, value can be elided on the 316 LPWAN. 318 A matching list can be used if some well-known values are defined. 320 Otherwise these options should be sent as a residue (fixed or 321 variable length). 323 5.3. CoAP option Uri-Path and Uri-Query fields 325 This fields are unidirectional and must not be set to bidirectional 326 in a rule entry. They are used only by the client to access to a 327 specific resource and are never found in server responses. 329 Uri-Path and Uri-Query elements are a repeatable options, the Field 330 Position (FP) gives the position in the path. 332 A Mapping list can be used to reduce size of variable Paths or 333 Queries. In that case, to optimize the compression, several elements 334 can be regrouped into a single entry. Numbering of elements do not 335 change, MO comparison is set with the first element of the matching. 337 FID FL FP DI TV MO CDA 338 URI-Path 1 up ["/a/b", equal not-sent 339 "/c/d"] 340 URI-Path 3 up ignore value-sent 342 Figure 2: complex path example 344 In Figure 2 a single bit residue can be used to code one of the 2 345 paths. If regrouping was not allowed, a 2 bits residue is needed. 347 5.3.1. Variable length Uri-Path and Uri-Query 349 When the length is known at the rule creation, the Field Length must 350 be set to variable, and the unit is set to bytes. 352 The MSB MO can be apply to a Uri-Path or Uri-Query element. Since 353 MSB value is given in bit, the size must always be a multiple of 8 354 bits and the LSB CDA must not carry any value. 356 The length sent at the beginning of a variable length residue 357 indicates the size of the LSB in bytes. 359 For instance for a CoMi path /c/X6?k="eth0" the rule can be set to: 361 FID FL FP DI TV MO CDA 362 URI-Path 1 up "c" equal not-sent 363 URI-Path 2 up ignore value-sent 364 URI-Query 1 up "k=" MSB (16) LSB 366 Figure 3: CoMi URI compression 368 Figure 3 shows the parsing and the compression of the URI. where c is 369 not sent. The second element is sent with the length (i.e. 0x2 X 6) 370 followed by the query option (i.e. 0x05 "eth0"). 372 5.3.2. Variable number of path or query elements 374 The number of Uri-path or Uri-Query element in a rule is fixed at the 375 rule creation time. If the number varies, several rules should be 376 created to cover all the possibilities. Another possibilities is to 377 define the length of Uri-Path to variable and send a compression 378 residue with a length of 0 to indicate that this Uri-Path is empty. 379 This add 4 bits to the compression residue. 381 5.4. CoAP option Size1, Size2, Proxy-URI and Proxy-Scheme fields 383 These fields are unidirectional and must not be set to bidirectional 384 in a rule entry. They are used only by the client to access to a 385 specific resource and are never found in server response. 387 If the field value must be sent, TV is not set, MO is set to "ignore" 388 and CDA is set to "value-sent. A mapping can also be used. 390 Otherwise the TV is set to the value, MO is set to "equal" and CDA is 391 set to "not-sent" 393 5.5. CoAP option ETag, If-Match, If-None-Match, Location-Path and 394 Location-Query fields 396 These fields are unidirectional. 398 These fields values cannot be stored in a rule entry. They must 399 always be sent with the compression residues. 401 6. Other RFCs 403 6.1. Block 405 Block [rfc7959] allows a fragmentation at the CoAP level. SCHC 406 includes also a fragmentation protocol. They are compatible. If a 407 block option is used, its content must be sent as a compression 408 residue. 410 6.2. Observe 412 [rfc7641] defines the Observe option. The TV is not set, MO is set 413 to "ignore" and the CDA is set to "value-sent". SCHC does not limit 414 the maximum size for this option (3 bytes). To reduce the 415 transmission size either the device implementation should limit the 416 delta between two consecutive value or a proxy can modify the 417 incrementation. 419 Since RST message may be sent to inform a server that the client does 420 not require Observe response, a rule must allow the transmission of 421 this message. 423 6.3. No-Response 425 [rfc7967] defines an No-Response option limiting the responses made 426 by a server to a request. If the value is not known by both ends, 427 then TV is set to this value, MO is set to "equal" and CDA is set to 428 "not-sent". 430 Otherwise, if the value is changing over time, TV is not set, MO is 431 set to "ignore" and CDA to "value-sent". A matching list can also be 432 used to reduce the size. 434 6.4. Time Scale 436 Time scale [I-D.toutain-core-time-scale] option allows a client to 437 inform the server that it is in a slow network and that message ID 438 should be kept for a duration given by the option. 440 If the value is not known by both ends, then TV is set to this value, 441 MO is set to "equal" and CDA is set to "not-sent". 443 Otherwise, if the value is changing over time, TV is not set, MO is 444 set to "ignore" and CDA to "value-sent". A matching list can also be 445 used to reduce the size. 447 6.5. OSCORE 449 OSCORE [I-D.ietf-core-object-security] defines end-to-end protection 450 for CoAP messages. This section describes how SCHC rules can be 451 applied to compress OSCORE-protected messages. 453 0 1 2 3 4 5 6 7 <--------- n bytes -------------> 454 +-+-+-+-+-+-+-+-+--------------------------------- 455 |0 0 0|h|k| n | Partial IV (if any) ... 456 +-+-+-+-+-+-+-+-+--------------------------------- 457 | | | 458 |<-- CoAP -->|<------ CoAP OSCORE_piv ------> | 459 OSCORE_flags 461 <- 1 byte -> <------ s bytes -----> 462 +------------+----------------------+-----------------------+ 463 | s (if any) | kid context (if any) | kid (if any) ... | 464 +------------+----------------------+-----------------------+ 465 | | | 466 | <------ CoAP OSCORE_kidctxt ----->|<-- CoAP OSCORE_kid -->| 468 Figure 4: OSCORE Option 470 The encoding of the OSCORE Option Value defined in Section 6.1 of 471 [I-D.ietf-core-object-security] is repeated in Figure 4. 473 The first byte is used for flags that specify the contents of the 474 OSCORE option. The 3 most significant bits are reserved and always 475 set to 0. Bit h, when set, indicates the presence of the kid context 476 field in the option. Bit k, when set, indicates the presence of a 477 kid field. The 3 least significant bits n indicate the length of the 478 piv field in bytes. When n = 0, no piv is present. 480 After the flag byte follow the piv field, kid context field and kid 481 field in order and if present; the length of the kid context field is 482 encoded in the first byte denoting by s the length of the kid context 483 in bytes. 485 This draft recommends to implement a parser that is able to identify 486 the OSCORE Option and the fields it contains. 488 Conceptually, it discerns up to 4 distinct pieces of information 489 within the OSCORE option: the flag bits, the piv, the kid context, 490 and the kid. It is thus recommended that the parser split the OSCORE 491 option into the 4 subsequent fields: 493 o CoAP OSCORE_flags, 495 o CoAP OSCORE_piv, 497 o CoAP OSCORE_kidctxt, 499 o CoAP OSCORE_kid. 501 These fields are superposed on the OSCORE Option format in Figure 4, 502 the CoAP OSCORE_kidctxt field including the size bits s. Their size 503 may be reduced using the MSB matching operator. 505 7. Examples of CoAP header compression 507 7.1. Mandatory header with CON message 509 In this first scenario, the LPWAN compressor receives from outside 510 client a POST message, which is immediately acknowledged by the 511 Device. For this simple scenario, the rules are described Figure 5. 513 Rule ID 1 514 +-------------+--+--+--+------+---------+-------------++------------+ 515 | Field |FL|FP|DI|Target| Match | CDA || Sent | 516 | | | | |Value | Opera. | || [bits] | 517 +-------------+--+--+--+------+---------+-------------++------------+ 518 |CoAP version | | |bi| 01 |equal |not-sent || | 519 |CoAP version | | |bi| 01 |equal |not-sent || | 520 |CoAP Type | | |dw| CON |equal |not-sent || | 521 |CoAP Type | | |up|[ACK, | | || | 522 | | | | | RST] |match-map|matching-sent|| T | 523 |CoAP TKL | | |bi| 0 |equal |not-sent || | 524 |CoAP Code | | |bi| ML1 |match-map|matching-sent|| CC CCC | 525 |CoAP MID | | |bi| 0000 |MSB(7 ) |LSB(9) || M-ID| 526 |CoAP Uri-Path| | |dw| path |equal 1 |not-sent || | 527 +-------------+--+--+--+------+---------+-------------++------------+ 529 Figure 5: CoAP Context to compress header without token 531 The version and Token Length fields are elided. Code has shrunk to 5 532 bits using a matching list. Uri-Path contains a single element 533 indicated in the matching operator. 535 Figure 6 shows the time diagram of the exchange. A client in the 536 Application Server sends a CON request. It can go through a proxy 537 which reduces the message ID to a smallest value, with at least the 9 538 most significant bits equal to 0. SCHC Compression reduces the 539 header sending only the Type, a mapped code and the least 9 540 significant bits of Message ID. 542 Device LPWAN SCHC C/D 543 | | 544 | rule id=1 |<-------------------- 545 |<-------------------| +-+-+--+----+------+ 546 <------------------- | CCCCCMMMMMMMMM | |1|0| 4|0.01|0x0034| 547 +-+-+--+----+-------+ | 00001000110100 | | 0xb4 p a t| 548 |1|0| 1|0.01|0x0034 | | | | h | 549 | 0xb4 p a t | | | +------+ 550 | h | | | 551 +------+ | | 552 | | 553 | | 554 ---------------------->| rule id=1 | 555 +-+-+--+----+--------+ |------------------->| 556 |1|2| 0|2.05| 0x0034 | | TCCCCCMMMMMMMMM |---------------------> 557 +-+-+--+----+--------+ | 001100000110100 | +-+-+--+----+------+ 558 | | |1|2| 0|2.05|0x0034| 559 v v +-+-+--+----+------+ 561 Figure 6: Compression with global addresses 563 7.2. OSCORE Compression 565 OSCORE aims to solve the problem of end-to-end encryption for CoAP 566 messages. The goal, therefore, is to hide as much of the message as 567 possible while still enabling proxy operation. 569 Conceptually this is achieved by splitting the CoAP message into an 570 Inner Plaintext and Outer OSCORE Message. The Inner Plaintext 571 contains sensible information which is not necessary for proxy 572 operation. This, in turn, is the part of the message which can be 573 encrypted until it reaches its end destination. The Outer Message 574 acts as a shell matching the format of a regular CoAP message, and 575 includes all Options and information needed for proxy operation and 576 caching. This decomposition is illustrated in Figure 7. 578 CoAP options are sorted into one of 3 classes, each granted a 579 specific type of protection by the protocol: 581 o Class E: Encrypted options moved to the Inner Plaintext, 583 o Class I: Integrity-protected options included in the AAD for the 584 encryption of the Plaintext but otherwise left untouched in the 585 Outer Message, 587 o Class U: Unprotected options left untouched in the Outer Message. 589 Additionally, the OSCORE Option is added as an Outer option, 590 signaling that the message is OSCORE protected. This option carries 591 the information necessary to retrieve the Security Context with which 592 the message was encrypted so that it may be correctly decrypted at 593 the other end-point. 595 Original CoAP Message 596 +-+-+---+-------+---------------+ 597 |v|t|tkl| code | Msg Id. | 598 +-+-+---+-------+---------------+....+ 599 | Token | 600 +-------------------------------.....+ 601 | Options (IEU) | 602 . . 603 . . 604 +------+-------------------+ 605 | 0xFF | 606 +------+------------------------+ 607 | | 608 | Payload | 609 | | 610 +-------------------------------+ 611 / \ 612 / \ 613 / \ 614 / \ 615 Outer Header v v Plaintext 616 +-+-+---+--------+---------------+ +-------+ 617 |v|t|tkl|new code| Msg Id. | | code | 618 +-+-+---+--------+---------------+....+ +-------+-----......+ 619 | Token | | Options (E) | 620 +--------------------------------.....+ +-------+------.....+ 621 | Options (IU) | | OxFF | 622 . . +-------+-----------+ 623 . OSCORE Option . | | 624 +------+-------------------+ | Payload | 625 | 0xFF | | | 626 +------+ +-------------------+ 628 Figure 7: OSCORE inner and outer header form a CoAP message 630 Figure 7 shows the message format for the OSCORE Message and 631 Plaintext. 633 In the Outer Header, the original message code is hidden and replaced 634 by a default dummy value. As seen in sections 4.1.3.5 and 4.2 of 636 [I-D.ietf-core-object-security], the message code is replaced by POST 637 for requests and Changed for responses when Observe is not used. If 638 Observe is used, the message code is replaced by FETCH for requests 639 and Content for responses. 641 The original message code is put into the first byte of the 642 Plaintext. Following the message code, the class E options comes and 643 if present the original message Payload is preceded by its payload 644 marker. 646 The Plaintext is now encrypted by an AEAD algorithm which integrity 647 protects Security Context parameters and eventually any class I 648 options from the Outer Header. Currently no CoAP options are marked 649 class I. The resulting Ciphertext becomes the new Payload of the 650 OSCORE message, as illustrated in Figure 8. 652 This Ciphertext is, as defined in RFC 5116, the concatenation of the 653 encrypted Plaintext and its authentication tag. Note that Inner 654 Compression only affects the Plaintext before encryption, thus we can 655 only aim to reduce this first, variable length component of the 656 Ciphertext. The authentication tag is fixed in length and considered 657 part of the cost of protection. 659 Outer Header 660 +-+-+---+--------+---------------+ 661 |v|t|tkl|new code| Msg Id. | 662 +-+-+---+--------+---------------+....+ 663 | Token | 664 +--------------------------------.....+ 665 | Options (IU) | 666 . . 667 . OSCORE Option . 668 +------+-------------------+ 669 | 0xFF | 670 +------+-------------------------+ 671 | | 672 | Encrypted Inner Header and | 673 | Payload | 674 | | 675 +--------------------------------+ 677 Figure 8: OSCORE message 679 The SCHC Compression scheme consists of compressing both the 680 Plaintext before encryption and the resulting OSCORE message after 681 encryption, see Figure 9. 683 This translates into a segmented process where SCHC compression is 684 applied independently in 2 stages, each with its corresponding set of 685 rules, with the Inner SCHC Rules and the Outer SCHC Rules. This way 686 compression is applied to all fields of the original CoAP message. 688 Note that since the Inner part of the message can only be decrypted 689 by the corresponding end-point, this end-point will also have to 690 implement Inner SCHC Compression/Decompression. 692 Outer Message OSCORE Plaintext 693 +-+-+---+--------+---------------+ +-------+ 694 |v|t|tkl|new code| Msg Id. | | code | 695 +-+-+---+--------+---------------+....+ +-------+-----......+ 696 | Token | | Options (E) | 697 +--------------------------------.....+ +-------+------.....+ 698 | Options (IU) | | OxFF | 699 . . +-------+-----------+ 700 . OSCORE Option . | | 701 +------+-------------------+ | Payload | 702 | 0xFF | | | 703 +------+------------+ +-------------------+ 704 | Ciphertext |<---------\ | 705 | | | v 706 +-------------------+ | +-----------------+ 707 | | | Inner SCHC | 708 v | | Compression | 709 +-----------------+ | +-----------------+ 710 | Outer SCHC | | | 711 | Compression | | v 712 +-----------------+ | +-------+ 713 | | |Rule ID| 714 v | +-------+--+ 715 +--------+ +------------+ | Residue | 716 |Rule ID'| | Encryption | <--- +----------+--------+ 717 +--------+--+ +------------+ | | 718 | Residue' | | Payload | 719 +-----------+-------+ | | 720 | Ciphertext | +-------------------+ 721 | | 722 +-------------------+ 724 Figure 9: OSCORE Compression Diagram 726 7.3. Example OSCORE Compression 728 An example is given with a GET Request and its consequent CONTENT 729 Response. A possible set of rules for the Inner and Outer SCHC 730 Compression is shown. A dump of the results and a contrast between 731 SCHC + OSCORE performance with SCHC + COAP performance is also 732 listed. This gives an approximation to the cost of security with 733 SCHC-OSCORE. 735 Our first example CoAP message is the GET Request in Figure 10 737 Original message: 738 ================= 739 0x4101000182bb74656d7065726174757265 741 Header: 742 0x4101 743 01 Ver 744 00 CON 745 0001 tkl 746 00000001 Request Code 1 "GET" 748 0x0001 = mid 749 0x82 = token 751 Options: 752 0xbb74656d7065726174757265 753 Option 11: URI_PATH 754 Value = temperature 756 Original msg length: 17 bytes. 758 Figure 10: CoAP GET Request 760 Its corresponding response is the CONTENT Response in Figure 11. 762 Original message: 763 ================= 764 0x6145000182ff32332043 766 Header: 767 0x6145 768 01 Ver 769 10 ACK 770 0001 tkl 771 01000101 Successful Response Code 69 "2.05 Content" 773 0x0001 = mid 774 0x82 = token 776 0xFF Payload marker 777 Payload: 778 0x32332043 780 Original msg length: 10 782 Figure 11: CoAP CONTENT Response 784 The SCHC Rules for the Inner Compression include all fields that are 785 already present in a regular CoAP message, what is important is the 786 order of appearance and inclusion of only those CoAP fields that go 787 into the Plaintext, Figure 12. 789 Rule ID 0 790 +----------------+--+--+-----------+-----------+-----------++--------+ 791 | Field |FP|DI| Target | MO | CDA || Sent | 792 | | | | Value | | || [bits] | 793 +----------------+--+--+-----------+-----------+-----------++--------+ 794 |CoAP Code | |up| 1 | equal |not-sent || | 795 |CoAP Code | |dw|[69,132] | match-map |match-sent || c | 796 |CoAP Uri-Path | |up|temperature| equal |not-sent || | 797 |COAP Option-End | |dw| 0xFF | equal |not-sent || | 798 +----------------+--+--+-----------+-----------+-----------++--------+ 800 Figure 12: Inner SCHC Rules 802 Figure 13 shows the Plaintext obtained for our example GET Request 803 and follows the process of Inner Compression and Encryption until we 804 end up with the Payload to be added in the outer OSCORE Message. 806 In this case the original message has no payload and its resulting 807 Plaintext can be compressed up to only 1 byte (size of the Rule ID). 808 The AEAD algorithm preserves this length in its first output, but 809 also yields a fixed-size tag which cannot be compressed and must be 810 included in the OSCORE message. This translates into an overhead in 811 total message length, which limits the amount of compression that can 812 be achieved and plays into the cost of adding security to the 813 exchange. 815 ________________________________________________________ 816 | | 817 | OSCORE Plaintext | 818 | | 819 | 0x01bb74656d7065726174757265 (13 bytes) | 820 | | 821 | 0x01 Request Code GET | 822 | | 823 | bb74656d7065726174757265 Option 11: URI_PATH | 824 | Value = temperature | 825 |________________________________________________________| 827 | 828 | 829 | Inner SCHC Compression 830 | 831 v 832 _________________________________ 833 | | 834 | Compressed Plaintext | 835 | | 836 | 0x00 | 837 | | 838 | Rule ID = 0x00 (1 byte) | 839 | (No residue) | 840 |_________________________________| 842 | 843 | AEAD Encryption 844 | (piv = 0x04) 845 v 846 _________________________________________________ 847 | | 848 | encrypted_plaintext = 0xa2 (1 byte) | 849 | tag = 0xc54fe1b434297b62 (8 bytes) | 850 | | 851 | ciphertext = 0xa2c54fe1b434297b62 (9 bytes) | 852 |_________________________________________________| 854 Figure 13: Plaintext compression and encryption for GET Request 856 In Figure 14 we repeat the process for the example CONTENT Response. 857 In this case the misalignment produced by the compression residue (1 858 bit) makes it so that 7 bits of padding must be applied after the 859 payload, resulting in a compressed Plaintext that is the same size as 860 before compression. This misalignment also causes the hexcode from 861 the payload to differ from the original, even though it has not been 862 compressed. On top of this, the overhead from the tag bytes is 863 incurred as before. 865 ________________________________________________________ 866 | | 867 | OSCORE Plaintext | 868 | | 869 | 0x45ff32332043 (6 bytes) | 870 | | 871 | 0x45 Successful Response Code 69 "2.05 Content" | 872 | | 873 | ff Payload marker | 874 | | 875 | 32332043 Payload | 876 |________________________________________________________| 878 | 879 | 880 | Inner SCHC Compression 881 | 882 v 883 __________________________________________ 884 | | 885 | Compressed Plaintext | 886 | | 887 | 0x001919902180 (6 bytes) | 888 | | 889 | 00 Rule ID | 890 | | 891 | 0b0 (1 bit match-map residue) | 892 | 0x32332043 >> 1 (shifted payload) | 893 | 0b0000000 Padding | 894 |__________________________________________| 896 | 897 | AEAD Encryption 898 | (piv = 0x04) 899 v 900 _________________________________________________________ 901 | | 902 | encrypted_plaintext = 0x10c6d7c26cc1 (6 bytes) | 903 | tag = 0xe9aef3f2461e0c29 (8 bytes) | 904 | | 905 | ciphertext = 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) | 906 |_________________________________________________________| 908 Figure 14: Plaintext compression and encryption for CONTENT Response 910 The Outer SCHC Rules (Figure 17) must process the OSCORE Options 911 fields. In Figure 15 and Figure 16 we show a dump of the OSCORE 912 Messages generated from our example messages once they have been 913 provided with the Inner Compressed Ciphertext in the payload. These 914 are the messages that are to go through Outer SCHC Compression. 916 Protected message: 917 ================== 918 0x4102000182d7080904636c69656e74ffa2c54fe1b434297b62 919 (25 bytes) 921 Header: 922 0x4102 923 01 Ver 924 00 CON 925 0001 tkl 926 00000010 Request Code 2 "POST" 928 0x0001 = mid 929 0x82 = token 931 Options: 932 0xd7080904636c69656e74 (10 bytes) 933 Option 21: OBJECT_SECURITY 934 Value = 0x0904636c69656e74 935 09 = 000 0 1 001 Flag byte 936 h k n 937 04 piv 938 636c69656e74 kid 940 0xFF Payload marker 941 Payload: 942 0xa2c54fe1b434297b62 (9 bytes) 944 Figure 15: Protected and Inner SCHC Compressed GET Request 946 Protected message: 947 ================== 948 0x6144000182d008ff10c6d7c26cc1e9aef3f2461e0c29 949 (22 bytes) 951 Header: 952 0x6144 953 01 Ver 954 10 ACK 955 0001 tkl 956 01000100 Successful Response Code 68 "2.04 Changed" 958 0x0001 = mid 959 0x82 = token 961 Options: 962 0xd008 (2 bytes) 963 Option 21: OBJECT_SECURITY 964 Value = b'' 966 0xFF Payload marker 967 Payload: 968 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) 970 Figure 16: Protected and Inner SCHC Compressed CONTENT Response 972 For the flag bits, a number of compression methods could prove to be 973 useful depending on the application. The simplest alternative is to 974 provide a fixed value for the flags, combining MO equal and CDA not- 975 sent. This saves most bits but could hinder flexibility. Otherwise, 976 match-mapping could allow to choose from a number of configurations 977 of interest to the exchange. If neither of these alternatives is 978 desirable, MSB could be used to mask off the 3 hard-coded most 979 significant bits. 981 Note that fixing a flag bit will limit the choice of CoAP Options 982 that can be used in the exchange, since their values are dependent on 983 certain options. 985 The piv field lends itself to having a number of bits masked off with 986 MO MSB and CDA LSB. This could prove useful in applications where 987 the message frequency is low such as that found in LPWAN 988 technologies. Note that compressing the sequence numbers effectively 989 reduces the maximum amount of sequence numbers that can be used in an 990 exchange. Once this amount is exceeded, the SCHC Context would need 991 to be re-established. 993 The size s included in the kid context field may be masked off with 994 CDA MSB. The rest of the field could have additional bits masked 995 off, or have the whole field be fixed with MO equal and CDA not-sent. 996 The same holds for the kid field. 998 Figure 17 shows a possible set of Outer Rules to compress the Outer 999 Header. 1001 Rule ID 0 1002 +-------------------+--+--+--------------+---------+-----------++--------+ 1003 | Field |FP|DI| Target | MO | CDA || Sent | 1004 | | | | Value | | || [bits] | 1005 +-------------------+--+--+--------------+---------+-----------++--------+ 1006 |CoAP version | |bi| 01 |equal |not-sent || | 1007 |CoAP Type | |up| 0 |equal |not-sent || | 1008 |CoAP Type | |dw| 2 |equal |not-sent || | 1009 |CoAP TKL | |bi| 1 |equal |not-sent || | 1010 |CoAP Code | |up| 2 |equal |not-sent || | 1011 |CoAP Code | |dw| 68 |equal |not-sent || | 1012 |CoAP MID | |bi| 0000 |MSB(12) |LSB ||MMMM | 1013 |CoAP Token | |bi| 0x80 |MSB(5) |LSB ||TTT | 1014 |CoAP OSCORE_flags | |up| 0x09 |equal |not-sent || | 1015 |CoAP OSCORE_piv | |up| 0x00 |MSB(4) |LSB ||PPPP | 1016 |COAP OSCORE_kid | |up|0x636c69656e70|MSB(52) |LSB ||KKKK | 1017 |COAP OSCORE_kidctxt| |bi| b'' |equal |not-sent || | 1018 |CoAP OSCORE_flags | |dw| b'' |equal |not-sent || | 1019 |CoAP OSCORE_piv | |dw| b'' |equal |not-sent || | 1020 |CoAP OSCORE_kid | |dw| b'' |equal |not-sent || | 1021 |COAP Option-End | |dw| 0xFF |equal |not-sent || | 1022 +-------------------+--+--+--------------+---------+-----------++--------+ 1024 Figure 17: Outer SCHC Rules 1026 These Outer Rules are applied to the example GET Request and CONTENT 1027 Response. The resulting messages are shown in Figure 18 and 1028 Figure 19. 1030 Compressed message: 1031 ================== 1032 0x001489458a9fc3686852f6c4 (12 bytes) 1033 0x00 Rule ID 1034 1489 Compression Residue 1035 458a9fc3686852f6c4 Padded payload 1037 Compression residue: 1038 0b 0001 010 0100 0100 (15 bits -> 2 bytes with padding) 1039 mid tkn piv kid 1041 Payload 1042 0xa2c54fe1b434297b62 (9 bytes) 1044 Compressed message length: 12 bytes 1046 Figure 18: SCHC-OSCORE Compressed GET Request 1048 Compressed message: 1049 ================== 1050 0x0014218daf84d983d35de7e48c3c1852 (16 bytes) 1051 0x00 Rule ID 1052 14 Compression residue 1053 218daf84d983d35de7e48c3c1852 Padded payload 1054 Compression residue: 1055 0b0001 010 (7 bits -> 1 byte with padding) 1056 mid tkn 1058 Payload 1059 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) 1061 Compressed msg length: 16 bytes 1063 Figure 19: SCHC-OSCORE Compressed CONTENT Response 1065 For contrast, we compare these results with what would be obtained by 1066 SCHC compressing the original CoAP messages without protecting them 1067 with OSCORE. To do this, we compress the CoAP messages according to 1068 the SCHC rules in Figure 20. 1070 Rule ID 1 1071 +---------------+--+--+-----------+---------+-----------++------------+ 1072 | Field |FP|DI| Target | MO | CDA || Sent | 1073 | | | | Value | | || [bits] | 1074 +---------------+--+--+-----------+---------+-----------++------------+ 1075 |CoAP version | |bi| 01 |equal |not-sent || | 1076 |CoAP Type | |up| 0 |equal |not-sent || | 1077 |CoAP Type | |dw| 2 |equal |not-sent || | 1078 |CoAP TKL | |bi| 1 |equal |not-sent || | 1079 |CoAP Code | |up| 2 |equal |not-sent || | 1080 |CoAP Code | |dw| [69,132] |equal |not-sent || | 1081 |CoAP MID | |bi| 0000 |MSB(12) |LSB ||MMMM | 1082 |CoAP Token | |bi| 0x80 |MSB(5) |LSB ||TTT | 1083 |CoAP Uri-Path | |up|temperature|equal |not-sent || | 1084 |COAP Option-End| |dw| 0xFF |equal |not-sent || | 1085 +---------------+--+--+-----------+---------+-----------++------------+ 1087 Figure 20: SCHC-CoAP Rules (No OSCORE) 1089 This yields the results in Figure 21 for the Request, and Figure 22 1090 for the Response. 1092 Compressed message: 1093 ================== 1094 0x0114 1095 0x01 = Rule ID 1097 Compression residue: 1098 0b00010100 (1 byte) 1100 Compressed msg length: 2 1102 Figure 21: CoAP GET Compressed without OSCORE 1104 Compressed message: 1105 ================== 1106 0x010a32332043 1107 0x01 = Rule ID 1109 Compression residue: 1110 0b00001010 (1 byte) 1112 Payload 1113 0x32332043 1115 Compressed msg length: 6 1117 Figure 22: CoAP CONTENT Compressed without OSCORE 1119 As can be seen, the difference between applying SCHC + OSCORE as 1120 compared to regular SCHC + COAP is about 10 bytes of cost. 1122 8. Normative References 1124 [I-D.ietf-core-object-security] 1125 Selander, G., Mattsson, J., Palombini, F., and L. Seitz, 1126 "Object Security for Constrained RESTful Environments 1127 (OSCORE)", draft-ietf-core-object-security-15 (work in 1128 progress), August 2018. 1130 [I-D.ietf-lpwan-ipv6-static-context-hc] 1131 Minaburo, A., Toutain, L., Gomez, C., and D. Barthel, 1132 "LPWAN Static Context Header Compression (SCHC) and 1133 fragmentation for IPv6 and UDP", draft-ietf-lpwan-ipv6- 1134 static-context-hc-16 (work in progress), June 2018. 1136 [I-D.toutain-core-time-scale] 1137 Minaburo, A. and L. Toutain, "CoAP Time Scale Option", 1138 draft-toutain-core-time-scale-00 (work in progress), 1139 October 2017. 1141 [rfc7252] Shelby, Z., Hartke, K., and C. Bormann, "The Constrained 1142 Application Protocol (CoAP)", RFC 7252, 1143 DOI 10.17487/RFC7252, June 2014, 1144 . 1146 [rfc7641] Hartke, K., "Observing Resources in the Constrained 1147 Application Protocol (CoAP)", RFC 7641, 1148 DOI 10.17487/RFC7641, September 2015, 1149 . 1151 [rfc7959] Bormann, C. and Z. Shelby, Ed., "Block-Wise Transfers in 1152 the Constrained Application Protocol (CoAP)", RFC 7959, 1153 DOI 10.17487/RFC7959, August 2016, 1154 . 1156 [rfc7967] Bhattacharyya, A., Bandyopadhyay, S., Pal, A., and T. 1157 Bose, "Constrained Application Protocol (CoAP) Option for 1158 No Server Response", RFC 7967, DOI 10.17487/RFC7967, 1159 August 2016, . 1161 Authors' Addresses 1162 Ana Minaburo 1163 Acklio 1164 1137A avenue des Champs Blancs 1165 35510 Cesson-Sevigne Cedex 1166 France 1168 Email: ana@ackl.io 1170 Laurent Toutain 1171 Institut MINES TELECOM; IMT Atlantique 1172 2 rue de la Chataigneraie 1173 CS 17607 1174 35576 Cesson-Sevigne Cedex 1175 France 1177 Email: Laurent.Toutain@imt-atlantique.fr 1179 Ricardo Andreasen 1180 Universidad de Buenos Aires 1181 Av. Paseo Colon 850 1182 C1063ACV Ciudad Autonoma de Buenos Aires 1183 Argentina 1185 Email: randreasen@fi.uba.ar