111 lines
6.6 KiB
Python
111 lines
6.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Link current Windows runtime/units after the actual matching Linux84 proof.
|
|
|
|
No VM access, unit execution, enrollment, capability activation or deployment.
|
|
Windows native lists remain explicitly pending; old42 names are never relabelled.
|
|
"""
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import uuid
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PACK = ROOT / 'devstate/script-console-qualification/run-29461892-343f-42f4-b469-88703535425e'
|
|
PACK_SHA = 'ddd1a78d1cd289b02b1f98572f9652171ec00be84e01ce099fd722d689bcaacd'
|
|
LINUX = ROOT / 'devstate/script-console-native/7b61ce46-7913-492b-9c6b-414a0c2b6ffc/passed-e214cd9b-21ac-48ce-82dc-d10364329d04.json'
|
|
LINUX_SHA = 'a831a70a3cf76a3e8a9bf5820dcca7100d2ef9860dd9388539fe9c13f949f470'
|
|
IMAGE = 'sha256:1b2fd985d2c1fcc3545ace602405dc68fa899201bd8a73fa319ff96377203fa9'
|
|
PIPE_SHA = 'ce525dab23f2e4faa2c9816280c1a5a8b40e56d0e63a350256e83b2df1d9229d'
|
|
|
|
|
|
def sha(path):
|
|
return hashlib.sha256(Path(path).read_bytes()).hexdigest()
|
|
|
|
|
|
def require(value, code):
|
|
if not value:
|
|
raise RuntimeError(code)
|
|
|
|
|
|
def load(path):
|
|
require(not path.is_symlink() and path.stat().st_uid == os.getuid()
|
|
and path.stat().st_mode & 0o777 == 0o600, 'private source evidence')
|
|
return json.loads(path.read_bytes())
|
|
|
|
|
|
def main():
|
|
os.umask(0o077)
|
|
require(sha(PACK / 'manifest.json') == PACK_SHA and sha(LINUX) == LINUX_SHA, 'exact current source and actual Linux84 proof')
|
|
source = load(PACK / 'manifest.json'); proof = load(LINUX)
|
|
require(proof['verified'] is True and proof['manifest_sha256'] == PACK_SHA
|
|
and proof['native']['passed'] == 84 and proof['native']['ignored_database_cases'] == 5
|
|
and proof['native']['all_lists_before_any_tests'] is True
|
|
and all(proof['native'][flag] is False for flag in ('product_state_writes','rmm_jobs','capabilities_activated','approvals')),
|
|
'actual bounded Linux-first proof, not an old fixture count')
|
|
frozen = source['source_files']
|
|
require(len(frozen) == 158 and all(sha(ROOT / name) == value for name, value in frozen.items())
|
|
and sha(ROOT / 'crates/agent-windows/src/helper_ipc.rs') == PIPE_SHA, 'unchanged current source including actual PipeV2')
|
|
state = ROOT / 'devstate/script-console-windows-link'; state.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
out = state / ('run-' + str(uuid.uuid4())); out.mkdir(mode=0o700)
|
|
target = ROOT / 'devstate/script-console-windows-target'; target.mkdir(mode=0o700, exist_ok=True)
|
|
checks = {}
|
|
|
|
def command(label, args):
|
|
value = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=False)
|
|
log = out / (label + '.log'); log.write_bytes(value.stdout)
|
|
checks[label] = dict(exit_code=value.returncode, log_sha256=sha(log))
|
|
require(value.returncode == 0, 'link failed: inspect private ' + str(log))
|
|
return value.stdout
|
|
|
|
docker = ['docker','run','--rm','--network','none','--read-only','--tmpfs','/tmp:rw,size=512m',
|
|
'-v',str(ROOT)+':/src:ro','-v',str(target)+':/target','-e','CARGO_TARGET_DIR=/target','--entrypoint','cargo',IMAGE]
|
|
common = ['--manifest-path','/src/Cargo.toml','--locked','--offline','--target','x86_64-pc-windows-gnu',
|
|
'-p','rmm-agent-windows','--features','system-helper','--release']
|
|
units = command('windows-current-unit-link',docker+['test',*common,'--lib','--bin','rmm-agent-windows','--no-run','--message-format=json'])
|
|
binaries = command('windows-current-runtime-link',docker+['build',*common,'--bins','--message-format=json'])
|
|
artifacts = {}
|
|
for kind, raw in (('units', units), ('runtime', binaries)):
|
|
for line in raw.splitlines():
|
|
try:
|
|
value = json.loads(line)
|
|
except ValueError:
|
|
continue
|
|
if value.get('reason') != 'compiler-artifact' or not value.get('executable'):
|
|
continue
|
|
name = value['target']['name']
|
|
if kind == 'units':
|
|
label = {'rmm_agent_windows':'windows-lib-tests.exe','rmm-agent-windows':'windows-agent-tests.exe'}.get(name)
|
|
require(value.get('profile',{}).get('test') is True, 'test artifact only')
|
|
else:
|
|
label = {'rmm-helper-windows':'rmm-helper-windows.exe','rmm-agent-windows':'rmm-agent-windows.exe'}.get(name)
|
|
if label is None:
|
|
continue
|
|
require(label not in artifacts, 'exact unique PE artifact')
|
|
linked = target / Path(value['executable']).relative_to('/target')
|
|
original = out / (label + '.original'); delivery = out / label
|
|
shutil.copyfile(linked, original); shutil.copyfile(linked, delivery)
|
|
command(label+'-strip', ['docker','run','--rm','--network','none','--read-only','-v',str(out)+':/artifacts',
|
|
'--entrypoint','x86_64-w64-mingw32-strip',IMAGE,'--strip-debug','/artifacts/'+label])
|
|
data = delivery.read_bytes(); offset = int.from_bytes(data[60:64], 'little')
|
|
require(data[:2] == b'MZ' and data[offset:offset+6] == b'PE\0\0\x64\x86', 'actual Windows AMD64 PE')
|
|
require(sha(linked) == sha(original), 'original linked bytes retained')
|
|
artifacts[label] = dict(sha256=sha(delivery),bytes=delivery.stat().st_size,original_sha256=sha(original),
|
|
original_bytes=original.stat().st_size,debug_stripped_delivery=True,native_executed=False)
|
|
require(set(artifacts) == {'windows-lib-tests.exe','windows-agent-tests.exe','rmm-helper-windows.exe','rmm-agent-windows.exe'}, 'complete current runtime/unit set')
|
|
require(all(sha(ROOT/name) == digest for name,digest in frozen.items()) and sha(LINUX)==LINUX_SHA, 'same158 inputs and actual Linux proof before/after')
|
|
result = dict(type='rmm.script-console.windows-link-pack',schema_version=1,source_manifest_sha256=PACK_SHA,
|
|
source_files=frozen,source_before_after_equal=True,linux_native_proof_sha256=LINUX_SHA,linux_actual_passed=84,
|
|
linux_explicit_database_ignored=5,image_id=IMAGE,windows_target='x86_64-pc-windows-gnu',pipe_v2_sha256=PIPE_SHA,
|
|
checks=checks,artifacts=artifacts,windows_native_lists_executed=False,windows_native_tests_executed=False,
|
|
require_all_actual_native_lists_before_any_test=True,reuses_old_42_test_expectation=False,
|
|
clock_qualified=False,capabilities_activated=False,deployed=False,rmm_jobs=False,approvals=False)
|
|
path = out/'manifest.json'; path.write_text(json.dumps(result,indent=2)+'\n')
|
|
print(json.dumps(dict(manifest=str(path),sha256=sha(path),windows_native_executed=False,capabilities_activated=False)))
|
|
|
|
|
|
if __name__=='__main__':
|
|
main()
|