Commit Graph

58 Commits

Author SHA1 Message Date
Morten Linderud bedb8e8c83
main: fixed typo
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-09-05 15:33:17 +02:00
Morten Linderud 73be015150
list-*: Fixup linting
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-09-05 15:33:06 +02:00
Morten Linderud 9ff60964d5
list-*: Ensure we list all entries on error
Return some formatted string and return nil instead of aborting the
entire listing when we encounter an error.

Fixes: https://github.com/Foxboron/sbctl/issues/88

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-09-05 14:54:45 +02:00
Morten Linderud 947b6ba8e8
Formating: Added some misc formatting
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-09-05 14:42:31 +02:00
Hugo Osvaldo Barrera 1aca349c90 Attempt to trigger automounts to find the ESP
The ESP may be an automount partition, so try touching a file in each
candidate location so as to trigger an automounts.

This is the same way systemd attempts to find it:
https://github.com/systemd/systemd/blob/f565b86/src/shared/bootspec.c#L1014-L1018

I've also changed the function to return an error if no ESP is found.
The previous behaviour (an empty string) just results in a crash later
on.

When no ESP is found, the `bundle` command will have no default for the
`esp` flag. Passing an empty string to it as a default results in no
value being show in the output of `--help`.

This seemed like the most reasonable compromise instead of panicking.

Fixes #78
2021-06-28 20:37:56 +02:00
Érico Nogueira 9e0ea82854 sbctl/verify: remove accidental newline
Was leading to double newlines in the "sbctl verify" output.

Signed-off-by: Érico Nogueira <erico.erc@gmail.com>
2021-06-17 00:30:17 -03:00
Morten Linderud a43373ce3f
sbctl: Error looks better then Fatal
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-14 00:24:43 +02:00
Morten Linderud d8af3d80a1
sbctl/status: refactor to cleaner code
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-13 19:41:03 +02:00
Morten Linderud 4ba10b9393
sbctl/remove-*: Added remove logging to the commands 2021-06-13 00:01:44 +02:00
Morten Linderud 64cbd26bb3
sbctl/sign: Added proper messages
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-12 21:38:13 +02:00
Morten Linderud 4de27722ee
Replace fmt.Println with internal logging
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-12 21:37:55 +02:00
Morten Linderud 7c23cf35da
sign-all: don't exit if -g is used and we can't create bundles
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-05 14:36:02 +02:00
Morten Linderud 7e01fec4fa
generate-bundles: Return better error messages
Current errors doesn't really give you any details what is failing if
there is a failure. This rearranges it a little bit

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-05 14:34:54 +02:00
Morten Linderud 03f9ab94d9
Removed erronous println
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-02 21:56:02 +02:00
Morten Linderud 9587644626
sbctl/enroll-keys: Implement support for enrolling keys with go-uefi
This enrolls the keys using go-uefi. Essentially it reworks the
sbkeysync into a set of enroll commands taken from the go-uefi test
suite.

