Commit graph

55 commits

Author SHA1 Message Date
bunnie
2097afc166 add efuse burning flow to rootkeys
currently only available for builds that have the `efuse` feature
enabled
2022-12-10 18:58:06 +08:00
Jean-Pierre De Jesus DIAZ
59e3378d11
services/root-keys: Implement From instead of Into
Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2022-10-12 15:38:43 +02:00
bunnie
f815ed85b5 fix rust 1.64.0 rkyv warning regressions on unused enum types
rkyv-derived enums throw warnings that they are unused.
Not sure how to get rid of them; I've tried surrounding them in
`#[allow(dead_code)]` directives, and also explicitly creating
each enum variant that I'm aware of through some dummy code and
some log prints of the dummy code calls to ensure the results are
used, and the warnings still persist.

Significantly, the warnings only happen for enums that take
a value. Simple rkyv enums do not throw a warning.

These warnings overwhelm the build logs, so they need to be isolated
in order for us to ensure that the build is clean of other more
important warnings.

The method chosen to isolate them is to take the enums that are
problematic, carve them into their own special file, and add
a file-wide `#![allow(dead_code)]` directive. This only happens
in 7 service crates, and this change commits all of the modifications
in a single big commit that could be undone later if this turns out
to be a compiler regression or something similar.

I also opened an issue with the rkyv maintainer to see what his
opinion is on the situation.

https://github.com/rkyv/rkyv/issues/318
2022-10-09 17:17:20 +08:00
bunnie
99c6e005ad fix hosted mode 2022-10-09 02:46:24 +08:00
bunnie
2ff9163789 add checksums to PDDB backup
every 1MiB block is checksummed with a sha512/256 truncated to
128 bits. This is used to confirm the media and transport integrity
only. It is not intended to be a cryptographic check, it just confirms
that the backup data was transferred correctly assuming no intentionally
malicious actors in the middle.
2022-10-09 01:10:42 +08:00
bunnie
c471ca0fbb fix overly restrictive version match on backup version 2022-10-08 15:29:37 +08:00
bunnie
df12dcdd1e fix hash count computation 2022-10-08 02:25:46 +08:00
bunnie
a416069002 add hash protection on the metadata header
stage is set for hash protection on the PDDB data itself.
that comes next.
2022-10-08 01:22:14 +08:00
bunnie
4e40ae6c5d move from target selectors to feature selectors for back-ends
This will allow for e.g. xous on riscv32-imac but not a precursor
target, for example: by using feature selectors we get to have
a bigger range of targets that we support, such as for implementations
that haven't been upstreamed or have official target-triples.

The downsides are:

- patch override libraries don't absorb feature flags. so, for
example, the AES crate that is used to patch other crates won't
be aware of the target features without modifying the referencing
crates.

- features are normally meant to be additive, but target features
are mutually exclusive. The mutex is enforced by a check in
utralib that throws a panic on build if two targets are accidentally
selected at the same time.
2022-10-02 02:56:44 +08:00
bunnie
9122186900 eliminate rendundant boot PIN request; fix bug in boot key generation
- boot PIN is not requested on root password init. it's redundant,
as it is actually set when you format the PDDB
- boot key was mistakenly a copy of the encrypted private key
for ed25519 key signing. "oops". didn't catch that bug until now...
i don't think it has a big impact on existing user base, because
the key is never exposed outside the rootkey server, and the
ed25519 key itself is encrypted with the root password and then
used as the boot key. But still -- that's just not what was intended.
- root password is requested twice to check the validity of the password
2022-08-12 20:18:32 +08:00
bunnie
ec5cc29ccd hotfix for incorrect AES-KWP implementation
The crate we originally grabbed for AES-KWP seems to be non-compliant
(or I'm an idiot and I can't figure out how to call it in a way
that is compliant).

See https://github.com/jedisct1/rust-aes-keywrap/issues/9

Turns out that `aes_kw` *is* compliant, but unfortunately, it didn't
exist back when the PDDB was being written. The PDDB started in October
2021, and `aes_kw` was pushed in Jan 2022. *just* barely missed it.

Anyways, caught this error while trying to implement some CI for
backups. Hurray for testing!

This patch removes the encryption path using the incorrect version
of the algorithm, but leaves the decryption path in place. The
system will try to decrypt initially with the correct version,
but if that fails, it will fall back and try the incorrect version.
If that succeeds, it returns an error code with the correct key and
an updated wrapped key, which the caller can store so that future
calls do not fail. Thus, we have a seamless migration from the
incorrect version to the correct version.

