Internet-Draft GNUnet CBOR Profile December 2026
Grothoff Expires 8 June 2027 [Page]
Workgroup:
Independent Stream
Internet-Draft:
draft-gnunet-cbor-00
Published:
Intended Status:
Informational
Expires:
Author:
C. Grothoff
Berner Fachhochschule

The GNUnet CBOR Profile

Abstract

This document specifies the profile of CBOR in which GNUnet encodes the bodies of its peer-to-peer messages and the objects they carry, such as the HELLO. The profile is a strict subset of the deterministic encoding of RFC 8949: receivers reject every other encoding, so that every value has exactly one valid encoding and independent implementations accept and reject the same messages. It also fixes conventions that the specifications of GNUnet messages share: positional arrays and extensible maps whose keys say whether a receiver may ignore them, fixed-size byte strings, typed keys, times, and the relation between the encoding and the data that GNUnet signs and hashes.

This specification was developed outside the IETF and does not have IETF consensus. It is published here to inform readers about the encoding of GNUnet messages, guide future implementations, and ensure interoperability among implementations.

Status of This Memo

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

This Internet-Draft will expire on 8 June 2027.

▲

Table of Contents

1. Introduction

A GNUnet message is a short header, which gives the size and the type of the message, followed by a body. The bodies of GNUnet's peer-to-peer messages used to be packed C structures, with hand-written code for every variable-length part. GNUnet moves the bodies of its peer-to-peer control messages to CBOR [RFC8949] in one clean break, starting with the HELLO [LSD0018], so that each protocol breaks only once.

CBOR permits several encodings of one value: integers and lengths in longer forms than necessary, items of indefinite length, and map keys in any order. Most CBOR libraries accept all of them by default. In a peer-to-peer network with more than one implementation, an encoding that one implementation accepts and another rejects splits the network: in a distributed hash table, some peers store and forward such an item and others drop it. Where a hash of an item serves as its identity, a second encoding of the same value is a second identity. Each specification could state its own rules against this, but rules restated in every document drift apart. This document states them once.

The profile is a strict subset of the core deterministic encoding of Section 4.2.1 of [RFC8949], which encoders produce and receivers enforce (Section 3). It adds conventions for the structures that GNUnet messages share (Section 4), places the encoded items in GNUnet's message framing (Section 5), and states how they relate to the data that GNUnet signs and hashes (Section 6). Section 7 lists what a specification that uses the profile must state.

The profile does not apply to formats that another specification fixes, such as the record sets and blocks of the GNU Name System [RFC9498] and the content blocks of file-sharing, to the headers of data-plane messages, to the obfuscated outer layer of the communicators (Section 5.4), or to the data that GNUnet signs, which remains a packed structure (Section 6).

This specification was developed outside the IETF and does not have IETF consensus. It is published here to guide implementers of GNUnet and to ensure interoperability among implementations.

1.1. Requirements Notation

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.

2. Terminology

CBOR, item, well-formed, valid:
As in [RFC8949]. "The encoding of X" is the byte string that represents the item X under the rules of Section 3.
CDDL:
The Concise Data Definition Language [RFC8610].
Specification:
A document that defines items encoded under this profile, such as [LSD0018].
Container:
The byte string from which an item is decoded: a message body, a DHT block, a byte string inside another item, or a decoded URL parameter.
Depth:
The nesting depth of an item. An item that is not inside an array or a map has depth 1; an item inside an array or a map has the depth of that array or map plus 1.
Critical, optional:
Properties of the keys of an extensible map (Section 4.2): a receiver that does not know a critical key rejects the item, and one that does not know an optional key ignores its entry.
Absolute time:
An unsigned integer counting microseconds since midnight (0 hour), January 1, 1970 UTC.
NBO:
Network byte order (big endian).

3. Encoding Rules

