Error "x509: malformed certificate" on first boot after IncusOS installation

I am installing IncusOS on a bare-metal system. The installation itself goes fine, however after the first reboot I see the following two messages on my screen:

INFO: Upgrading LUKS TPM PCR bindings, this may take a few seconds
ERROR: x509 malformed certificate

After the error is displayed, the system does not make any further progress.

Initially I thought I might have made an error in my image preseed, but this does not seem to be the case as the exact same image installs fine on a virtual machine.

The bare-metal system I am installing on is a workstation with dual Intel Xeon CPUs and an NVIDIA RTX-2000 as a discrete GPU. Because of this config, I have provisioned a custom Secure Boot certificate chain, including:

  • PK: my own certificate
  • KEK: my own + IncusOS’s certificates
  • db: IncusOS’s db certs plus the hash of my GPU’s OpRom

I saw that my GPU’s OpRom is signed with the MS UEFI CA 2011 and I really did not want to onboard this cert in Secure Boot, as this is kind of opening the gates to hell. Therefore, I considered as a better approach to enroll in my db the hash of my GPU’s OpRom. This is fully supported by UEFI Secure Boot and I saw no issues pre-boot.

I believe this hash entry might be the root cause of the error I see in IncusOS. When reconstructing PCR 7 from the TPM event log, both getSigningCertBytes() (event_log.go) and computeExpectedVariableAuthority() (pcrs.go) assume every EV_EFI_VARIABLE_AUTHORITY event’s payload is a full X.509 certificate.

When my GPU’s OpRom executes, I assume that the firmware will log an EV_EFI_VARIABLE_AUTHORITY event recording that it was authorized by the hash entry in db, not a certificate.
If that event’s payload is a SHA256 digest rather than a DER-encoded cert, feeding it to x509.ParseCertificate()will yield the failure I see?

Since this system has only a dGPU, it is not really an option to have the GPU excluded in UEFI (I won’t have any video output). Moreover, given the cert the GPU’s OpRom is signed with, I am also reluctant to “onboard” the MS UEFI CA 2011 cert in db.

Regarding IncusOS:

  • Is hash-based db authorization expected to work with IncusOS PCR7 handling?
  • If so, would it be feasible to provide a fix for the issue I describe?
  • If not, is there any other way forward (which I’m possibly overlooking), apart from onboarding the MS UEFI CA 2011 certificate? It is essential for me to have GPU video output.

Finally, if my hypothesis is correct, could you please consider making the error message I see a bit more descriptive, at least by hinting that this refers to Secure Boot (and not any other certificate that might be provisioned on the system)?

If needed, I am happy to report this as a GitHub Issue. I considered it better to ask here first, to confirm if my hypothesis is correct and if this is actually an issue.

@gibmat any idea what may be raising this error?

Is that likely to be about a SecureBoot certificate or more likely to be about the Incus trust certificate provided by the user through the seed?

Today I repeated the installation with a different structure in my Secure Boot certificates.
Specifically, I replaced the GPU OpRom hash with the MS UEFI CA 2011 certificate and I don’t see the “x509 malformed certificate” error any more. This was the only change I performed.

This observation aligns with my hypothesis that a hash-based db entry produces an EV_EFI_VARIABLE_AUTHORITY event whose payload isn’t an X.509 certificate, which the PCR7 reconstruction can’t handle.

However, I’d greatly appreciate an independent check on that, so @gibmat, could you confirm whether hash entries are expected to be supported?

Finally, enrolling the MS UEFI CA was done purely for a diagnostic purpose :face_with_medical_mask: . I’d prefer not to keep it in my chain. If hash-based authorization turns out to be unsupported, I’m happy to open a GitHub issue and try to collect any logging that could prove useful/support my case!

Yes, it looks like something about the hashed value of your GPU option ROM in the Secure Boot db variable is causing an issue. I’ve tried reproducing this locally, both with the hash of a PE binary (using hash-to-efi-sig-list) and a hash of an actual certificate (using cert-to-efi-hash-list), but those work as expected. We actually do test logic involving these less-common options when present in the dbx variable, but don’t currently test anything other than normal certificates in db.

The library IncusOS uses to parse the Secure Boot variables actually only handles a subset of the entire spec, and I’ve had to extend it in the past to properly recognize less-common entries. :slightly_smiling_face:

Could you send me the hash value that you’ve enrolled on your system (it will likely be a .esl file)? I can then enroll that locally in a VM and see exactly what’s going on.

We should be able to get IncusOS behaving properly, as I agree its far more preferable to whitelist a specific option ROM versus allowing anything that might have been signed by an OEM certificate.