Have verified that the aes_kw version *does* work with the CI
script, insofar as it has been written (we just got to that point
and got stuck). So, full speed ahead. Users shouldn't notice this
change.

Also, fwiw, I did take a look at the "incorrect" implementation,
and it doesn't look obviously insecure. Printing out the various
rounds of the wrapping function looks like the first couple rounds
match, but it diverges somewhere probably due to an off-by-one
in a counter or something like that. I didn't chase it out -- just
wanted to make sure that nothing looked like a huge data compromise.

Good news is this comes right on the heels of v0.9.9 release, so
this will be pushed as a hotfix right away.
2022-07-25 02:56:20 +08:00
bunnie
6f10061653 reset "don't ask again" flag for password creation during factory test
this facility is necessary in case a worker accidentally picks
the wrong setting, disabling the feature for the device. When
the factory test completes, a call is made to reset the parameter.

This was a slightly complicated affair because the the don't ask
flag is contained within the rootkeys enclave itself, and we can't
just give access to rootkeys willy-nilly. So the flag is passed
through the PDDB and then to the rootkeys enclave. It's not harmful
to have it reset by an unauthorized actor; the pop-up will not
happen if passwords are, in fact, already set.
2022-07-19 23:57:25 +08:00
bunnie
37154f3350 add edge case handling for restore to new device
Just remembered that the PDDB is *locked* to a given device.
To restore to a new device, you have to unlock all the Bases,
and re-encrypt them to the new device's DNA.

This commit adds the facilities to detect this condition, but
the actual code to do this is quite involved...let's handle that
after we've got a "simple" restore to the same device going.

Why do we lock to a device's DNA? the idea is to prevent
attacks where people are taking static blocks of crypto data
and just swapping it between devices to see if they can
get something to decrypt. It also makes it harder for
an adversary to replace the physical device -- e.g., an
evil maid prepared a replacement with implants in advance, and they
image your PDDB onto the replaced device, hoping that you don't
notice. Because the PDDB is device-locked, the "evil maid"
would have to forge the devices DNA to match yours:
possible, but would require kernel mods that patch over the
reported ID; that would trigger the line across the top of the
screen; or, somehow editing the FPGA itself to force
its device ID to report the same as yours. This last attack
vector would be successful, but afaik there is no known way
to modify an FPGA's DNA code. I'm sure there is some proprietary
secret know that Xilinx uses to set it, and if you were
a large government you may be able to coerce Xilinx into giving
you those codes plus some tool that could set the fuses
plus some unfused devices (the fuses are burn-once) but....
2022-07-16 02:31:18 +08:00
bunnie
13e11b83ae add backup of keyboard layout and language 2022-07-16 00:39:14 +08:00
bunnie
d5d6461dc5 fix details on forward-version autoupdate flow 2022-07-14 02:00:06 +08:00
bunnie
b4b6fc2a49 unbreak hosted mode 2022-07-13 05:01:36 +08:00
bunnie
7b72966c09 add restore flow to the root keys server (still untested)
- also recycles the PDDB when keys are initialized
2022-07-13 04:44:13 +08:00
bunnie
09e1b99315 initial infrastructure for running backups
code to serialize/deserialize and encrypt/decrypt the backup
block.

now filling in the UX flow around this.
2022-07-12 03:32:33 +08:00
bunnie
ed2f029874 add SoC autoupdate flow options -- still needs testing 2022-07-11 18:36:00 +08:00
bunnie
ead5bd7dac enable gateware updates when no root keys are present 2022-06-30 22:58:54 +08:00
Sean Cross
a16252e0fb root-keys: add explicit discriminants to enums
This ensures this API is stable across builds.

Signed-off-by: Sean Cross <sean@xobs.io>
2022-06-25 11:07:15 +08:00
bunnie
b498669003 use NIST SP800-38F (AES-KWP) to wrap the system key for the PDDB
this is instead of our lolfail ECB-based method with a check block.
2022-02-03 18:24:06 +08:00
bunnie
6653d42114 cleanup UX context registry
it's now a much smaller nightmare to maintain the registry, as all
the items are concentrated into a single location
2022-01-23 14:31:21 +08:00
bunnie
11162860a8 suppress codegen for unused policy menu (save RAM/disk space) 2022-01-17 04:26:49 +08:00
bunnie
f10827c037 clean up rootkeys to use the new modals dialog box facility 2022-01-17 03:30:09 +08:00
bunnie
8b37303b06 add a check on correct password entry
The rootkey enclave actually doesn't check if your password is
correct -- it has no way of knowing because it doesn't know how
the keys will be used. Password checking is delegated to the
requesting process because also the password retry method and
policy depends upon the application, and is a significant amount
of UX plumbing (in fact the rootkeys should have less UX plumbing
than it has right now - this is something to do in the near future).

