diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-10-06 17:25:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-10-06 17:25:40 +0200 |
| commit | 8cd4b39ab3be8547737cba79b1ca76f147ba88e1 (patch) | |
| tree | 57ce7fd772092619ed58c5d6fe7483e06e5a31cf /python | |
| parent | 87e0a46281746f92a0dde4c7d71c86aa00ec90ea (diff) | |
| parent | da6941e2a80697e31c0f62c0f62c52f570ebb7e9 (diff) | |
| download | vyos-1x-8cd4b39ab3be8547737cba79b1ca76f147ba88e1.tar.gz vyos-1x-8cd4b39ab3be8547737cba79b1ca76f147ba88e1.zip | |
Merge pull request #5537 from c-po/T861-show-secure-boot-detail
op-mode: T861: add "show secure-boot detail" command
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/utils/system.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/python/vyos/utils/system.py b/python/vyos/utils/system.py index 7cc6919a4..90ab74ea6 100644 --- a/python/vyos/utils/system.py +++ b/python/vyos/utils/system.py @@ -157,3 +157,33 @@ def get_secure_boot_state() -> bool: return False tmp = cmdl(['mokutil', '--sb-state'], expect=[0, 255]) return bool('enabled' in tmp) + +def get_secure_boot_certificates(kernel: str='/boot/vmlinuz') -> list: + """ + Return the signature certificates of the given Linux Kernel image as a + list of dictionaries with the keys "issuer" and "subject". Returns an + empty list if the image is unsigned or the signature could not be read. + """ + from vyos.utils.process import cmdl + try: + tmp = cmdl(['sbverify', '--list', kernel]) + except OSError: + return [] + + certificates = [] + subject = None + in_certificates = False + for line in tmp.splitlines(): + line = line.strip() + if line.startswith('signature '): + in_certificates = False + elif line == 'image signature certificates:': + in_certificates = True + elif in_certificates and line.startswith('- subject:'): + subject = line.removeprefix('- subject:').strip() + elif in_certificates and line.startswith('issuer:') and subject: + issuer = line.removeprefix('issuer:').strip() + certificates.append({'issuer': issuer, 'subject': subject}) + subject = None + + return certificates |
