Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b078316
compiler.h: add some checked arithmetic primitives
vathpela Feb 16, 2026
aebdcf6
sbchooser: add a man page
vathpela Mar 3, 2026
0aa0d0b
sbchooser: add header definitions for PE files.
vathpela Feb 19, 2026
3564e7d
sbchooser: add some empty files and Make stuff.
vathpela Sep 22, 2025
53b11fa
sbchooser: load security databases
vathpela Jan 15, 2026
8bce87d
sbchooser: parse secdb entries
vathpela Feb 13, 2026
52c698e
sbchooser: Add basic PE parsing.
vathpela Jan 15, 2026
27dbc0b
sbchooser: load PE files specified on the command line.
vathpela Jan 15, 2026
bad9fe5
sbchooser: read the list of input PEs from stdin
vathpela Feb 24, 2026
ddf0b18
sbchooser: generate authenticode hashes for input PE files
vathpela Mar 6, 2026
df7b36a
sbchooser: check for hashes in db and dbx
vathpela Feb 24, 2026
1688daa
sbchooser: sort our output list.
vathpela Feb 24, 2026
ed6df86
sbchooser: Add some test data
vathpela Mar 2, 2026
75dd41e
sbchooser: test sha512 db vs sha256 db
vathpela Mar 2, 2026
932e983
sbchooser: parse PE signatures
vathpela Mar 6, 2026
ae7e4b4
sbchooser: Evaluate certificate trust based on db and dbx.
vathpela Mar 6, 2026
bcd67f6
sbchooser: evaluate the trust of each signature.
vathpela Mar 6, 2026
0e62666
sbchooser: evaluate security strength of our PE signatures.
vathpela Mar 6, 2026
159d2d9
sbchooser: compare validity of two PE files.
vathpela Mar 6, 2026
fcd4cb4
sbchooser: test sha512 db vs untrusted
vathpela Mar 2, 2026
341cbc6
sbchooser: test sha512 db vs sha256 db vs dbx
vathpela Mar 2, 2026
338d87d
sbchooser: test sha512 db vs RSA 2K db
vathpela Mar 2, 2026
e3e8e53
sbchooser: test cert in db and dbx
vathpela Mar 2, 2026
14a78ce
sbchooser: test two certs in db with same security
vathpela Mar 2, 2026
a38ed59
sbchooser: add support for only using one signature
vathpela Mar 4, 2026
49f5a2d
sbchooser: test --first-sig-only
vathpela Mar 2, 2026
2e9a561
sbchooser: add --explain
vathpela Mar 6, 2026
84afcb7
sbchooser: handle a malformed security directory better.
vathpela Mar 10, 2026
89305a0
sbchooser: test with a padded security directory
vathpela Mar 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
efisecdb.1
sbchooser.1
5 changes: 3 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ include $(TOPDIR)/src/include/rules.mk
include $(TOPDIR)/src/include/defaults.mk

MAN1TARGETS = efisecdb.1 \
efivar.1
efivar.1 \
sbchooser.1

MAN3TARGETS = efi_append_variable.3 \
efi_del_variable.3 \
Expand Down Expand Up @@ -41,7 +42,7 @@ MAN3TARGETS = efi_append_variable.3 \
all : $(MAN1TARGETS) $(MAN3TARGETS)

clean :
@rm -f efisecdb.1
@rm -f efisecdb.1 sbchooser.1

prep :

Expand Down
227 changes: 227 additions & 0 deletions docs/sbchooser.1.mdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
.Dd $Mdocdate: Mar 3 2026$
.Dt SBCHOOSER 1
.Sh NAME
.Nm sbchooser
.Nd Utility to sort bootloaders by trust
.Nm
.Sh SYNOPSIS
.Nm
.Oo OPTIONS
.Ek
.Sh DESCRIPTION
.Nm
is a command line utility to determine which of several UEFI bootloaders is
most preferred based on what certificates it is signed by. The output is a
list, one entry per line, of the acceptable loaders, with the best choice
first.

This utility is meant to be used by system installation and upgrade software,
in order to choose the most appropriate bootloader to install based on the
system trust, especially during periods of transition between trust anchors.