hey @gibmat , thanks for your reply!

my .esl file’s contents (base64 encoded) are:
JhbEwUxQkkCsqUH5NpNDKEwAAAAAAAAAMAAAAFCrXWBG4ABDq7Y92BDdiyMSP00z0ilL3glEaf7/
S2QwYK/MEAw4JpzQePb0dFkD+A==

if you decode this, it should produce an .esl with the following hexdump contents:
$ xxd -c 256 -p gpu_uefi.esl
2616c4c14c509240aca941f9369343284c000000000000003000000050ab5d6046e00043abb63dd810dd8b23123f4d33d2294bde094469feff4b643060afcc100c38269cd078f6f4745903f8

my OpROM’s hash is: 123f4d33d2294bde094469feff4b643060afcc100c38269cd078f6f4745903f8

regarding the behavior I mention above, the following simple(r) example might help you replicate what’s going on in the TPM logging:

  1. In IncusOS, create a VM based on e.g. Ubuntu, let’s call this ubuntu-vanilla and also add to it a TPM device.
  2. Now, create another e.g. Ubuntu VM (let’s call this ubuntu-secureboot) with security.secureboot: 'false'and also add a TPM to it. Further:
    1. Create your own certs for PK and KEK
    2. Create your db based on the hash of Ubuntu’s shim (e.g. hash-to-efi-sig-list /boot/efi/EFI/ubuntu/shimx64.efi db.esl
    3. Generate the .esl files for your PK and KEK .crt files
    4. Sign the .esl files (e.g. sign-efi-sig-list) and enroll the produced .auth files in Secure Boot (e.g. with efi-updatevar)
    5. Reboot the VM

Once both VMs are booted (and ubuntu-secureboot rebooted), it is interesting to observe the TPM log:

  • On ubuntu-secureboot, run tpm2_eventlog /sys/kernel/security/tpm0/binary_bios_measurements |
    grep -A17 'EV_EFI_VARIABLE_AUTHORITY' |
    grep -E 'UnicodeName:|VariableDataLength:|VariableData:' – you should see something like:
    VariableDataLength: 48
    UnicodeName: db
    VariableData: "50ab5d6046e00043abb63dd810dd8b2398a7fb4df6de7e9c57602d7599dc56d5c84685bf61862cdc4fbf8c58ae4367b5"
    which is the EV_EFI_VARIABLE_AUTHORITY authorizing the shimx64.efi to run.
  • On ubuntu-vanilla, if you run the same command you should see:
    VariableDataLength: 1572
    UnicodeName: db
    VariableData: "bd9afa775903324dbd6028f4e78f784b30820610308203f8a003020102020a6108d3c4000000000004300d06092a864886f70d01010b0500308191310b3009060355040613025553311330110603550408130a57617368696e67746f6e3110300e060355040713075265646d6f6e64311e301c060355040a13154d6963726f736f667420436f72706f726174696f6e313b3039060355040313324d6963726f736f667420436f72706f726174696f6e205468697264205061727479204d61726b6574706c61636520526f6f74301e170d3131303632373231323234355a170d3236303632373231333234355a308181310b3009060355040613025553311330110603550408130a57617368696e67746f6e3110300e060355040713075265646d6f6e64311e301c060355040a13154d6963726f736f667420436f72706f726174696f6e312b3029060355040313224d6963726f736f667420436f72706f726174696f6e2055454649204341203230313130820122300d06092a864886f70d01010105000382010f003082010a0282010100a5086c4cc745096a4b0ca4c0877f06750c43015464e0167f07ed927d0bb273bf0c0ac64a4561a0c5162d96d3f52ba0fb4d499b4180903cb954fde6bcd19dc4a4188a7f418a5c59836832bb8c47c9ee71bc214f9a8a7cff443f8d8f32b22648ae75b5eec94c1e4a197ee4829a1d78774d0cb0bdf60fd316d3bcfa2ba551385df5fbbadb7802dbffec0a1b96d583b81913e9b6c07b407be11f2827c9faef565e1ce67e947ec0f044b27939e5dab2628b4dbf3870e2682414c933a40837d558695ed37cedc1045308e74eb02a876308616f631559eab22b79d70c61678a5bfd5ead877fba86674f71581222042222ce8bef547100ce503558769508ee6ab1a201d50203010001a382017630820172301206092b060104018237150104050203010001302306092b060104018237150204160414f8c16bb77f77534af325371d4ea1267b0f207080301d0603551d0e0416041413adbf4309bd82709c8cd54f316ed522988a1bd4301906092b0601040182371402040c1e0a00530075006200430041300b0603551d0f040403020186300f0603551d130101ff040530030101ff301f0603551d2304183016801445665243e17e5811bfd64e9e2355083b3a226aa8305c0603551d1f045530533051a04fa04d864b687474703a2f2f63726c2e6d6963726f736f66742e636f6d2f706b692f63726c2f70726f64756374732f4d6963436f725468695061724d6172526f6f5f323031302d31302d30352e63726c306006082b0601050507010104543052305006082b060105050730028644687474703a2f2f7777772e6d6963726f736f66742e636f6d2f706b692f63657274732f4d6963436f725468695061724d6172526f6f5f323031302d31302d30352e637274300d06092a864886f70d01010b05000382020100350842ff30cccef7760cad1068583529463276277cef124127421b4aaa6d813848591355f3e95834a6160b82aa5dad82da808341068fb41df203b9f31a5d1bf15090f9b3558442281c20bdb2ae5114c5c0ac9795211c90db0ffc779e95739188cabdbd52b905500ddf579ea061ed0de56d25d9400f1740c8cea34ac24daf9a121d08548fbdc7bcb92b3d492b1f32fc6a21694f9bc87e4234fc3606178b8f2040c0b39a257527cdc903a3f65dd1e736547ab950b5d312d107bfbb74dfdc1e8f80d5ed18f42f14166b2fde668cb023e5c784d8edeac13382ad564b182df1689507cdcff072f0aebbdd8685982c214c332bf00f4af06887b592553275a16a826a3ca32511a4edadd704aecbd84059a084d1954c6291221a741d8c3d470e44a6e4b09b3435b1fab653a82c81eca40571c89db8bae81b4466e447540e8e567fb39f1698b286d0683e9023b52f5e8f50858dc68d825f41a1f42e0de099d26c75e4b669b52186fa07d1f6e24dd1daad2c77531e253237c76c52729586b0f135616a19f5b23b815056a6322dfea289f94286271855a182ca5a9bf830985414a64796252fc826e441941a5c023fe596e3855b3c3e3fbb47167255e22522b1d97be703062aa3f71e9046c3000dd61989e30e352762037115a6efd027a0a0593760f83894b8e07870f8ba4c868794f6e0ae0245ee65c2b6a37e69167507929bf5a6bc598358"

The EV_EFI_VARIABLE_AUTHORITY, which are the events logged in PCR-7, in ubuntu-vanillagives you in VariableData the DER certificate with which Ubuntu’s shim is signed.

In the case of ubuntu-secureboot you get instead the shim’s hash value.

When you pass each of these in x509.ParseCertificate(data), the DER should be parsed w/o issues, while the hash should produce you an x509: malformed certificate error, similar to the one I see.

Apologies for the long post, I hope this makes the issue somewhat more clear, obviously if there’s anything more I can provide feel free to let me know.

Well, that was fun! :grin: Should hopefully be fixed in the next IncusOS release after this PR is merged:

Well, that was fun! :grin:

Yeah, secure boot “fun” :laughing:

many thanks for your effort @gibmat and for looking into this in such short notice! I will try again a clean install with my initial Secure Boot structure and will report back here. once I validate this is solved, I will also mark your reply as the solution.

is it safe to assume that this change should be already included in 202610112007?

Yes, although that’s a daily build, but we generally recommend against running daily builds as they are auto-published without any of the normal tests/checks that are run before a build gets promoted from the testing to stable channels. IncusOS 202610121429 was recently published to the stable channel and should also have the fix included. :slightly_smiling_face:

coming back with an update, sorry it took some time before I was able to test things.

in short:

  1. I re-provisioned the Secure Boot chain containing my GPU’s OpRom hash + the IncusOS certificates in db
  2. The system went in lock-down mode (as expected), since the TPM state got altered outside IncusOS.
  3. I (manually) unlocked the system and triggered a TPM rebind, which was successful. From then and on, the system was able to reboot and unlock w/o manual actions, based on the TPM state.

this works now flawlessly :slight_smile:

I believe this hash entry might be the root cause of the error I see in IncusOS. When reconstructing PCR 7 from the TPM event log, both getSigningCertBytes() (event_log.go) and computeExpectedVariableAuthority() (pcrs.go) assume every EV_EFI_VARIABLE_AUTHORITY event’s payload is a full X.509 certificate.

I assume that the TPM rebind and/or the TPM-based unlock of the system will trigger the functionality that was previously giving issues. is this the case?

in this case, I skipped a full re-install (which is where I first observed the wrong behavior). is this something I should explicitly test to cover all angles?