Before You Begin

This tutorial explains how to use the mokutil tool to update the certificates used for UEFI Secure Boot on Oracle Linux.

Background

A system in Secure Boot mode only loads boot loaders and kernels that have been signed by Oracle. Oracle updates the kernel and grub2 packages to sign them with a valid Extended Validation (EV) certificate in the event that a key may expire or for additional security updates. The EV certificate is compiled into the shim binary and is signed by Microsoft. The UEFI Secure Boot feature is fully supported from Oracle Linux 7 Update 3 onward.

In the case that Oracle updates the EV certificate for a kernel release, or related dependency packages such as grub2 and shim, you may find it difficult to boot older kernels without downgrading packages or without updating the UEFI Secure Boot key database to recognize the certificate or hash for a particular kernel. Kernel UEFI key updates are tracked in the notice at https://docs.oracle.com/en/operating-systems/oracle-linux/notice-secure-boot/.

If you wish to downgrade to an older kernel, you may also need to downgrade any associated packages. If you are changing between kernels frequently, for testing reasons or to debug an issue, you may want to avoid constantly reinstalling the dependency packages. If you wish to update these packages independently so that you can continue to use the newer grub2 and shim packages with an older kernel or vice versa, it is possible to use the Machine Owner Key (MOK) facility to update the UEFI Secure Boot key database and import the keys manually. The MOK facility can also be used to import keys that you use to sign your own development build kernel, so that it is able to boot in UEFI Secure Boot mode. Furthermore, the MOK facility can be used to import keys used to sign third party or custom kernel modules so that these can load while in UEFI Secure Boot mode.

There are two approaches to handling the enrollment of keys within the UEFI Secure Boot key database:

Important

Using the MOK utility with your system may depend on server firmware implementation and configuration. Check that your server supports this before attempting to manually update signature keys used for UEFI Secure Boot. If you are unsure, do not follow the instructions provided here.

There are known issues when using the MOK utility with UEK R3. If you are using UEK R3, please do not follow the instructions provided here.

Adding certificates to the UEFI Secure Boot key database by using the MOK utility requires that you have physical access to the system so that you can complete the enrollment request at the UEFI console. If you do not have physical access to the system, do not follow the instructions that are provided here.

You can repeat these steps to import additional signing certificates into the MOK list so that you can use UEFI Secure Boot to boot alternate kernels that are signed with any matching certificate. By importing both certificates into the MOK list, you are able to use UEFI Secure Boot to boot kernels that are signed with either certificate without any requirement to upgrade or downgrade related packages.


Install the mokutil and pesign packages

Install the mokutil and pesign packages. The mokutil package is used to update the MOK list with a certificate or hash. The pesign package is used to sign kernels and tools with a certificate, but it can also extract a hash from a specific kernel, that can then be added to the MOK list.

If you are using Oracle Linux 8:

# dnf install mokutil pesign

If you are using Oracle Linux 7, also, make sure that you have the yum-utils package installed so that you can use the yumdownloader command to download the shim source package.:

# yum install mokutil pesign yum-utils

Enroll a hash for a specific kernel

The pesign command is the tool used to create the shim with Oracle's signed keys, but it can equally be used to create your own shim with your own signed keys if required. In this example, the command is used to extract a padded hash of from a specific signed kernel binary. This hash is imported into the MOK list so that the associated kernel can load at boot time. This approach is more secure than importing an entire certificate into the MOK list as it is restricted to a specific kernel binary.


Import the hash into the MOK list

Use the mokutil command with the pesign command to extract the hash from a selected kernel binary and import it into the MOK list. This can be achieved as a single command. For example to import the hash for the kernel image at /boot/vmlinuz-4.18.0-193.el8.x86_64:

# mokutil --import-hash $(pesign -P -h -i /boot/vmlinuz-4.18.0-193.el8.x86_64  | cut -f 2 -d ' ')

The command prompts you to enter and confirm a password for the MOK enrollment request. You can use any password for this purpose, but you should note the password that you use, as you are prompted for it again when the system reboots.

Enroll a certificate for a kernel or package

To enroll a certificate for a set of kernels that are signed using the same certificate, you must first obtain the certificate file for the appropriate set of kernel binaries. The certificate keys that are used to sign each kernel and shim are contained in the source packages. If you download the appropriate source package and extract the certificate, you can use the mokutil command to import this certificate into the MOK list.

Download the kernel source package

On Oracle Linux 8, use dnf to download the kernel or kernel-uek source package that you require. For example, to download the latest UEK source package:

# dnf download --source kernel-uek

On Oracle Linux 7 run the yumdownloader command to download the kernel or kernel-uek source package that you require. For example, to download the kernel-uek-4.14.35-1902.303.4.1.el7uek version of this package:

# yumdownloader --source kernel-uek-4.14.35-1902.303.4.1.el7uek

Note that you can repeat the instructions in this tutorial to download multiple versions of each source package and extract the certificates from each, to import into the UEFI Secure Boot database, as you require. Use the Oracle Linux UEFI Secure Boot Update Notices to find guidance on the package versions that you might need for different minimum kernel versions.


Extract the source package

Extract the source package to access the EV certificate that is included for the kernel or kernel-uek package:

# rpm2cpio ./kernel-uek*.rpm | cpio -idmv

Import certificate into the MOK list

Use the mokutil command to request that the certificate that you have extracted from the source package is included in the MOK list:

# mokutil --import ./secureboot.cer

The command prompts you to enter and confirm a password for the MOK enrollment request. You can use any password for this purpose, but you should note the password that you use, as you are prompted for it again when the system reboots.

Do not import the CA certificate, securebootca.cer, that is included in the source packages. Importing the CA certificate allows any kernel that uses a certificate signed by the same CA to load and renders UEFI Secure Boot ineffective.



Reboot the system and complete enrollment

Reboot the system.

The pending MOK key enrollment request is detected, and you must complete the enrollment from the UEFI console. You are prompted for the password that you set when you imported the certificate. When you have entered the correct password, the certificate is added to the MOK list and is automatically propagated to the system key ring on this boot, as well as subsequent boots.


Want to Learn More?