Commit graph

204 commits

Author SHA1 Message Date
bunnie
05a7c4ca7e use auto-release of accelerator hardware 2024-03-28 16:15:29 +08:00
bunnie
4eab8a35b5 don't try to release hardware in hosted mode 2024-03-25 08:08:06 +08:00
bunnie
f5fdcf7d5b lock rootkeys into a particular version of the dalek crates + cooperative release of hw accelerator
the cooperative release is THE problem that we need to discuss.
2024-03-11 18:18:37 +08:00
bunnie
a68d0513e3 upgrade blowfish so we can retire the old cipher API
the pin was holding back another package
2024-02-08 13:59:26 +08:00
bunnie
df7c31a7df clean up warnings in dummy implementations 2024-02-08 13:10:08 +08:00
David Kotval
e619803114 fix: don't break hosted mode 2024-02-07 13:56:02 -06:00
bunnie
6de48e90f3 fix formatting problem 2024-02-08 00:49:00 +08:00
bunnie
5636e07eb8 Upgrade Ed25519 to latest version; fix zeroize derive. 2024-02-07 22:41:57 +08:00
David Kotval
a70832b3ce wip: dumping deps to get curve25519 to 4.1.1 2024-02-04 14:12:36 -06:00
bunnie
0c7be94c22 re-introduce "wait for hardware" hashes for "big hashes" 2024-02-01 00:52:21 +08:00
bunnie
31efca3e9c add fixme notes for where the Scalar was decomposed due to hash api incompatibility 2024-01-31 04:16:05 +08:00
bunnie
4c99f6da3d patch over rootkeys issues with the new hash
- new api incantations
- KeyInit trait demotion into individual functions
- decomposition of Scalar derivations because the hasher
API changes and is no longer directly passable into Scalar
(this should probably get reverted if/when curve25519/ed25519
is bumped in API later...)
- notes about areas that should be hardware accelerated but are not
2024-01-31 04:12:54 +08:00
bunnie
cc2c11f84c revise API on backups routine to use 0.10 2024-01-31 04:08:06 +08:00
bunnie
da954783ee format services/root-keys
formatted some pretty big blocks of either autogenerated
or copy/pasted blobs used for emulation.

I think I'll let the formatting stand because the autogen
code is "never" going to change (i.e. they are physical constants
tied to the properties of the hardware) or the pasted blobs
have no real meaning beyond the blob itself so if they were
regenerated it'd be another copypasta with format.
2024-01-14 22:38:46 +08:00
bunnie
0c657cffcd cleanup a hosted mode warning 2024-01-08 02:24:05 +08:00
bunnie
055231cb5a extract loader hash from environment
also fix region alignment bug and version code bug.

tested, now works.
2024-01-08 01:44:17 +08:00
bunnie
b87dde9208 add new signature version code to api 2024-01-08 01:44:01 +08:00
bunnie
10154b8372 add some comments and an assert to check consistency 2024-01-05 16:47:31 +08:00
bunnie
61686007c7 modify the signing routine to work with an unmapped kernel region
Now, we finally get to addressing the root cause of #472.

We can't map all of kernel memory anymore, because exclusivity of
ownership of pages is now properly enforced. This means that XIP
images, which run directly out of FLASH, map their code region of
FLASH into their processes. This disallows measurement of their
code spaces by the rootkeys crate; previously we had mapped all
of code space and could measure everyone's code but it also means
we had a double-ownership.

Having resolved that single-ownership is cleaner, we now have
a scheme where the loader, which sees all of the kernel anyways,
computes a hash and signature check of the kernel at boot time,
and pashes the unsigned hash on to the environment variables of Xous
(environment variables pending @xobs commits).

This commit fixes up all the kernel signing routines to work with
a now disjoint kernel memory space. In particular, the key signing
routine needs access to three parts of the FLASH region devoted
to storing `xous.img` (which is loosely and imprecisely referred
to as "kernel memory"; this does lead to confusion thinking that
we're referring to the RAM devoted to the kernel, but for this
discussion we are talking about the window of FLASH where `xous.img`
is written, along with other metadata related to it):

