240 Commits

Author SHA1 Message Date
Michael Vogt
a79c7b8121 secboot: use half the mem for KDF in AddRecoveryKey
* osutil: rework TotalSystemMemory to TotalUsableMemory

This commit renames total TotalSystemMemory to TotalUsableMemory
and also changes the code to take the CmaTotal into account. This
is the memory reserved by the  "Contiguous Memory Allocator" and
it is not usable for normal processes. This kind of memory is
used e.g. by the framebuffer of the Raspberry Pi or by DSPs on
certain boards.

* secboot: use half the mem for KDF in AddRecoveryKey

Instead of benchmarking the KDF parameters for the recovery key
(which takes some time to run) we can also use defaults for the
KDF parameters. The defaults suggested by Chris are "4 iterations"
and half the usable memory. This commit implements the suggestions.

* secboot: update KDF memory heuristic

After discussing with Chris and Samuele we updated the KDF memory
heuristic so that it takes more parameters in mind. It now
considers the usable memory and substracts a hardcoded 384MB
that is required to have a working system (a bit of a conservative
estiamte) and then takes half of this for the KDF memory.

* osutil,secboot: fix typos

* secboot: add comment about minimum mem
2021-08-19 22:22:43 +02:00
Michael Vogt
2214a4f419 secboot: switch main key KDF memory cost to 32KB
The main encryption key is high entropy 256bit already so there is
no need to use a strong KDF on top of this. There was a PR already
that switched this to 32MB but it turns out that 32KB is enough.
2021-08-19 19:15:15 +02:00
Michael Vogt
fccd80e8d3 Merge remote-tracking branch 'upstream/release/2.51' into update-2.52 2021-08-17 08:25:53 +02:00
Michael Vogt
7261ba0991 vendor: move to snapshot-4c814e1 branch and set fixed KDF options
* vendor: move to snapshot-4c814e1 branch with KDF fixes

This commit moves our secboot code to the `snapshot-4c814e1` branch
that contains fixes around the KDF benchmarking. This will improve
the install performance.

* secboot: update code to latest api

* secboot: hardcode KDFOptions to avoid benchmarking them and speed up the process
2021-08-09 16:42:34 +02:00
Maciej Borzecki
37fc0edcdc boot: decouple model from seal/reseal handling via an auxiliary type
It is desired that the seal/reseal code only operates on the input provided in
modeenv rather than poking other external structures. The change decouples the
lower level code from accessing the model directly.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2021-06-11 13:16:53 +02:00
Samuele Pedroni
8c76d5fde8 Merge remote-tracking branch 'upstream/master' into HEAD 2021-05-27 11:19:20 +02:00
Michael Vogt
d319961250 secboot: improve error notice about dectivating the volume
Co-authored-by: Ian Johnson <person.uwsome@gmail.com>
2021-05-17 12:54:07 +02:00
Michael Vogt
eca4743411 secboot: switch encryption key size to 32 byte (thanks to Chris)
* secboot: switch encryption key size to 32 byte (thanks to Chris)

We are using an incorrect size for encryption key in secboot. Chris
mentioned this a while ago and this commit fixes it and moves to
a 32 byte key instead of the 64 byte key.

* tests: update uc20-create-partitions-encrypt test to match new keysize
2021-05-12 09:21:06 +02:00
Michael Vogt
a577bcb30e secboot: close unlocked volume when there is any error condition
After opening the encrypted volume we need to be careful to close
it again if there is any error condition that prevents the model
checker from verifying that the model is authorized to read the
volume (thanks Samuele).
2021-05-10 10:45:56 +02:00
Michael Vogt
58ac2151f8 secboot: deactivate volume again when model checker fails
The model checker runs after the device is opened. However if this
check fails we want to make sure to close the device again.
2021-04-27 18:00:43 +02:00
Samuele Pedroni
7b5e0944b4 secboot: fix go test -tags nosecboot 2021-04-25 23:15:57 +02:00
Samuele Pedroni
63d0fdadf3 boot,secboot: generate aux key and bind keys to initial model
TODO about needing more work for resealing

As we so far do for the TPM policy-aut-key, we also save the aux key
into ubuntu-save
2021-04-25 21:26:36 +02:00
Samuele Pedroni
53d4d9fd5b secboot: use the model checker returned when using fde hooks v2 keys
XXX about what to do with the unlocked disk if the model check fails
2021-04-25 21:26:36 +02:00
Samuele Pedroni
2e00d04aaa c/snap-bootstrap,secboot: pass which model is trying to unlock disks
add a WhicModel function field to secboot.UnlockVolumeUsingSealedKeyOptions
2021-04-25 21:26:36 +02:00
Samuele Pedroni
b67daf87a8 secboot: switch to use ActivateVolumeWithKeyData with FDE hooks
this will allow to check/bind to model
2021-04-25 21:26:36 +02:00
Samuele Pedroni
134203ec32 many: drop some now spurious [:] slicing 2021-04-25 13:56:57 +02:00
Samuele Pedroni
c671a47246 kernel/fde,secboot: small cleanups 2021-04-25 13:47:39 +02:00
Samuele Pedroni
1876c57b56 secboot: actually write v2 keys (but use a dummy aux key for now)
also make sure the activation function was called
2021-04-24 20:49:08 +02:00
Samuele Pedroni
ed9bb579d8 Merge remote-tracking branch 'upstream/master' into fde-hooks-v2.4
Adjusted code to the refactoring using kernel/fde.
Split responsibility to deal with v1/v2 hooks with kernel/fde.
Now dealing with aux key will come later.
2021-04-24 19:33:52 +02:00
Samuele Pedroni
948551fba7 many: adjust for nosecboot 2021-04-23 20:56:18 +02:00
Samuele Pedroni
7ad08957ef boot,seboot: introduce and use secboot.SealKeysWithFDESetupHook 2021-04-23 20:06:40 +02:00
Samuele Pedroni
e4c4589ca4 kernel/fde,secboot: move infra to run fde-reveal-key to kernel/fde
deprecate KeyName in fde-reveal-key "reveal"
2021-04-23 20:06:40 +02:00
Samuele Pedroni
4c0d5078b3 secboot,o/devicestate: rename to CheckTPMKeySealingSupported for clarity 2021-04-23 16:15:33 +02:00
Samuele Pedroni
e509090cac many: disentagle kernel/fde from secboot, reorg files in the latter
this stops kernel/fde from importing secboot, which also means that
secboot can now kernel/fde naturally

rename/reorg/split secboot_tpm.go into hooks specific bits
and general secboot-using secboot_sb.go
2021-04-23 16:09:58 +02:00
Samuele Pedroni
4b8a2621ed many: hide the size of the encryption key, we might likely change it
also rename some files that are not really tpm related only
2021-04-23 14:24:51 +02:00