An item encoded under this profile MUST satisfy the following rules, and a receiver MUST reject an item that violates any of them. Specifications refer to them by number.

  1. Deterministic encoding. The core deterministic encoding requirements of Section 4.2.1 of [RFC8949] apply: integers, lengths and counts use the shortest form, all items have definite length, the keys of a map are sorted in the bytewise lexicographic order of their encodings, and no map has duplicate keys.
  2. Restricted data model. Only unsigned and negative integers, byte strings, text strings, arrays, maps, false, true and null are allowed. Tags (among them bignums and the self-described CBOR tag), floating-point values, undefined and all other simple values are not.
  3. Map keys are unsigned integers.
  4. Text strings are valid UTF-8 [RFC3629] and do not contain U+0000.
  5. Nesting depth. Every specification states the maximum depth of the items it defines, at most 16. A receiver rejects an item that exceeds it, before it decodes the deeper item.
  6. Nothing follows the item. An item is the whole content of its container. Bytes after it are an error, except the padding of Section 5.3.

These rules leave exactly one valid encoding for every value. An item decoded from a byte string inside another item, such as a nested message (Section 5.2), is an item of its own: its depth is counted from 1, and the rules apply to it again.

Rule 3 also settles an ambiguity. The "canonical" order of map keys of Section 3.9 of [RFC7049], which Section 4.2.3 of [RFC8949] keeps as "length-first" ordering, sorts shorter encodings first, whereas rule 1 sorts bytewise. The two orders differ for some keys, for example for a negative integer and an unsigned integer of more than 23. For unsigned integers in their shortest form, both orders are the numeric order of the keys, so an implementation that uses the older definition sorts them correctly as well.

The profile is a subset of the core deterministic encoding of Section 4.2.1 of [RFC8949]. Since it excludes floating-point values and tags, the further rules that Section 4.2.2 of [RFC8949] and other deterministic profiles of CBOR make for them do not arise. This document states its rules in full rather than referring to such a profile, so that they do not change with it.

3.1. Enforcement

A receiver enforces the rules while it decodes, or it decodes the item with a more permissive decoder, checks rules 2 to 5 on the result, encodes it again deterministically and compares the result with its input byte for byte. Either way, it accepts an encoding only if it is the one encoding of its value.

A decoder MUST NOT allocate memory based on a declared length or count before checking it against the remaining input: a byte or text string of n bytes needs n more bytes, an array of n elements at least n, and a map of n entries at least 2n. The work and memory that decoding takes are then bounded by the size of the container and the maximum depth. A decoder MUST NOT recurse deeper than the maximum depth.

Implementations SHOULD test their decoder against an independent CBOR implementation by differential fuzzing, and against the test vectors of Appendix A.

4. Conventions

The following conventions apply to every specification that uses this profile, unless the specification states otherwise and gives its reason.

4.1. Positional Arrays

A structure whose fields are fixed by its specification is an array whose elements are the fields, in the order the specification gives. The number of elements is fixed as well. Arrays are not an extension mechanism: a specification that needs another field defines a new message type, or uses an extensible map (Section 4.2) for the fields that can grow. An optional element that is absent is null, if the specification permits it.

4.2. Extensible Maps

A structure that later revisions or other parties extend is a map with unsigned integer keys. Whether a key is critical or optional is a property of the key, fixed when it is assigned, and given by its number:

Critical keys (odd numbers):
A receiver that does not know the key MUST reject the item.
Optional keys (even numbers):
A receiver that does not know the key MUST ignore its entry for processing.

A receiver can therefore apply the rule to keys it does not know. Key 0 is reserved and MUST NOT occur. A key occurs at most once (rule 1); a key whose value can occur several times has an array as its value. An absent entry is omitted, not null. Keys from 1 to 23 encode in one byte, and specifications assign them to the entries that occur most often. Where the keys of a map are allocated by a registry, as the record types of a HELLO are [LSD0018], the registry assigns each number with the parity that matches the treatment it requires.

An entry that a receiver ignores is still part of the item. A peer that stores or forwards an item it has received SHOULD keep the bytes it received. If it encodes the item again, it MUST preserve every entry, including those it does not know, so that the result is byte for byte the same. How unknown entries relate to signatures is stated in Section 6.

