Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/hardware-review-consistency.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Hardware Review Consistency RDTE

on:
pull_request:
paths:
- 'scripts/hardware_review.py'
- 'scripts/test_hardware_review.py'
- '.github/workflows/hardware-review-consistency.yml'

permissions:
contents: read

jobs:
synthetic-consistency:
if: github.repository == 'SemperSupra/WineBot' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- name: Check exact source and offline synthetic consistency
env:
SOURCE_SHA: ${{ github.event.pull_request.head.sha }}
run: |
test "$(git rev-parse HEAD)" = "$SOURCE_SHA"
python3 scripts/test_hardware_review.py
- name: Assert publication remains closed
run: |
if output="$(env GITHUB_EVENT_NAME=push GITHUB_REF=refs/heads/rdte/r066-installer-integrated-20261127 bash scripts/ci/publish-candidate-images.sh 2>&1)"; then
exit 1
fi
test "$output" = 'WINE11_CANDIDATE stage=pre_hardware_admission_required result=fail'
139 changes: 139 additions & 0 deletions scripts/hardware_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
"""Offline hardware gate receipt consistency check; never authorizes publication.

The review ledger digest must come from an independent trusted authority.
A digest supplied by the submitter is NOT a trust anchor. This tool checks
consistency only: it neither verifies CI via GitHub nor establishes reviewer
identity, security clearance, or authority to release. Publication stays closed.
"""
import argparse
import hashlib
import hmac
import json
import re
from pathlib import Path

GATES = frozenset({
"immutable_images", "wine_recovery_soak", "layer_state_restore",
"real_app_game", "installer_replay", "control_accessibility",
"security_supply_chain", "hardware_test_manifest",
})
LIMIT = 65536


class InvalidReview(ValueError):
"""A fixed, public-safe error category."""


def require(condition, reason):
if not condition:
raise InvalidReview(reason)


def unique_object(pairs):
result = {}
for key, value in pairs:
require(key not in result, "duplicate_json_key")
result[key] = value
return result


def read_json(path):
with Path(path).open("rb") as stream:
data = stream.read(LIMIT + 1)
require(len(data) <= LIMIT, "oversize")
return data


def decode(data):
require(len(data) <= LIMIT, "oversize")
return json.loads(data, object_pairs_hook=unique_object)


def digest(data):
return "sha256:" + hashlib.sha256(data).hexdigest()


def is_digest(value):
return isinstance(value, str) and re.fullmatch(r"sha256:[0-9a-f]{64}", value)


def exact_keys(value, keys):
return isinstance(value, dict) and set(value) == set(keys)


def positive_int(value):
return type(value) is int and value > 0


def validate(ledger_bytes, receipts_bytes, trusted_ledger_digest, source,
runtime, instrumented, app_manifest):
require(is_digest(trusted_ledger_digest), "missing_review_anchor")
require(hmac.compare_digest(digest(ledger_bytes), trusted_ledger_digest),
"untrusted_review_ledger")
require(isinstance(source, str) and re.fullmatch(r"[0-9a-f]{40}", source),
"invalid_source")
require(all(is_digest(item) for item in (runtime, instrumented, app_manifest))
and runtime != instrumented, "invalid_subject")
subjects = {"runtime_image_id": runtime, "instrumented_image_id": instrumented,
"app_manifest_sha256": app_manifest}
ledger = decode(ledger_bytes)
require(exact_keys(ledger, {"schema", "source", "subjects", "gate_receipts",
"security_review"}), "invalid_ledger")
require(ledger["schema"] == "winebot.hardware-review-ledger/1", "schema")
require(ledger["source"] == source and ledger["subjects"] == subjects,
"stale_review")
require(ledger["security_review"] == "approved", "security_hold")
approved = ledger["gate_receipts"]
require(exact_keys(approved, GATES) and all(is_digest(v) for v in approved.values()),
"incomplete_review")
require(len(set(approved.values())) == len(GATES), "duplicate_review_receipt")
receipts = decode(receipts_bytes)
require(isinstance(receipts, list) and len(receipts) == len(GATES),
"incomplete_receipts")
seen = set()
for record in receipts:
require(exact_keys(record, {"schema", "gate", "source", "subjects", "result",
"evidence_class", "run_id", "job_id",
"evidence_sha256"}), "invalid_receipt")
gate = record["gate"]
require(isinstance(gate, str) and gate in GATES and gate not in seen,
"unknown_or_duplicate_gate")
seen.add(gate)
require(record["schema"] == "winebot.hardware-gate-receipt/1", "schema")
require(record["source"] == source and record["subjects"] == subjects,
"stale_receipt")
require(record["result"] == "pass", "gate_not_passed")
require(record["evidence_class"] in ("PRODUCT_QUALIFICATION",
"RELEASE_QUALIFICATION"),
"insufficient_evidence_class")
require(positive_int(record["run_id"]) and positive_int(record["job_id"])
and is_digest(record["evidence_sha256"]), "invalid_evidence_identity")
canonical = json.dumps(record, sort_keys=True, separators=(",", ":"),
ensure_ascii=True).encode("ascii")
require(hmac.compare_digest(digest(canonical), approved[gate]),
"unreviewed_receipt")
require(seen == GATES, "incomplete_receipts")


