|
10 | 10 |
|
11 | 11 | from keylime import config
|
12 | 12 | from keylime import keylime_logging
|
13 |
| - |
| 13 | +from keylime.failure import Failure, Component |
14 | 14 | logger = keylime_logging.init_logging('measured_boot')
|
15 | 15 |
|
16 | 16 | def read_mb_refstate(mb_path=None):
|
@@ -61,20 +61,23 @@ def get_policy(mb_refstate_str):
|
61 | 61 |
|
62 | 62 | return mb_policy, mb_refstate_data
|
63 | 63 |
|
64 |
| -def evaluate_policy(mb_policy, mb_refstate_data, mb_measurement_data, pcrsInQuote, pcrPrefix, agent_id): |
| 64 | +def evaluate_policy(mb_policy, mb_refstate_data, mb_measurement_data, pcrsInQuote, pcrPrefix, agent_id) -> Failure: |
| 65 | + failure = Failure(Component.MEASURED_BOOT) |
65 | 66 | missing = list(set(config.MEASUREDBOOT_PCRS).difference(pcrsInQuote))
|
66 | 67 | if len(missing) > 0:
|
67 | 68 | logger.error("%sPCRs specified for measured boot not in quote: %s", pcrPrefix, missing)
|
68 |
| - return False |
| 69 | + failure.add_event("missing_pcrs", {"context": "PCRs are missing in quote", "data": missing}, True) |
69 | 70 | try:
|
70 | 71 | reason = mb_policy.evaluate(mb_refstate_data, mb_measurement_data)
|
71 | 72 | except Exception as exn:
|
72 | 73 | reason= "policy evaluation failed: %s"%(str(exn))
|
73 | 74 | if reason:
|
74 | 75 | logger.error("Boot attestation failed for agent %s, configured policy %s, refstate=%s, reason=%s",
|
75 | 76 | agent_id, config.MEASUREDBOOT_POLICYNAME, json.dumps(mb_refstate_data), reason)
|
76 |
| - return False |
77 |
| - return True |
| 77 | + failure.add_event("policy", |
| 78 | + {"context": "Boot attestation failed", "policy": config.MEASUREDBOOT_POLICYNAME, |
| 79 | + "refstate": mb_refstate_data, "reason": reason}, True) |
| 80 | + return failure |
78 | 81 |
|
79 | 82 | def main():
|
80 | 83 | parser = argparse.ArgumentParser()
|
|
0 commit comments