Skip to content

Commit 5f6a2fd

Browse files
Hernan GattaDaniel Kiper
Hernan Gatta
authored and
Daniel Kiper
committed
util/grub-protect: Add new tool
To utilize the key protectors framework, there must be a way to protect full-disk encryption keys in the first place. The grub-protect tool includes support for the TPM2 key protector but other protectors that require setup ahead of time can be supported in the future. For the TPM2 key protector, the intended flow is for a user to have a LUKS 1 or LUKS 2-protected fully-encrypted disk. The user then creates a new LUKS key file, say by reading /dev/urandom into a file, and creates a new LUKS key slot for this key. Then, the user invokes the grub-protect tool to seal this key file to a set of PCRs using the system's TPM 2.0. The resulting sealed key file is stored in an unencrypted partition such as the EFI System Partition (ESP) so that GRUB may read it. The user also has to ensure the cryptomount command is included in GRUB's boot script and that it carries the requisite key protector (-P) parameter. Sample usage: $ dd if=/dev/urandom of=luks-key bs=1 count=32 $ sudo cryptsetup luksAddKey /dev/sdb1 luks-key --pbkdf=pbkdf2 --hash=sha512 To seal the key with TPM 2.0 Key File (recommended): $ sudo grub-protect --action=add \ --protector=tpm2 \ --tpm2-pcrs=0,2,4,7,9 \ --tpm2key \ --tpm2-keyfile=luks-key \ --tpm2-outfile=/boot/efi/efi/grub/sealed.tpm Or, to seal the key with the raw sealed key: $ sudo grub-protect --action=add \ --protector=tpm2 \ --tpm2-pcrs=0,2,4,7,9 \ --tpm2-keyfile=luks-key \ --tpm2-outfile=/boot/efi/efi/grub/sealed.key Then, in the boot script, for TPM 2.0 Key File: tpm2_key_protector_init --tpm2key=(hd0,gpt1)/efi/grub/sealed.tpm cryptomount -u <SDB1_UUID> -P tpm2 Or, for the raw sealed key: tpm2_key_protector_init --keyfile=(hd0,gpt1)/efi/grub/sealed.key --pcrs=0,2,4,7,9 cryptomount -u <SDB1_UUID> -P tpm2 The benefit of using TPM 2.0 Key File is that the PCR set is already written in the key file, so there is no need to specify PCRs when invoking tpm2_key_protector_init. Signed-off-by: Hernan Gatta <[email protected]> Signed-off-by: Gary Lin <[email protected]> Reviewed-by: Stefan Berger <[email protected]> Reviewed-by: Daniel Kiper <[email protected]> Tested-by: Stefan Berger <[email protected]>
1 parent ad0c527 commit 5f6a2fd

File tree

5 files changed

+1469
-0
lines changed

5 files changed

+1469
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ widthspec.bin
169169
/grub-ofpathname.exe
170170
/grub-probe
171171
/grub-probe.exe
172+
/grub-protect
173+
/grub-protect.exe
172174
/grub-reboot
173175
/grub-render-label
174176
/grub-render-label.exe

Makefile.util.def

+26
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,32 @@ program = {
208208
ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
209209
};
210210

