321 lines
24 KiB
Python
321 lines
24 KiB
Python
#!/usr/bin/env python3
|
|
"""Frozen four lease guards on Linux; two fixed ELFs, no product clocks or service actions.
|
|
|
|
Prepare copies the independently reviewed snapshot locally. Execute is one
|
|
root-only Cloud-VM fixture run. After any lost reply read the original case;
|
|
never execute it again or substitute another binary/source generation.
|
|
"""
|
|
import argparse
|
|
import base64
|
|
import hashlib
|
|
import inspect
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import stat
|
|
import uuid
|
|
|
|
import windows_msi_runtime_acceptance as support
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ACCESS_ROOT = ROOT.parent / 'rust-discovery'
|
|
QUALIFICATION = ROOT / 'devstate/windows-signed-clock/runtime-qualification-476c0212-4af9-42d2-92ca-1c488d158d21'
|
|
STATE = ROOT / 'devstate/windows-time-runtime-native-linux'
|
|
PROFILE = 'rmm.windows-time-runtime.four-linux-guards.v1'
|
|
RECEIPT_SHA = '8e219d37fef9f1495225b817a62418a4dab240442c0b08724954237e282d1c13'
|
|
INPUTS_SHA = '505008211630e2b7528cdf085a76309328626fe1e51540170eea293052e53272'
|
|
ARTIFACTS = {'helper_reconcile': {'filename': 'helper_reconcile-deadline-tests', 'bytes': 7975776, 'sha256': '393c62c0aa8a2850ee88850549d49071811012e18f57347a1b187243a223522f', 'complete_test_list': ['abandon_after_expiry_records_deny_only_evidence_and_requires_normal_signed_unlock', 'abandon_preserves_existing_known_unknown_missing_start_and_foreign_request_rows', 'abandon_rejects_wrong_signature_scope_clock_boot_lineage_instance_and_dispatch_proof', 'abandon_storage_failure_rolls_back_consumption_start_and_outcome_together', 'both_live_profiles_apply_one_signature_and_checkpoint_without_inheriting_readiness', 'checkpoint_repair_verifies_complete_signed_history_and_detects_removed_predecessor', 'checkpoint_rollback_is_sticky_and_cannot_be_fixed_by_omission', 'clean_ready_shared_lock_and_reopen_start_closed', 'definitive_unlock_is_transactional_idempotent_and_keeps_tombstones', 'exact_signatures_fake_key_wrong_domain_and_all_identity_bindings', 'false_clock_expiry_and_invalid_independent_key_stay_closed', 'general_and_apt_instances_share_fencing_but_never_inherit_a_process_gate', 'independently_remembered_agent_journal_cannot_be_replaced_by_server_ready', 'malformed_original_protobuf_or_digest_does_not_open_gate', 'missing_signed_checkpoint_history_closes_the_live_gate_stickily', 'mutated_root_ledger_after_capture_is_not_the_signed_snapshot', 'native_stop_intent_is_original_head_bound_create_once_and_transactional', 'old_process_response_fails_after_fresh_capture_even_inside_ttl', 'omitted_unknown_root_row_is_sticky_despite_signed_ready', 'real_local_boot_must_match_signed_reboot_completion', 'restarted_update_can_only_schedule_control_from_its_verified_original_not_unknown', 'root_and_system_are_distinct_explicit_helper_domains', 'shared_database_only_and_missing_local_start_fail_closed', 'signed_noncanonical_outcome_bytes_do_not_unlock_root_consumption', 'stale_process_connection_does_not_poison_a_new_fenced_process', 'system_helper_lease_denies_interval_upper_at_or_after_deadline', 'targeted_final_unlock_does_not_release_an_unrelated_unknown', 'unknown_code_or_no_result_never_unlocks_even_signed_ready', 'unrelated_action_plan_and_previous_outcome_cannot_unlock', 'update_handoff_consumption_start_and_stop_intent_are_one_transaction', 'update_inflight_negative_control_keeps_every_start_closed_and_owner_loss_is_terminal'], 'selected': ['system_helper_lease_denies_interval_upper_at_or_after_deadline', 'clean_ready_shared_lock_and_reopen_start_closed']}, 'reconcile': {'filename': 'reconcile-deadline-tests', 'bytes': 7084528, 'sha256': '7a7e068e4c832ee139877f84a45283fb2a1101ad3b6626aecd277a14cf97becc', 'complete_test_list': ['accepted_unstarted_keeps_ids_and_never_consumes_or_executes', 'authenticated_helper_outcome_is_imported_as_new_durable_evidence_not_reexecuted', 'clean_reconnect_and_reopen_require_new_signed_challenge', 'client_lease_requires_entire_fresh_upper_before_deadline', 'crash_after_durable_outcome_before_result_recovers_original_then_signed_sync_closes', 'crash_after_result_commit_before_finish_retains_exact_result_and_local_prior', 'crash_before_running_event_recovers_real_consumption_without_inventing_completion', 'definite_nonstart_result_is_unconsumed_not_ambiguous', 'exact_signatures_all_identity_channel_checkpoint_and_request_bindings', 'final_result_preserves_original_envelope_outputs_and_exact_acks', 'foreign_ack_and_noncanonical_outcome_are_transactionally_rejected', 'helper_gate_requires_exact_signed_instruction_and_applied_checkpoint', 'helper_omitting_a_consumed_root_attempt_is_a_sticky_restore_fault', 'independent_helper_checkpoint_regression_is_sticky', 'independent_local_outcome_mismatch_never_unlocks', 'missing_server_job_fault_is_sticky_even_if_attempt_disappears_later', 'negative_server_revision_never_rolls_back_local_unknown_revision', 'original_completion_after_reconnect_unknown_is_recovered_without_reexecuting', 'reboot_keeps_lock_until_signed_new_authenticated_boot_inventory_evidence', 'requesting_running_and_omitted_attempts_cannot_regain_readiness', 'rollback_and_false_clock_close_mutations_but_do_not_destroy_journal', 'signed_attempt_mutation_or_terminal_regression_is_rejected', 'signed_terminal_nonstart_stays_unconsumed_across_sync_and_pending_denial', 'signed_unlock_still_rejects_a_missing_local_outcome_in_legacy_crash_window', 'system_helper_import_requires_explicit_system_identity_and_never_root_alias', 'terminal_labels_never_override_grant_consumption_or_unclear_attempts', 'uncertain_request_preserves_pending_request_and_last_applied_anchor'], 'selected': ['client_lease_requires_entire_fresh_upper_before_deadline', 'definite_nonstart_result_is_unconsumed_not_ambiguous']}}
|
|
AGENT_SHA = '0a7ad6eefaefda79ee80b6a41b2df904e9e7f50ae6ebeed01b98c25b6ce5c06f'
|
|
HELPER_SHA = '79442727c3ba31cda02a8bc0e67481f14db9f39fc07520a880a90b64f10f1eaf'
|
|
|
|
|
|
def sha(raw):
|
|
return hashlib.sha256(raw).hexdigest()
|
|
|
|
|
|
def save_local(path, value):
|
|
support.save(path, value)
|
|
fd = os.open(path.parent, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
|
|
try:
|
|
os.fsync(fd)
|
|
finally:
|
|
os.close(fd)
|
|
|
|
|
|
def copy_exact(source, destination, digest, size):
|
|
metadata = source.lstat()
|
|
support.require(stat.S_ISREG(metadata.st_mode) and metadata.st_nlink == 1
|
|
and metadata.st_uid in (0, os.getuid()) and not metadata.st_mode & 0o002
|
|
and metadata.st_size == size and size <= (16 if source.name.endswith('-deadline-tests') else 2) * 1024 * 1024, 'bounded regular frozen input')
|
|
raw = source.read_bytes()
|
|
support.require(sha(raw) == digest, 'frozen snapshot input hash')
|
|
destination.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
support.private(destination.parent, True)
|
|
fd = os.open(destination, os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW | os.O_WRONLY, 0o600)
|
|
with os.fdopen(fd, 'wb') as stream:
|
|
stream.write(raw); stream.flush(); os.fsync(stream.fileno())
|
|
fd = os.open(destination.parent, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW)
|
|
try:
|
|
os.fsync(fd)
|
|
finally:
|
|
os.close(fd)
|
|
|
|
|
|
def verify_case(folder):
|
|
value = support.load(folder / 'manifest.json')
|
|
support.require(value['profile'] == PROFILE and value['artifacts'] == ARTIFACTS
|
|
and value['runner_sha256'] == sha(Path(__file__).read_bytes())
|
|
and value['receipt_sha256'] == RECEIPT_SHA, 'same original reviewed manifest')
|
|
support.require(sha((folder / 'receipt.json').read_bytes()) == RECEIPT_SHA
|
|
and sha((folder / 'inputs.json').read_bytes()) == INPUTS_SHA, 'original qualification provenance')
|
|
source = support.load(folder / 'inputs.json')
|
|
support.require(len(source) == 202 and source == value['source_files'], 'exact frozen 202 compiler inputs')
|
|
paths = set()
|
|
for item in source:
|
|
path = Path(item['path'])
|
|
support.require(not path.is_absolute() and '..' not in path.parts and str(path) not in paths, 'unique relative frozen source')
|
|
paths.add(str(path)); file = folder / 'source' / path
|
|
support.private(file)
|
|
support.require(file.stat().st_size == item['bytes'] and sha(file.read_bytes()) == item['sha256'], 'retained source freeze')
|
|
for item in ARTIFACTS.values():
|
|
binary = folder / item['filename']; support.private(binary)
|
|
support.require(binary.stat().st_size == item['bytes'] and sha(binary.read_bytes()) == item['sha256'], 'original qualified ELF')
|
|
for path, digest in value['transport_sources'].items():
|
|
support.require(sha((ROOT / path).read_bytes()) == digest, 'original strict transport source')
|
|
return value
|
|
|
|
|
|
def remote(p):
|
|
import base64
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import selectors
|
|
import signal
|
|
import stat
|
|
import subprocess
|
|
import time
|
|
import uuid
|
|
|
|
def require(ok, message):
|
|
if not ok:
|
|
raise RuntimeError(message)
|
|
|
|
def enc(value):
|
|
return json.dumps(value, sort_keys=True, separators=(',', ':')).encode()
|
|
|
|
def create(path, raw, mode=0o600):
|
|
fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, mode)
|
|
with os.fdopen(fd, 'wb') as stream:
|
|
stream.write(raw); stream.flush(); os.fsync(stream.fileno())
|
|
fd = os.open(path.parent, os.O_DIRECTORY | os.O_RDONLY | os.O_NOFOLLOW)
|
|
try:
|
|
os.fsync(fd)
|
|
finally:
|
|
os.close(fd)
|
|
|
|
def run(args, timeout=20):
|
|
# Keep the owned group leader unreaped until its entire group has been
|
|
# cleaned up. Its PID therefore cannot be recycled before killpg.
|
|
child = subprocess.Popen(args, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE, start_new_session=True,
|
|
env={'PATH': '/usr/bin:/bin', 'LC_ALL': 'C', 'HOME': '/nonexistent', 'TMPDIR': str(folder / 'tmp')})
|
|
selector = selectors.DefaultSelector()
|
|
buffers = {'stdout': bytearray(), 'stderr': bytearray()}
|
|
deadline = time.monotonic() + timeout
|
|
try:
|
|
for stream, name in ((child.stdout, 'stdout'), (child.stderr, 'stderr')):
|
|
os.set_blocking(stream.fileno(), False); selector.register(stream, selectors.EVENT_READ, name)
|
|
while True:
|
|
require(time.monotonic() < deadline, 'owned native command timeout; read original case only')
|
|
for key, _ in selector.select(0.02):
|
|
raw = os.read(key.fileobj.fileno(), 4096)
|
|
if raw:
|
|
buffers[key.data].extend(raw)
|
|
require(len(buffers[key.data]) <= 65536, 'bounded native output')
|
|
else:
|
|
selector.unregister(key.fileobj)
|
|
ended = os.waitid(os.P_PID, child.pid, os.WEXITED | os.WNOHANG | os.WNOWAIT)
|
|
if ended is not None:
|
|
# Child remains a zombie until finally: no PID/group reuse.
|
|
os.killpg(child.pid, signal.SIGKILL)
|
|
for key in list(selector.get_map().values()):
|
|
while True:
|
|
try:
|
|
raw = os.read(key.fileobj.fileno(), 4096)
|
|
except BlockingIOError:
|
|
break
|
|
if not raw:
|
|
break
|
|
buffers[key.data].extend(raw)
|
|
require(len(buffers[key.data]) <= 65536, 'bounded native output')
|
|
code = ended.si_status if ended.si_code == os.CLD_EXITED else -ended.si_status
|
|
return code, bytes(buffers['stdout']), bytes(buffers['stderr'])
|
|
finally:
|
|
os.killpg(child.pid, signal.SIGKILL)
|
|
child.wait()
|
|
selector.close(); child.stdout.close(); child.stderr.close()
|
|
|
|
def metadata_identity(value):
|
|
return (value.st_dev, value.st_ino, value.st_uid, value.st_gid, value.st_mode,
|
|
value.st_nlink, value.st_size, value.st_mtime_ns, value.st_ctime_ns)
|
|
|
|
def hashed(path, maximum, process_image=False):
|
|
fd = os.open(path, os.O_RDONLY | os.O_CLOEXEC | (0 if process_image else os.O_NOFOLLOW))
|
|
with os.fdopen(fd, 'rb') as stream:
|
|
before = os.fstat(stream.fileno()); require(stat.S_ISREG(before.st_mode) and before.st_size <= maximum, 'bounded witness file')
|
|
digest = hashlib.sha256(); total = 0
|
|
while True:
|
|
raw = stream.read(32768)
|
|
if not raw:
|
|
break
|
|
total += len(raw); require(total <= maximum, 'bounded witness hash'); digest.update(raw)
|
|
after = os.fstat(stream.fileno())
|
|
require(metadata_identity(before) == metadata_identity(after) and total == before.st_size, 'stable witness hash')
|
|
return before, digest.hexdigest()
|
|
|
|
def witness():
|
|
out = {'boot_id': Path('/proc/sys/kernel/random/boot_id').read_text().strip(), 'services': {}, 'files': {}}
|
|
release = dict(line.split('=', 1) for line in Path('/etc/os-release').read_text().splitlines() if '=' in line)
|
|
require(release.get('ID', '').strip('"') == 'ubuntu' and release.get('VERSION_ID', '').strip('"') == '24.04', 'fixed native Ubuntu24.04')
|
|
out['os'] = {'id': 'ubuntu', 'version': '24.04', 'machine': os.uname().machine, 'kernel': os.uname().release}
|
|
for name, uid, binary in (
|
|
('rmm-agent-remote.service', 993, p['agent_sha256']),
|
|
('rmm-helper-cloud.service', 0, p['helper_sha256']),
|
|
('rmm-full-maintenance-helper.service', 0, p['helper_sha256'])):
|
|
code, stdout, _ = run(['/usr/bin/systemctl', 'show', name, '-p', 'ActiveState', '-p', 'MainPID', '-p', 'UnitFileState', '-p', 'InvocationID'])
|
|
require(code == 0, 'existing service read')
|
|
service = dict(line.split('=', 1) for line in stdout.decode().splitlines())
|
|
pid = int(service['MainPID']); require(service['ActiveState'] == 'active' and pid > 1, 'three existing services active')
|
|
proc = Path('/proc', str(pid)); birth = (proc / 'stat').read_text().rsplit(') ', 1)[1].split()[19]
|
|
ids = {line.split(':')[0]: line.split()[1:] for line in (proc / 'status').read_text().splitlines() if line.startswith(('Uid:', 'Gid:'))}
|
|
metadata, image = hashed(proc / 'exe', 256 * 1024 * 1024, process_image=True)
|
|
current = (proc / 'exe').stat()
|
|
require(ids['Uid'] == [str(uid)] * 4 and ids['Gid'] == ['984'] * 4 and image == binary
|
|
and (metadata.st_dev, metadata.st_ino) == (current.st_dev, current.st_ino)
|
|
and (proc / 'stat').read_text().rsplit(') ', 1)[1].split()[19] == birth, 'current generation/account/image')
|
|
out['services'][name] = dict(service, birth=birth, image=image, ids=ids)
|
|
code, stdout, _ = run(['/usr/bin/systemctl', 'show', 'rmm-apt-helper.service', '-p', 'ActiveState', '-p', 'UnitFileState'])
|
|
apt = dict(line.split('=', 1) for line in stdout.decode().splitlines())
|
|
require(code == 0 and apt == {'ActiveState': 'inactive', 'UnitFileState': 'disabled'}, 'APT remains closed')
|
|
out['apt'] = apt
|
|
for name in ('/etc/rmm-remote/helper-general.json', '/etc/rmm-remote/helper-full-maintenance.json',
|
|
'/etc/rmm-remote/full-maintenance-helper-proof.json', '/etc/systemd/system/rmm-full-maintenance-helper.service'):
|
|
path = Path(name); metadata = path.lstat()
|
|
require(not path.is_symlink() and stat.S_ISREG(metadata.st_mode) and metadata.st_uid == 0
|
|
and not metadata.st_mode & 0o022 and metadata.st_nlink == 1, 'protected known control')
|
|
current, digest = hashed(path, 65536)
|
|
require(metadata_identity(current) == metadata_identity(metadata), 'same known control file')
|
|
out['files'][name] = [metadata.st_dev, metadata.st_ino, metadata.st_uid, metadata.st_gid, metadata.st_mode,
|
|
metadata.st_size, metadata.st_mtime_ns, metadata.st_ctime_ns, digest]
|
|
for name in ('/var/lib/rmm-helper/consumption.sqlite', '/var/lib/rmm-helper/executor.lock',
|
|
'/var/lib/rmm-agent-remote/journal.sqlite', '/var/lib/rmm-agent-remote/consumption.sqlite'):
|
|
path = Path(name); metadata = path.lstat()
|
|
require(not path.is_symlink() and stat.S_ISREG(metadata.st_mode) and metadata.st_nlink == 1, 'existing state identity')
|
|
out['files'][name] = [metadata.st_dev, metadata.st_ino, metadata.st_uid, metadata.st_gid, metadata.st_mode]
|
|
return out
|
|
|
|
require(os.geteuid() == 0 and os.uname().machine == 'x86_64', 'fixed Cloud Linux root contract fixtures')
|
|
ident = str(uuid.UUID(p['id'])); require(ident == p['id'], 'canonical original case')
|
|
folder = Path('/var/tmp') / ('rmm-windows-time-runtime-linux-' + ident)
|
|
require(p['action'] in ('execute', 'read'), 'fixed once/read actions')
|
|
if p['action'] == 'read':
|
|
metadata = folder.lstat()
|
|
require(stat.S_ISDIR(metadata.st_mode) and not folder.is_symlink() and metadata.st_uid == 0
|
|
and stat.S_IMODE(metadata.st_mode) == 0o700, 'own original case only')
|
|
intent = json.loads((folder / 'intent.json').read_bytes())
|
|
require(intent == {key:value for key,value in p.items() if key not in ('action','binary_b64')}, 'same original payload binding')
|
|
result = folder / 'result.json'
|
|
return {'read_only': True, 'id': ident, 'entered': (folder / 'entered.json').exists(),
|
|
'result': json.loads(result.read_bytes()) if result.exists() else None, 'current_witness': witness()}
|
|
os.umask(0o077); folder.mkdir(mode=0o700)
|
|
create(folder / 'intent.json', enc({key:value for key,value in p.items() if key not in ('action','binary_b64')}))
|
|
(folder / 'tmp').mkdir(mode=0o700)
|
|
commands = {}
|
|
for kind, item in p['artifacts'].items():
|
|
require(len(p['binary_b64'][kind]) == 4 * ((item['bytes'] + 2) // 3), 'bounded exact ELF transfer')
|
|
raw = base64.b64decode(p['binary_b64'][kind], validate=True)
|
|
require(len(raw) == item['bytes'] and hashlib.sha256(raw).hexdigest() == item['sha256'], 'fixed qualified ELF')
|
|
binary = folder / item['filename']; create(binary, raw, 0o700)
|
|
commands[kind] = ['/usr/bin/setpriv', '--reuid=0', '--regid=0', '--clear-groups', '--no-new-privs', str(binary)]
|
|
before = witness(); create(folder / 'before.json', enc(before))
|
|
for kind, command in commands.items():
|
|
code, stdout, stderr = run(command + ['--list', '--format', 'terse'])
|
|
create(folder / (kind + '-list.stdout'), stdout); create(folder / (kind + '-list.stderr'), stderr)
|
|
lines = stdout.decode().splitlines(); item = p['artifacts'][kind]
|
|
require(code == 0 and stderr == b'' and len(lines) == len(item['complete_test_list'])
|
|
and all(line.endswith(': test') for line in lines)
|
|
and sorted(line[:-6] for line in lines) == item['complete_test_list'], 'complete fixed lists before any test')
|
|
create(folder / 'entered.json', enc({'id': ident, 'run_once': True, 'time_ns': time.time_ns()}))
|
|
runs = []
|
|
for kind, command in commands.items():
|
|
item = p['artifacts'][kind]; filtered = len(item['complete_test_list']) - 1
|
|
for name in item['selected']:
|
|
code, stdout, stderr = run(command + ['--exact', name, '--test-threads=1', '--nocapture'])
|
|
create(folder / (name + '.stdout'), stdout); create(folder / (name + '.stderr'), stderr)
|
|
require(code == 0 and stderr == b'' and ('1 passed; 0 failed; 0 ignored; 0 measured; '+str(filtered)+' filtered out').encode() in stdout
|
|
and ('test '+name+' ... ok').encode() in stdout, 'one exact selected guard passed')
|
|
runs.append({'kind':kind,'test':name,'passed':1,'filtered':filtered,'stdout_sha256':hashlib.sha256(stdout).hexdigest()})
|
|
after = witness(); create(folder / 'after.json', enc(after))
|
|
require(before == after and len(runs) == 4, 'four guards and retained target state')
|
|
receipt = dict(id=ident, profile=p['profile'], passed=4, ignored=0, filtered=sum(x['filtered'] for x in runs), execution_uid=0,
|
|
runs=runs, artifacts=p['artifacts'], before=before, after=after,
|
|
source_receipt_sha256=p['receipt_sha256'], source_manifest_sha256=p['manifest_sha256'],
|
|
no_rmm_jobs=True, no_product_time_query=True, no_apply=True, no_service_control=True)
|
|
create(folder / 'result.json', enc(receipt)); return receipt
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('action', choices=('prepare','execute','read')); parser.add_argument('--case')
|
|
args=parser.parse_args(); os.umask(0o077)
|
|
STATE.mkdir(mode=0o700, parents=True, exist_ok=True); support.private(STATE, True)
|
|
if args.action == 'prepare':
|
|
support.require(args.case is None, 'new local case only')
|
|
receipt_path=QUALIFICATION/'receipt.json'; support.private(receipt_path)
|
|
support.require(sha(receipt_path.read_bytes()) == RECEIPT_SHA, 'exact original local qualification')
|
|
receipt=support.load(receipt_path); original=support.load(QUALIFICATION/'inputs.json')
|
|
support.require(sha((QUALIFICATION/'inputs.json').read_bytes()) == INPUTS_SHA and len(original)==202
|
|
and receipt['inputs_sha256']==INPUTS_SHA and receipt['checks']['linux_selected_guards']==4, 'frozen 202-input four-guard proof')
|
|
ident=str(uuid.uuid4()); folder=STATE/ident; folder.mkdir(mode=0o700)
|
|
copy_exact(receipt_path, folder/'receipt.json', RECEIPT_SHA, receipt_path.stat().st_size)
|
|
copy_exact(QUALIFICATION/'inputs.json', folder/'inputs.json', INPUTS_SHA, (QUALIFICATION/'inputs.json').stat().st_size)
|
|
paths=set()
|
|
for item in original:
|
|
path=Path(item['path'])
|
|
support.require(not path.is_absolute() and '..' not in path.parts and str(path) not in paths, 'unique relative frozen source')
|
|
paths.add(str(path)); copy_exact(QUALIFICATION/'source'/path, folder/'source'/path, item['sha256'], item['bytes'])
|
|
for kind,item in ARTIFACTS.items():
|
|
actual=receipt['linux_tests'][kind]
|
|
support.require(all(actual[key]==item[key] for key in ('bytes','sha256','complete_test_list','selected'))
|
|
and actual['binary']==item['filename'] and actual['selected_passed']==2, 'two actual local guards per fixed ELF')
|
|
copy_exact(QUALIFICATION/item['filename'], folder/item['filename'], item['sha256'],item['bytes'])
|
|
transports={path:sha((ROOT/path).read_bytes()) for path in ('deploy/windows_msi_runtime_acceptance.py','deploy/vm_access_check.py')}
|
|
save_local(folder/'manifest.json',dict(id=ident,profile=PROFILE,runner_sha256=sha(Path(__file__).read_bytes()),
|
|
receipt_sha256=RECEIPT_SHA,artifacts=ARTIFACTS,source_files=original,transport_sources=transports))
|
|
verify_case(folder); print(json.dumps({'id':ident,'prepared_locally':True})); return
|
|
support.require(args.case is not None, 'original --case required')
|
|
ident=str(uuid.UUID(args.case)); support.require(ident==args.case,'same canonical original case')
|
|
folder=STATE/ident; support.private(folder,True); verify_case(folder)
|
|
payload=dict(id=ident,action=args.action,profile=PROFILE,artifacts=ARTIFACTS,receipt_sha256=RECEIPT_SHA,
|
|
manifest_sha256=sha((folder/'manifest.json').read_bytes()),agent_sha256=AGENT_SHA,helper_sha256=HELPER_SHA)
|
|
if args.action=='execute':
|
|
save_local(folder/'execute-entered.json',{'once':True,'no_retry':True})
|
|
payload['binary_b64']={kind:base64.b64encode((folder/item['filename']).read_bytes()).decode() for kind,item in ARTIFACTS.items()}
|
|
code='import json\n'+inspect.getsource(remote)+'\nprint(json.dumps(remote('+repr(payload)+')))\n'
|
|
response=support.transport(support.access_settings(ACCESS_ROOT,'linux'),'python3 -',code.encode(),folder,timeout=120)
|
|
save_local(folder/(args.action+'-'+str(uuid.uuid4())+'.json'),response)
|
|
result=response.get('result') if args.action=='read' else response
|
|
if result is not None:
|
|
support.require(result['source_manifest_sha256']==sha((folder/'manifest.json').read_bytes())
|
|
and result['source_receipt_sha256']==RECEIPT_SHA and result['artifacts']==ARTIFACTS
|
|
and result['passed']==4 and result['filtered']==112 and result['before']==result['after'], 'exact original four-guard result')
|
|
if args.action=='read': support.require(response['current_witness']==result['after'],'same-case retained native state')
|
|
print(json.dumps({'id':ident,'action':args.action,'passed':None if result is None else result['passed'],
|
|
'complete':result is not None,'read_only':args.action=='read'}))
|
|
|
|
|
|
if __name__=='__main__':
|
|
main()
|