this adds, with a feature-gate, the option for userspace
programs to use & access keys in the APPLICATION data slots.
The implementation bounds-checks the requested indices to ensure
sensitive data in slots around the APPLICATION region cannot
be accessed. Even with corrupted AppKeyOp packets, it shouldn't
be possible to access other slot ranges, but because this code
is so intimate with importan secrets it's recommended to
gate the feature off unless required by the end user application
code.
by default the knob is not frobbable because frobbing the
knob can lead to potential griefing
more specifically the owc (one way counters) control some
security state. they are all designed to "fail on increment"
but just giving someone a button to increment random counters
gives a DoS vector. So unless you need to open the API it's
recommended to not have it activated.
- adds API for retrieving & setting the ephemeral key. This is
a key that is erased by a power-on reset, but is preserved between
deep-sleep sleep/wake cycles. It is intended for securing a lock
PIN, and can be up to 192 bits long.
- adds API for checking the warm boot flags, which are also stored
in the backup registers.
there was a thought to speed up CI testing by introducing a
"cheater" routine that allowed us to re-initialize the keystore.
Turns out this doesn't work because it's not possible to fully
revert a system out of developer mode - because, in my infinite
previous-self wisdom, I realized that this is something someone
might try and there is a one-way counter that logs if the
system has *ever* been in developer mode, and that has no
known bypass.
This means that even if you could repopulate the keystore, it
would be cleared on the next boot by merit of the developer
flag being set.
So - we did it the hard way, every single test we have to
re-image the system from scratch. C'est la vie.
Removing this patch eliminates a code path that could later be
abused for unforeseen ill purposes.
This is useful in CI to test various stages of dev-key signed
image vs secret key erase without having to go through a complete
suicide cycle on the chip.
This command is gated behind a feature flag that would only be
invoked for beta testing. I think it's still safe to have even
as a beta-signed feature because the worst you can do with this
is replace existing keys - so it could be used to DoS/brick, but not
leak secrets.
The panic on failure causes incompatibility with older boot0's
that don't set up the collateral area correctly.
Make the failure more graceful, but we also promise ourselves
to add CI tests to check for this explicitly, because we can't
just rely on panics to enforce behavior.
Three pieces of inforation are leaked about the root seed:
- whether or not the first 64 bits are all 0
- whether or not the first 64 bits are all 3's
- whether if none of the above are true
It's fairly indirect leakage, and I think it is a relatively
minor price to pay for the confidence it gives that some underlying
library behavior didn't accidentally lead to faulty keygen.
Note that these 64 bits are 64 bits out of tens of thousands
of bits that go into the keygen, because the nuisance keys
and the chaff key are all blended together to create the final
derived root key. Thus the security margin on the key is quite
large and even a full disclosure of these 64-bits is a minor
impact on overall security.
The keystore is a sensitive server, and the one-way counters
have security-critical propoerties. So instead of revealing a
generic one-way counter API to the world, specific, limited
requests to do things are going to be created for the keystore.
In this case, the bootwait flag would be convenient to be able
to set from userspace. The motivation for this requirement is
actually continuous integration - a normal human could just
hold down a button while turning on power, but in CI, I don't
have a robotic thumb (or an alternative electrical signal) to
simulate the nerve-pinch on boot.
Previously I was "cheating" and simulating this by nuking the
loader, which effectively forces a bootwait.
However, in production, this is *not possible* because the JTAG
port is sealed off. Thus, this may be the first of a series
of small PRs to incorporate CI tooling that clears up tech
debt like nuking the loader to get into boot wait.
this is constructed in a way such that
1. it's gated off in production builds
2. if it was accidentally gated on, there is some security impact
but not a significant loss of security
We do need the telemetry so that during CI we can confirm that things
are actually working. I think the risk of being too buttoned-up
and then accidentally doing something like accidentally never
initializing keys and leaving them all zero is greater than the
risk of accidental partial leakage of information due to a procedural
mix-up in the image signing ceremony.
in theory, no production images should be signed that have this
feature enabled. But, reducing the amount of leakage just in
case an accident happens and this flag is somehow slipped
into a signed production image.
This moves the key store initialization to the key manager
process itself.
It has been tested to work with signed images, and to also
protect the system in case of another process trying to access
the key data as well as in the case of developer keys being
used.
After some contemplation, we should include the keystore in the
core service set featured by the dabao-xous configuration.
The pros are: any compatibility/sharing of resources
that require access to RRAM, one-way counters, UUIDs, etc.
will either require a wholly separate implementation that is
"insecure" or it could just reuse the baosec work. Furthermore,
as cryptographic accelerators are laid into the keystore,
the APIs become available to the dabao environment
The cons are: more space is used in a space-constrained
dabao environment (roughly 140k "deadweight" at the start, but
as cryptographic APIs get layered in this can grow substantially);
the key slots are "used up" in part by the scheme, which leaves
less key slots available for user-defined purposes.
This is mitigated by the fact that there are a couple thousand
key slots, and so even though we use a couple hundred of them
it's still not the whole range.
Also, the baosec/dabao feature flag can be used to feature-out
cryptographic APIs/accelerators that are too obscure or not
useful for the dabao environment, to "lighten up" the
firmware load.
the master key is currently derived from a number of factors:
- the key seed
- chaff keys
- nuisance keys
and then a salt of the uuid/cpid and some info based on the
developer bit is added.
The info addition ensures that the key rotates if developer
mode is entered, so in addition to the key material being
deleted, the info itself is different which should cause
the master key to rotate and "be lost" even if the key
erasure routine is flawed.
Chaff keys harden against side channel analysis of data
in flight from the RRAM array - under the theory that
the RRAM array is a big, long set of wires (on the order
of mm's) that should make a great target for EM microprobes.
The chaff keys are read out in a random order every boot,
to make it harder to accumulate enough samples to average
out what's going on.
The nuisance keys are just read straight out of the array.
They might be recoverable by side channel analysis, but
their purpose is to make it annoying for a brute-force
read-out of the key array by a microscopist. The location
and size of the nuisance keys are picked to force the attacker
to really dial in their polishing process so that they have
to hit the right layer across the entire chip (or at least
a couple mm's); and then a set of bits are packed closely
together to try and induce as much cross talk on the word
lines, running under the theory that any attack relying
on stray electrons activating the bitlines to enable read-out
are likely to non-selectively activate bitlines, so the
resulting "glow" of the word line is going to be a superposition
of several bits at once. An attacker could, of course, cap
each bit line with a FIB, read the word lines, then uncap/recap
them one by one - but this drives up the cost of the attack
and ensures that it's not just a single imaging run but
will take at least hours if not days for a skilled adversary
with the most modern equipment to extract the data. Furthermore,
the large amount of bits demands that the attacker read out
the data with better than 97% accuracy (the last 3% can be
cleaned by the ECC coded into the array), so mistakes
are costly.
The chaff/nuisance keys are read out where the chaff keys
(which are order-independent) are interleaved with the nuisance
key readout. The chaff keys are read roughly twice, using
a continuous-time algorithm to pick which version of the
chaff key is read, making it a bit harder for sidechannel
analysis to pick out which key is in flight.
It's an attempt at sidechannel hardening, we'll see how it
holds up. Pretty sure there's still some low hanging fruit
in the read-out, it'll be interesting to see what the red
team comes up with.
Hopefully this at least makes the keystore not the low hanging
fruit, and we're back at looking at bootloader/kernel exploits etc.
to do key extraction, which I'm sure there are many; but at
least those can be patched.
this is done after critical setup is done. it doesn't guarantee
that it has an infinite time slice, but it makes the startup sequence
more deterministic.
the snippet `attack_keystore()` is left in place along with hints
on how to attack the keystore. Nominally, the attack should fail,
but there are some critical pre-assumptions that can be violated.
I am interested in knowing how robust those assumptions are, so,
documentation and sample code is provided to would-be attackers.
Do me a solid and if you do find a vulnerability, open an issue
ASAP and let me know. Full well aware that some vulns may well
be unpatchable; it is what it is. Hardware is hard, but maybe
we can work together to make it better.
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.
The code base had evolved through several code names, interim
names, company names and chip names that alternatively did or did
not exist.
Baochip is the definitive name of the company, and the Baochip1x
(full part number BAO1X2S4F-WA) is the definitivey part number of
the SoC. For convenience, the part number is shortened to 'bao1x'
in most feature flags and variable references.
This commit fixes all of the odd names and removes some unmaintained
early targets.
This relies on a trick I was not aware of previously, which is
that transitive dependencies absorb the additive set of features
enabled within a crate.
see
https://doc.rust-lang.org/cargo/reference/features.html#feature-unification
for the full description. but basically by referring to the feature
required in "aes" despite not being used in the crate but pulled
in by aes-gcm-siv, i can ensure that the transitive dependency
is in fact used.
I think this was always there but previously I just didn't understand
it correctly or didn't use it right when I tried to deploy it, but
this time I think I got it right.
remove features that we don't need so as to make the tree as
simple as possible to descend
in particular if we're just pinging the HAL layer for some simple
constants we don't have to pull in the hairball of std targets
this is a common api problem because yes, while arg1 is strictly
the second item, previously arg0 was hidden and in the argument
list arg1 took the first place not the second. so i make this
mistake a lot...