4.3. Integers

The specification gives the range of every integer, in its CDDL. A receiver MUST reject an item with an integer outside its range, and MUST NOT truncate it to a narrower type: 70000 in a field whose range is that of a 16-bit integer makes the item invalid. Negative integers occur only where the specification allows them. Integers are not used as booleans.

4.4. Fixed-Size Values and Lists

Hashes, signatures, raw public keys, nonces and peer identities are byte strings of exactly the size that the specification fixes (bstr .size N in CDDL), and a receiver MUST check the size.

A list whose elements all have the same fixed size, such as a list of peer identities, is one byte string that holds the elements one after another. A receiver MUST reject it unless its length is a multiple of the element size. This saves the head of every element and lets a receiver use the elements in place. A list whose elements differ in size, such as a list of signers (Section 4.5), is an array.

If an array represents a set, the specification SHOULD require its elements in strictly ascending order of their encodings, compared bytewise lexicographically. This excludes duplicates and leaves one encoding for every set, as for the addresses of a HELLO [LSD0018].

4.5. Typed Keys

A public key whose algorithm can vary is an array of its type and the key, [type: uint, key: bstr], with the type from a GANA registry that fixes the encoding and the length of the key. [LSD0018] defines the identity key types and the KEM types of GNUnet peers, and the items that carry them: a signer, which is a typed identity key with a signature, an identity, and a kem-ct. Specifications SHOULD use these items rather than define their own.

A key whose encoding another specification fixes is carried in that encoding, as one byte string. For example, a zone key of the GNU Name System is the 4-byte type followed by the key, as [RFC9498] defines it, so that it is the same in every GNUnet format.

4.6. Times

An absolute time is an unsigned integer that counts microseconds since the epoch, and a relative time is an unsigned integer that counts microseconds. The largest value, 2^64 - 1, means "forever" in both. The specification states for every time whether "forever" is allowed. These are the semantics of the absolute and relative times of the GNUnet implementation.

abs-time = uint                    ; microseconds since the epoch
rel-time = uint                    ; microseconds
forever  = 18446744073709551615    ; 2^64 - 1

4.7. Text

Text strings hold text that people read, and addresses and URIs. Every other string of bytes is a byte string. Text strings are compared byte for byte, without Unicode normalization. The ban on U+0000 (rule 4) lets an implementation pass a decoded text string to code that expects a NUL-terminated string without truncating it.

5. Framing

5.1. Message Bodies

A GNUnet message is a header, which gives the size of the message and its type, followed by the body. The header is defined by GNUnet's message framing, not by this profile, and is not CBOR. The GNUnet implementation uses a 4-byte header of a 16-bit size and a 16-bit type in NBO; nothing in this profile depends on that layout.

The body of a message whose specification uses this profile is exactly one item, whose CDDL rule the message type determines. There is no other indication of the encoding: one message type has one encoding of its body, and a version or flag in the header MUST NOT select another. A receiver MUST NOT read beyond the size that the header gives. Specifications SHOULD state the maximum size of the body of each message type, so that a receiver can reject a larger message before it reads the body.

CBOR sequences [RFC8742] are not used for framing. Finding the end of a message in a byte stream then needs only the header, not a CBOR decoder.

5.2. Nested Messages

A message that another message carries is a byte string that holds the complete inner message, header and body. Its body is decoded from that byte string as an item of its own (Section 3).

5.3. Padding

A specification MAY declare that the body of a message type is padded, for example to hide its length. The padding is a run of zero bytes after the item, inside the container; a receiver MUST reject padding that contains a byte other than zero. Padding is useful only inside encryption, and the specification states how much is allowed. A container whose specification declares no padding has none.

5.4. Obfuscated Layers

Some communicators make the bytes they send look random to an observer of the underlay. The initial byte of a CBOR array or map at a fixed offset would identify them. Specifications therefore MUST NOT place items of this profile where the bytes must look random. Items of this profile travel inside encryption, where only their length is visible, or out of band, as a HELLO URL does.

