fix(01): CR-02 bind original evidence to pristine inventory members
This commit is contained in:
1 parent
5569bc2b8b
commit
bda35e5bf5
3 files changed
+75
-11
No files matched your search
@@ -5,6 +5,7 @@ Human findings are declarations bound to exact receipts, never inferred from
|
||||
successful tools. --allow-open is structural inspection, not acceptance.
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
@@ -59,7 +60,7 @@ def ready(checkpoint):
|
||||
'meaning': 'Identified offline materials only; all execution/review remains separate'}
|
||||
|
||||
|
||||
def _bind(receipt, root, manifest):
|
||||
def _bind(receipt, root, manifest, original_inventory=None):
|
||||
identity = receipt['identity']
|
||||
if receipt['evidence_kind'] == 'native_port':
|
||||
rid = {'linux': 'linux-x64', 'windows': 'win-x64'}[receipt['platform']['os']]
|
||||
@@ -79,12 +80,25 @@ def _bind(receipt, root, manifest):
|
||||
if resources != expected['resources'] and identity['resources']['sha256'] != expected['seal']['sha256']:
|
||||
raise ValueError('Wrong current resources')
|
||||
elif receipt['evidence_kind'] == 'original_dxwnd':
|
||||
before = read_json(contained_path(root, identity['original_pre']['path']))
|
||||
if before.get('tree_sha256') != manifest['original_pre']['tree_sha256']:
|
||||
files = (original_inventory or {}).get('files')
|
||||
if not isinstance(files, list) or not files:
|
||||
raise ValueError('Missing authoritative original file inventory')
|
||||
digest = hashlib.sha256(canonical_bytes(files)).hexdigest()
|
||||
if (digest != manifest['original_pre']['tree_sha256'] or
|
||||
len(files) != manifest['original_pre']['count']):
|
||||
raise ValueError('Wrong authoritative original inventory')
|
||||
for key in ('original_pre', 'original_post', 'package', 'resources'):
|
||||
inventory = read_json(contained_path(root, identity[key]['path']))
|
||||
if inventory.get('files') != files or inventory.get('tree_sha256') != digest:
|
||||
raise ValueError('Wrong authoritative original inventory: ' + key)
|
||||
executable = identity['executable']
|
||||
member = executable.get('original_member')
|
||||
expected = next((item for item in files if item['path'] == member), None)
|
||||
if not expected or any(executable.get(k) != expected[k] for k in ('sha256', 'size', 'header')):
|
||||
raise ValueError('Wrong selected original executable member identity')
|
||||
|
||||
|
||||
def audit_records(protocol, manifest, records, review):
|
||||
def audit_records(protocol, manifest, records, review, original_inventory=None):
|
||||
errors, usable, seen = [], [], set()
|
||||
if manifest.get('tooling_only'):
|
||||
errors.append('Synthetic checkpoint cannot qualify as runtime evidence')
|
||||
@@ -98,7 +112,7 @@ def audit_records(protocol, manifest, records, review):
|
||||
if receipt.get('superseded_by') or receipt.get('historical'):
|
||||
raise ValueError('Superseded/historical receipt is not current applicability')
|
||||
if valid['accepted']:
|
||||
_bind(receipt, root, manifest)
|
||||
_bind(receipt, root, manifest, original_inventory)
|
||||
usable.append((receipt, root))
|
||||
except (KeyError, TypeError, ValueError, OSError) as error:
|
||||
errors.append(label + ': ' + str(error))
|
||||
@@ -143,7 +157,8 @@ def audit(checkpoint, results):
|
||||
if expected != identify_file(path)['sha256']:
|
||||
review = dict(review, checks={})
|
||||
break
|
||||
return audit_records(read_json(root / 'protocol/scenarios.json'), manifest, records, review)
|
||||
return audit_records(read_json(root / 'protocol/scenarios.json'), manifest, records, review,
|
||||
read_json(root / 'protocol/original-manifest.json'))
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
|
||||
Reference in new issue
Block a user