Add a mechanism in the PDDB to check if a password was entered
correctly, and retry if it isn't. Without this, an incorrect
password would actually trigger a reformat of the PDDB, since
it can't find the system basis structure with a bad password.
2022-01-05 11:17:13 +08:00
bunnie
fe04f5684f fix a critical bug that prevents root key initialization
This is going to require users to update their devices before
doing a key initialization.

The problem is that we can't trust the length of data presented
to us to self-sign, so we sign the whole area. In v0.9.2 of the
loader, a check was introduced to check the putative length of
the signed area against the actual length of the signed area,
by encoding the length of the signed area within the signed
region.

This would require the rootkeys algorithm to also encode that
new length at the end of the signed area, but this was never
done. However, this bug was never found during testing probably
because I failed to completely erase the original key provisioning
(I was more fixated on checking that existing keys were not damaged by
firmware updates at the time), and thus did not trigger a full
rootkey provisioning cycle when I did the test. I had only just
caught it now while porting the PDDB from simulation to real
hardware.
2022-01-03 19:06:21 +08:00
bunnie
c3fc3ff23f add bbram provisioning sequence 2021-08-19 04:22:28 +08:00
bunnie
498f530165 the base layer of the AES oracle is in place for the rootkeys 2021-08-17 04:15:24 +08:00
bunnie
a1967a2128 make parblock size parametrizeabel (almost)
there's a weird bit where GenericArray needs a U-size (U16)
to match the CONST declaration.
2021-08-17 00:53:26 +08:00
bunnie
944a506f7a aes ops are there but we need to wrap it in a UX... 2021-08-17 00:02:24 +08:00
bunnie
8a82caf2fc intermediate check-in on rootkeys enclave 2021-08-16 23:35:36 +08:00
bunnie
a19fc87687 clean up warnings, and fix some hosted mode issues 2021-08-15 00:46:16 +08:00
bunnie
c88c986aea clean up key signing routines, finally everything "seems" to work 2021-08-14 19:46:42 +08:00
bunnie
ee4368e747 gateware update code in place 2021-08-13 06:00:21 +08:00
bunnie
f334199ee6 commit host mode debugging 2021-08-12 23:01:34 +08:00
bunnie
192109d09a add some skeletal jtag access routines to rootkeys 2021-08-12 02:32:38 +08:00
bunnie
0ccd487f5a test case now failing, now we can solve the problem faster 2021-08-11 23:22:15 +08:00
bunnie
799bb6050e add jtag commands, reboot after burn 2021-08-11 06:15:04 +08:00
bunnie
352b725f7a add an abort option to the initialization flow 2021-08-10 02:48:32 +08:00
bunnie
29f7cbe53b refactor main menu to give options for rootkey operations 2021-08-10 01:54:35 +08:00
bunnie
ec6a3fd1a3 self-signing working, but the patch to use the SHA hash engine seems to be disregarded... 2021-08-09 03:27:43 +08:00
bunnie
bc6ec8caf4 initial key provisioning demo working 2021-08-07 22:21:49 +08:00
bunnie
07bf3478fa add the KEYROM patching database for rewriting bitstreams with new keys
This code was originally in https://github.com/betrusted-io/rom-locate.
However, the majority of that crate is concerned with creating the database
files necessary for the patching, and it pulls in a lot of dependencies.

Changing hardware targets is considered to be a "huge" change for this
project, so we're pushing the code generator directly into xous-core,
and commiting the generated code directly. The theory is that we would
probably never have to modify this code, since it's so intimately linked
to the hardware; it's a bit like committing an include file with
register offsets for a particular peripheral.
2021-08-03 16:28:17 +08:00
bunnie
d112d49524 clean up UX work before switching back into crypto work 2021-08-01 17:52:15 +08:00
bunnie
d56e58cb06 ux now to the point of gathering all the required passwords. 2021-07-31 03:54:10 +08:00
bunnie
d7d052b6ff refactor ux flow, now on a good footing 2021-07-31 03:27:16 +08:00
bunnie
41843db988 intermediate progress on the main UX flow again
does not build clean because still deciding on how to handle
UX feedback.
2021-07-30 19:04:02 +08:00
bunnie
919e9e87ff add bcrypt for password hashing, take care of life cycle of plaintext 2021-07-30 04:07:10 +08:00
bunnie
86a5c34a5b refactor root-keys to use the latest UX features
UX flow for requesting passwords is now more or less complete...

this yak is shaved?
2021-07-29 03:30:03 +08:00