Commit Graph

701 Commits

Author SHA1 Message Date
Andrew Gunnerson b2d280eb20 CHANGELOG.md: Add entry for PR #430
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-03-13 20:23:48 -04:00
Andrew Gunnerson e2dc5174b4 format/ota: Decouple OTA signature parsing from verification
This way, we can fail hard for parsing errors, but not for verification
errors in `avbroot ota verify`.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-03-13 20:22:16 -04:00
Andrew Gunnerson 80c47e9a02 CHANGELOG.md: Add entry for PR #429
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-03-13 19:49:54 -04:00
Andrew Gunnerson 65ba3ad5cc Fix clippy 1.85 warnings
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-03-13 19:48:32 -04:00
Andrew Gunnerson a7438876ce CHANGELOG.md: Add entry for PR #428
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-03-13 19:38:16 -04:00
Andrew Gunnerson c039901a85 cli/ota: Improve ota verify otacerts.zip handling
* Try to avoid fail-fast behavior to show as many errors as possible.
  Parsing errors always fail immediately, but verification errors don't.
* Move the recovery otacerts.zip check to the end to let more important
  checks run first.
* Improve error message when otacerts.zip does not contain the signing
  certificate for the OTA to make it clear the issue is not that the zip
  contains no certificates at all.
* Always run the recovery otacerts.zip check, but just log the error as
  a warning when running with --skip-recovery-ota-cert.
* Fix unformatted error context string when parsing a boot image's
  otacerts.zip file fails.

Discussion: #426

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-03-13 19:34:42 -04:00
Andrew Gunnerson 0cdc7172dd Version 3.13.0
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
v3.13.0
2025-03-12 18:39:59 -04:00
Andrew Gunnerson 1296275418 CHANGELOG.md: Add entry for PR #427
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-03-12 18:38:43 -04:00
Andrew Gunnerson a62d0a5c91 Update dependencies
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-03-12 18:25:35 -04:00
Andrew Gunnerson de433a2724 README.md: Clarify what --skip-{system,recovery}-ota-cert affects
Discussion: #426

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-03-12 18:07:17 -04:00
Andrew Gunnerson c08af33343 CHANGELOG.md: Add entry for PR #425
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-24 21:17:44 -05:00
Andrew Gunnerson e224884591 format/lp: Relax validation checks to parse on-device super partition
There are two documented behaviors in liblp that are violated with the
on-disk super partition layout after a virtual A/B CoW merge:

1. The partition name includes a `-` due to the `-cow` suffix. This is
   not meant to be a valid character.
2. The extent list is likely to have many gaps and not be sorted. The
   format documentation says that gaps are not allowed.

This commit updates avbroot's LP parser to be less strict so that it can
load real on-device super partitions. The extent allocator for the
`pack` subcommand remains unchanged though, so avbroot will always
produce LP images with sorted, gapless extents.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-24 21:05:28 -05:00
Andrew Gunnerson a525fc4550 CHANGELOG.md: Add entry for PR #424
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-21 21:34:30 -05:00
Andrew Gunnerson 8c6b0fdfc5 cli/ota: Discard unmodified system image temp file earlier
This is the same optimization as is currently done for boot images.
There's no reason to keep the temp file around for the entire patching
process if it's unmodified and we're not going to be copying its data
into the payload.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-21 21:23:10 -05:00
Andrew Gunnerson 36d4ed19ad CHANGELOG.md: Add entry for PR #423
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-21 21:18:12 -05:00
Andrew Gunnerson f9b06b33e6 cli/ota: Fix incorrect unprotected partition warning with --skip-system-ota-cert
The filtering out of partitions was done at the wrong scope, causing
avbroot to warn that extracted-but-unmodified partitions were not
protected by AVB. We never encountered this before because the system
image was always patched and unmodified boot images got filtered out at
an earlier phase during patching.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-21 21:00:59 -05:00
Andrew Gunnerson 620c873be5 CHANGELOG.md: Add entry for PR #422
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-21 21:00:20 -05:00
Andrew Gunnerson e929ecbe44 Replace ring with aws-lc
The author of ring recently announced that the library is no longer
being maintained and fixes for security issues may be significantly
delayed. Big thanks to Brian Smith for creating and maintaining the
library for so long!

This commit replaces ring with aws-lc, a cryptography library maintained
by Amazon AWS. It seems to be well-regarded and is used by high-profile
projects like rustls. It is also API-compatible with ring, so it is
effectively a drop-in replacement.

Unfortunately, we still cannot switch back to the RustCrypto SHA1 and
SHA2 implementations because they are still significantly slower than
ring and aws-lc on systems that do not support the SHA-NI extensions.

