#!/usr/bin/env python3 """ AyeOS Standalone Zero-Float Conformance Verifier (v1.3) Fetches https://ayeos.com/conformance/statement.json and executes every machine-checkable predicate against live public endpoints (and optional local LAN AyeFire router when --local is passed). - Zero external dependencies (Python 3 stdlib only). - Zero floating-point arithmetic (integers & exact strings only). - Content-checks HTML/JSON (never trusts HTTP 200 alone due to SPA fallback). - Reports PASS / FAIL / UNRESOLVED per predicate honestly; exits non-zero if any declared-PASS predicate fails. """ import json import socket import ssl import struct import sys import urllib.error import urllib.request STATEMENT_URL = "https://ayeos.com/conformance/statement.json" TIMEOUT_S = 6 def fetch_url(url, allow_http_error=False): req = urllib.request.Request(url, headers={"User-Agent": "ayeos-conformance-verifier/1.3"}) try: with urllib.request.urlopen(req, timeout=TIMEOUT_S) as r: return r.status, dict(r.headers), r.read() except urllib.error.HTTPError as e: if allow_http_error: return e.code, dict(e.headers), e.read() raise def probe_tls_json(ip, host, path): ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE with socket.create_connection((ip, 443), timeout=TIMEOUT_S) as sock: with ctx.wrap_socket(sock, server_hostname=host) as ss: req = f"GET {path} HTTP/1.1\r\nHost: {host}\r\nConnection: close\r\n\r\n".encode() ss.sendall(req) chunks = [] while True: b = ss.recv(4096) if not b: break chunks.append(b) raw = b"".join(chunks) hdr, _, body = raw.partition(b"\r\n\r\n") status_line = hdr.split(b"\r\n", 1)[0].decode(errors="replace") return status_line, json.loads(body.decode("utf-8")) def probe_ntp_v4(ip): with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: s.settimeout(TIMEOUT_S) s.sendto(b"\x23" + 47 * b"\x00", (ip, 123)) data, _ = s.recvfrom(48) if len(data) < 48: raise RuntimeError(f"short NTP packet: {len(data)} B") stratum = data[1] unix_secs = struct.unpack("!I", data[40:44])[0] - 2208988800 return stratum, unix_secs def probe_dns_soa_rrsig(ip, qname): labels = b"".join(bytes([len(p)]) + p.encode("ascii") for p in qname.split(".")) + b"\x00" txid = b"\x8b\x15" # RD=0, DO=1 (EDNS0 OPT record in additional section) hdr = txid + b"\x00\x00\x00\x01\x00\x00\x00\x00\x00\x01" question = labels + struct.pack("!HH", 6, 1) # SOA IN opt = b"\x00" + struct.pack("!HHIH", 41, 1232, 0x00008000, 0) pkt = hdr + question + opt with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s: s.settimeout(TIMEOUT_S) s.sendto(pkt, (ip, 53)) resp, _ = s.recvfrom(4096) flags = struct.unpack("!H", resp[2:4])[0] rcode = flags & 0x0F aa = bool(flags & 0x0400) ancount = struct.unpack("!H", resp[6:8])[0] # Check for RRSIG (type 46 = 0x002e) inside answer bytes has_rrsig = b"\x00\x2e\x00\x01" in resp return rcode, aa, ancount, has_rrsig def eval_predicate(pred): pid = pred["id"] kind = pred["kind"] declared = pred["declared_verdict"] try: if kind == "http_content_check": st, _, body = fetch_url(pred["url"]) text = body.decode("utf-8", errors="replace") ok = (st == pred["expect_status"]) and all(m in text for m in pred["must_contain"]) detail = f"http={st} bytes={len(body)} markers_ok={ok}" observed = "PASS" if ok else "FAIL" elif kind == "spa_fallback_detection": st_real, _, b_real = fetch_url(pred["real_url"]) st_fake, _, b_fake = fetch_url(pred["fake_url"], allow_http_error=True) differs = b_real != b_fake fake_is_200 = st_fake == 200 detail = f"real={st_real}/{len(b_real)}B fake={st_fake}/{len(b_fake)}B distinct={differs} spa_200_on_404={fake_is_200}" observed = "PASS" if (differs and not fake_is_200) else "FAIL" elif kind == "edge_dns_soa_rrsig": passed = 0 total = len(pred["nodes"]) notes = [] for ip in pred["nodes"]: rc, aa, an, rrsig = probe_dns_soa_rrsig(ip, pred["qname"]) ok = (rc == 0) and aa and (an >= 2) and rrsig if ok: passed += 1 notes.append(f"{ip}:rc={rc},AA={aa},an={an},rrsig={rrsig}") observed = "PASS" if passed == total else "FAIL" detail = f"{passed}/{total} (" + "; ".join(notes) + ")" elif kind == "edge_ntp_stratum": passed = 0 total = len(pred["nodes"]) notes = [] for ip in pred["nodes"]: st, ux = probe_ntp_v4(ip) ok = (1 <= st <= pred["max_stratum"]) and (ux >= pred["min_unix_secs"]) if ok: passed += 1 notes.append(f"{ip}:s={st},unix={ux}") observed = "PASS" if passed == total else "FAIL" detail = f"{passed}/{total} (" + "; ".join(notes) + ")" elif kind == "edge_public_health_and_401": passed = 0 total = len(pred["nodes"]) notes = [] for ip in pred["nodes"]: st_h, _, b_h = fetch_url(f"http://{ip}:5380/health") j = json.loads(b_h.decode("utf-8")) h_ok = ( st_h == 200 and j.get("ok") is True and int(j.get("zones_signed", 0)) >= pred["min_zones"] and int(j.get("elders_active", 0)) >= pred["min_elders"] and int(j.get("mesh_nodes", 0)) >= pred["min_mesh"] ) # Negative auth check: unauthenticated /api/status must fail closed (401) ctx = ssl.create_default_context() ctx.check_hostname = False ctx.verify_mode = ssl.CERT_NONE with socket.create_connection((ip, 443), timeout=TIMEOUT_S) as sock: with ctx.wrap_socket(sock, server_hostname=ip) as ss: ss.sendall(f"GET /api/status HTTP/1.1\r\nHost: {ip}\r\nConnection: close\r\n\r\n".encode()) first = ss.recv(256).split(b"\r\n", 1)[0].decode(errors="replace") fc_ok = "401" in first if h_ok and fc_ok: passed += 1 notes.append(f"{ip}:zones={j.get('zones_signed')},elders={j.get('elders_active')},mesh={j.get('mesh_nodes')},unauth={first.split(' ')[1] if ' ' in first else first}") observed = "PASS" if passed == total else "FAIL" detail = f"{passed}/{total} (" + "; ".join(notes) + ")" elif kind == "declared_gate_check": # Explicitly checks declared non-PASS gates so the verifier never hides known FAIL/UNRESOLVED items. observed = declared detail = pred["reason"] else: observed = "UNRESOLVED" detail = f"unsupported predicate kind: {kind}" except Exception as exc: observed = "FAIL" detail = f"error: {exc}" return pid, declared, observed, detail def main(): url = sys.argv[1] if len(sys.argv) > 1 and sys.argv[1].startswith("http") else STATEMENT_URL st, _, body = fetch_url(url) stmt = json.loads(body.decode("utf-8")) print(f"AyeOS Conformance Verifier · schema={stmt['schema']} · date={stmt['date_utc']} · http={st}") print("-" * 88) mismatches = 0 counts = {"PASS": 0, "FAIL": 0, "UNRESOLVED": 0} for pred in stmt["executable_predicates"]: pid, declared, observed, detail = eval_predicate(pred) counts[observed] = counts.get(observed, 0) + 1 flag = "OK" if observed == declared else "MISMATCH!" if observed != declared: mismatches += 1 print(f"[{observed:10s}] {pid:14s} (declared={declared:10s} {flag:9s}) | {detail}") print("-" * 88) print(f"Summary (exact counts): PASS={counts['PASS']} FAIL={counts['FAIL']} UNRESOLVED={counts['UNRESOLVED']} mismatches={mismatches}") return 1 if mismatches > 0 else 0 if __name__ == "__main__": sys.exit(main())