How to extract the signer's certificate and verify the signature of a Linux kernel image | SUSE Communities

How to extract the signer’s certificate and verify the signature of a Linux kernel image


It’s been quite a while since the introduction of UEFI and Secure Boot, which ensures that only code bearing a signature by a trusted party will get executed by the firmware. After a brief period of uncertainty this is now well supported by default in many Linux distributions. The Zero trust security model gaining popularity lately also stipulates – “never trust, always verify”, and do it at every step, always. For this to be effective it has to start at the moment you power on your computer.

The usual boot process for a PC running Linux nowadays is that the UEFI loads a small piece of software (called shim), which in turn loads the bootloader (usually GRUB), and at each step the previous one makes sure the next is digitally signed by a trusted party. To extend this “chain of trust” one step further the Linux kernel has gained support for digitally signing kernel images and modules too. So now the bootloader (or even the UEFI firmware directly) can verify the signature on the kernel image it’s loading. With the correct config options enabled (CONFIG_MODULE_SIG_FORCE and CONFIG_KEXEC_SIG_FORCE) the kernel will itself check the signatures when loading a module or performing a kexec .

Unfortunately this extra security comes at the price of additional complexity. When loading a module or doing a kexec fails because of a problem with signature verification it may not be trivial to find out exactly why. The gory details of how all this intricate machinery works are way outside the scope of this write up, but one possible reason for the failure is that the module or kernel image either doesn’t contain a valid signature at all or it contains one, but the signer is not in the kernel’s list of trusted parties.

With the above in mind when debugging such an issue a logical first step is to check if the module or kernel contains a valid signature and if yes by whom.

Some documentation exists about how to do this for modules, and there are even some helper scripts in the kernel sources, but I didn’t find anything about kernel images.

First, I assume you have a bzImage file on your hands. To figure out if it contains a signature and by whom we need to understand a bit more about it’s file format. And you may be surprised to find that it is actually a Portable Executable file. Yes, your Linux kernel image is in a Microsoft Windows executable file format! Or, more precisely, it pretends to be one just closely enough, so that if you have the CONFIG_EFI_STUB option enabled UEFI can load the Linux kernel directly and verify it’s signature.

Since the PE file format signature was already there the Linux kernel developers decided to reuse it for kexec too. More details about the signatures in a PE executable can be found in this (Microsoft Word!) document.

There are libraries to work with PE files for various languages but I’ve found it simpler to use the standalone osslsigncode utility. If you are using openSUSE Tumbleweed it is just a ‘zypper in osslsigncode’ command away and if not check your favorite distribution’s package manager or compile it from sources. Note that you should be using a fairly recent version of osslsigncode (>=2.6), as I’ve encountered problems with both signature extraction and verification using previous versions.

Once you have that in place, let’s see if the kernel image we are dealing with has a valid signature and if yes, extract it to a file. I’ll use the kernel that came with the distribution for the examples below and run this command:

osslsigncode extract-signature -in /boot/vmlinuz-6.5.2-1-default -out kernel.sig

If the image is signed we get a “Succeeded” message and the signature stored in the kernel.sig file. And if not, you will see a “Unable to extract existing signature, Failed” message.

Now we can use openssl to see a human readable version of the certificates in the pkcs7 signature:

openssl pkcs7 -in kernel.sig -inform der -print_certs -noout -text

Version: 3 (0x2)
Serial Number:
Signature Algorithm: sha256WithRSAEncryption
Issuer: CN=openSUSE Secure Boot CA, C=DE, L=Nuremberg, O=openSUSE Project/
Not Before: Jun 13 13:22:16 2022 GMT
Not After : Apr 21 13:22:16 2032 GMT
Subject: CN=openSUSE Secure Boot Signkey, C=DE, L=Nuremberg, O=openSUSE Project/
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Basic Constraints: critical
X509v3 Subject Key Identifier:
X509v3 Authority Key Identifier:
DirName:/CN=openSUSE Secure Boot CA/C=DE/L=Nuremberg/O=openSUSE Project/
X509v3 Key Usage: critical
Digital Signature
X509v3 Extended Key Usage:
Code Signing
Signature Algorithm: sha256WithRSAEncryption
Signature Value:

From the above output we can see that the certificate used to sign our kernel image bears the “openSUSE Secure Boot Signkey” common name, and that it was issued by the “openSUSE Secure Boot CA” certificate authority. In order to verify the signature we’re going to also need the latter to complete the ‘chain of trust’.

If you have your own PKI you will use own certificates, but in this case the openSUSE CA certificate can be easily obtained by installing the shim package (zypper in shim) and found under /usr/share/efi/x86_64/shim-opensuse.der. We need to convert it from DER to PEM format first, as it’s the one expected by osslsigncode:

openssl x509 -in /usr/share/efi/x86_64/shim-opensuse.der -inform DER -out opensuse-ca.pem -outform PEM

Finally we can use osslsigncode to verify the signature on our kernel image:

osslsigncode verify -in /boot/vmlinuz-6.5.2-1-default -CAfile opensuse-ca.pem
Current PE checksum : 00000000
Calculated PE checksum: 00DC76A1
Warning: invalid PE checksum

Message digest algorithm : SHA256
Current message digest : 9564082AFF7452005D600F5D7C9884CD2F2D7C63544BEBAEC4C9DA1FF7A7EB21
Calculated message digest : 9564082AFF7452005D600F5D7C9884CD2F2D7C63544BEBAEC4C9DA1FF7A7EB21

Signature Index: 0 (Primary Signature)
Signer's certificate:
Signer #0:
Subject: /CN=openSUSE Secure Boot Signkey/C=DE/L=Nuremberg/O=openSUSE Project/
Issuer : /CN=openSUSE Secure Boot CA/C=DE/L=Nuremberg/O=openSUSE Project/
Serial : FABED8BF409A5E65
Certificate expiration date:
notBefore : Jun 13 13:22:16 2022 GMT
notAfter : Apr 21 13:22:16 2032 GMT

Number of certificates: 1
Signer #0:
Subject: /CN=openSUSE Secure Boot Signkey/C=DE/L=Nuremberg/O=openSUSE Project/
Issuer : /CN=openSUSE Secure Boot CA/C=DE/L=Nuremberg/O=openSUSE Project/
Serial : FABED8BF409A5E65
Certificate expiration date:
notBefore : Jun 13 13:22:16 2022 GMT
notAfter : Apr 21 13:22:16 2032 GMT

Message digest algorithm: SHA256

Authenticated attributes:
Signing time: Sep 11 20:04:11 2023 GMT
Message digest: C852448C1DBAC25B0F18D4F9711DA864F0E75A1A8FDD207315353042B84AC576

CAfile: osslsigncode/osslsigncode-2.7/build/opensuse-ca.pem

Timestamp is not available

Signature verification: ok

Number of verified signatures: 1

If all of the above looks good (don’t be alarmed by the invalid ‘PE checksum’ warning) and you still can’t kexec the image, then the problem must be a missing certificate in the ‘trusted signers’ list of the running kernel. Certificates in this list can be added either at kernel compile time, or during runtime using the ‘keyctl’ utility, but that may be a topic for another article …

Happy debugging!


Leave a Reply

Your email address will not be published. Required fields are marked *

No comments yet

Avatar photo
Radoslav Kolev I worked with Linux in one way or another all my professional life. After ~10 years in the embedded space I am now part of the Automotive team at SUSE.