6. Signatures and Hashes

The data that GNUnet signs is not CBOR. It is a packed structure: a 32-bit size and a 32-bit signature purpose from the GANA "GNUnet Signature Purposes" registry, in NBO, followed by the fields that the purpose defines. Signer and verifier build it; it is not transmitted. The purpose registry is shared with GNU Taler and the GNU Name System [RFC9498], a structure of fixed-size fields in NBO is a deterministic encoding by construction, and the purpose at a fixed offset lets the service that holds the signing key check what it signs. The one exception is the CAKE key exchange [LSD0012], which signs, as TLS 1.3 does, 64 zero bytes, a context string, a zero byte and a hash of the handshake transcript. The kinds of data that a peer's identity key signs, and how they are kept apart, are stated in [LSD0018].

A structure that is signed, or hashed for another purpose, relates to the encoding as follows:

The profile does not use COSE. [LSD0018] explains why the HELLO signature is not a COSE object; the same reasons apply to other signatures by a peer.

7. Using this Profile

A specification that uses this profile refers to this document and states:

8. Security Considerations

8.1. Parser Differentials

An item that one implementation accepts and another rejects is handled differently by different peers: in the DHT, some store and forward it and others drop it. Such differences are the usual way that networks with several implementations split, and they can be used to partition the network or to fingerprint implementations. The rules of Section 3 leave nothing for a receiver to decide: every encoding is either the one encoding of its value or invalid. The same holds for the semantic checks that specifications add, such as integer ranges, which is why Section 7 asks for them to be stated.

8.2. Resource Exhaustion

A declared length or count can be as large as 2^64 - 1, while the container holds a few bytes. A decoder that allocates according to the declared value can be made to exhaust its memory by a single small message. The checks of Section 3.1 bound memory and work by the size of the container, and the maximum depth bounds the recursion of the decoder. The size of the container is bounded by the message framing (Section 5.1).

8.3. Content Not Covered by a Signature

When a signed structure is built from decoded fields, every field that the receiver uses has to be part of it. A field that is transmitted but left out of the signed structure is accepted without a signature, and so is an unknown map entry. Section 6 requires receivers to reject unknown entries in that case. Specifications SHOULD have tests that change each field of a signed message in turn and expect the verification to fail.

8.4. Narrowing and Strings

Decoders written in C copy decoded values into fixed-width integers and pass text to functions that expect NUL-terminated strings. An integer that is silently truncated, or a string that is cut at an embedded U+0000, means something else to the decoder than to the sender. The range checks of Section 4.3 and rule 4 exclude both.

8.5. Traffic Analysis

The structure of CBOR is visible to anyone who sees the bytes. Items of this profile travel inside encryption (Section 5.4), where their length is visible as the length of a packed structure was. Where the length itself reveals too much, the specification declares padding (Section 5.3).

9. GANA Considerations

This document requests no registry and no allocation. GANA continues to allocate GNUnet message types and signature purposes. The keys of a map are defined by the specification of the map, in its CDDL, unless that specification creates a registry for them.

10. Implementation Status

A patch series for the GNUnet implementation contains a strict CBOR codec in the GNUnet utility library, which enforces the encoding rules of the HELLO [LSD0018]. Those rules are the rules of Section 3 with a maximum depth of 8. The same series encodes the bodies of the peer-to-peer messages of several subsystems with it, as listed in [LSD0018]. It predates this document, and its conventions have yet to be checked against Section 4.

The test vectors of Appendix A were checked with a validator written for this document in Python and, for well-formedness, with the CBOR decoder of Qt 6.8 (QCborStreamReader).

11. Open Issues

12. Normative References

