16 Commits

Author SHA1 Message Date
Miguel Pires
79c5ac14b2 many: remove usages of deprecated io/ioutil package (#13768)
* many: remove usages of deprecated io/ioutil package

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* .golangci.yml: remove errcheck ignore rule for io/ioutil

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* run-checks: prevent new usages of io/ioutil

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-04-03 23:23:24 +02:00
Miguel Pires
29c9752d66 many: s/ioutil.WriteFile/os.WriteFile (#13217)
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>
2023-09-26 11:38:46 +01:00
Fred Lotter
9a5accce42 secboot: UUID generator error instead of panic
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>
2023-05-25 09:10:43 +02:00
Fred Lotter
367bb1e52d randutil: add unittests for RandomKernelUUID() 2023-05-25 09:10:43 +02:00
Fred Lotter
e21246f6bf randutil: make RandomKernelUUID() return an error
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.
2023-05-25 09:10:43 +02:00
Ian Johnson
813b511210 randutil: fix panic message
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2020-05-11 15:31:11 -05:00
Ian Johnson
9cefa40625 randutil: add RandomKernelUUID
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>
2020-05-11 14:52:08 -05:00
Samuele Pedroni
504b7bcf39 randutil: improving comments 2020-03-21 08:34:16 +01:00
Samuele Pedroni
17f893f7bf avoid consuming kernel entropy, just mix hostname and interfaces info 2020-03-20 21:08:00 +01:00
Samuele Pedroni
cba743d757 randutil: try to re-improve the quality of RandomDuration 2020-03-20 09:06:00 +01:00
Samuele Pedroni
b17d4905fd randutil: switch back to setting up seed with lower entropy data 2020-03-19 22:12:32 +01:00
Samuele Pedroni
da0a326458 randutil,o/snapstate,-mkauthors.sh: follow ups to randutil introduction (#8090)
* follow-up: fix typo

* follow-up: make cookies slightly shorter (312 bits)

* mkauthors.sh is unused now
2020-02-05 08:55:54 +01:00
Samuele Pedroni
d7479b55d1 many: rename MakeRandomString to just RandomString 2020-02-03 19:02:21 +01:00
Samuele Pedroni
ba5b0c7a07 randutil: improt the CryptoToken* doc comments 2020-02-03 18:57:27 +01:00
Samuele Pedroni
f755429240 randutil: introduce RandomDuration 2020-02-03 14:43:35 +01:00
Samuele Pedroni
0464160230 randutil: introduce an utility package for random value generation 2020-02-03 14:43:35 +01:00