Skip to content

Commit

Permalink
Merge pull request grawity#7 from squarooticus/override-blob
Browse files Browse the repository at this point in the history
Allow override of BSA path
  • Loading branch information
grawity authored Feb 27, 2022
2 parents 1affff7 + b3f731d commit 96faa8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tpm_futurepcr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def main():
help="write binary PCR values to specified file")
parser.add_argument("--allow-unexpected-bsa", action="store_true",
help="accept BOOT_SERVICES_APPLICATION events with weird paths")
parser.add_argument("--substitute-bsa-unix-path", action=KeyValueAction,
help="substitute BOOT_SERVICES_APPLICATION path (syntax: <computed unix path>=<new unix path>)")
parser.add_argument("--compare", action="store_true",
help="compare computed PCRs against live values")
parser.add_argument("-v", "--verbose", action="store_true",
Expand Down Expand Up @@ -91,6 +93,8 @@ def main():
event_data = parse_efi_bsa_event(event["event_data"])
try:
unix_path = device_path_to_unix_path(event_data["device_path_vec"])
if args.substitute_bsa_unix_path:
unix_path = args.substitute_bsa_unix_path.get(unix_path, unix_path)
except Exception as e:
print(e)
errors = 1
Expand Down
14 changes: 14 additions & 0 deletions tpm_futurepcr/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import signify.fingerprinter
import subprocess
import argparse

def to_hex(buf):
import binascii
Expand Down Expand Up @@ -119,3 +120,16 @@ def find_mountpoint_by_partuuid(partuuid):
stdout=subprocess.PIPE)
res.check_returncode()
return res.stdout.splitlines()[0].decode()

class KeyValueAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
if getattr(namespace, self.dest, None) is None:
setattr(namespace, self.dest, dict())
kvmap = getattr(namespace, self.dest)
if not isinstance(values, list):
values = [ values ]
kvpairs = [ v.split('=', 1) for v in values ]
try:
kvmap.update(kvpairs)
except ValueError:
raise argparse.ArgumentTypeError("Value for option %s malformed: %s" % (self.dest, values))

0 comments on commit 96faa8c

Please sign in to comment.