Commit Graph

65 Commits (b9dc7eee4677a4f0188cb3b2c30e60505ee6b44e)

Author SHA1 Message Date
John Bland 6c3940fafc refactor final step of powerfail safe update and add
emergency fallback test
2024-07-10 16:58:23 -04:00
Daniele Lacamera 32d6592e50 Fixed regression on powerfail resume 2024-07-04 18:19:02 +02:00
Daniele Lacamera 68f3bfad58 Take into account resumed delta updates due to powerfail events 2024-07-04 17:31:17 +02:00
Daniele Lacamera 929f9d3343 Fix base_version mismatch 2024-07-04 17:27:04 +02:00
Daniele Lacamera fce6149cf8 Update license GPL2 -> GPL3 2024-04-16 16:46:15 +02:00
Daniele Lacamera 37d92fdd3d DISABLE_BACKUP is now powerfail-safe.
By not checking/updating sector flags during copies from UPDATE to
BOOT partitions, a copy operation getting interrupted by power failure
will be less likely to cause problems to the integrity of the BOOT
image. This is because in case of interruptions, the copy operation
will be restarted from the first sector.
2024-02-22 09:36:21 +01:00
Daniele Lacamera f4e0cc61b3 Delta update fixes
- img_size: use 32-bit variable
- remove '+1' from pa_start calculation
- fix broken delta.c wb_diff check for distance between matching
  patterns (root cause for the delta+encrypt bug)