When sorting, \fBsbchooser\fR chooses the most preferred binary using the
following criteria, from highest priority to lowest:
.Bl -dash
.It
binaries hashed directly into DB, according to the security strength of the digest used
.It
binaries signed by a certificate in db or chaining to one, sorted by the
security strength of the signature. A binary signed by a certificate with 80
bits of security strength and another signature with a 256-bit security
strength signature which are both trusted is scored as 80 bits; if only the
256-bit signature is trusted, it's scored as 256 bits.
.It
if all that is equal, it prefers the binary with the latest not_after in the
certificate chain.
.It
if all that is equal, it prefers the binary with the earliest not_before in
the certificate chain.
.El
.Pp
When an individual signature is scored, it is much the same. Each
signature's security strength is computed by checking each X509 certificate
in its signatures and taking the lowest security strength of any encryption
algorithm or message digest in use. That is to say, if an individual
signature has (for example) if there are 2 X509 certs co-signing a
signature and one has an RSA-1024 key but the other has an RSA-2048 key,
it's an RSA-1024 (80-bit) signature. In comparing signatures, again the
validity dates are used as a last resort in determining a preference.
.Sh OPTIONS
.Bl -tag
.It Ao Fl d | Fl Fl db Ar db-file Ac
Load a UEFI trusted key database from \fIdb\-file\fR
.It Ao Fl D | Fl Fl no-system-db Ac
Do not load the UEFI trusted key database from this system.
.It Ao Fl s | Fl Fl system-db Ac
Load the UEFI trusted key database from this system (default)
.It Ao Fl f | Fl Fl first-sig-only Ac
Only consider the first signature on an input file
.It Ao Fl x | Fl Fl dbx Ar dbx-file Ac
Load a UEFI revoked key database from \fIdbx\-file\fR
.It Ao Fl X | Fl Fl no-system-dbx Ac
Do not load the UEFI revoked key database from this system.
.It Ao Fl S | Fl Fl system-dbx Ac
Load the UEFI revoked key database from this system (default)
.It Ao Fl i | Fl Fl input Ar pe-file Ac
Load an EFI binary from \fIpe\-file\fR.