Preferably this should be more flexible e.g for key rotation.

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-02 21:56:02 +02:00
Morten Linderud d04e117cbc
sbctl/create-keys: Rework output and keypath handling
In the future we might want to initialize a new set of keys. It makes
sense to pass the output directory so we can create new keys directly in
an alternative path and overwrite, e.g for key rotation.

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-02 21:55:37 +02:00
Morten Linderud 13bbb90c03
sbctl/enroll-keys: Refactor immutable checking
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-02 21:55:37 +02:00
Morten Linderud 28eee4464d
sbctl/status: Do not fail if sbctl is not initialized
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-02 21:55:37 +02:00
Morten Linderud 0781f6bb98
sbctl/create-keys: Move up the GUID logic
We also make a helper for creating directories in a proper way

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-02 21:55:37 +02:00
Morten Linderud ae1aec15fb
sbctl: Ensure all commands inherit stdout turning off
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 15:18:09 +02:00
Morten Linderud 550b4e6365
Move global flags to persistent
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:47:46 +02:00
Morten Linderud 57a1c93eb9
Remove last of the log.* stuff
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:47:45 +02:00
Morten Linderud 6b0242c953
Added print layout for key syncing
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:38 +02:00
Morten Linderud fe514e1af7
Added errors to WriteFileDatabase
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:38 +02:00
Morten Linderud 0d121672ca
Move verify to top-level
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:37 +02:00
Morten Linderud 6dfc186d43
enroll changes
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:08 +02:00
Morten Linderud 3f05d1df52
Propegate errors better
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:08 +02:00
Morten Linderud a318695f44
Moved generate-bundles top-level
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:08 +02:00
Morten Linderud 3454841a75
Moved create-keys top-level
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:07 +02:00
Morten Linderud 97435cc48e
More internal restructuring
Move more logic top-level, move prints to top-level

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:07 +02:00
Morten Linderud f01453a978
Change immutable error a little bit
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:07 +02:00
Morten Linderud 235238c987
Fixed lint issues
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:07 +02:00
Morten Linderud 3505f1b571
New structure
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:05 +02:00
Morten Linderud adadb52e73
Give status the ability to display owner GUID
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:43:05 +02:00
Morten Linderud 70b00f3184
Added new error
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:43:05 +02:00
Morten Linderud 30e16f5bd7
Catch for unknown command
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:43:05 +02:00
Morten Linderud fb9b3c7b33
🤷
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:43:05 +02:00
Morten Linderud 1508b290d6
Moved json out function
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:43:04 +02:00
Morten Linderud 3568e9d34b
sbctl: Buble up errors from the "library"
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:43:04 +02:00
Morten Linderud a05e6c8fb8
Fixed commands with colors off
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:43:04 +02:00
Morten Linderud 62d653d0f8
Added status new format
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:43:04 +02:00
Morten Linderud 431363f285
Added list-files new WIP for commands
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:43:03 +02:00
Morten Linderud ba6dfc183e
sbctl/bundle: Do not default to ESP for fetching kernel and initramfs
Most distros (I think) default to stuffing this into `/boot` so our ESP
selection is going to mess this up more often then not.

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:15:02 +02:00
Morten Linderud 36a1849942
sbctl/bundle: Change default cmdline to /etc/kernel/cmdline
Should probably try include some documentation to this, but this changes
the default from /proc/cmdline to /etc/kernel/cmdline.

This is partially a standard and a bit more flexible for everyday use
for most people.

https://www.freedesktop.org/software/systemd/man/kernel-install.html

Fixes #39

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-04-05 16:24:19 +02:00
Morten Linderud a426eeb0c6
cmd/sbctl: Typo in err
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-03-12 23:01:15 +01:00
Morten Linderud 17fc0e5ff4
cmd/sbctl: proper exit if we fail creating bundle
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-03-06 19:53:13 +01:00
Morten Linderud a0cd90a0b0
sbctl: Fixed up some missing error handling
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-02-28 14:06:58 +01:00
Érico Rolim f94f185652 Use ReadOrCreateFile in ReadBundleDatabase.
Using the function also removed code that had hardcoded globals for the
location of some files instead of using the dbpath parameter.

Add error checking around the function where appropriate.

Also fail early when creating a new bundle if it isn't possible to
access the bundle database.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
2021-01-11 00:51:32 -03:00
Érico Rolim 92bb91172d Improve error propagation and permission checking.
- Introduces dependency on sys/unix for unix.Access. This is necessary
only in keys.go, since we run 'sbsign' as a command and can't check if
it failed due to permissions.

- Allows removing special casing in main.go for commands that don't
require root permissions.

- ReadFileDatabase() can now return errors due to the multiple ways in
which it can fail; it also warns the user about possibly requiring root.

- ReadFileDatabase() was using the global DBPath instead of its dbpath
parameter in multiple places. This has been fixed.

- VerifyESP() can now run without root.

- SignFile() checks if it can read the DB key before running sbsign.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
2021-01-11 00:49:45 -03:00
Dan Bond 8264a3e370 add staticcheck linter 2020-11-08 10:20:56 +00:00