2023-11-04 19:32:34 +01:00
Daniele Lacamera dcb82b6545 cppcheck: added "--enable=warning" 2023-10-13 16:08:22 +02:00
John Bland 6c2a37bdea remove complicated key saving process and instead
leave the encryption key for wolfBoot_success to erase.
FINAL_SWAP was also stopping the case where the partition was put into testing before the update sector status flags could be erased. now, don't erase the update sector flags. instead put the update partition in IMG_STATE_FINAL_FLAGS state before putting the boot partition in IMG_STATE_TESTING. Then only erase the update sector flags on wolfBoot_update_trigger. under this scheme, the sector flags are intact if the power failed before we could set IMG_STATE_TESTING but are wiped if we do need to swap over after after wolfBoot_success fails to be called
2023-10-13 14:30:04 +02:00
John Bland 5a7665a9e3 add missing FINAL_SWAP check 2023-10-13 14:30:04 +02:00
John Bland 00a9572b94 change the final steps of wolfBoot_update into
repeatable steps so that power failure wont erase the encryption key and wont cause skipping the testing phase of boot. this is done by marking the update partition as final swap when erasing the final sector and backing up the key in boot sector 0 after swaping the real boot sector 0 to swap. then when a power failure occurs the encryption key will be available in either boot sector 0 or the normal location. the intermediate phase also prevents skipping the testing phase since the last sector, which holds the boot state, is erased and then set repeatably, since the final swap state is set on the update partition
2023-10-13 14:30:04 +02:00
David Garske eb2978ab7f TPM sealing cleanups. If using simulator don't extend the unseal PCR to prevent further access. Added `WOLFBOOT_NO_UNSEAL_PCR_EXTEND` option to prevent locking of PCR by random extend. Improvements to the `policy_sign` tool (example usage, ecc384 support). 2023-10-06 13:34:37 -07:00
Daniele Lacamera fd862cbd8f Working PKCS11 test.
Temporarily removed some features so the image fits in 64Kb
2023-09-21 08:28:09 +02:00
David Garske 6dbe4a0129 Refactor to allow using seal/unseal without image header. Just pass the public key hint and policy directly. 2023-09-12 12:26:48 +02:00
David Garske 05b83544fb Fixes based on peer review. Add output of signed policy to file (append .sig). Tested successfully with multiple PCRs. In example unlock_disk extend PCR with random value after unseal to prevent unsealing after boot. 2023-09-12 12:26:48 +02:00
David Garske 2349a68e76 Added support for storing sealed blobs into NV. Refactor the TPM signature verify to use existing load public key function and generic verify hash TPM function. Added support for RSA sign with ASN.1 encoding (Example: `SIGN=RSA2048ENC`). 2023-09-12 12:26:48 +02:00
David Garske 490286be7d Support for sealing/unseal a secret based on an externally signed PCR policy.
* Added new `WOLFBOOT_TPM_SEAL` and `WOLFBOOT_TPM_SEAL_NV_BASE` config options.
* Added new `tools/tpm/policy_create` tool for assisting with creation of a policy digest. The sign keytool `--policy=file` signs the policy.
* Added new `WOLFBOOT_TPM_VERIFY` option to enable offloading of the asymmetric verification to the TPM. By default wolfCrypt will be used.
* Added example seal/unseal to update_flash for ARCH_SIM.
* Renamed `WOLFBOOT_TPM_KEYSTORE_NV_INDEX` to `WOLFBOOT_TPM_KEYSTORE_NV_BASE` to support multiple public keys.
* Refactored most TPM code into tpm.c.
* Refactored the keystore ROT to use new `wolfBoot_check_rot` API.
* Refactored the sign keytool to have a sign_digest function to allow signing firmware and policy for sealing/unsealing.
* Fix for make distclean && make using the wrong key tools.
2023-09-12 12:26:48 +02:00
David Garske 701674be4f
Merge pull request #343 from jpbland1/add-nvm-configs
add combinations of NVM_FLASH_WRITEONCE config tests
2023-08-17 07:02:51 -07:00
David Garske 69adb25496 wolfBoot TPM improvements:
* Added TPM SPI wait state support and debug logging.
* Added platform auth ownership (change platform password to random value before boot). Can be disabled using `WOLFBOOT_TPM_NO_CHG_PLAT_AUTH`.
* Added parameter encryption support.
* Added TPM based root of trust based on https://github.com/wolfSSL/wolfTPM/pull/276
* Removed the TPM hashing feature (not practical).
* Fixed RSA with wolfTPM build.
* Fixed cleanup wolfTPM objects on make clean.
2023-08-17 13:43:58 +02:00
John Bland d63316fd7f erase the sector flags when wolfBoot_update_trigger
is called for NVM_FLASH_WRITEONCE and WOLFBOOT_FLAGS_INVERT since NVM_FLASH_WRITEONCE relies on finding non-erased flags to determine which sector is fresh and since WOLFBOOT_FLAGS_INVERT may use a different fill byte than what bin-assemble was compiled with
2023-08-17 01:22:47 -04:00
John Bland c26f1e6a9c update based on pr comments 2023-08-15 15:20:20 -04:00
John Bland 36bf4c3d80 fix powerfail case where the first and second sectors
are swapped and therefore the fw_sizes are wrong
2023-08-15 14:45:16 -04:00
David Garske 7190392245 Simulator fixes and support for using MacOS:
* Added simulator support for Mac.
* Fix for simulator to properly assemble wolfboot.bin + signedtestapp + update + swap.
* Fixes for handling 64-bit assigned mmap virtual addresses. Added hal_flash_write and hal_flash_erase support for 64-bit address using uintptr_t. Enabled if platform is 64-bit and `FORCE_32BIT` is not defined
* Fix simulator conflict with src/libwolfboot.o object in test-app.
* Cleanup test-app linker flags.
2023-08-07 20:54:18 +02:00
David Garske a56e2252c1 Revert the TPM based key store (root of trust). This feature is not ready for next release. 2023-07-04 08:36:41 +02:00
David Garske 0b7603f7bf
Merge pull request #303 from jpbland1/preseal
add script for preseal a public key to tpm
2023-05-05 15:02:55 -07:00
John Bland bf3ebee8bb use correct digest when getting unsealing the pubkey
add deinit call when wolfboot exits so the TPM doesn't have a hanging session
2023-05-05 16:27:22 -04:00
David Garske ef35f473c9
Merge pull request #296 from jpbland1/tpm-root-trust
wolfTPM pubkey storage with policy based access restriction
2023-05-04 15:09:06 -07:00
John Bland eb30566bba add encryption key unsealing from the tpm
make the config/examples/stm32f4-tpm-keystore.config config use ecc256
2023-04-24 13:23:09 -04:00
John Bland b94249f8f7 correctly identify a forward powerfail vs a revert
powerfail and add an exception to wolfBoot_delta_update when a revert gets
interrupted since the version will change in the middle of the update process
2023-04-22 06:13:53 +02:00
John Bland 14ec346e1c before calling wolfBoot_delta_update, check if the
0th sector has been changed with the update partition still being in
IMG_STATE_UPDATING state. the state still being IMG_STATE_UPDATING means that a
delta update started and that the version may have been switched over, in which
case wolfBoot_current_firmware_version() >= wolfBoot_update_firmware_version()
no longer tells us if we need to perform an inverse operation on it's own.