211+
program = {
212+
name = grub-protect;
213+
mansection = 1;
214+
215+
common = grub-core/kern/emu/argp_common.c;
216+
common = grub-core/osdep/init.c;
217+
common = grub-core/lib/tss2/buffer.c;
218+
common = grub-core/lib/tss2/tss2_mu.c;
219+
common = grub-core/lib/tss2/tpm2_cmd.c;
220+
common = grub-core/commands/tpm2_key_protector/args.c;
221+
common = grub-core/commands/tpm2_key_protector/tpm2key_asn1_tab.c;
222+
common = util/grub-protect.c;
223+
common = util/probe.c;
224+
225+
cflags = '-I$(srcdir)/grub-core/lib/tss2 -I$(srcdir)/grub-core/commands/tpm2_key_protector';
226+
227+
ldadd = libgrubmods.a;
228+
ldadd = libgrubgcry.a;
229+
ldadd = libgrubkern.a;
230+
ldadd = grub-core/lib/gnulib/libgnu.a;
231+
ldadd = '$(LIBTASN1)';
232+
ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
233+
234+
condition = COND_GRUB_PROTECT;
235+
};
236+
211237
program = {
212238
name = grub-mkrelpath;
213239
mansection = 1;

configure.ac

+30
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ grub_TRANSFORM([grub-mkpasswd-pbkdf2])
7676
grub_TRANSFORM([grub-mkrelpath])
7777
grub_TRANSFORM([grub-mkrescue])
7878
grub_TRANSFORM([grub-probe])
79+
grub_TRANSFORM([grub-protect])
7980
grub_TRANSFORM([grub-reboot])
8081
grub_TRANSFORM([grub-script-check])
8182
grub_TRANSFORM([grub-set-default])
@@ -2068,6 +2069,29 @@ fi
20682069
AC_SUBST([LIBZFS])
20692070
AC_SUBST([LIBNVPAIR])
20702071

2072+
AC_ARG_ENABLE([grub-protect],
2073+
[AS_HELP_STRING([--enable-grub-protect],
2074+
[build and install the `grub-protect' utility (default=guessed)])])
2075+
if test x"$enable_grub_protect" = xno ; then
2076+
grub_protect_excuse="explicitly disabled"
2077+
fi
2078+
2079+
LIBTASN1=
2080+
if test x"$grub_protect_excuse" = x ; then
2081+
AC_CHECK_LIB([tasn1], [asn1_write_value], [LIBTASN1="-ltasn1"], [grub_protect_excuse="need libtasn1 library"])
2082+
fi
2083+
AC_SUBST([LIBTASN1])
2084+
2085+
if test x"$enable_grub_protect" = xyes && test x"$grub_protect_excuse" != x ; then
2086+
AC_MSG_ERROR([grub-protect was explicitly requested but can't be compiled ($grub_protect_excuse)])
2087+
fi
2088+
if test x"$grub_protect_excuse" = x ; then
2089+
enable_grub_protect=yes
2090+
else
2091+
enable_grub_protect=no
2092+
fi
2093+
AC_SUBST([enable_grub_protect])
2094+
20712095
LIBS=""
20722096

20732097
AC_SUBST([FONT_SOURCE])
@@ -2184,6 +2208,7 @@ AM_CONDITIONAL([COND_GRUB_EMU_SDL], [test x$enable_grub_emu_sdl = xyes])
21842208
AM_CONDITIONAL([COND_GRUB_EMU_PCI], [test x$enable_grub_emu_pci = xyes])
21852209
AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes])
21862210
AM_CONDITIONAL([COND_GRUB_MOUNT], [test x$enable_grub_mount = xyes])
2211+
AM_CONDITIONAL([COND_GRUB_PROTECT], [test x$enable_grub_protect = xyes])
21872212
AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x])
21882213
if test x$FONT_SOURCE != x ; then
21892214
HAVE_FONT_SOURCE=1
@@ -2311,6 +2336,11 @@ echo grub-mount: Yes
23112336
else
23122337
echo grub-mount: No "($grub_mount_excuse)"
23132338
fi
2339+
if [ x"$grub_protect_excuse" = x ]; then
2340+
echo grub-protect: Yes
2341+
else
2342+
echo grub-protect: No "($grub_protect_excuse)"
2343+
fi
23142344
if [ x"$starfield_excuse" = x ]; then
23152345
echo starfield theme: Yes
23162346
echo With DejaVuSans font from $DJVU_FONT_SOURCE

docs/man/grub-protect.h2m

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[NAME]
2+
grub-protect \- protect a disk key with a key protector
3+
[DESCRIPTION]
4+
grub-protect helps to protect a disk encryption key with a specified key protector.

0 commit comments

Comments
 (0)