Recover an unused maintenance helper with no applied decision
This commit is contained in:
@@ -100,7 +100,7 @@ def observation(ids, opened, cutoff=None):
|
||||
"""
|
||||
|
||||
|
||||
def verify(snapshot, ids):
|
||||
def verify(snapshot, ids, *, prepared_only=False):
|
||||
require(snapshot['open_jobs'] == 0, 'Device has open or uncertain jobs')
|
||||
require(snapshot['helper_id'] and snapshot['helper_checkpoint'] > 0, 'Expected bound helper journal')
|
||||
raw = bytes.fromhex(snapshot['signed'])
|
||||
@@ -143,7 +143,17 @@ def verify(snapshot, ids):
|
||||
attempts.append({**{k:j[k] for k in ('job','attempt','grant','state','payload_sha256')},
|
||||
'outcome_sha256':a['outcome_sha256']})
|
||||
require(not outcomes, 'The helper still owns SYSTEM attempts outside this window')
|
||||
return {**ids, **{k:snapshot[k] for k in (*fields,'helper_id')}, 'attempts':attempts}
|
||||
witness = {**ids, **{k:snapshot[k] for k in (*fields,'helper_id')}, 'attempts':attempts}
|
||||
if prepared_only and not attempts and d['helper_checkpoint'] == 1:
|
||||
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat
|
||||
# Binding is hashed in Rust's fixed declaration order.
|
||||
binding = {k:ids[k] for k in ('tenant_id','asset_id','agent_id')}
|
||||
binding.update(enrollment_generation=1,assignment_version=1,
|
||||
public_key_hex=public.public_bytes(Encoding.Raw,PublicFormat.Raw).hex())
|
||||
witness['prepared_first_capture'] = {
|
||||
'binding_sha256':hashlib.sha256(json.dumps(binding,separators=(',',':')).encode()).hexdigest(),
|
||||
'request_id':d['request_id'], 'request_hash':d['request_hash'], 'boot_id':d['boot_id']}
|
||||
return witness
|
||||
|
||||
|
||||
def prepared_baseline(case, data, ids):
|
||||
@@ -268,7 +278,7 @@ def server(action, data):
|
||||
require_native_verification(data, receipt)
|
||||
scope.atomic(done,scope.encode(receipt))
|
||||
return receipt
|
||||
witness = verify(record,ids)
|
||||
witness = verify(record,ids,prepared_only=prepared is not None and (receipt is None or 'prepared_first_capture' in receipt))
|
||||
require(receipt in (None,witness) and data.get('witness',witness) == witness, 'Device or witness changed')
|
||||
if action == 'witness':
|
||||
return witness
|
||||
|
||||
Reference in New Issue
Block a user