also removes part of the update powerfail test that does checks for the
previous version without triggering a rollback
2023-04-21 20:31:58 +02:00
John Bland 3fbc99d36e wolfTPM pubkey storage with policy based access restriction
this update uses the tpm to retreive the public key used to validate the image that will boot and restricts access to that key by tpm policy. when the image is updated it's signature is used to extend the PCR and when the image is loaded it's signature must match what was sealed in order to get the public key from the tpm. enabling this option is done by setting WOLFBOOT_TPM_KEYSTORE in .config
2023-04-11 11:46:21 -04:00
Daniele Lacamera e04a35bbdb Fix compile errors 2023-01-26 14:23:45 +01:00
Daniele Lacamera 3d517cfe8c NVM_FLASH_WRITEONCE refactoring
- Using two sectors to keep partition/sector flags
- Keep two redundant set of flags, update one at a time
- Erase is done when the sector is old
- Flags update is faster because Erase is done in advance
- Accessing trailer information (including encryption keys) is done by
  selecting the newest information

Tested via renode, using nrf52 with NVM_FLASH_WRITEONCE flag on.
2023-01-26 09:22:48 +01:00
Daniele Lacamera 88a48e5332 Fixed bug in encrypted-delta update 2022-10-21 14:09:12 +02:00
Daniele Lacamera a6fdec3901 self-encrypt prototype; tested on stm32l0 2022-09-21 18:49:52 +02:00
Daniele Lacamera b47b9cef9b Corrected style (indentation, line wrap) 2022-05-23 20:39:57 +02:00
Daniele Lacamera 957b9d3c8c Initial support for delta-encrypted updates 2022-05-23 12:00:57 +02:00
Daniele Lacamera 73fe84c55c Fixed version check armor, add no-downgrade tests 2022-03-16 11:19:05 +01:00
Daniele Lacamera 0665eeff67 Reverted 'return -1' fix; removed _update() optim. 2022-03-14 18:14:50 +01:00
Daniele Lacamera 028d184b17 Added armored image version, improve armor 2022-03-14 17:45:47 +01:00
Daniele Lacamera 32ecb5c3b6 Added pre-boot sanity check 2022-03-14 16:04:11 +01:00
Daniele Lacamera 5a15fe1138 Added armored panic() function form arm cortex-m 2022-03-14 13:06:13 +01:00
Marco Oliverio b7026a5b1c update: don't set IV on SWAP based on SWAP address.
New update logic when using encrypted external flash:

- an update sector is copied to swap. No decryption and re-encryption is done in
this step. This is important, because the swap address never changes and
otherwise the data will be encrypted, one sector at the time, with the same
IV. It's also a performance improvement.

- a boot sector is copied to update. In this step the boot sector is encrypted

- the swap sector is copied into boot. In this step the swap sector is decrypted

This commit moves the set_iv logic into wolfBoot_copy_sector to account for
this.
2022-02-07 15:03:08 +01:00
Marco Oliverio 0f9613837a libwolfboot: make crypto_*() functions public 2022-02-07 15:03:08 +01:00
Daniele Lacamera f26dd61e23 Fixed delta updates from external devices (+ test) 2021-10-07 14:32:51 +02:00
Daniele Lacamera aaf780fae9 Added test for delta-update-ext 2021-10-07 14:32:51 +02:00
Daniele Lacamera 922c17f1cc Draft: integrate delta updates with external flash support 2021-10-07 14:32:48 +02:00
Elms d302c633c2 TMS570LC43xx: flash updates and init stack pointer
- cleanup warnings and rework exceptions to be more robust
 - CORTEX R5: Initialization of stack pointer
 - updates to F021 flash from testing
 - sync options for command line build with IDE
2021-10-07 01:45:18 -07:00
Daniele Lacamera 39ee01a948 Added roll-back feature via inverse patch 2021-08-17 15:44:34 +02:00
Daniele Lacamera b21f0f93b7 Using fixed delta blocks of 256B to save memory 2021-08-16 16:38:06 +02:00