In this first scenario, the SCHC compressor on the NGW side receives a POST message from an Internet client, which is immediately acknowledged by the Device.
Table 3 describes the SCHC Rule descriptions for this scenario.
RuleID 1 |
Field |
FL |
FP |
DI |
TV |
MO |
CDA |
Sent [bits] |
CoAP version |
2 |
1 |
Bi |
01 |
equal |
not-sent |
|
CoAP Type |
2 |
1 |
Dw |
CON |
equal |
not-sent |
|
CoAP Type |
2 |
1 |
Up |
[ACK,RST] |
match-mapping |
matching-sent |
T |
CoAP TKL |
4 |
1 |
Bi |
0 |
equal |
not-sent |
|
CoAP Code |
8 |
1 |
Bi |
[0.00,...5.05] |
match-mapping |
matching-sent |
CC CCC |
CoAP MID |
16 |
1 |
Bi |
0000 |
MSB(7) |
LSB |
MID |
CoAP Uri-Path |
var |
1 |
Dw |
path |
equal 1 |
not-sent |
|
Table 3: CoAP Context to Compress Header without Token
In this example, SCHC compression elides the version and Token Length fields. The 25 Method and Response Codes defined in [
RFC 7252] have been shrunk to 5 bits using a "match-mapping" MO. The Uri-Path contains a single element indicated in the TV and elided with the CDA "not-sent".
SCHC compression reduces the header, sending only the Type, a mapped code, and the least significant bits of the Message ID (9 bits in the example above).
Note that a client located in an Application Server sending a request to a server located in the Device may not be compressed through this Rule, since the MID might not start with 7 bits equal to 0. A CoAP proxy placed before SCHC C/D can rewrite the Message ID to fit the value and match the Rule.
OSCORE aims to solve the problem of end-to-end encryption for CoAP messages. Therefore, the goal is to hide the message as much as possible while still enabling proxy operation.
Conceptually, this is achieved by splitting the CoAP message into an Inner Plaintext and Outer OSCORE message. The Inner Plaintext contains sensitive information that is not necessary for proxy operation. However, it is part of the message that can be encrypted until it reaches its end destination. The Outer Message acts as a shell matching the regular CoAP message format and includes all options and information needed for proxy operation and caching.
Figure 5 below illustrates this analysis.
CoAP arranges the options into one of three classes, each granted a specific type of protection by the protocol:
-
Class E:
-
Encrypted options moved to the Inner Plaintext.
-
Class I:
-
Integrity-protected options included in the Additional Authenticated Data (AAD) for the encryption of the Plaintext but otherwise left untouched in the Outer Message.
-
Class U:
-
Unprotected options left untouched in the Outer Message.
These classes point out that the Outer option contains the OSCORE option and that the message is OSCORE protected; this option carries the information necessary to retrieve the Security Context. The endpoint will use this Security Context to decrypt the message correctly.
Original CoAP Packet
+-+-+---+-------+---------------+
|v|t|TKL| code | Message ID |
+-+-+---+-------+---------------+....+
| Token |
+-------------------------------.....+
| Options (IEU) |
. .
. .
+------+-------------------+
| 0xFF |
+------+------------------------+
| |
| Payload |
| |
+-------------------------------+
/ \
/ \
/ \
/ \
Outer Header v v Plaintext
+-+-+---+--------+---------------+ +-------+
|v|t|TKL|new code| Message ID | | code |
+-+-+---+--------+---------------+....+ +-------+-----......+
| Token | | Options (E) |
+--------------------------------.....+ +-------+------.....+
| Options (IU) | | 0xFF |
. . +-------+-----------+
. OSCORE Option . | |
+------+-------------------+ | Payload |
| 0xFF | | |
+------+ +-------------------+
Figure 5 shows the packet format for the OSCORE Outer header and Plaintext.
In the Outer header, the original header code is hidden and replaced by a default dummy value. As seen in Sections
4.1.3.5 and
4.2 of [
RFC 8613], the message code is replaced by POST for requests and Changed for responses when CoAP is not using the Observe Option. If CoAP uses Observe, the OSCORE message code is replaced by FETCH for requests and Content for responses.
The first byte of the Plaintext contains the original packet code, followed by the message code, the class E options, and, if present, the original message payload preceded by its payload marker.
An Authenticated Encryption with Associated Data (AEAD) algorithm now encrypts the Plaintext. This integrity-protects the Security Context parameters and, eventually, any class I options from the Outer header. The resulting ciphertext becomes the new payload of the OSCORE message, as illustrated in
Figure 6.
As defined in [
RFC 5116], this ciphertext is the encrypted Plaintext's concatenation of the Authentication Tag. Note that Inner Compression only affects the Plaintext before encryption. The Authentication Tag, fixed in length and uncompressed, is considered part of the cost of protection.
Outer Header
+-+-+---+--------+---------------+
|v|t|TKL|new code| Message ID |
+-+-+---+--------+---------------+....+
| Token |
+--------------------------------.....+
| Options (IU) |
. .
. OSCORE Option .
+------+-------------------+
| 0xFF |
+------+---------------------------+
| |
| Ciphertext: Encrypted Inner |
| Header and Payload |
| + Authentication Tag |
| |
+----------------------------------+
The SCHC compression scheme consists of compressing both the Plaintext before encryption and the resulting OSCORE message after encryption; see
Figure 7.
The OSCORE message translates into a segmented process where SCHC compression is applied independently in two stages, each with its corresponding set of Rules, with the Inner SCHC Rules and the Outer SCHC Rules. This way, compression is applied to all fields of the original CoAP message.
Outer Message OSCORE Plaintext
+-+-+---+--------+---------------+ +-------+
|v|t|TKL|new code| Message ID | | code |
+-+-+---+--------+---------------+....+ +-------+-----......+
| Token | | Options (E) |
+--------------------------------.....+ +-------+------.....+
| Options (IU) | | 0xFF |
. . +-------+-----------+
. OSCORE Option . | |
+------+-------------------+ | Payload |
| 0xFF | | |
+------+------------+ +-------------------+
| Ciphertext |<---------\ |
| | | v
+-------------------+ | +-----------------+
| | | Inner SCHC |
v | | Compression |
+-----------------+ | +-----------------+
| Outer SCHC | | |
| Compression | | v
+-----------------+ | +-------+
| | |RuleID |
v | +-------+-----------+
+--------+ +------------+ |Compression Residue|
|RuleID' | | Encryption | <-- +----------+--------+
+--------+-----------+ +------------+ | |
|Compression Residue'| | Payload |
+-----------+--------+ | |
| Ciphertext | +-------------------+
| |
+--------------------+
Note that since the corresponding endpoint can only decrypt the Inner part of the message, this endpoint will also have to implement Inner SCHC Compression/Decompression.
This section gives an example with a GET request and its consequent Content response from a Device-based CoAP client to a cloud-based CoAP server. The example also describes a possible set of Rules for Inner SCHC Compression and Outer SCHC Compression. A dump of the results and a contrast between SCHC + OSCORE performance with SCHC + CoAP performance are also listed. This example gives an approximation of the cost of security with SCHC-OSCORE.
Our first CoAP message is the GET request in
Figure 8.
Original message:
=================
0x4101000182bb74656d7065726174757265
Header:
0x4101
01 Ver
00 CON
0001 TKL
00000001 Request Code 1 "GET"
0x0001 = mid
0x82 = token
Options:
0xbb74656d7065726174757265
Option 11: URI_PATH
Value = temperature
Original message length: 17 bytes
Its corresponding response is the Content response in
Figure 9.
Original message:
=================
0x6145000182ff32332043
Header:
0x6145
01 Ver
10 ACK
0001 TKL
01000101 Successful Response Code 69 "2.05 Content"
0x0001 = mid
0x82 = token
0xFF Payload marker
Payload:
0x32332043
Original message length: 10 bytes
The SCHC Rules for the Inner Compression include all fields already present in a regular CoAP message. The methods described in
Section 4 apply to these fields.
Table 4 provides an example.
RuleID 0 |
Field |
FL |
FP |
DI |
TV |
MO |
CDA |
Sent [bits] |
CoAP Code |
8 |
1 |
Up |
1 |
equal |
not-sent |
|
CoAP Code |
8 |
1 |
Dw |
[69,132] |
match-mapping |
mapping-sent |
c |
CoAP Uri-Path |
|
1 |
Up |
temperature |
equal |
not-sent |
|
Table 4: Inner SCHC Rule
Figure 10 shows the Plaintext obtained for the example GET request. The packet follows the process of Inner Compression and encryption until the payload. The Outer OSCORE message adds the result of the Inner process.
________________________________________________________
| |
| OSCORE Plaintext |
| |
| 0x01bb74656d7065726174757265 (13 bytes) |
| |
| 0x01 Request Code GET |
| |
| bb74656d7065726174757265 Option 11: URI_PATH |
| Value = temperature |
|________________________________________________________|
|
|
| Inner SCHC Compression
|
v
_________________________________
| |
| Compressed Plaintext |
| |
| 0x00 |
| |
| RuleID = 0x00 (1 byte) |
| (No Compression Residue) |
|_________________________________|
|
| AEAD Encryption
| (piv = 0x04)
v
_________________________________________________
| |
| encrypted_plaintext = 0xa2 (1 byte) |
| tag = 0xc54fe1b434297b62 (8 bytes) |
| |
| ciphertext = 0xa2c54fe1b434297b62 (9 bytes) |
|_________________________________________________|
In this case, the original message has no payload, and its resulting Plaintext is compressed up to only 1 byte (the size of the RuleID). The AEAD algorithm preserves this length in its first output and yields a fixed-size tag. SCHC cannot compress the tag, and the OSCORE message must include it without compression. The use of integrity protection translates into an overhead in total message length, limiting the amount of compression that can be achieved and playing into the cost of adding security to the exchange.
Figure 11 shows the process for the example Content response. The Compression Residue is 1 bit long. Note that since SCHC adds padding after the payload, this misalignment causes the hexadecimal code from the payload to differ from the original, even if SCHC cannot compress the tag. The overhead for the tag bytes limits SCHC's performance but brings security to the transmission.
________________________________________________________
| |
| OSCORE Plaintext |
| |
| 0x45ff32332043 (6 bytes) |
| |
| 0x45 Successful Response Code 69 "2.05 Content" |
| |
| ff Payload marker |
| |
| 32332043 Payload |
|________________________________________________________|
|
|
| Inner SCHC Compression
|
v
_________________________________________________
| |
| Compressed Plaintext |
| |
| 0x001919902180 (6 bytes) |
| |
| 00 RuleID |
| |
| 0b0 (1 bit match-mapping Compression Residue) |
| 0x32332043 >> 1 (shifted payload) |
| 0b0000000 Padding |
|_________________________________________________|
|
| AEAD Encryption
| (piv = 0x04)
v
_________________________________________________________
| |
| encrypted_plaintext = 0x10c6d7c26cc1 (6 bytes) |
| tag = 0xe9aef3f2461e0c29 (8 bytes) |
| |
| ciphertext = 0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes) |
|_________________________________________________________|
The Outer SCHC Rule (
Table 5) must process the OSCORE options fields. Figures [
12] and [
13] show a dump of the OSCORE messages generated from the example messages. They include the Inner Compressed ciphertext in the payload. These are the messages that have to be compressed via the Outer SCHC Compression scheme.
Table 5 shows a possible set of Outer Rule items to compress the Outer header.
RuleID 0 |
Field |
FL |
FP |
DI |
TV |
MO |
CDA |
Sent [bits] |
CoAP version |
2 |
1 |
Bi |
01 |
equal |
not-sent |
|
CoAP Type |
2 |
1 |
Up |
0 |
equal |
not-sent |
|
CoAP Type |
2 |
1 |
Dw |
2 |
equal |
not-sent |
|
CoAP TKL |
4 |
1 |
Bi |
1 |
equal |
not-sent |
|
CoAP Code |
8 |
1 |
Up |
2 |
equal |
not-sent |
|
CoAP Code |
8 |
1 |
Dw |
68 |
equal |
not-sent |
|
CoAP MID |
16 |
1 |
Bi |
0000 |
MSB(12) |
LSB |
MMMM |
CoAP Token |
tkl |
1 |
Bi |
0x80 |
MSB(5) |
LSB |
TTT |
CoAP OSCORE_flags |
8 |
1 |
Up |
0x09 |
equal |
not-sent |
|
CoAP OSCORE_piv |
var |
1 |
Up |
0x00 |
MSB(4) |
LSB |
PPPP |
CoAP OSCORE_kid |
var |
1 |
Up |
0x636c69656e70 |
MSB(52) |
LSB |
KKKK |
CoAP OSCORE_kidctx |
var |
1 |
Bi |
b'' |
equal |
not-sent |
|
CoAP OSCORE_flags |
8 |
1 |
Dw |
b'' |
equal |
not-sent |
|
CoAP OSCORE_piv |
var |
1 |
Dw |
b'' |
equal |
not-sent |
|
CoAP OSCORE_kid |
var |
1 |
Dw |
b'' |
equal |
not-sent |
|
Table 5: Outer SCHC Rule
Protected message:
==================
0x4102000182d8080904636c69656e74ffa2c54fe1b434297b62
(25 bytes)
Header:
0x4102
01 Ver
00 CON
0001 TKL
00000010 Request Code 2 "POST"
0x0001 = mid
0x82 = token
Options:
0xd8080904636c69656e74 (10 bytes)
Option 21: OBJECT_SECURITY
Value = 0x0904636c69656e74
09 = 000 0 1 001 flag byte
h k n
04 piv
636c69656e74 kid
0xFF Payload marker
Payload:
0xa2c54fe1b434297b62 (9 bytes)
Protected message:
==================
0x6144000182d008ff10c6d7c26cc1e9aef3f2461e0c29
(22 bytes)
Header:
0x6144
01 Ver
10 ACK
0001 TKL
01000100 Successful Response Code 68 "2.04 Changed"
0x0001 = mid
0x82 = token
Options:
0xd008 (2 bytes)
Option 21: OBJECT_SECURITY
Value = b''
0xFF Payload marker
Payload:
0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes)
For the flag bits, some SCHC compression methods are useful, depending on the application. The most straightforward alternative is to provide a fixed value for the flags, combining a MO of "equal" and a CDA of "not-sent". This SCHC definition saves most bits but could prevent flexibility. Otherwise, SCHC could use a "match-mapping" MO to choose from several configurations for the exchange. If not, the SCHC description may use an "MSB" MO to mask off the three hard-coded most significant bits.
Note that fixing a flag bit will limit the choices of CoAP options that can be used in the exchange, since the values of these choices are dependent on specific options.
The piv field lends itself to having some bits masked off with an "MSB" MO and an "LSB" CDA. This SCHC description could be useful in applications where the message frequency is low, such as LPWAN technologies. Note that compressing the sequence numbers may reduce the maximum number of sequence numbers that can be used in an exchange. Once the sequence number exceeds the maximum value, the OSCORE keys need to be re-established.
The size, s, that is included in the kid context field
MAY be masked off with an "LSB" CDA. The rest of the field could have additional bits masked off or have the whole field fixed with a MO of "equal" and a CDA of "not-sent". The same holds for the kid field.
The Outer Rule of
Table 5 is applied to the example GET request and Content response. Figures [
14] and [
15] show the resulting messages.
Compressed message:
==================
0x001489458a9fc3686852f6c4 (12 bytes)
0x00 RuleID
1489 Compression Residue
458a9fc3686852f6c4 Padded payload
Compression Residue:
0b 0001 010 0100 0100 (15 bits -> 2 bytes with padding)
mid tkn piv kid
Payload
0xa2c54fe1b434297b62 (9 bytes)
Compressed message length: 12 bytes
Compressed message:
==================
0x0014218daf84d983d35de7e48c3c1852 (16 bytes)
0x00 RuleID
14 Compression Residue
218daf84d983d35de7e48c3c1852 Padded payload
Compression Residue:
0b0001 010 (7 bits -> 1 byte with padding)
mid tkn
Payload
0x10c6d7c26cc1e9aef3f2461e0c29 (14 bytes)
Compressed message length: 16 bytes
In contrast, comparing these results with what would be obtained by SCHC compressing the original CoAP messages without protecting them with OSCORE is done by compressing the CoAP messages according to the SCHC Rule in
Table 6.
RuleID 1 |
Field |
FL |
FP |
DI |
TV |
MO |
CDA |
Sent [bits] |
CoAP version |
2 |
1 |
Bi |
01 |
equal |
not-sent |
|
CoAP Type |
2 |
1 |
Up |
0 |
equal |
not-sent |
|
CoAP Type |
2 |
1 |
Dw |
2 |
equal |
not-sent |
|
CoAP TKL |
4 |
1 |
Bi |
1 |
equal |
not-sent |
|
CoAP Code |
8 |
1 |
Up |
2 |
equal |
not-sent |
|
CoAP Code |
8 |
1 |
Dw |
[69,132] |
match-mapping |
mapping-sent |
C |
CoAP MID |
16 |
1 |
Bi |
0000 |
MSB(12) |
LSB |
MMMM |
CoAP Token |
tkl |
1 |
Bi |
0x80 |
MSB(5) |
LSB |
TTT |
CoAP Uri-Path |
|
1 |
Up |
temperature |
equal |
not-sent |
|
Table 6: SCHC-CoAP Rule (No OSCORE)
The Rule in
Table 6 yields the SCHC compression results as shown in
Figure 16 for the request and
Figure 17 for the response.
Compressed message:
==================
0x0114
0x01 = RuleID
Compression Residue:
0b00010100 (1 byte)
Compressed message length: 2 bytes
Compressed message:
==================
0x010a32332043
0x01 = RuleID
Compression Residue:
0b00001010 (1 byte)
Payload
0x32332043
Compressed message length: 6 bytes
As can be seen, the difference between applying SCHC + OSCORE as compared to regular SCHC + CoAP is about 10 bytes.