the backup RAM region is being used as a way to check if the
system is coming out of a cold power-on. Deep sleep is indistinguishable
from a power-on from the hashing perspective. Check if the RTC is
*enabled* and if not, enable it and reset the time; don't always
reset it if the backup ram is scrambled.
there is a circular dependency that has to be broken: the board
type wants to be set via USB, but you can't set the board type
until the USB enumerates. USB enumeration can be unreliable on
baosec because the SE0 pin isn't mapped as the board type defaults
to dabao.
The baosec SE0 pin is PF5 - this is inaccesible in dabao. Thus
the decision was mode to pull both possibilities during the boot1
initialization phase.
This could cause some trouble for OEM configurations that are relying
on these pins to be e.g. inputs or some other value, but this will
need to be documented as a hazard for OEM designers.
this should erase the secret keys if the boot1 pubkeys don't match
this enables OEM-signed boot1 images. the policy is that all OEM
images signed by baochip are considered to be untrusted, and thus
loading them onto a device would wipe any secret keys, making
them less useful for extracting secrets.
There are 2048 keys and about 500 keys are used by baochip,
so there are still plenty of keyslots available for OEMs to
use to implement their own version of security.
The TL;DR is this now treats dabao exactly the same as
baosec in terms of keystore setup from the security flow perspective.
baosec & dabao were different originally because baosec would
rely upon the Avalanche generator TRNG as supplemental randomness
and dabao would not. This special case had to be handled in the
bootloader and propagated through.
However, in a previous commit, the keystore setup was moved to
the OS *anyways* - thus making this difference moot.
This patch backs out the one-way counters that would track the
dabao initialization state.
It also doesn't fail the boot on the erase key proof check
failing if the keystores aren't initialized yet. This creates
yet another condition that could be glitched over to bypass
the erase check but it is checked twice indepedently.
The original RTC was set to a 1Hz tick, which isn't sufficient
for the time API
This has been reworked to give a 1/1024 second increment.
Rollover logic is implemented in the RTC. Requires the system
to be powered on at least once every 48 days to capture the
rollover, otherwise it could miss a rollover event. This is
fine because the backup battery doesn't last that long, and
scans of QR codes for password login always reset the RTC anyways.
The RTC offset randomization code is now gone because we're
not tracking long-term power-on information in the RTC.
this makes i2c accessible without having to rely explicitly
on the server itself, making the library callable in more contexts.
necessitated avoiding a name space collision and moving the
I2C hardware drivers to a stucture named I2cDriver; the I2C
object now unambiguously refers to the userspace interface
to I2C.
non-paranoid mode responses happen through IRQs (recall that
paranoid mode is a hair-trigger hardware reset with no
exceptions). This patch installs the IRQ handlers in boot0
and boot1.
- boot0 in particular now even has an IRQ handler. Previously,
it didn't have the IRQ facility configured, because there was no need
for one.
- boot0 sets up the sensors, and the IRQs
- boot1 merely continues with boot0's settings, but re-installing
the trap handler to be its own and double-checking some
register settings.
An old testing IRQ handler stub for keyboard presses was also removed,
as it can never be triggered as that IRQ is never set up.
this is the final part of the developer mode bit hardening.
If an adversary manages to increment the developer mode
bit, the next reboot they have to contend with active counter-
measures that would attempt to erase the secrets due to
the developer mode bit being set.
As noted in the top of the commit set, previously, without
this, the attacker would have the luxury of being able to
flip the bit and try many times to bypass the developer
mode check.
boot1 hardening is similar to boot0 hardening - bollard & delay
insertion, checking that we're in PLL mode. Also the first phase
mesh results are checked and second phase is setup for the loader
to finally check.
clocks are still local to the routine - there's a to-do to consolidate
that routine into the API layer later on.
takes 8 samples and makes sure those values aren't repeated in the
next 8 samples.
has a ~1 in 500 million chance of giving a false positive. But
generally should catch: stuck-at fault, and also, a highly trained
oscillator fault.
- add `paranoid` command - when set, puts the chip into
paranoid mode. Not set by default because we need to check that
the security countermeasures are not too aggressive
- `lockdown` now revokes all developer keys in both main and
redundant array, and sets paranoid mode
- api fixes for sig validate
- audit now prints results of paranoid mode and attack count
- don't slot-check in altboot (altboot actually runs in a security
environment that doesn't have boot privileges)
- force bootwait ON by default if altboot is entered - otherwise
we enter a boot-loop
- update release description as towards beta-0
The -A1 stepping is going to tie the IFR access control
bits for data and key slots together. This is due to an RTL
bug where the key slot maps were typo'd and they ended
up mapping to the same IFR ACL.
We "could" continue to use key slots with a rule that
key and data slots would have to coordinate with each
other and not use the same slot number.
However, because of this linkage, and because there are
other bugs suspected in the keyslot implementation, an
executive decision was made to disregard the key slot
feature in the chip.
The main downsides of this are:
- fewer slots (2048 vs 4096)
- no key access linkage to HMAC auth on SCE
I *think* that's it.
Fewer slots - 2048 slots is still a lot of slots, about half are
used now, I think this is plenty.
Key access linkage to HMAC auth on SCE - I have reasons to
suspect this feature is broken anyways for subtle reasons
related to malleability of the HMAC round constants. Even
without that brokenness, it's hard to use HMAC auth to manage
the system because it requires per-device unique keys: so,
we're using a PKI scheme and no symmetric secrets to handle
access controls.
Removing the key slots also greatly simplifies the code
base analytically. This culling removes the key slot
abstraction the "simple" way, but without the weirdness
of the keyslots (in particular the key ID chaining which
makes them different from data slots) I could remove even
more abstractions and simplify the code.
One upside is now all elements can enjoy the write mode
behavior which can force the slot to be only 0->1 writeable,
which could be useful for other things down the road.
This was tested to not interfere with Dabao-Alpha 0
bootloaders.
Since in-system keying has to happen in the factory, it doesn't
add anything to burn it into the bootloader. Furthermore, the
access controls are already set up so that the keys can only
be accessed by the OS code.
The "press button" path cleanly shuts down the USB stack
before going into the next stage.
"boot" does not; it missed the additional code added at the
end of the main routine.
Refactor the "boot" routine to be a function call now, so any
future improvements to the boot process are used by both paths.
audit is now expanded to track one way counters and
summarizes security state
boot0 key indelibility test added as a feature, to be
used in the future for CI
The motivation for this is to make the tester configuration
exactly identical to that used in production. Right now a
"cheater" step is used to set the board type to dabao and
enable boot waiting because in the test environment there
isn't a physical switch anyone can press to invoke that
behavior.
So, in order to get the test environment to work just like
production, the behavior goes from insta-die if no valid
image is found on the next stage, to "wait for new image".
This is slightly less secure of a default, but only slightly
so. Basically the previous scheme required someone to be
physically present to press the "give me a new image" button,
this one causes the system to automatically accept a new image.
I suppose the main downside is this does allow the possibility
of say, a fully remote, automated exploit to be delivered
if an adversary can damage the loader image such that it
doesn't pass signature check and then it will automatically
go into a mode looking for a new image, at which point
an arbitrary image could be potentially loaded (although
because the image would need to be signed, and there is
a trap that destroys secrets if a developer image is
presented, it wouldn't instantly lead to secret disclosure,
but it would be a denial of service).
The flip side is that with the paranoid default, developers
are "confused" by the silent failure of a brand new chip that
has no code loaded in it (because it goes catatonic until
the developer knows to press the load button).
The loader image is protected from writes after boot, so
in theory there isn't a direct path to "spoil" the loader
image and trigger this path, so it's not like we're just
hanging in the wind. It just means that there isn't a
full human-presence requirement as a defense in depth against
a potential denial of service if an adversary could find
a way to spoil the loader image.
If the DoS path is a concern, one option is to configure
the system such that the developer key is revoked. This
would disallow that from being recognized as a valid
image, and would also prevent the DoS from happening,
as it would require the adversary to present a valid,
signed image which presumably they can't as long as
the signing keys are kept safe.
- feature gate some unsafe-debug
- tie akey_id to 0xff which should disable key chaining, which
is not used in our scheme because authentication is not hmac-based,
uses public keys instead
latest rev of the board seems to handle the heat load OK.
board gets a little warm to touch when the system is clocked
at max frequency, but not unpleasantly so.
this accommodates the notion of erasing secret keys when
a developer key is detected. Some hackery in the API is
required, because I'm trying to use the same signature
routine for both boot0 and boot1, but coreuser settings
should not be set until boot1.
Boot0 has *no* coreuser settings, whereas boot1 starts
to lay them in - this interferes with key erasure, and
so the nice clean "boot or die" abstraction disappears
because we have to now just check if a key matches a criteria
and then return because we have to handle the environment
dependent case of coreuser settings.
the key setup seems to work correctly
but the data ACL setting doesn't "stick". The region
could be write-protected by some other element in the
CP/IFR config, need to dig a lot more. For now we need
to move on and crank out something to stick on the alpha
dabao boards...
this code audits the status of the data/key slots,
initializes them according to the platform, and sets
the permissions on them to prevent read-out later on.
A TRNG routine is built into boot1 now, I think it's
reasonably conservatively coded but more testing/inspection
is always good.
this does not seem to have a large effect on update times and
allows us to operate over more platform configurations absent
specific power-on control code
have to absorb a version change due to xous-semver change
might as well also update the utra/svd generator dependencies
since that's been held off for a long time now.
main thing in this commit is remembering to activate PWM
mode on DCDC2 for a quieter power supply. the chip draws
so little power that the power-saving regulator hiccups
and has too much ripple.
- add boardtype setting
- work around usb serial tx timeout hangs - not sure why they happen,
but let's not hang the repl on them.
- various cleanup code & comments
- note boot frequency
present a 128MiB FAT32 disk based on a dumped image that was
clean-initialized on a windows machine (windows is the most
picky so it is used as the template maker).
add hooks for emulating sparse reads of file system structures
that are well outside our available memory range.
add hooks for writing uf2 files when valid sectors are encountered.
this basically works, you can whack a uf2 file into the disk
and the update happens.
the problem now is that something breaks in the repl loop
when USB disk traffic happens, this commit gives us a checkpoint
to work against.