[RFC2119]
Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, , <https://www.rfc-editor.org/info/rfc2119>.
[RFC3629]
Yergeau, F., "UTF-8, a transformation format of ISO 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, , <https://www.rfc-editor.org/info/rfc3629>.
[RFC8174]
Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, , <https://www.rfc-editor.org/info/rfc8174>.
[RFC8610]
Birkholz, H., Vigano, C., and C. Bormann, "Concise Data Definition Language (CDDL): A Notational Convention to Express Concise Binary Object Representation (CBOR) and JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, , <https://www.rfc-editor.org/info/rfc8610>.
[RFC8949]
Bormann, C. and P. Hoffman, "Concise Binary Object Representation (CBOR)", STD 94, RFC 8949, DOI 10.17487/RFC8949, , <https://www.rfc-editor.org/info/rfc8949>.

13. Informative References

[RFC7049]
Bormann, C. and P. Hoffman, "Concise Binary Object Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, , <https://www.rfc-editor.org/info/rfc7049>.
[RFC8742]
Bormann, C., "Concise Binary Object Representation (CBOR) Sequences", RFC 8742, DOI 10.17487/RFC8742, , <https://www.rfc-editor.org/info/rfc8742>.
[RFC9498]
Schanzenbach, M., Grothoff, C., and B. Fix, "The GNU Name System", RFC 9498, DOI 10.17487/RFC9498, , <https://www.rfc-editor.org/info/rfc9498>.
[LSD0004]
Schanzenbach, M., Grothoff, C., and B. Fix, "The R5N Distributed Hash Table", Work in Progress, Internet-Draft, draft-schanzen-r5n-07, , <https://lsd.gnunet.org/lsd0004>.
[LSD0012]
Schanzenbach, M. and ch3, "CORE Authenticated Key Exchange (CAKE)", Work in Progress, Internet-Draft, draft-schanzen-cake-00, , <https://lsd.gnunet.org/lsd0012>.
[LSD0018]
Schanzenbach, M., "The GNUnet HELLO Format, Version 2", Work in Progress, Internet-Draft, draft-gnunet-hello-00, , <https://lsd.gnunet.org/lsd0018>.

Appendix A. Test Vectors

Each line gives an encoding in hexadecimal, the item in diagnostic notation, and whether a receiver accepts it under this profile with a maximum depth of 8. For a rejected encoding, the rule of Section 3 that it violates is given. The encodings rejected under rules 1 to 6 are well-formed CBOR, and a permissive decoder accepts them, except that some decoders check UTF-8 themselves (Section 5.3.1 of [RFC8949] calls such a string well-formed but not valid). The last three are not well-formed at all.

Table 1: Encodings and Their Treatment.
Encoding Item Result
830141006161 [1, h'00', "a"] valid
a201f51818f6 {1: true, 24: null} valid
82201bffffffffffffffff [-1, 18446744073709551615] valid
8480a04060 [[], {}, h'', ""] valid
8181818181818180 [[[[[[[[]]]]]]]], depth 8 valid
1801 1, in two bytes rule 1
580100 h'00', length in two bytes rule 1
9f01ff [_ 1], indefinite length rule 1
a21818f601f5 {24: null, 1: true}, keys out of order rule 1
a201f501f4 {1: true, 1: false}, duplicate key rule 1
f93c00 1.0, a half-precision float rule 2
c24101 2(h'01'), a bignum rule 2
f7 undefined rule 2
f0 simple(16) rule 2
a1616101 {"a": 1}, a text key rule 3
a12001 {-1: 1}, a negative key rule 3
62c328 a text string that is not UTF-8 rule 4
6100 "\u0000" rule 4
818181818181818180 [[[[[[[[[]]]]]]]]], depth 9 rule 5
0100 1, followed by a zero byte rule 6
5affffffff00 a byte string of 2^32 - 1 bytes, of which 1 is present not well-formed
1c reserved additional information 28 not well-formed
ff a "break" outside an item of indefinite length not well-formed

A decoder must reject the byte string of 2^32 - 1 bytes without allocating memory for it (Section 3.1). The second valid encoding shows the order of map keys: the encoding of 1 (01) sorts before that of 24 (18 18).

Author's Address

Christian Grothoff
Berner Fachhochschule
Hoeheweg 80
CH-2501 Biel/Bienne
Switzerland