https://rustsec.org/advisories/RUSTSEC-2025-0007

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-21 20:44:19 -05:00
Andrew Gunnerson 31685713ef CHANGELOG.md: Add entry for PR #421
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-21 19:33:58 -05:00
Andrew Gunnerson 0dab7aa32c Switch to stable bzip2-rs release and use zlib-rs flate2 backend
* There is now a stable release of bzip2-rs with the fix for both the C
  and Rust versions of bzip2 being compiled.

* The zlib-rs deflate implementation is faster than the default
  miniz_oxide. Changing this requires updating the checksums in the e2e
  tests due to slight differences in compression levels between the two
  implementations.

* Temporarily silence RUSTSEC-2025-0007 to avoid blocking CI. The ring
  library is no longer maintained.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-21 19:27:18 -05:00
Ivan ba6c1b1400 README.ru.md: update translation
* https://github.com/chenxiaolong/avbroot/commit/c198646c7c9b3eb8013dca43df6df8502e619e3c
* https://github.com/chenxiaolong/avbroot/commit/d4eb231dd49e7e6c7320135785cde7cd57634a50
* https://github.com/chenxiaolong/avbroot/commit/1484cd47c354197e1179a554f9f001020297aac8
* https://github.com/chenxiaolong/avbroot/commit/84fa6c6bc63b62d1b3b96dcb50b18b13dea0076f

Signed-off-by: Ivan <reddxae@proton.me>
2025-02-11 14:20:11 +03:00
Andrew Gunnerson 1ecbf1144d CHANGELOG.md: Add entry for PR #418
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-09 21:59:13 -05:00
Andrew Gunnerson 84fa6c6bc6 Add option to skip replacing OTA cert in system image
This is analogous to the existing --skip-recovery-ota-cert option,
except for the system image.

Discussion: #417

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-09 21:42:18 -05:00
Andrew Gunnerson 15b7db4631 CHANGELOG.md: Add entry for PR #415
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-04 00:16:38 -05:00
Andrew Gunnerson 1d9c1574da lp: Stop checking for zeroed first block
AOSP says that for non-empty images, the first 4 KiB block is supposed
to be filled with zeros to prevent it from being interpreted as an old
BIOS boot sector. The previous implementation relied on that to
distinguish between empty and non-empty images. However, Samsung decided
to use this region for their own SignerVer02 structure, so the heuristic
doesn't work.

AOSP's liblp tries to parse the input file as an empty image before
falling back to parsing as a normal image. We'll do the same.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-02-04 00:13:27 -05:00
Andrew Gunnerson 43db728b9d Version 3.12.0
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
v3.12.0
2025-01-26 18:20:06 -05:00
Andrew Gunnerson fbe9f629ab CHANGELOG.md: Add entry for PR #411
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-01-26 18:11:40 -05:00
Andrew Gunnerson 80d5f19223 Update dependencies
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-01-26 18:10:42 -05:00
Andrew Gunnerson cff5ac6b2e CHANGELOG.md: Add entry for PR #410
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-01-26 18:04:35 -05:00
Andrew Gunnerson 2e3b5db9fe cli/key: Rename extract-avb to encode-avb
For consistency with decode-avb. The old syntax will remain supported
indefinitely for backwards compatibility.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-01-26 18:01:24 -05:00
Andrew Gunnerson 58a279f3a4 CHANGELOG.md: Add entry for PR #409
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-01-26 17:53:08 -05:00
Andrew Gunnerson 1484cd47c3 cli/ota: Add support for extracting OTA certificate and AVB public key
This also adds a new --none option so that these two components can be
extracted without extracting any partition images.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-01-26 17:50:09 -05:00
Andrew Gunnerson 2ee38b716b CHANGELOG.md: Add entry for PR #408
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-01-26 16:48:08 -05:00
Andrew Gunnerson d4eb231dd4 cli/ota: Add support for extracting specific images
Previously, we only supported extracting all images or the subset of
images that could potentially be patched by avbroot. This was
unnecessarily slow if the user only needed to extract a specific image.

