Commit graph

10340 commits

Author SHA1 Message Date
bunnie
9e5c57b7de
inline the pll check
this prevents it from being a single area that has to be patched
to bypass the pll check
2025-12-04 15:30:43 +08:00
bunnie
1c210b3541
other boot0 hardening
- harden the check that the boot0 public keys match those in the
data array
- security mesh setup
- insertion of random delays & bollards
- upgrade API on signature verification to allow for random delays
during the signature check
2025-12-04 15:28:52 +08:00
bunnie
b00acba907
boot0 platform hardening
- paranoid mode entry is implemented here. The main outcome of
paranoid mode is that when activated, the system will automatically
reset anytime a voltage glitch is detected.

- clean up PLL mode setting. For boot0, the mode is fixed & hardened
to 175MHz CPU operation, running off the PLL, under the theory that
running at this speed makes glitch attacks harder as the cycle time
is now 5.71ns, and simply disturbing the XTAL clock doesn't cause
the PLL to straight-up stop.

- some hardening to ensure that we are actually in PLL mode, and
that the switch to PLL mode wasn't glitched over
2025-12-04 15:15:16 +08:00
bunnie
78036d71dc
add code to check the flag
there's a dummy flag checked in, and this code helps check that
the flag is treated correctly during CI testing
2025-12-04 15:10:51 +08:00
bunnie
d8f4ef9fe0
baremetal changes
- update to use new clock API
- add test routines for security sensors
2025-12-04 15:07:51 +08:00
bunnie
362124127e
add redundant counters, paranoid mode, attack counters
This allocates some additional one way counters dedicated
to hardening:

- Paranoid mode is duplicated in slots 65 & 67
- An attack counter is in slot 66
- Redundant revocation counters are seated in slot 68

The primary revocation counters are in slot 116. This means
that cutting out the revocation counters would probably require
at least two edits to the memory array - simply cutting the
word addressing line for those columns might be enough to
defeat a counter.

Paranoid mode duplicate is stored somewhat close to the
primary counter, which means it could be subject to a single
line cut to fully defeat the counter, but the space is getting
pretty crowded so I'll leave it like that; I really want to
leave the bottom 64 slots available for application use.

A "flag" key is allocated, plus a dummy flag is committed
to the repo. This is a value that, if retrieved, would
ostensibly bring the retriever glory and bounty, to the
extent that any glory or bounty is to be had (ps: I'm poor
and this project is obscure). The actual flag, of course,
is not in the repo...I hope!

The flag value is different from all other values in that
this is the only shared, common secret across all devices.

All other device secrets are generated on a per-device
basis from the TRNGs. So the flag needs some special treatment
such that it's not overwritten during device keying.

The flag exists because I'm hoping that anyone who manages
to extract it will also provide a helpful explanation of
the procedure to get it out, so that the system could be
patched (if the error is patchable) or rev'd in future
silicon. That being said, a flag retrieval is not necessarily
equal to a full break of security across all devices because
as mentioned above, most device secrets are on a per-device
basis. The flag represents then, the amount of effort necessary
to apply to every device to retrieve the secrets within.
2025-12-04 14:56:07 +08:00
bunnie
31385a5599
start moving clock routines into an API library
clock setting calls, for legacy reasons, are duplicated in all the
stages of the bootloaders. This is a start toward moving these routines
into a common set of calls that improves maintainability.
2025-12-04 14:54:26 +08:00
bunnie
bd08328530
add bollard macro and HardenedBool
These macros are added to the platform-agnostic API crate.

bollard is a macro that can respond to the following argument
formats:

bollard!(): inserts 4 illegal instructions and a jump over them
bollard!(#): inserts # of illegal instructions and a jump over them
bollard!(f, #): inserts # of an interleave of illegal instructions
and a jump to f

the last form is intended to "up the ante" by including a call
to a routine that can shut down the chip and/or wipe secrets
should the defender choose to do that. The other ones just
trampoline into an illegal instruction vector which is a fairly
weak defense because the CPU could once again get glitched out
of that.

HardenedBool is a boolean represented by a high-hamming distance
numeric value so that single-bit flips just lead to an invalid
bool, instead of a change in the meaning of the bool.
2025-12-04 14:50:33 +08:00
bunnie
75fb1a1889
Harden the signature check routine
- key revocation check is fully duplicated and tested twice
- bollards & random delays added throughout the code. Random
delays require passing in a csprng object from the calling
environment.
- the primary go/no-go decision on whether a signature passes
or not is unfortunately not hardenable because the API is in
a third party crate. However, the regions around that call are
random-delayed and surrounded with bollards
- the state bits that determine whether the system is secure
and/or in developer mode are implemented using HardenedBool
- erase_secrets has some delays added to it as well as bollards.
However, it does remain a weakness that an attacker
could pull RRAM power during the erase cycle by just isolating
the RRAM power supply and putting a fast current limit on it,
thus preventing effective erasure by starving the circuit
of power.

Nothing we can really do about an active attack on the power
supply to prevent erasure, I think. It is unfortunately required
by design to have an isolated power supply for the RRAM to perform
elevated-voltage forming at CP time, and so, it should always
be possible to limit the current going into it thus preventing,
at least somewhat, any programming operations on the array.
2025-12-04 14:36:28 +08:00
bunnie
05af4f3f62
add hardened_get() and hardened_get2() to one way counters
One way counters are used ot record some security-critical properties,
such as key revocations and paranoid mode.

Two methods of retrieving the counters so that they are hardened
are provide here. Both of them rely on the fact that any value
other than 0 for the counter means it is set.

`hardened_get()` retrieves the counter value and sums it several
times. It does this *twice*, and returns *both* values as a tuple.
By returning both values as a tuple, it reduces the likelihood
that the compiler optimizes out the redundant read. The receiver
should implement serial checks that operate on the hardened_get()
result (i.e., test one value of the tuple, then test the other
value of the tuple redundantly, instead of OR'ing them together
into a single test)

`hardened_get2()` is for counters that are fully duplicated in
the array. For extremely critical counters, they are stored in
two physically separate elements. This is done to make bypass
of the counter harder than just FIB'ing out a single bit in
the memory array. In the case of `hardened_get2()`, a tuple
is returned, but instead of reading the same value twice, the
tuple corresponds to the summed value over each of the redundant
counters.
2025-12-04 14:29:30 +08:00
bunnie
9294c06d45
Add glitch hardening library
This library contains the following primitives:

check_pll() - checks that the PLL is the primary clock source.
This is important because allowing direct clocking of the system
from the external clock pin makes glitching much, much easier.

die() - a routine that implements a reaction to attacks. At the
moment, we just note attacks and then halt the machine. Eventually,
this could be upgraded to be more reactive, e.g. erasing secrets
or bricking the chip.

Csprng - this is a chacha8 cipher seeded with ring oscillator
TRNG data, plus whatever tiny bit of entropy we can scavenge
from uninitialized RAM (to make it so that it's not as trivial
as cutting the RO wire and tying it to 0 to bypass the library).
There's also a tiny health check on the RO before using it, again,
to make it harder than just cutting the RO wire. The sole purpose
of the Csprng is to generate random delays that frustrate glitching
attacks. The delay is currently tuned to a range of 0-255 iterations
of a loop.

paranoid_mode() - turns on fully automatic reactive sensor
countermeasures. Whenever a voltage glitch is detected, the system
will just reboot.

mesh countermeasures - these set up the secure mesh and the
reaction policy to tamper detection on the secure meshes

apply_attack_policy() - an API call that applies the currently
determined countermeasure in case that the detected attacks
counter has gone above a threshold. The reason we don't simply
react right away is that some countermeasures are fairly
sensitive, and *also*, very importantly, the chip *is* packaged
in a CSP and thus especially for dabao users you will expect
to see random trips of the attack sensors due to environmental
noise (photoflashes, nearby lightning strikes, etc.).
2025-12-04 13:34:01 +08:00
bunnie
4cd712b2b0
Merge pull request #747 from betrusted-io/chaffing
AES Chaffing
2025-12-01 21:45:36 +03:00
bunnie
3663ea1276 revert inadvertent testing flag that was checked in
this only makes sense for testing on specific builds.
2025-12-02 02:39:28 +08:00
bunnie
9b54fdb64f fix dabao target dependencies 2025-12-02 02:27:01 +08:00
bunnie
988570d6a6 update lockfile dependencies 2025-12-02 01:43:32 +08:00
bunnie
46fb57628e remove aes dependency from kernel
this is a false dependency, there is no AES in the kernel
2025-12-02 01:42:59 +08:00
bunnie
52215251a4 add a random seed to the environment
this is randomly genverated on boot and inserted into the
environment. it is unique per-PID.

This is useful for seeding psuedorandom number generators,
especially in environments where syscalls are not possible.
2025-12-02 01:40:49 +08:00
bunnie
01475137bb add code to test the random seed 2025-12-02 01:40:39 +08:00
bunnie
fcc6fc5538 add chaffing feature to the swapper
the main imagined attack vector on the swapper is recovery
of the AES key through side channel analysis.
2025-12-02 01:06:36 +08:00
bunnie
5b4d6c1932 add benchmark data on chaffing
unchaffed AES is 5.36us/block
chaffed AES is 10.27us/block

so ~2x overhead for chaffing - about what we expect for the
implementation.
2025-12-02 01:05:26 +08:00
bunnie
da44e98257 add chaffing implementation to AES 2025-12-02 01:04:17 +08:00
bunnie
712ee68df5
Merge pull request #746 from betrusted-io/build-fixes
fix TTS target API change
2025-11-30 17:27:53 +03:00
bunnie
9034a08b5e fix TTS target API change 2025-11-30 22:21:31 +08:00
bunnie
cbe5c4ae4e
Merge pull request #745 from betrusted-io/towards-time-setting
Vault2: Set time & other UI improvements
2025-11-30 17:12:51 +03:00
bunnie
d9a65a51d9 fix hosted mode 2025-11-30 21:56:32 +08:00
bunnie
7ec01905aa add password creation, and password generator configuration
also vendors in the password generator so that we can customize
special characters
2025-11-30 21:34:05 +08:00
bunnie
852a12645b round out stateful list creation in the ux-api libraries 2025-11-30 21:33:04 +08:00
bunnie
381dee01eb fix interfaces in GAM for stateful lists 2025-11-30 21:32:26 +08:00
bunnie
49456db837 fix typos 2025-11-30 21:32:08 +08:00
bunnie
98e9d99de8 add stateful list creation
this allows us to have "pre-checked" checklists
2025-11-30 21:31:39 +08:00
bunnie
7d7fa75e7d add debug telemetry for keyboard connect error
sometimes on boot, a process tries to send keyboard an incorrectly
formatted message. I think this might be the IOX interrupt handler
firing due to random noise. Corrective action towards debugging
includes instrumenting the keyboard call with debug info, and also
ensuring that the iox interrupt handler banks are initialized to 0.
2025-11-29 15:49:40 +08:00
bunnie
18dd921cb8 setup time setting from QR code scan
this is a stub based off the password scanning QR code

still need to add actual password setting, will do that tomorrow
2025-11-29 01:02:21 +08:00
bunnie
e8edb3f4b2 remove unused file 2025-11-29 01:01:57 +08:00
bunnie
b702a68c1c test what local time returns 2025-11-29 01:01:24 +08:00
bunnie
4ec0eda2b5 migrate service name to some place public 2025-11-29 01:01:04 +08:00
bunnie
4a62108da2 many ui improvements to vault2
passwords are now using scrollable list, instead of the paned
view from Precursor. Paned view doesn't make sense because the
panes are so small.

scrolling accelerates with time spent pushing the scroll wheel,
allowing lists of hundreds of passwords to be navigated in a few
seconds.

a bunch of unused APIs are now deprecated in the itemcache -
scrolling lists off-load most of the ui functions. itemcache is
now used just for caching entries from the PDDB and also, more
importantly, filtering entries - filters are of course TBD implementation
2025-11-28 18:45:36 +08:00
bunnie
6918e275d0 map the center key to "fire"
This allows the center key to be used as a UI trigger action
without creating a carriage return on the console. this prevents
console actions from errantly triggering during complex ui navs.

probably later on we should filter out more of the UI nav items
going to the console because the console is always listening
2025-11-28 18:43:59 +08:00
bunnie
7631ad9e20 move bao-video to XIP flash
we've got the space - might as well.

there's about 300k of space left in the xous image after this
modification. This is starting to cut it close, so this is
the last item that makes it into the "fixed" xous image.
2025-11-28 18:43:08 +08:00
bunnie
3b1784d346 make screen panic messages somewhat more useful
some panic messages are hundreds of characters long, most of them
are path hashes or paths to crates that are less useful.

truncate any panic messages to the last set of displayable
characters, so that the "most useful" portion (e.g. file name
and line number) are always visible in a panic.
2025-11-28 18:41:53 +08:00
bunnie
106f7153a1 filter key presses through the video layer
the video layer is the "traffic cop" managing when modals
get focus. This patch creates a feed from the video layer
that listers to subscribe to that filters out key presses
destined for modals.
2025-11-28 18:40:56 +08:00
bunnie
738797754b make widgets respond to the "fire" button 2025-11-28 18:40:33 +08:00
bunnie
be7dbf2d22
Merge pull request #744 from betrusted-io/fix-dabao
fix dabao target - keyboard server
2025-11-28 04:42:09 +01:00
bunnie
647ec0dfb4 fix dabao target - keyboard server
dabao needs to have a vestigial keyboard server which handles
forwarding USB/serial key events to listeners. otherwise, there
is no input interface.
2025-11-28 11:35:17 +08:00
bunnie
1c31390106
Merge pull request #727 from betrusted-io/vault2-progress
WIP: vault2
2025-11-27 17:47:53 +01:00
bunnie
7dcf5d34ba add notes on how to update boot1 on a dabao 2025-11-27 23:31:41 +08:00
bunnie
f099c67168 move the todo list out of the source file 2025-11-27 23:31:32 +08:00
bunnie
a5721b5271 update lockfile 2025-11-27 22:11:32 +08:00
bunnie
84a083017c gate off incompatible features for hosted mode 2025-11-27 22:11:13 +08:00
bunnie
720680a931 build a hosted mode dummy for aqcuire qr 2025-11-27 22:10:57 +08:00
bunnie
b88f6cad91 fix hosted mode 2025-11-27 22:10:43 +08:00