def main():
parser = argparse.ArgumentParser(description=__doc__)
for name in ("ledger", "receipts", "trusted-ledger-digest", "source",
"runtime", "instrumented", "app-manifest"):
parser.add_argument("--" + name, required=True)
args = parser.parse_args()
try:
validate(read_json(args.ledger), read_json(args.receipts),
args.trusted_ledger_digest, args.source, args.runtime,
args.instrumented, args.app_manifest)
except InvalidReview as exc:
print("HARDWARE_REVIEW_CONSISTENCY result=fail reason=" + str(exc))
return 1
except (OSError, ValueError, TypeError, RecursionError):
print("HARDWARE_REVIEW_CONSISTENCY result=fail reason=invalid_input")
return 1
print("HARDWARE_REVIEW_CONSISTENCY result=pass publication=blocked")
return 0


if __name__ == "__main__":
raise SystemExit(main())
105 changes: 105 additions & 0 deletions scripts/test_hardware_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""Synthetic negative and positive consistency fixtures, not product proof."""
import copy
import json
import unittest

import hardware_review as review


def encode(value):
return json.dumps(value, sort_keys=True, separators=(",", ":")).encode("ascii")


class ReviewTest(unittest.TestCase):
def setUp(self):
self.source = "a" * 40
self.runtime = "sha256:" + "b" * 64
self.instrumented = "sha256:" + "c" * 64
self.app = "sha256:" + "d" * 64
self.subjects = {"runtime_image_id": self.runtime,
"instrumented_image_id": self.instrumented,
"app_manifest_sha256": self.app}
self.receipts = [
{"schema": "winebot.hardware-gate-receipt/1", "gate": gate,
"source": self.source, "subjects": copy.deepcopy(self.subjects),
"result": "pass", "evidence_class": "PRODUCT_QUALIFICATION",
"run_id": i + 1, "job_id": i + 101, "evidence_sha256": self.app}
for i, gate in enumerate(sorted(review.GATES))
]
self.ledger = {"schema": "winebot.hardware-review-ledger/1",
"source": self.source, "subjects": self.subjects,
"security_review": "approved",
"gate_receipts": {r["gate"]: review.digest(encode(r))
for r in self.receipts}}
self.anchor = review.digest(encode(self.ledger))

def check(self):
review.validate(encode(self.ledger), encode(self.receipts), self.anchor,
self.source, self.runtime, self.instrumented, self.app)

def reanchor(self):
self.anchor = review.digest(encode(self.ledger))

def reject(self, reason):
with self.assertRaisesRegex(review.InvalidReview, "^" + reason + "$"):
self.check()

def test_complete_synthetic_review_consistency(self):
self.check()

def test_missing_anchor(self):
self.anchor = ""
self.reject("missing_review_anchor")

def test_untrusted_ledger(self):
self.ledger["security_review"] = "pending"
self.reject("untrusted_review_ledger")

def test_security_hold_even_with_matching_anchor(self):
self.ledger["security_review"] = "pending"
self.reanchor()
self.reject("security_hold")

def test_stale_source(self):
self.source = "e" * 40
self.reject("stale_review")

def test_other_image(self):
self.runtime = "sha256:" + "f" * 64
self.reject("stale_review")

def test_missing_gate(self):
self.receipts.pop()
self.reject("incomplete_receipts")

def test_duplicate_gate(self):
self.receipts[-1] = self.receipts[0]
self.reject("unknown_or_duplicate_gate")

def test_synthetic_evidence_not_admissible(self):
self.receipts[0]["evidence_class"] = "MOCKED_BEHAVIOR"
self.reject("insufficient_evidence_class")

def test_failed_receipt(self):
self.receipts[0]["result"] = "fail"
self.reject("gate_not_passed")

def test_mismatched_receipt_subject(self):
self.receipts[0]["subjects"]["runtime_image_id"] = self.app
self.reject("stale_receipt")

def test_unreviewed_receipt(self):
self.receipts[0]["job_id"] = 9999
self.reject("unreviewed_receipt")

def test_duplicate_json_keys(self):
with self.assertRaisesRegex(review.InvalidReview, "duplicate_json_key"):
review.decode(b'{"schema":1,"schema":2}')

def test_bool_not_job_id(self):
self.receipts[0]["job_id"] = True
self.reject("invalid_evidence_identity")


if __name__ == "__main__":
unittest.main()