EAC Linux v2 on Gentoo with OpenRC: ebuilds, host config, tools, docs
This commit is contained in:
Executable
+62
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
"""List the entries of UEFI signature lists and count duplicates.
|
||||
|
||||
Usage: efi-sig-list.py FILE...
|
||||
FILE = an efivarfs dump (/sys/firmware/efi/efivars/{PK,KEK,db,dbx}-<guid> or a
|
||||
`cat` copy; the 4-byte attribute prefix is skipped) or a plain `.esl` file
|
||||
(e.g. from `sbctl enroll-keys --export esl`).
|
||||
Prints per entry: sha256 prefix, subject CN, issuer CN; then entries vs unique.
|
||||
No arguments runs a self-check.
|
||||
"""
|
||||
import hashlib
|
||||
import struct
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
X509 = bytes.fromhex("a159c0a5e494a74a87b5ab155c2bf072")
|
||||
SHA256 = bytes.fromhex("2616c4c14c509240aca941f936934328")
|
||||
|
||||
|
||||
def cn(der, field):
|
||||
out = subprocess.run(["openssl", "x509", "-inform", "DER", "-noout", f"-{field}", "-nameopt", "multiline"],
|
||||
input=der, capture_output=True).stdout.decode()
|
||||
return next((l.split("=", 1)[1].strip() for l in out.splitlines() if "commonName" in l), "?")
|
||||
|
||||
|
||||
def entries(b):
|
||||
i = 0
|
||||
while i + 28 <= len(b):
|
||||
stype = b[i:i + 16]
|
||||
lsize, hsize, ssize = struct.unpack_from("<III", b, i + 16)
|
||||
if lsize < 28:
|
||||
break
|
||||
j = i + 28 + hsize
|
||||
while j + ssize <= i + lsize:
|
||||
data = b[j + 16:j + ssize] # skip the owner GUID
|
||||
fp = hashlib.sha256(data).hexdigest()[:12]
|
||||
yield (fp, cn(data, "subject"), cn(data, "issuer")) if stype == X509 else (fp, "hash", "")
|
||||
j += ssize
|
||||
i += lsize
|
||||
|
||||
|
||||
def load(path):
|
||||
blob = open(path, "rb").read()
|
||||
return blob if path.endswith(".esl") else blob[4:]
|
||||
|
||||
|
||||
def selftest():
|
||||
sig = b"\0" * 16 + b"\x11" * 32
|
||||
lst = SHA256 + struct.pack("<III", 28 + 2 * len(sig), 0, len(sig)) + 2 * sig
|
||||
found = list(entries(lst))
|
||||
assert len(found) == 2 and len({f[0] for f in found}) == 1
|
||||
print("selftest ok")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) == 1:
|
||||
selftest()
|
||||
for path in sys.argv[1:]:
|
||||
found = list(entries(load(path)))
|
||||
print(f"{path}: {len(found)} entries, {len({f[0] for f in found})} unique")
|
||||
for fp, subject, issuer in found:
|
||||
print(f" {fp} {subject:<40} issued by {issuer}")
|
||||
Reference in New Issue
Block a user