- the first page, where the signature is stored
- the end of the kernel, where the kernel length check is stored
- the end of the entire flash window, where the backup records
are stored

The first page is fairly self-explanatory, this is the signature,
some version information, and an unprotected length hint for the
kernel.

Because the length hint in the signature record is unprotected,
we have to repeat it at the end of the kernel data and include
it in the signed region. Thus, there is a window of memory
that is 2 pages large that captures the dynamically varying
(dynamically varying as in build-to-build this offset changes so
it can't be a `const`) location of the length data. 2 pages
are mapped because the region of interest can fall across a
page boundary, so we map the potential lower page and upper
page that captures the length field (although in most cases
the upper page is not used, it is harmless to map it pre-emptively).
A mask is provided so that we can use the previous compuattions
for offsets and just mask it to compute the offest within this
window.

The end of the flash window, the last page, contains the backup
records. This is a set of metadata that records information
about PDDB backups including the checksums of the regions and
encrypted access keys.

This patch attempts to find all accesses to kernel space and
bin them into their respective regions, while adjust their offsets.

Testing will require us to check signing, updating, and backups --
all aspects of the machine lifecycle are impacted!
2024-01-05 16:31:19 +08:00
bunnie
c73df68e15 add sha512-digest wrapper class
this is a trait wrapper that allows us to take pre-hash as
a `[u8]` and wrap it into a thing that hase a finalize() method
and the requisite traits to satisfy Rust, allowing us to pass
our loader-generated, environment-variable-passed hash into
an otherwise unawares cryptography crate.

mea culpa.
2024-01-05 16:29:41 +08:00
bunnie
8ec08c9c76 fix rust v1.75.0 warnings that are probably benign
a lot of re-import warnings have cropped up. While I appreciate
their studiousness on this, the problem is that removing some
of these exports in the API crate could mean that future users
who want access to some API features that aren't used in this
configuration are now unaccessible.

I think it's not a huge problem at the moment, just spam-cleaning
the warnings because there are too many to deal with carefully
at the moment.
2024-01-04 19:15:28 +08:00
Sean Cross
5dfad296ae xous: mark MemoryRange::as_slice and friends as unsafe
Mark `MemoryRange::as_slice()` and `MemoryRange::as_slice_mut()` as
unsafe.

This is due to the fact that not all representable types can be cast to
an arbitrary value. For example, if Process A sends random values to
Process B, then Process B casts the memory to a slice of `bool`, then
any values that are not 0 or 1 are undefined.

Because these functions can leak UB into the program, they are marked as
unsafe.

This patch adds `unsafe {}` blocks to all instances where this function
is called. Additionally, all instances have been checked to verify that
they do not cast to any invalid types -- most use `u8` or `u32`.

Additionally, the long-deprecated `MemoryRange::from_parts()` call was
removed, since that causes UB without being marked as unsafe.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-09-12 10:07:38 +08:00
bunnie
9932d971c4 clean up the warnings that are deemed safe to clean up
one warning remains, will address this in a future PR.
2023-07-16 17:55:28 +08:00
bunnie
b2c64eb61a aesthetic cleanup; change default font for all modals
I decided to go back on the idea of not changing the modals
and now all modals use the new larger font as well.

This creates issue #396, which I will deal with later once
I have the time to do some more testing. I'm pretty sure
some other dialog boxes are broken now too.
2023-07-05 15:13:38 +08:00
Jean-Pierre De Jesus DIAZ
2af737b57e
xous-rs: move LANG variable to locales
This change is made with the intention of making the xous-rs crate a bit
more freestanding without depending on the xtask build system.

Signed-off-by: Jean-Pierre De Jesus DIAZ <me@jeandudey.tech>
2023-06-15 18:23:12 +02:00
bunnie
fa20b90973 add rand_core trait to functions that require fill_bytes() 2023-02-26 01:01:30 +08:00
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