bpak 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bpak-1.0.1/.gitattributes +2 -0
- bpak-1.0.1/.gitignore +20 -0
- bpak-1.0.1/CHANGELOG.md +202 -0
- bpak-1.0.1/CMakeLists.txt +67 -0
- bpak-1.0.1/LICENSE +32 -0
- bpak-1.0.1/LICENSES/bsdiff.txt +24 -0
- bpak-1.0.1/LICENSES/heatshrink.txt +14 -0
- bpak-1.0.1/LICENSES/sais-lite.txt +24 -0
- bpak-1.0.1/PKG-INFO +125 -0
- bpak-1.0.1/README.md +95 -0
- bpak-1.0.1/include/bpak/bpak.h +610 -0
- bpak-1.0.1/include/bpak/bsdiff.h +89 -0
- bpak-1.0.1/include/bpak/bspatch.h +140 -0
- bpak-1.0.1/include/bpak/crc.h +26 -0
- bpak-1.0.1/include/bpak/crypto.h +216 -0
- bpak-1.0.1/include/bpak/heatshrink_decoder.h +90 -0
- bpak-1.0.1/include/bpak/id.h +66 -0
- bpak-1.0.1/include/bpak/key.h +40 -0
- bpak-1.0.1/include/bpak/keystore.h +70 -0
- bpak-1.0.1/include/bpak/merkle.h +128 -0
- bpak-1.0.1/include/bpak/pkg.h +270 -0
- bpak-1.0.1/include/bpak/transport.h +175 -0
- bpak-1.0.1/include/bpak/utils.h +92 -0
- bpak-1.0.1/include/bpak/verify.h +96 -0
- bpak-1.0.1/lib/CMakeLists.txt +156 -0
- bpak-1.0.1/lib/bpak.c +502 -0
- bpak-1.0.1/lib/bpak.pc.in +12 -0
- bpak-1.0.1/lib/bsdiff.c +615 -0
- bpak-1.0.1/lib/bspatch.c +493 -0
- bpak-1.0.1/lib/build_config.h.in +15 -0
- bpak-1.0.1/lib/crc.c +113 -0
- bpak-1.0.1/lib/crypto.c +136 -0
- bpak-1.0.1/lib/crypto_mbedtls.c +413 -0
- bpak-1.0.1/lib/crypto_mbedtls.h +27 -0
- bpak-1.0.1/lib/id.c +44 -0
- bpak-1.0.1/lib/internal.h +107 -0
- bpak-1.0.1/lib/keystore.c +29 -0
- bpak-1.0.1/lib/keystore_file.c +110 -0
- bpak-1.0.1/lib/mem.c +46 -0
- bpak-1.0.1/lib/merkle.c +348 -0
- bpak-1.0.1/lib/pkg.c +643 -0
- bpak-1.0.1/lib/pkg_create.c +349 -0
- bpak-1.0.1/lib/pkg_sign.c +100 -0
- bpak-1.0.1/lib/pkg_verify.c +106 -0
- bpak-1.0.1/lib/transport_decode.c +486 -0
- bpak-1.0.1/lib/transport_encode.c +364 -0
- bpak-1.0.1/lib/utils.c +176 -0
- bpak-1.0.1/lib/vendor/heatshrink/heatshrink_decoder.c +377 -0
- bpak-1.0.1/lib/vendor/heatshrink/heatshrink_decoder.h +54 -0
- bpak-1.0.1/lib/vendor/heatshrink/heatshrink_encoder.c +474 -0
- bpak-1.0.1/lib/vendor/heatshrink/heatshrink_encoder.h +91 -0
- bpak-1.0.1/lib/vendor/sais/sais.c +767 -0
- bpak-1.0.1/lib/vendor/sais/sais.h +8 -0
- bpak-1.0.1/lib/verify.c +319 -0
- bpak-1.0.1/lib/version.h.in +10 -0
- bpak-1.0.1/pyproject.toml +128 -0
- bpak-1.0.1/tools/CMakeLists.txt +61 -0
- bpak-1.0.1/tools/_bpak/exceptions.c +118 -0
- bpak-1.0.1/tools/_bpak/meta.c +383 -0
- bpak-1.0.1/tools/_bpak/module.c +419 -0
- bpak-1.0.1/tools/_bpak/module.h +74 -0
- bpak-1.0.1/tools/_bpak/package.c +1051 -0
- bpak-1.0.1/tools/_bpak/part.c +271 -0
- bpak-1.0.1/tools/bpak/__init__.py +13 -0
- bpak-1.0.1/tools/bpak/__main__.py +6 -0
- bpak-1.0.1/tools/bpak/_bpak.pyi +178 -0
- bpak-1.0.1/tools/bpak/cli.py +943 -0
- bpak-1.0.1/tools/bpak/py.typed +0 -0
- bpak-1.0.1/uv.lock +512 -0
- bpak-1.0.1/version.txt +1 -0
bpak-1.0.1/.gitignore
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Build directories, e.g. build/ and build-minimal/
|
|
2
|
+
/build*/
|
|
3
|
+
/dist/
|
|
4
|
+
.venv/
|
|
5
|
+
__pycache__/
|
|
6
|
+
|
|
7
|
+
# Coverage report, see docs/development.md
|
|
8
|
+
/coverage.info
|
|
9
|
+
/coverage_report/
|
|
10
|
+
|
|
11
|
+
# Coverity Scan, see .github/workflows/build.yml
|
|
12
|
+
/cov-int/
|
|
13
|
+
|
|
14
|
+
# Packages created when trying the tool in the repository root
|
|
15
|
+
/*.bpak
|
|
16
|
+
|
|
17
|
+
# Editors
|
|
18
|
+
*~
|
|
19
|
+
*.bak
|
|
20
|
+
tags
|
bpak-1.0.1/CHANGELOG.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Changes that affect users of the library, the python package and the `bpak`
|
|
4
|
+
tool. The package format and the library ABI stay compatible, see
|
|
5
|
+
[Compatibility](docs/development.md#compatibility). The SONAME of the
|
|
6
|
+
shared library follows the major version.
|
|
7
|
+
|
|
8
|
+
## 1.0.1 (2026-11-08)
|
|
9
|
+
|
|
10
|
+
The upload of 1.0.0 to PyPI failed, 1.0.1 is the first release on PyPI.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- `bpak extract` to stdout and `bpak show --binary-hash` exited with 120
|
|
15
|
+
and printed `Exception ignored ... BrokenPipeError` when the reader of the
|
|
16
|
+
output exited, for example in `bpak extract demo.bpak --part fs | head -c
|
|
17
|
+
16`. They exit with 1 without a message, like the other commands.
|
|
18
|
+
|
|
19
|
+
## 1.0.0 (2026-10-29)
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- The python package with the `bpak` tool is published on PyPI,
|
|
24
|
+
`pip install bpak`, with wheels for Linux on x86_64 and aarch64.
|
|
25
|
+
- `bpak set --part-ref` changes meta data that refers to a part, for
|
|
26
|
+
example `pb-load-addr`. `set` could only change meta data without a part
|
|
27
|
+
reference.
|
|
28
|
+
- `bpak_id_to_string` knows `bpak-key-id` and `bpak-key-store`, which
|
|
29
|
+
`bpak show` prints as the names of such meta data.
|
|
30
|
+
- `bpak.transport_encode` and `bpak.transport_decode` accept `origin=None`
|
|
31
|
+
for packages without diff based encoders.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- The SONAME of the shared library is `libbpak.so.1`. The ABI is compatible
|
|
36
|
+
with 0.9, but programs linked against `libbpak.so.0` have to be linked
|
|
37
|
+
again.
|
|
38
|
+
- The `bpak` tool is implemented in python and is part of the `bpak` python
|
|
39
|
+
package, install it with `pip install .` or `uv tool install .`. The C
|
|
40
|
+
implementation in `src/` is removed. Commands and options are unchanged,
|
|
41
|
+
but usage errors exit with 2, and `bpak compare` marks parts that only
|
|
42
|
+
exist in the second package with `+` instead of `-`.
|
|
43
|
+
- The python wrapper is the `bpak` python package, built with
|
|
44
|
+
scikit-build-core and CMake. It links the library statically, requires
|
|
45
|
+
Python 3.10 or later and is typed. It replaces `python/setup.py`.
|
|
46
|
+
- The documentation is Markdown in `docs/`, which replaces Sphinx and Read
|
|
47
|
+
the Docs. The public headers document the complete C API.
|
|
48
|
+
- libuuid is no longer a build dependency.
|
|
49
|
+
- `version.txt` holds the version.
|
|
50
|
+
- The python package declares and ships the licenses of the third-party
|
|
51
|
+
code, see `LICENSES/`.
|
|
52
|
+
- Programs that are compiled with other mbedtls headers than the library
|
|
53
|
+
fail to compile, `struct bpak_hash_context` contains the mbedtls contexts.
|
|
54
|
+
- `bpak_printf` is declared with the `format(printf)` attribute, compilers
|
|
55
|
+
check the arguments of calls to it.
|
|
56
|
+
- `bpak/heatshrink_decoder.h` only defines the decoder state that
|
|
57
|
+
`struct bpak_bspatch_context` embeds. The declarations of the heatshrink
|
|
58
|
+
functions, which the library does not export, and `HEATSHRINK_USE_INDEX`
|
|
59
|
+
are removed.
|
|
60
|
+
- `Part.id`, `Meta.id` and `Meta.part_id_ref` of the python package are
|
|
61
|
+
read-only. Add the part or meta data again to change its id.
|
|
62
|
+
- `Package.digest` raises the error of `Package.update_hash()` instead of
|
|
63
|
+
returning `None`.
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- Merkle tree verification compared only the first byte of the root hash.
|
|
68
|
+
- Verifying a package against a keystore with an RSA key crashed.
|
|
69
|
+
- A patch was not detected when applied to an origin from another package.
|
|
70
|
+
- Opening a file smaller than a header that is not a package wrote a header
|
|
71
|
+
into it.
|
|
72
|
+
- Keystores contained stack memory in the padding after keys.
|
|
73
|
+
- `bpak_bin2hex` and `bpak show` could overflow a buffer.
|
|
74
|
+
- Extracting a transport encoded part truncated it.
|
|
75
|
+
- `bpak transport` used an uninitialized origin without `--origin`.
|
|
76
|
+
- `bpak generate keystore` wrote trailing spaces, and a line with only spaces
|
|
77
|
+
after keys whose size is a multiple of 8, for example secp384r1 keys.
|
|
78
|
+
- `bpak_verify_compute_header_hash` ignored errors.
|
|
79
|
+
- A failed `bpak_add_meta` left a meta data entry in the header, and
|
|
80
|
+
`bpak_pkg_write_raw_signature` could overflow the signature field.
|
|
81
|
+
- Memory leaks when loading keys with mbedtls, and compiler warnings in 32-bit
|
|
82
|
+
builds.
|
|
83
|
+
- A patch with negative lengths in its control data overflowed buffers when
|
|
84
|
+
it was applied, for example with `bpak transport --decode`. Such patches
|
|
85
|
+
fail with `BPAK_SIZE_ERROR`, as do patches that seek before the origin.
|
|
86
|
+
- `bpak_pkg_verify` read past the signature field when the signature size in
|
|
87
|
+
the header was larger than the field, it fails with `BPAK_SIZE_ERROR`.
|
|
88
|
+
- Deleting meta data, for example with `bpak delete --part`, corrupted the
|
|
89
|
+
value of the following meta data when it was larger than the deleted one,
|
|
90
|
+
and with 32 meta data entries it cleared the first part header.
|
|
91
|
+
- `bpak_valid_header` accepted parts and meta data after an empty slot, which
|
|
92
|
+
the lookups find, unaligned meta data, part sizes that overflow and
|
|
93
|
+
signature sizes larger than the signature field. The payload hash and
|
|
94
|
+
transport decoding did not validate the header. Lookups of id 0 found
|
|
95
|
+
empty slots.
|
|
96
|
+
- bspatch computed offsets that overflow `off_t` from large lengths in a
|
|
97
|
+
patch, such patches fail with `BPAK_SIZE_ERROR`.
|
|
98
|
+
- Transport decoding wrote past the part that it decoded and read past the
|
|
99
|
+
origin part when the patch, the copied data or the merkle hash tree was
|
|
100
|
+
larger than the part.
|
|
101
|
+
- `bpak_calloc`, `bpak_free` and `bpak_transport_encode` were declared in
|
|
102
|
+
the public headers but not exported by the shared library.
|
|
103
|
+
- With an allocator from `bpak_set_calloc_free`, the lzma encoder and
|
|
104
|
+
decoder freed memory from `malloc` with it. The lzma decoder may use at
|
|
105
|
+
most 64 MiB (`BPAK_BSPATCH_LZMA_MEMLIMIT`), it had no limit.
|
|
106
|
+
- `bpak_pkg_add_key` and the python package freed keys with `free` instead
|
|
107
|
+
of `bpak_free`.
|
|
108
|
+
- `bpak_meta_to_string` did not terminate a `bpak-version` that filled the
|
|
109
|
+
buffer, left the buffer uninitialized when it was too small for a hash and
|
|
110
|
+
read the values of known meta data regardless of their size. `bpak show`
|
|
111
|
+
prints `<invalid>` for values that are too small for their type.
|
|
112
|
+
- Transport decoding compares the merkle root hash of a generated hash tree
|
|
113
|
+
with `merkle-root-hash` and fails with `BPAK_BAD_ROOT_HASH`, and the sizes
|
|
114
|
+
of the merkle salt and root hash are checked. `bpak transport --decode`
|
|
115
|
+
printed the offset of the merkle tree.
|
|
116
|
+
- `bpak_merkle_init` rejected data of 8 GiB to 1 TiB, which
|
|
117
|
+
`bpak_merkle_compute_size` accepts, so adding such a file with
|
|
118
|
+
`--encoder merkle` crashed. Earlier versions can not verify these
|
|
119
|
+
packages. `bpak_merkle_write_chunk` wrote past the hash tree when it got
|
|
120
|
+
more data than the tree was created for, it fails with `BPAK_SIZE_ERROR`.
|
|
121
|
+
- Every package created with `--encoder merkle` had the same merkle salt,
|
|
122
|
+
it came from `random()`, which was never seeded.
|
|
123
|
+
- Transport decoding leaked the lzma decoder when a patch failed in the
|
|
124
|
+
middle of a part, `bpak_transport_decode_free` frees it now.
|
|
125
|
+
- Adding a part: a file that could not be read, for example a directory,
|
|
126
|
+
or that changed size made `bpak_pkg_add_file` loop forever, a part added
|
|
127
|
+
after a transport encoded part was written at the wrong offset, and a
|
|
128
|
+
failed add left the part in the package. `bpak add --encoder merkle`
|
|
129
|
+
computed the hash tree from the file instead of the added data, which
|
|
130
|
+
overflowed a buffer when the file grew.
|
|
131
|
+
- Deleting a part looped forever when the file had data after the last part
|
|
132
|
+
or ended before it, moved the offsets of the following parts by the
|
|
133
|
+
transport size of a transport encoded part, and left the in-memory
|
|
134
|
+
header changed when it failed. A failed `bpak_pkg_open` left the closed
|
|
135
|
+
file in the package, and `filename` was never set.
|
|
136
|
+
- `BPAK_DECLARE_STATIC_KEY` stored the key in a byte array, which is not
|
|
137
|
+
aligned for `struct bpak_key`.
|
|
138
|
+
- The mbedtls backend ignored the results of the hash functions and of
|
|
139
|
+
parsing key files, did not check an allocation when it loaded a public
|
|
140
|
+
key, leaked the key when verification could not parse it and left the
|
|
141
|
+
private key in a stack buffer.
|
|
142
|
+
- `bpak_pkg_sign` signed directly into the header, a failure left it with a
|
|
143
|
+
cleared signature, and the private key was not cleared before it was
|
|
144
|
+
freed. It sets the signature kind of the header to the kind of the key,
|
|
145
|
+
which was not checked.
|
|
146
|
+
- `bpak_keystore_load_key_from_file` verifies the payload hash of the
|
|
147
|
+
keystore and fails with `BPAK_BAD_PAYLOAD_HASH` when it is corrupted, it
|
|
148
|
+
read `keystore-provider-id` regardless of its size, and returns
|
|
149
|
+
`BPAK_KEY_NOT_FOUND` instead of `BPAK_NOT_FOUND` when the keystore does
|
|
150
|
+
not contain the key. `bpak verify --keystore` exits with the code of
|
|
151
|
+
`BPAK_KEY_NOT_FOUND` (228) for an unknown key instead of 254.
|
|
152
|
+
- File offsets were passed to `fseek` as `long`, packages larger than 2 GiB
|
|
153
|
+
did not work on targets with a 32-bit `long`. Programs that are compiled
|
|
154
|
+
with another size of `off_t` than the library fail to compile, see
|
|
155
|
+
[the C library](docs/c-library.md), and `bpak/bpak.h` compiles with
|
|
156
|
+
`-std=c99`.
|
|
157
|
+
- The static library defined the functions of heatshrink and sais without a
|
|
158
|
+
prefix, which clashed with programs that use heatshrink themselves.
|
|
159
|
+
- `bpak_pkg_size` and `bpak_pkg_installed_size` wrapped around when the size
|
|
160
|
+
does not fit `size_t`, they return `SIZE_MAX`.
|
|
161
|
+
- `bpak_pkg_transport_decode` and `bpak.transport_decode` cleared the
|
|
162
|
+
transport flags in the header of the input package instead of the output
|
|
163
|
+
package, so the input package reported the wrong sizes, and the output
|
|
164
|
+
package kept the header it was opened with until it was opened again.
|
|
165
|
+
- bsdiff truncated the length of matches to 32 bits, a match longer than
|
|
166
|
+
2 GiB made `bpak transport --encode` scan backwards.
|
|
167
|
+
- `bpak_pkg_delete_part`, and with it `bpak delete --part` and
|
|
168
|
+
`Package.delete_part`, left the `<part>-hash-tree` part of a part added
|
|
169
|
+
with a merkle hash tree in the package. It deletes the hash tree part as
|
|
170
|
+
well.
|
|
171
|
+
- `bpak_transport_encode`, and with it `bpak transport --encode --origin`,
|
|
172
|
+
crashed when the origin or the input package had no `bpak-package` meta
|
|
173
|
+
data, and read past a `bpak-package` that is smaller than a UUID. It fails
|
|
174
|
+
with `BPAK_NOT_FOUND` and `BPAK_SIZE_ERROR` like transport decoding.
|
|
175
|
+
- Log messages of the library used printf formats that do not match their
|
|
176
|
+
arguments, they printed wrong values, for example in 32-bit builds.
|
|
177
|
+
- The public headers were not installed when the library is built as a
|
|
178
|
+
CMake subproject with `add_subdirectory`.
|
|
179
|
+
- `bpak/key.h` did not compile unless `bpak/bpak.h` was included first.
|
|
180
|
+
- `bpak_transport_encode` returned -1 instead of an error code when a seek
|
|
181
|
+
or the header write failed and for an unknown encoder, which is
|
|
182
|
+
`BPAK_NOT_SUPPORTED` now: `bpak transport --encode` exits with 249 instead
|
|
183
|
+
of 255 for an encoder that `bpak transport --add` added but that does not
|
|
184
|
+
exist.
|
|
185
|
+
- Python package: crashes when opening a file that is not a package, when
|
|
186
|
+
using a closed package and after the log callback was released, reference
|
|
187
|
+
leaks in `Package.parts` and `Package.meta`, meta data larger than the
|
|
188
|
+
meta data area overflowed the header, empty parts could not be read, and
|
|
189
|
+
short reads, errors in the log function and failed header writes when
|
|
190
|
+
clearing the signature were not reported.
|
|
191
|
+
- `bpak` tool: `delete --all --part`, file errors printed a traceback, file
|
|
192
|
+
names that are not UTF-8.
|
|
193
|
+
- Python package: deleting an int attribute, for example `del pkg.key_id`,
|
|
194
|
+
crashed, and values that do not fit the field were truncated,
|
|
195
|
+
`pkg.hash_kind = 256` stored 0. Such values raise `OverflowError` and
|
|
196
|
+
deleting an attribute raises `TypeError`.
|
|
197
|
+
- Python package: `Package.sign()` reported argument errors as `verify()`,
|
|
198
|
+
`Meta.as_uuid()` did not check that the `uuid` module has `UUID`, and the
|
|
199
|
+
docstring of `Package.meta` described the parts.
|
|
200
|
+
- Python package: ids from `0x80000000` and sizes from 2 GiB were negative
|
|
201
|
+
or wrong on targets with a 32-bit `long`, and `repr()` of a part passed
|
|
202
|
+
its size as `int`.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.10)
|
|
2
|
+
|
|
3
|
+
# version.txt is the single source of the project version
|
|
4
|
+
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" BPAK_VERSION LIMIT_COUNT 1)
|
|
5
|
+
|
|
6
|
+
if (NOT BPAK_VERSION MATCHES "^[0-9]+\\.[0-9]+\\.[0-9]+$")
|
|
7
|
+
message(FATAL_ERROR
|
|
8
|
+
"version.txt must contain MAJOR.MINOR.PATCH, got '${BPAK_VERSION}'")
|
|
9
|
+
endif()
|
|
10
|
+
|
|
11
|
+
# Re-run cmake when the version changes
|
|
12
|
+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS version.txt)
|
|
13
|
+
|
|
14
|
+
project(bpak VERSION ${BPAK_VERSION}
|
|
15
|
+
DESCRIPTION BitPacker
|
|
16
|
+
HOMEPAGE_URL https://github.com/jonasblixt/bpak
|
|
17
|
+
LANGUAGES C
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
enable_testing()
|
|
21
|
+
set(CMAKE_C_STANDARD 99)
|
|
22
|
+
|
|
23
|
+
option(BPAK_BUILD_MINIMAL "Build a minimal version of the library" OFF)
|
|
24
|
+
option(BPAK_BUILD_TESTS "Build test cases" OFF)
|
|
25
|
+
option(BPAK_WERROR "Treat compiler warnings as errors" ON)
|
|
26
|
+
option(BPAK_BUILD_FUZZERS "Build the libFuzzer targets, requires clang" OFF)
|
|
27
|
+
|
|
28
|
+
add_compile_options(-Wall)
|
|
29
|
+
if (BPAK_WERROR)
|
|
30
|
+
add_compile_options(-Werror)
|
|
31
|
+
endif()
|
|
32
|
+
|
|
33
|
+
if (NOT BPAK_BUILD_MINIMAL)
|
|
34
|
+
set(BPAK_CONFIG_MERKLE 1)
|
|
35
|
+
set(BPAK_CONFIG_LZMA 1)
|
|
36
|
+
set(BPAK_CONFIG_MBEDTLS 1)
|
|
37
|
+
find_library(MBEDCRYPTO_LIBRARY mbedcrypto REQUIRED)
|
|
38
|
+
find_library(LZMA_LIBRARY lzma REQUIRED)
|
|
39
|
+
else()
|
|
40
|
+
set(BPAK_CONFIG_MBEDTLS 0)
|
|
41
|
+
set(BPAK_CONFIG_LZMA 0)
|
|
42
|
+
set(BPAK_CONFIG_MERKLE 0)
|
|
43
|
+
endif()
|
|
44
|
+
|
|
45
|
+
add_subdirectory("lib")
|
|
46
|
+
|
|
47
|
+
# Test builds and python package builds with scikit-build-core, see
|
|
48
|
+
# pyproject.toml, build the C extension
|
|
49
|
+
if (BPAK_BUILD_TESTS OR SKBUILD)
|
|
50
|
+
add_subdirectory("tools")
|
|
51
|
+
endif()
|
|
52
|
+
|
|
53
|
+
if (BPAK_BUILD_TESTS)
|
|
54
|
+
# Python for the examples and the tests, tools/ finds it with the
|
|
55
|
+
# components that the C extension needs
|
|
56
|
+
find_package(Python 3.10 REQUIRED COMPONENTS Interpreter)
|
|
57
|
+
add_subdirectory("examples")
|
|
58
|
+
add_subdirectory("test")
|
|
59
|
+
endif()
|
|
60
|
+
|
|
61
|
+
# The fuzz targets, and their corpus as tests in test builds
|
|
62
|
+
if (BPAK_BUILD_TESTS OR BPAK_BUILD_FUZZERS)
|
|
63
|
+
if (BPAK_BUILD_MINIMAL)
|
|
64
|
+
message(FATAL_ERROR "BPAK_BUILD_FUZZERS requires BPAK_BUILD_MINIMAL=OFF")
|
|
65
|
+
endif()
|
|
66
|
+
add_subdirectory("test/fuzz")
|
|
67
|
+
endif()
|
bpak-1.0.1/LICENSE
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Bit Packer
|
|
2
|
+
|
|
3
|
+
SPDX-License-Identifier: BSD-3-Clause
|
|
4
|
+
|
|
5
|
+
Copyright 2019, Jonas Blixt <jonpe960@gmail.com>
|
|
6
|
+
|
|
7
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
8
|
+
are permitted provided that the following conditions are met:
|
|
9
|
+
|
|
10
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer.
|
|
12
|
+
|
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
18
|
+
may be used to endorse or promote products derived from this software
|
|
19
|
+
without specific prior written permission.
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
23
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
24
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
25
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
26
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
27
|
+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
28
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
29
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
30
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
31
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
32
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Copyright 2003-2005 Colin Percival
|
|
2
|
+
Copyright 2012 Matthew Endsley
|
|
3
|
+
All rights reserved
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted providing that the following conditions
|
|
7
|
+
are met:
|
|
8
|
+
1. Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
documentation and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
15
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
16
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
17
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
18
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
20
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
21
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
22
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
23
|
+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
24
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Copyright (c) 2013-2015, Scott Vokes <vokes.s@gmail.com>
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
6
|
+
copyright notice and this permission notice appear in all copies.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
9
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
10
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
11
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
12
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
13
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
14
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
sais.c for sais-lite
|
|
2
|
+
Copyright (c) 2008-2010 Yuta Mori All Rights Reserved.
|
|
3
|
+
Copyright (c) 2019, Erik Moqvist (Python wrapper).
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
|
6
|
+
obtaining a copy of this software and associated documentation
|
|
7
|
+
files (the "Software"), to deal in the Software without
|
|
8
|
+
restriction, including without limitation the rights to use,
|
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the
|
|
11
|
+
Software is furnished to do so, subject to the following
|
|
12
|
+
conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
19
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
24
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
bpak-1.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bpak
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Bitpacker, a tool and library for signed firmware archives
|
|
5
|
+
Author-Email: Jonas Blixt <jonpe960@gmail.com>
|
|
6
|
+
License-Expression: BSD-3-Clause AND BSD-2-Clause AND ISC AND MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
License-File: LICENSES/bsdiff.txt
|
|
9
|
+
License-File: LICENSES/heatshrink.txt
|
|
10
|
+
License-File: LICENSES/sais-lite.txt
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Embedded Systems
|
|
14
|
+
Classifier: Programming Language :: C
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Project-URL: Homepage, https://github.com/jonasblixt/bpak
|
|
25
|
+
Project-URL: Documentation, https://github.com/jonasblixt/bpak/tree/master/docs
|
|
26
|
+
Project-URL: Issues, https://github.com/jonasblixt/bpak/issues
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
|
+
Requires-Dist: click<9,>=8.1
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
<img src="https://raw.githubusercontent.com/jonasblixt/bpak/master/docs/bitpacker.svg" width="60" alt="bitpacker logo">
|
|
32
|
+
|
|
33
|
+
# Bitpacker
|
|
34
|
+
|
|
35
|
+
[](https://github.com/jonasblixt/bpak/actions/workflows/build.yml)
|
|
36
|
+
[](https://scan.coverity.com/projects/jonasblixt-bpak)
|
|
37
|
+
|
|
38
|
+
Bitpacker, or bpak, is a C library, a python package and a command line tool
|
|
39
|
+
for signed firmware packages, primarily for embedded systems.
|
|
40
|
+
|
|
41
|
+
An embedded system is often composed of several software components: a
|
|
42
|
+
bootloader, a kernel, file systems, device configuration and applications,
|
|
43
|
+
each with its own format and tools. A bpak package holds all of them as parts,
|
|
44
|
+
together with meta data, in a format that a bootloader can verify:
|
|
45
|
+
|
|
46
|
+
- **Signed packages.** ECDSA (P-256, P-384, P-521) or RSA 4096 signatures
|
|
47
|
+
over a sha256, sha384 or sha512 hash. Packages can be signed with keys on
|
|
48
|
+
disk during development, and release candidates can be signed again by an
|
|
49
|
+
external signing service or HSM without being rebuilt.
|
|
50
|
+
- **Meta data.** Package type and version, load addresses or any
|
|
51
|
+
application specific data, protected by the signature.
|
|
52
|
+
- **dm-verity.** Merkle hash trees for file system images, compatible with
|
|
53
|
+
the Linux dm-verity device mapper target.
|
|
54
|
+
- **Small updates.** Packages can be transport encoded with binary diffs
|
|
55
|
+
against the installed version. The device decodes the update as it is
|
|
56
|
+
received and gets a package that is identical to the original, signature
|
|
57
|
+
included.
|
|
58
|
+
- **Keystores.** Sets of public keys in a package, which can be compiled into
|
|
59
|
+
a bootloader or loaded at runtime to extend the root of trust.
|
|
60
|
+
|
|
61
|
+
The library is small and depends neither on a file system nor on a
|
|
62
|
+
particular crypto library, which makes it suitable for bootloaders, for
|
|
63
|
+
example [punchboot](https://github.com/jonasblixt/punchboot).
|
|
64
|
+
|
|
65
|
+
bpak is not a package manager. It provides the package format and the
|
|
66
|
+
primitives to verify and update packages. How packages are installed is up
|
|
67
|
+
to the system that uses them.
|
|
68
|
+
|
|
69
|
+
## Installation
|
|
70
|
+
|
|
71
|
+
The `bpak` tool is part of the bpak python package on
|
|
72
|
+
[PyPI](https://pypi.org/project/bpak). Install it with
|
|
73
|
+
[uv](https://docs.astral.sh/uv), which puts it in an isolated environment,
|
|
74
|
+
or with pip:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
$ uv tool install bpak
|
|
78
|
+
$ pip install bpak
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The package includes the library and requires Python 3.10 or later. There
|
|
82
|
+
are wheels for Linux on x86_64 and aarch64. On other platforms, and when
|
|
83
|
+
installed from the repository root with `pip install .`, the package is built
|
|
84
|
+
with CMake, which needs a C compiler and the mbedtls and liblzma development
|
|
85
|
+
packages, for example `libmbedtls-dev` and `liblzma-dev` on Debian and
|
|
86
|
+
Ubuntu.
|
|
87
|
+
|
|
88
|
+
Build and install the C library:
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
$ cmake -B build
|
|
92
|
+
$ cmake --build build
|
|
93
|
+
$ sudo cmake --install build
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Example
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
$ bpak create demo.bpak
|
|
100
|
+
$ bpak add demo.bpak --meta bpak-version --from-string 1.0.0
|
|
101
|
+
$ bpak add demo.bpak --part kernel --from-file kernel.bin
|
|
102
|
+
$ bpak sign demo.bpak --key prime256v1-key-pair.pem
|
|
103
|
+
$ bpak verify demo.bpak --key prime256v1-public-key.der
|
|
104
|
+
Verification OK
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Documentation
|
|
108
|
+
|
|
109
|
+
- [User guide](https://github.com/jonasblixt/bpak/blob/master/docs/user-guide.md): the `bpak` tool, step by step
|
|
110
|
+
- [Package format](https://github.com/jonasblixt/bpak/blob/master/docs/format.md): parts, meta data, ids, signing and
|
|
111
|
+
transport encoding
|
|
112
|
+
- [C library](https://github.com/jonasblixt/bpak/blob/master/docs/c-library.md): architecture, building and using the
|
|
113
|
+
library
|
|
114
|
+
- [Python package](https://github.com/jonasblixt/bpak/blob/master/docs/python.md): the python API
|
|
115
|
+
- [Development](https://github.com/jonasblixt/bpak/blob/master/docs/development.md): building, testing and contributing
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
BSD-3-Clause, see [LICENSE](https://github.com/jonasblixt/bpak/blob/master/LICENSE). The library includes third-party code
|
|
120
|
+
under other licenses, see [LICENSES](https://github.com/jonasblixt/bpak/tree/master/LICENSES):
|
|
121
|
+
|
|
122
|
+
- binary diff and patch (`lib/bsdiff.c`, `lib/bspatch.c`), based on bsdiff
|
|
123
|
+
by Colin Percival and Matthew Endsley: BSD-2-Clause
|
|
124
|
+
- heatshrink compression by Scott Vokes (`lib/vendor/heatshrink`): ISC
|
|
125
|
+
- sais-lite suffix array construction by Yuta Mori (`lib/vendor/sais`): MIT
|
bpak-1.0.1/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<img src="https://raw.githubusercontent.com/jonasblixt/bpak/master/docs/bitpacker.svg" width="60" alt="bitpacker logo">
|
|
2
|
+
|
|
3
|
+
# Bitpacker
|
|
4
|
+
|
|
5
|
+
[](https://github.com/jonasblixt/bpak/actions/workflows/build.yml)
|
|
6
|
+
[](https://scan.coverity.com/projects/jonasblixt-bpak)
|
|
7
|
+
|
|
8
|
+
Bitpacker, or bpak, is a C library, a python package and a command line tool
|
|
9
|
+
for signed firmware packages, primarily for embedded systems.
|
|
10
|
+
|
|
11
|
+
An embedded system is often composed of several software components: a
|
|
12
|
+
bootloader, a kernel, file systems, device configuration and applications,
|
|
13
|
+
each with its own format and tools. A bpak package holds all of them as parts,
|
|
14
|
+
together with meta data, in a format that a bootloader can verify:
|
|
15
|
+
|
|
16
|
+
- **Signed packages.** ECDSA (P-256, P-384, P-521) or RSA 4096 signatures
|
|
17
|
+
over a sha256, sha384 or sha512 hash. Packages can be signed with keys on
|
|
18
|
+
disk during development, and release candidates can be signed again by an
|
|
19
|
+
external signing service or HSM without being rebuilt.
|
|
20
|
+
- **Meta data.** Package type and version, load addresses or any
|
|
21
|
+
application specific data, protected by the signature.
|
|
22
|
+
- **dm-verity.** Merkle hash trees for file system images, compatible with
|
|
23
|
+
the Linux dm-verity device mapper target.
|
|
24
|
+
- **Small updates.** Packages can be transport encoded with binary diffs
|
|
25
|
+
against the installed version. The device decodes the update as it is
|
|
26
|
+
received and gets a package that is identical to the original, signature
|
|
27
|
+
included.
|
|
28
|
+
- **Keystores.** Sets of public keys in a package, which can be compiled into
|
|
29
|
+
a bootloader or loaded at runtime to extend the root of trust.
|
|
30
|
+
|
|
31
|
+
The library is small and depends neither on a file system nor on a
|
|
32
|
+
particular crypto library, which makes it suitable for bootloaders, for
|
|
33
|
+
example [punchboot](https://github.com/jonasblixt/punchboot).
|
|
34
|
+
|
|
35
|
+
bpak is not a package manager. It provides the package format and the
|
|
36
|
+
primitives to verify and update packages. How packages are installed is up
|
|
37
|
+
to the system that uses them.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
The `bpak` tool is part of the bpak python package on
|
|
42
|
+
[PyPI](https://pypi.org/project/bpak). Install it with
|
|
43
|
+
[uv](https://docs.astral.sh/uv), which puts it in an isolated environment,
|
|
44
|
+
or with pip:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
$ uv tool install bpak
|
|
48
|
+
$ pip install bpak
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The package includes the library and requires Python 3.10 or later. There
|
|
52
|
+
are wheels for Linux on x86_64 and aarch64. On other platforms, and when
|
|
53
|
+
installed from the repository root with `pip install .`, the package is built
|
|
54
|
+
with CMake, which needs a C compiler and the mbedtls and liblzma development
|
|
55
|
+
packages, for example `libmbedtls-dev` and `liblzma-dev` on Debian and
|
|
56
|
+
Ubuntu.
|
|
57
|
+
|
|
58
|
+
Build and install the C library:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
$ cmake -B build
|
|
62
|
+
$ cmake --build build
|
|
63
|
+
$ sudo cmake --install build
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Example
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
$ bpak create demo.bpak
|
|
70
|
+
$ bpak add demo.bpak --meta bpak-version --from-string 1.0.0
|
|
71
|
+
$ bpak add demo.bpak --part kernel --from-file kernel.bin
|
|
72
|
+
$ bpak sign demo.bpak --key prime256v1-key-pair.pem
|
|
73
|
+
$ bpak verify demo.bpak --key prime256v1-public-key.der
|
|
74
|
+
Verification OK
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Documentation
|
|
78
|
+
|
|
79
|
+
- [User guide](https://github.com/jonasblixt/bpak/blob/master/docs/user-guide.md): the `bpak` tool, step by step
|
|
80
|
+
- [Package format](https://github.com/jonasblixt/bpak/blob/master/docs/format.md): parts, meta data, ids, signing and
|
|
81
|
+
transport encoding
|
|
82
|
+
- [C library](https://github.com/jonasblixt/bpak/blob/master/docs/c-library.md): architecture, building and using the
|
|
83
|
+
library
|
|
84
|
+
- [Python package](https://github.com/jonasblixt/bpak/blob/master/docs/python.md): the python API
|
|
85
|
+
- [Development](https://github.com/jonasblixt/bpak/blob/master/docs/development.md): building, testing and contributing
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
BSD-3-Clause, see [LICENSE](https://github.com/jonasblixt/bpak/blob/master/LICENSE). The library includes third-party code
|
|
90
|
+
under other licenses, see [LICENSES](https://github.com/jonasblixt/bpak/tree/master/LICENSES):
|
|
91
|
+
|
|
92
|
+
- binary diff and patch (`lib/bsdiff.c`, `lib/bspatch.c`), based on bsdiff
|
|
93
|
+
by Colin Percival and Matthew Endsley: BSD-2-Clause
|
|
94
|
+
- heatshrink compression by Scott Vokes (`lib/vendor/heatshrink`): ISC
|
|
95
|
+
- sais-lite suffix array construction by Yuta Mori (`lib/vendor/sais`): MIT
|