Commit graph

178 commits

Author SHA1 Message Date
bunnie
b1b6d46d27 chore: more typos
probably should not have tried to spell check this, now i'm wasting
my time.
2022-12-13 22:56:37 +08:00
bunnie
399124f942 fix hosted mode 2022-12-10 22:05:47 +08:00
bunnie
939e13950d comment out debug in rootkeys implementation section 2022-12-10 18:59:55 +08:00
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
bunnie
f84a9d10c7 add placeholder for the efuse flow in the rootkey service 2022-12-04 18:13:37 +08:00
bunnie
67fc21fbdd harmonize hosted mode selection, but retain an explicit hosted flag
In general, hosted mode is assumed "by default" if the target
is not Xous. This allows packages to be built cleanly on command
lines that don't know to pass a --feature flag to specify a target.

However, an explicit "hosted" flag is still retained so that we
can confirm the build system intent. This saves us from the failure
mode that we thought we were building for target A, but accidentally
ommitted the flag, and instead we've been silently building for
"hosted" mode without any warning. The main consumer of the "hosted"
flag is now just the build.rs script inside of the utralib.
2022-10-25 17:21:02 +08:00
bunnie
9a4b530046 deprecate instances of llio reboot in favor of susres reboot 2022-10-17 05:05:37 +08:00
bunnie
db7d190270 handle bad signature cases with a dialog box 2022-10-13 03:11:33 +08:00
bunnie
be239f9812
Merge pull request #238 from Foundation-Devices/from-into
Implement From instead of Into.
2022-10-12 11:49:19 -07:00
bunnie
35584cf6bf
Merge pull request #226 from gsora/fix/root-keys-invalid-image-fail
root-keys: gracefully handle cases where gateware signature is malformed, invalid public key or signature type
2022-10-12 11:44:47 -07: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
2a440f6409 retry bad passwords on backups; add note that backups are not abortable
Because we unmount the PDDB and put the system in a semi-shutdown
state, backups are not abortable if you type in the wrong root password.
This patch retries the root password forever, but also adds a note
at the beginning of the process that the process cannot be stopped
once started.
2022-10-09 17:44:46 +08: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
Gianguido Sorà
89f5d568ff root-keys: gracefully handle cases
where gateware signature is malformed, invalid public key or
signature type
2022-09-30 15:17:38 +02:00
bunnie
f70dc246b8 fix hosted mode 2022-08-12 23:26:43 +08:00
bunnie
7aca2d64b3 lower debug level 2022-08-12 23:09:06 +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
5be62e372d chore: move AES-GCM-SIV off of branch to 0.11.1 official
this patch moves us off the branch we had to hop on for cipher
API compatibility to the one that's officially published by
RustCrypto. This closes #168.
2022-08-01 15:44:16 +08:00
bunnie
e943b35512 fix key wrapping in hosted mode
this will require you to regenerate your hosted mode PDDB
image, no migration was written for this mode.
2022-07-26 03:24:37 +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
c0bd7f7f8a add note about faulty keywrap implementation 2022-07-25 01:22:04 +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
6ea88dedee fix hosted mode 2022-07-19 05:28:32 +08:00
bunnie
7ad418be7c fix bug where RestoreDna backup op fails to be set. 2022-07-19 05:26:48 +08:00
bunnie
4ead1010cd add retry flow to restore; fix salt bug
salt was reading from the wrong location on a device that
previously was initialized but doing a restore to.
2022-07-19 05:07:22 +08:00
bunnie
7b3c928429 whoops, a debug statement is leaking private info. nuke that. 2022-07-19 04:45:07 +08:00
bunnie
2ca51b7d32 peeling that onion...another key verification failure in restore. 2022-07-17 23:51:45 +08:00
bunnie
c05e66b32c fix issue where pubkey was being erased before access
verification happens after the private key material is erased,
which incidentally nukes public key material, causing verification
to fail. This caches a copy of the pubkey material before
the erase happens.
2022-07-17 21:15:30 +08:00
bunnie
a5685c9e62 add debugging around restore verification
for some reason we're getting a bogus failure on restore...
2022-07-17 18:50:10 +08:00
bunnie
15ca22eacf fix hosted mode 2022-07-17 03:46:28 +08:00
bunnie
646a9fc1e5 fix hosted mode 2022-07-17 03:45:50 +08:00
bunnie
0cc2e46b02 fix dangling method invocation
complicated thing is complicated
2022-07-17 03:36:36 +08:00
bunnie
667470ba05 fix restore bugs
- read order of keys was wrong from staged data
 - make restore a blocking op so the Ux doesn't try to trigger
 other things at boot
 - fix pubkey check to use staged key for backup flow
 - fix some wording and skip redundant messages
2022-07-17 03:10:26 +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
fded17221f improve autoupdate work flow and error messaging
this is hopefully a work-around for #114 as well, assuming
users actually read the message...
2022-07-14 23:20:26 +08:00
bunnie
a5bcc50007 Merge branch 'backups' into main 2022-07-14 19:27:18 +08:00
bunnie
abade9e1af minor fixes in the autoupdate flow
- do not try to create root keys if we just did an SoC update.
that's just too many things going on, we should definitely force
a clean reboot first.

- add a clean reboot step after a no-key soc update

- try to switch USB debug mode on if a backup was created
2022-07-14 19:26:09 +08:00
bunnie
04f34c6320 Merge branch 'backups' into main 2022-07-14 04:46:21 +08:00
bunnie
f7dcbe0ab0 fix some formatting and CI messaging issues 2022-07-14 04:46:02 +08:00
bunnie
45a150362d Merge branch 'backups' into main 2022-07-14 04:20:51 +08:00
bunnie
b2f169c55e fix unpack signature on init flow to allow for both block and nonblock 2022-07-14 04:20:14 +08:00
bunnie
8a5c6000cc fix hosted mode 2022-07-14 03:15:39 +08:00
bunnie
d5d6461dc5 fix details on forward-version autoupdate flow 2022-07-14 02:00:06 +08:00