Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
The randutil.RandomKernelUUID() used to generate a panic on failure.
The process of consolidating common code used by Pebble and Snapd
(e.g. randutil) highlighted the fact that an error return, as relied on by
Pebble, is a more flexibie approach and allows application code to decide
the severity, instead of the library function.
- Make secboot unlock code to deal with an error that can now be returned
from the UUID generator.
- Add unit tests to cover the new error paths in the code.
Signed-off-by: Fred Lotter <fred.lotter@canonical.com>
Make RandomKernelUUID() return an error instead of generating a panic. This
is better suited for this library function. The severity of the failure can
be determined by the application code.
This is meant to be used from very specific pieces of code, namely right now the
initramfs via snap-bootstrap where we want a cryptographically secure UUID.
Also fix typo in error message for CryptoTokenBytes.
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>