Preserve native timestamp precision in passive time closeout
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-15 16:09:21 +01:00
parent 44f65c205b
commit cdcdb36c13
4 changed files with 52 additions and 12 deletions
+17 -9
View File
@@ -22,6 +22,7 @@ FIELDS = {'schema_version', 'agent_pid', 'observed_at', 'role', 'windows_boot_id
'connection_generation', 'verifier_incarnation', 'request_sha256', 'response_sha256'}
FILES = {'agent': 'agent-time-sample.json', 'system_helper': 'helper-time-sample.json'}
HEX = re.compile(r'[0-9a-f]{64}')
SECOND_NS = 1_000_000_000
# No report is requested from a service. The only content reads on the guest
# are these two public JSONs and public executable hashes. CIM/process queries
@@ -106,9 +107,16 @@ def strict(pairs):
def stamp(value):
need(type(value) is str and value.endswith('Z'), 'UTC_TIMESTAMP_REQUIRED')
result = dt.datetime.fromisoformat(value[:-1] + '+00:00')
return result
need(type(value) is str, 'UTC_TIMESTAMP_REQUIRED')
match = re.fullmatch(r'(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,9}))?Z', value)
need(match is not None, 'UTC_TIMESTAMP_REQUIRED')
base = dt.datetime.strptime(match[1], '%Y-%m-%dT%H:%M:%S').replace(tzinfo=dt.timezone.utc)
elapsed = base - dt.datetime(1970, 1, 1, tzinfo=dt.timezone.utc)
return (elapsed.days * 86400 + elapsed.seconds) * SECOND_NS + int((match[2] or '').ljust(9, '0'))
def utc_ns(value):
return stamp(value.astimezone(dt.timezone.utc).isoformat().replace('+00:00', 'Z'))
def canonical_uuid(value):
@@ -138,7 +146,7 @@ def windows_boot(ticks):
def filetime(value):
need(type(value) is str and value.isascii() and value.isdigit(), 'FILETIME_REQUIRED')
return dt.datetime(1601, 1, 1, tzinfo=dt.timezone.utc) + dt.timedelta(microseconds=int(value) // 10)
return (int(value) - 116444736000000000) * 100
def validate(native, server, since, observed_now):
@@ -151,7 +159,7 @@ def validate(native, server, since, observed_now):
generation = current['connection_generation']
need(type(generation) is int and generation > 0, 'CURRENT_POSITIVE_GENERATION')
now = stamp(native['observed_at'])
need(abs((now - observed_now).total_seconds()) <= 10, 'CURRENT_WINDOWS_UTC')
need(abs(now - utc_ns(observed_now)) <= 10 * SECOND_NS, 'CURRENT_WINDOWS_UTC')
records = []
for role, filename in FILES.items():
wrapped = native['reports'][filename]
@@ -168,9 +176,9 @@ def validate(native, server, since, observed_now):
observed = stamp(record['observed_at'])
modified = filetime(wrapped['metadata']['last_write_filetime'])
birth = filetime(native['runtime']['agent']['birth_filetime'])
need(since <= observed <= now + dt.timedelta(seconds=2) and birth <= observed, 'SAMPLE_CURRENT_INSTALL_WINDOW')
need(0 <= (now - modified).total_seconds() <= 180 and 0 <= (now - observed).total_seconds() <= 180, 'SAMPLE_FILE_AGE')
need(-2 <= (modified - observed).total_seconds() <= 90, 'SAMPLE_PUBLICATION_DELAY')
need(since <= observed <= now + 2 * SECOND_NS and birth <= observed, 'SAMPLE_CURRENT_INSTALL_WINDOW')
need(0 <= now - modified <= 180 * SECOND_NS and 0 <= now - observed <= 180 * SECOND_NS, 'SAMPLE_FILE_AGE')
need(-2 * SECOND_NS <= modified - observed <= 90 * SECOND_NS, 'SAMPLE_PUBLICATION_DELAY')
need(wrapped['metadata']['dacl_checked'] is True, 'SAMPLE_PROTECTED_METADATA')
records.append(record)
for field in ('verifier_incarnation', 'request_sha256', 'response_sha256'):
@@ -181,7 +189,7 @@ def validate(native, server, since, observed_now):
def collect(args):
need(HEX.fullmatch(args.agent_sha256) and HEX.fullmatch(args.helper_sha256), 'QUALIFIED_RUNTIME_HASHES_REQUIRED')
since = stamp(args.profile_after)
need(0 <= (dt.datetime.now(dt.timezone.utc) - since).total_seconds() <= 600, 'RECENT_PROFILE_INSTALL_WINDOW')
need(0 <= utc_ns(dt.datetime.now(dt.timezone.utc)) - since <= 600 * SECOND_NS, 'RECENT_PROFILE_INSTALL_WINDOW')
STATE.mkdir(parents=True, mode=0o700, exist_ok=True)
ident = str(uuid.uuid4())
folder = STATE / ident