diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-11-02 19:20:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-02 19:20:50 +0100 |
| commit | 98598dfc18f403916678cc532f5c1ae02cd0ec0b (patch) | |
| tree | b2277045b733bda35cd8644c004a0ad2d9666d22 /python | |
| parent | f43c1c3db5f78bb9e449efd8a609b6698ee7bac6 (diff) | |
| parent | f54ae33e49ef3e283906df692ce242367799982f (diff) | |
| download | vyos-1x-98598dfc18f403916678cc532f5c1ae02cd0ec0b.tar.gz vyos-1x-98598dfc18f403916678cc532f5c1ae02cd0ec0b.zip | |
Merge pull request #5602 from c-po/T9496-secure-boot-add-image
op-mode: T9496: verify secure-boot signature when using "add system image"
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/utils/system.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/python/vyos/utils/system.py b/python/vyos/utils/system.py index fc6507328..63b8e0828 100644 --- a/python/vyos/utils/system.py +++ b/python/vyos/utils/system.py @@ -213,3 +213,24 @@ def get_secure_boot_certificates(kernel: str='/boot/vmlinuz') -> list: subject = None return certificates + +def verify_secure_boot_signature(kernel: str) -> bool: + """ + Return True if the given Linux Kernel image is signed by one of the + Machine Owner Keys (MOK) enrolled in the UEFI firmware, which is what + shim checks before the Kernel is booted. + """ + from glob import glob + from tempfile import TemporaryDirectory + with TemporaryDirectory() as tmp_dir: + # mokutil always exports into the current working directory + run(['mokutil', '--export'], cwd=tmp_dir, capture_output=True) + for der in sorted(glob(f'{tmp_dir}/MOK-*.der')): + pem = f'{der}.pem' + if run(['openssl', 'x509', '-inform', 'DER', '-in', der, '-out', pem], + capture_output=True).returncode != 0: + continue + if run(['sbverify', '--cert', pem, kernel], + capture_output=True).returncode == 0: + return True + return False |