This commit also deprecates and hides the `--boot-only` option, though
the functionality will remain indefinitely.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2025-01-26 16:43:35 -05:00
Andrew Gunnerson cf064e145d Version 3.11.0
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
v3.11.0
2024-12-25 20:05:57 -05:00
Andrew Gunnerson 3b0c97a93d CHANGELOG.md: Add entry for PR #404
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-25 20:05:30 -05:00
Andrew Gunnerson 2d4f08f48b Update dependencies
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-25 19:56:02 -05:00
Andrew Gunnerson a753304dff CHANGELOG.md: Add entry for PR #403
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-25 19:39:42 -05:00
Andrew Gunnerson 9480e2ffa4 cpio: Read and write entire header at once
Avoids doing 14 small reads per cpio entry.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-25 19:37:58 -05:00
Andrew Gunnerson 140d0ddd8b CHANGELOG.md: Add entry for PR #402
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-25 15:08:11 -05:00
Andrew Gunnerson e0b114cf71 Switch to upstream master branch of bzip2-rs
The only remaining fix from our fork has been merged. This can be
switched to a stable release after the next release.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-25 14:59:44 -05:00
Andrew Gunnerson 78449f686d CHANGELOG.md: Add entry for PR #401
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-25 14:54:51 -05:00
Andrew Gunnerson a2fb807803 Remove all uses of implicit error propagation
Implicit error propagation was originally used because it was convenient
and made it easy to just bubble up errors via the ? operator without
thinking. However, there have been too many situations where this
resulted in error messages that were completely useless in
troubleshooting the problem. "I/O error", even with a specific reason
attached, is useless where there are potentially hundreds of operations
where I/O can fail.

I no longer think implicit error propagation is a good idea, so this
commit removes every single use of #[from] in every custom error type.
There are now many more error variants, allowing more context to be
attached to the underlying errors.

Previously, it was easy to encounter error messages like:

    Caused by:
        0: Failed to patch payload: payload.bin
        1: Failed to patch boot images: boot, init_boot, vendor_boot
        2: Boot image error
        3: I/O error
        4: failed to fill whole buffer

This is a terrible error message because it doesn't mention which of the
3 boot images failed to parse, nor does it mention during which I/O
operation it encountered EOF. With this commit, this sort of information
is now included. For example, if the boot image happened to be truncated
in the middle of the ramdisk, the error message would now be:

    Caused by:
        0: Failed to patch payload: payload.bin
        1: Failed to patch boot images: boot, init_boot, vendor_boot
        2: Failed to load boot image: init_boot
        3: Failed to read boot image data: Boot::V3::ramdisk
        4: failed to fill whole buffer

Changes:

* Remove all uses of #[from] from thiserror-derived error types.
* Errors during parsing and serialization of RSA private keys, RSA
  public keys, and X509 certificates now include the file path.
* Removed unnecessary uses of BufReader and BufWriter when reading and
  writing RSA private keys, RSA public keys, and X509 certificates,
  since they need to be fully read into memory anyway.
* Use ReadFixedSizeExt instead of read_exact() where possible.
* Use &'static str instead of String in error fields where all possible
  values are known at compile-time to avoid unnecessary heap allocation.
* Use ok_or() instead of ok_or_else() to construct errors when the error
  variant uses known data and does not require heap allocation.
* Using DebugString instead of String in error variants that store a
  preformatted debug string.

While working on this commit, an unrelated bug was found and fixed:

* Fix vendor v4 boot images that were truncated within the padding
  following the bootconfig section being treated as valid.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-25 02:34:17 -05:00
Andrew Gunnerson 6de5cb783a CHANGELOG.md: Add entry for PR #398
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-11 22:09:03 -05:00
Andrew Gunnerson 12d6f7f78c util: Wrap std's range types instead of inventing our own
This makes the type potentially more useful outside of just our current
use case of just error messages. Ranges where the starting value is
exclusive are no longer supported, but weren't used anyway.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-11 21:56:13 -05:00
Andrew Gunnerson 3c0a77df21 CHANGELOG.md: Add entry for PR #397
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-11 21:28:20 -05:00
Andrew Gunnerson d1b6bce227 Update bzip2-rs to 0.5.0 and switch to Rust backend implementation
The bzip2-rs library now has a new maintainer (same folks that maintain
the sudo-rs project). Version 0.5.0 was recently released, which
includes some much needed bug fixes, but is missing one final one, so we
still need to keep our fork for now.

This commit also switches the backend implementation from the official C
implementation to a Rust implementation maintained by the bzip2-rs
folks. This leaves xz as the only C dependency remaining in avbroot.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-11 20:23:40 -05:00
Andrew Gunnerson 10e0748d18 CHANGELOG.md: Add entry for PR #395
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-11 03:58:28 -05:00
Andrew Gunnerson 9cf63c7036 Treat Magisk versions newer than latest as supporting all features
Previously, when patching with a Magisk version newer than the latest
supported version and using --ignore-magisk-warnings, the upper bound of
VER_PREINIT_DEVICE and VER_XZ_BACKUP would prevent those features from
being used. It makes more sense to assume that a newer version supports
all the same features as the latest supported version instead.

Issue: #393

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-11 03:53:11 -05:00
Andrew Gunnerson 291b3c887b CHANGELOG.md: Add entry for PR #394
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2024-12-11 00:01:39 -05:00