By default, if \fB-i\fR is not used, \fBsbchooser\fR reads a list of input files on \fIstandard in\fR. If \fIpe-file\fR is \fB-\fR, \fBsbchooser\fR will look for input files on \fIstandard in\fR as well as any \fB-i\fR input options.
.It Ao Fl e | Fl Fl explain Ac
Instead of producing the normal results, attempt to explain the reason for
trusting or distrusting each input PE file.
.It Fl Fl Ec
All following options are treated as input files. Can be used with \fB-i -\fR to suppliment \fIstandard in\fR.
.El
.Sh EXAMPLES
In the following examples, the following conventions are observed:
.Bl -dash
.It
An EFI binary with \fB.nosigs.\fR in its name has no signatures.
.It
An EFI binary with \fB.msft2011.\fR in its name is signed by the UEFI 2011 certificate.
.It
An EFI binary with \fB.msft2023.\fR in its name is signed by the UEFI 2023 certificate.
.It
When an EFI binary has more than one signature, the order in the filename is the same as the order of the signatures on the binary.
.It
\fBdb.msft2011\fR is a security database containing the UEFI CA 2011 certificate.
.It
\fBdb.msft2023\fR is a security database containing the UEFI CA 2023 certificate.
.It
Database files of the form \fBdb.shim-15.5.el7.x64.sha256\fR contain a sha256 authenticode sum of \fBshim-15.5.el7.x64.efi\fR.
.El
.Ss Choosing which bootloader is most appropriate:
.Bd -literal
host:~$ sbchooser -- \\
/usr/lib/shim/shim-13-0.2.fedora.x64.nosigs.efi \\
/usr/lib/shim/shim-15-2.fedora.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.nosigs.efi \\
/usr/lib/shim/shim-15.5-1.el9.x64.msft2011.efi \\
/usr/lib/shim/shim-15.5.el7.x64.nosigs.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2023.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2023.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.efi
/usr/lib/shim/shim-15.5-1.el9.x64.msft2011.efi
/usr/lib/shim/shim-15-7.el7_2.x64.msft2011.efi
/usr/lib/shim/shim-15-2.fedora.x64.msft2011.efi
host:~$
.Ed
.Ss Choosing which bootloader is most appropriate with local security databases:
.Bd -literal
host:~$ sbchooser --db db.msft2023 --dbx db.msft2011 -- \\
/usr/lib/shim/shim-13-0.2.fedora.x64.nosigs.efi \\
/usr/lib/shim/shim-15-2.fedora.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.nosigs.efi \\
/usr/lib/shim/shim-15.5-1.el9.x64.msft2011.efi \\
/usr/lib/shim/shim-15.5.el7.x64.nosigs.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2023.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2023.efi
host:~$
.Ed
.Ss Choosing which bootloader is most appropriate with the system trusted database but a local revocation database:
.Bd -literal
host:~$ sbchooser --dbx db.msft2023 -- \\
/usr/lib/shim/shim-13-0.2.fedora.x64.nosigs.efi \\
/usr/lib/shim/shim-15-2.fedora.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.nosigs.efi \\
/usr/lib/shim/shim-15.5-1.el9.x64.msft2011.efi \\
/usr/lib/shim/shim-15.5.el7.x64.nosigs.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2023.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.efi
/usr/lib/shim/shim-15.5-1.el9.x64.msft2011.efi
/usr/lib/shim/shim-15-7.el7_2.x64.msft2011.efi
/usr/lib/shim/shim-15-2.fedora.x64.msft2011.efi
host:~$
.Ed
.Ss Choosing which bootloader is most appropriate with a local trusted database, but only considering the first signature:
.Bd -literal
host:~$ sbchooser -f -d db.msft2023 -- \\
/usr/lib/shim/shim-13-0.2.fedora.x64.nosigs.efi \\
/usr/lib/shim/shim-15-2.fedora.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.nosigs.efi \\
/usr/lib/shim/shim-15.5-1.el9.x64.msft2011.efi \\
/usr/lib/shim/shim-15.5.el7.x64.nosigs.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2023.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2023.efi
host:~$
.Ed
.Ss Augmenting the system trust database with only msft2011 enrolled:
.Bd -literal
host:~$ sbchooser -s -d db.shim-15.5.el7.x64.sha256 -- \\
/usr/lib/shim/shim-13-0.2.fedora.x64.nosigs.efi \\
/usr/lib/shim/shim-15-2.fedora.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.nosigs.efi \\
/usr/lib/shim/shim-15.5-1.el9.x64.msft2011.efi \\
/usr/lib/shim/shim-15.5.el7.x64.nosigs.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2023.efi
/usr/lib/shim/shim-15.5.el7.x64.nosigs.efi
/usr/lib/shim/shim-15.5-1.el9.x64.msft2011.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.efi
/usr/lib/shim/shim-15-7.el7_2.x64.msft2011.efi
/usr/lib/shim/shim-15-2.fedora.x64.msft2011.efi
host:~$
.Ed
.Ss Explanation of choosing which bootloader is most appropriate with local security databases:
.Bd -literal
host:~$ sbchooser --db db.msft2023 --dbx db.msft2011 --explain -- \\
/usr/lib/shim/shim-13-0.2.fedora.x64.nosigs.efi \\
/usr/lib/shim/shim-15-2.fedora.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.msft2011.efi \\
/usr/lib/shim/shim-15-7.el7_2.x64.nosigs.efi \\
/usr/lib/shim/shim-15.5-1.el9.x64.msft2011.efi \\
/usr/lib/shim/shim-15.5.el7.x64.nosigs.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi \\
/usr/lib/shim/shim-16.1-4.el10.x64.msft2023.efi
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.msft2023.efi is trusted because cert "/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=Microsoft UEFI CA 2023 signer" is trusted by "/C=US/O=Microsoft Corporation/CN=Microsoft UEFI CA 2023" in db
/usr/lib/shim/shim-16.1-4.el10.x64.msft2023.efi is trusted because cert "/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=Microsoft UEFI CA 2023 signer" is trusted by "/C=US/O=Microsoft Corporation/CN=Microsoft UEFI CA 2023" in db
/usr/lib/shim/shim-16.1-4.el10.x64.msft2011.efi is not trusted because cert "/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=Microsoft Windows UEFI Driver Publisher" is revoked by "/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=Microsoft Corporation UEFI CA 2011" in dbx
/usr/lib/shim/shim-15.5-1.el9.x64.msft2011.efi is not trusted because cert "/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=Microsoft Windows UEFI Driver Publisher" is revoked by "/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=Microsoft Corporation UEFI CA 2011" in dbx
/usr/lib/shim/shim-15-7.el7_2.x64.msft2011.efi is not trusted because cert "/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=Microsoft Windows UEFI Driver Publisher" is revoked by "/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=Microsoft Corporation UEFI CA 2011" in dbx
/usr/lib/shim/shim-15-2.fedora.x64.msft2011.efi is not trusted because cert "/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=Microsoft Windows UEFI Driver Publisher" is revoked by "/C=US/ST=Washington/L=Redmond/O=Microsoft Corporation/CN=Microsoft Corporation UEFI CA 2011" in dbx
/usr/lib/shim/shim-13-0.2.fedora.x64.nosigs.efi is not trusted because no certs or hashes trust it
/usr/lib/shim/shim-15-7.el7_2.x64.nosigs.efi is not trusted because no certs or hashes trust it
/usr/lib/shim/shim-15.5.el7.x64.nosigs.efi is not trusted because no certs or hashes trust it
host:~$
.Ed
.Sh STANDARDS
.Rs
.%A UEFI Specification Working Group
.%B Unified Extensible Firmware Interface (UEFI) Specification Version 2.11
.%I UEFI Forum
.%D March 2026
.%U https://uefi.org/specifications\ \&
.Sh SEE ALSO
.Xr pesign 1 ,
.Xr efikeygen 1 ,
.Xr efisecdb 1
.Sh AUTHORS
.An Peter Jones
.Sh BUGS
.Bl -dash
.It
.Nm
currently ignores \fI.sbat\fR revocation sections, and does not consider that a bootloader may be revoked by the \fISBAT\fR self-check.
.It
.Nm
currently does not treat certificates revoked by their \fITo-Be-Signed\fR hash in \fIdbx\fR as revoked.
.El
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ efisecdb-static
makeguids
guid-symbols.c
guids.lds
sbchooser
thread-test
util-makeguids.c
16 changes: 13 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ include $(TOPDIR)/src/include/defaults.mk

