Skip to content

New BPv7 with working UTS and patched cbor modules to support it - #5075

Open
BrianSipos wants to merge 6 commits into
secdev:masterfrom
BrianSipos:4874-add-bpv7
Open

New BPv7 with working UTS and patched cbor modules to support it#5075
BrianSipos wants to merge 6 commits into
secdev:masterfrom
BrianSipos:4874-add-bpv7

Conversation

@BrianSipos

Copy link
Copy Markdown

Description

Add a BPv7 packet family (bundle, blocks, block-type-specific data) using the new CBOR packet and field modules, and eventually the CRC module.

Fixes #4874 eventually

@BrianSipos

Copy link
Copy Markdown
Author

There seems to be some inconsistency with existing cborfields interface between use of _I internal types and _A CBOR_* class instances. I think it's better to keep with the scapy convention of using the basic python internal types, but right now the CBOR_* classes are used for some "internal" values.

Comment thread scapy/cbor/cborfields.py
# type: (CBOR_Packet) -> bytes
return b"".join(obj.build(pkt) for obj in self.seq)

class CBORF_ARRAY(CBORF_field[List[Any], List[Any]]):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array could be refactored to be a subclass of CBORF_SEQUENCE with the encoded prefix CBOR head.

Comment thread scapy/cbor/cborfields.py
if major_type != 4:
raise CBOR_Decoding_Error(
"Expected major type 4 (array), got %d" % major_type)
if count != len(self.seq):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic on seq does not account for optional or conditional fields not being part of the encoded array.

Comment thread scapy/cbor/cborfields.py
cond, # type: Callable[[Packet], bool]
):
fields.ConditionalField.__init__(self, fld, cond)
# Leave CBORF_field uninitialized

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know a good behavior here because ConditionalField.__getattr__ forwards all names to the sub-field.

Comment thread scapy/contrib/bpv7.py
CBORF_UNSIGNED_INTEGER('block_num', default=None),
CBORF_UNSIGNED_INTEGER('block_flags', default=0), #FIXME FLAGS
CBORF_UNSIGNED_INTEGER('crc_type', default=CrcType.NONE), #FIXME ENUM
CBORF_BYTE_STRING_PACKET('btsd', default=None,

@BrianSipos BrianSipos Aug 6, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is somewhat crude, but I can't find an analogy in other existing protocol definitions. The "btsd" field is the payload of this packet and bound to this layer via the "block_type" field. The nuance is that the payload is not at the end of the encoded bytes. Maybe something like how an Ethernet trailer is handled?

Comment thread scapy/contrib/bpv7.py

CBOR_root = CBORF_INDEFINITE_ARRAY(
CBORF_PACKET('primary', default=PrimaryBlock(), cls=PrimaryBlock),
CBORF_SEQUENCE_OF('blocks', default=[],

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here, the payload of the entire bundle is the btsd field of the block having block_type==1 (and supposed to be the last block in this sequence). Some magic could be added to copy/clone the payload content as a next-layer packet.

Comment thread scapy/contrib/bpv7.py
bind_layers(CanonicalBlock, BundleAgeBlock, type_code=7)
bind_layers(CanonicalBlock, HopCountBlock, type_code=10)

"""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the above strategy seems good, I can update the BPSec handling here to match the pattern.

@BrianSipos
BrianSipos marked this pull request as ready for review August 6, 2026 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[enhancement] Handle CBOR-based protocols in a consistent way

1 participant