LIBTARGETS=libefivar.so libefiboot.so libefisec.so
STATICLIBTARGETS=libefivar.a libefiboot.a libefisec.a
BINTARGETS=efivar efisecdb thread-test
STATICBINTARGETS=efivar-static efisecdb-static
BINTARGETS=efivar efisecdb sbchooser thread-test
STATICBINTARGETS=efivar-static efisecdb-static sbchooser-static
PCTARGETS=efivar.pc efiboot.pc efisec.pc
TARGETS=$(LIBTARGETS) $(BINTARGETS) $(PCTARGETS)
STATICTARGETS=$(STATICLIBTARGETS) $(STATICBINTARGETS)
Expand All @@ -26,6 +26,8 @@ EFIVAR_SOURCES = efivar.c guid.c util.c
EFIVAR_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(EFIVAR_SOURCES)))
EFISECDB_SOURCES = efisecdb.c guid-symbols.c secdb-dump.c util.c
EFISECDB_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(EFISECDB_SOURCES)))
SBCHOOSER_SOURCES = sbchooser.c sbchooser-pe.c sbchooser-db.c sbchooser-x509.c authenticode.c error.c
SBCHOOSER_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(SBCHOOSER_SOURCES)))
GENERATED_SOURCES = include/efivar/efivar-guids.h guid-symbols.c
MAKEGUIDS_SOURCES = makeguids.c util-makeguids.c
MAKEGUIDS_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(MAKEGUIDS_SOURCES)))
Expand All @@ -36,7 +38,7 @@ util-makeguids.c : util.c

ALL_SOURCES=$(LIBEFISEC_SOURCES) $(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) \
$(MAKEGUIDS_SOURCES) $(GENERATED_SOURCES) $(EFIVAR_SOURCES) \
$(EFISECDB_SOURCES) \
$(EFISECDB_SOURCES) $(SBCHOOSER_SOURCES) \
$(sort $(wildcard include/efivar/*.h))

ifneq ($(MAKECMDGOALS),clean)
Expand Down Expand Up @@ -126,6 +128,14 @@ efisecdb-static : $(patsubst %.o,%.static.o,$(LIBEFISEC_OBJECTS) $(LIBEFIVAR_OBJ
efisecdb-static : | $(GENERATED_SOURCES)
efisecdb-static : private LIBS=crypto dl

sbchooser : private LIBS=crypto efisec efivar
sbchooser : $(SBCHOOSER_OBJECTS)
sbchooser : | $(GENERATED_SOURCES)

sbchooser-static : private LIBS=crypto efisec efivar
sbchooser-static : $(SBCHOOSER_OBJECTS)
sbchooser-static : | $(GENERATED_SOURCES)

thread-test : libefivar.so
# make sure we don't propagate CFLAGS to object files used by 'libefivar.so'
thread-test.o : private CFLAGS=$(HOST_CFLAGS) -I$(TOPDIR)/src/include/efivar
Expand Down
Loading
Loading