Skip to main content

Trusted Machine-Readable Provenance (TMRP) monitoring engine with AST causal filter, ECDSA-signed receipts, and tamper-evident audit ledger

Project description

Aletheia

aletheia-core

TMRP — Trusted Machine-Readable Provenance

Agent X-ray Watcher (Snapshot Engine) for monitoring code changes, running an AST-based Causal Filter, generating ECDSA-signed Sovereign Receipts, quarantining malicious files (Active Interlock), broadcasting node health over UDP (Heartbeat), hardware-bound key derivation (HKDF), and persistent SQLite audit logging.

Quick Start

pip install watchdog ecdsa
python agent_xray_watcher.py .

Edit any .py file in the repo — the watcher prints the diff, trust mark, and a signed receipt in real time. Press Ctrl+C to stop.

How It Works

  1. File monitoringwatchdog watches the repo recursively (skipping .git).
  2. Diff computation — On each modification a unified diff is generated against the cached version.
  3. AST Causal Filter — For .py files the code is parsed and scanned for lateral-movement signatures:
    • Dangerous module imports (socket, subprocess, shutil, ctypes, pickle, …)
    • Dangerous function calls (os.system, eval, exec, subprocess.Popen, …)
    • Each violation includes line number, issue description, severity (high / critical), and category.
  4. Trust MarkGreen (all clear) or Red (violations detected).
  5. Active Interlock — When the filter returns Red, the file is immediately renamed to <file>.locked (quarantined) and a QuarantineReceipt is generated. The watcher's own script is excluded from quarantine (self-exclusion) since it legitimately uses socket/threading for the heartbeat.
  6. Hardware-Bound Key — The ECDSA signing key is derived from the device's hardware fingerprint (DMI UUID, MAC address) using HKDF (RFC 5869). The same key is produced on every run, making receipts verifiable across reboots. Falls back to an ephemeral random key if no hardware ID is available.
  7. Sovereign Receipt — A JSON-LD credential containing the diff hash, filter result, and structured violation_log, signed with ECDSA (SECP256k1).
  8. SQLite Audit Database — Every receipt (Green, Red, Quarantine) is persisted to audit.sqlite with timestamp, file path, status, full receipt JSON, and structured violation log. Supports forensics and compliance reporting.
  9. Heartbeat Broadcast — A UDP server (default port 12345, configurable via ALETHEIA_BROADCAST_PORT env var) responds to ping messages with a signed HeartbeatReceipt reporting node ID, security status, quarantine count, and uptime.

Receipt Format

Receipts follow the W3C Verifiable Credentials v2 @context. Key fields:

Field Description
credentialSubject.diffHash SHA-256 of the unified diff
credentialSubject.filterResult.pass true (Green) / false (Red)
credentialSubject.filterResult.reason Human-readable summary
credentialSubject.violation_log Structured array of violations (see below)
Causal_Filter_Signature Hex-encoded ECDSA signature over credentialSubject

violation_log Entry Schema

{
    "line": 8,
    "issue": "call to dangerous function 'os.system'",
    "severity": "critical",
    "category": "dangerous_call"
}
  • severity: high (dangerous imports) or critical (dangerous function calls / builtins).
  • category: dangerous_import, dangerous_call, dangerous_builtin, or parse_error.

See sample_red_receipt.json for a complete Red receipt example.

Quarantine Receipt

When the interlock activates, a QuarantineReceipt is generated with extra fields:

Field Description
credentialSubject.quarantinedPath Path the file was renamed to (.locked)
credentialSubject.quarantine.timestamp ISO 8601 UTC timestamp of quarantine
credentialSubject.quarantine.action Always "file_locked"
type ["SovereignReceipt", "QuarantineReceipt"]

Heartbeat Receipt

Send a UDP ping to receive a signed heartbeat:

python3 -c "
import socket, json
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(3)
s.sendto(b'ping', ('127.0.0.1', 12345))
data, _ = s.recvfrom(4096)
print(json.dumps(json.loads(data), indent=2))
"

Fields: nodeId, status, lastScan, health.quarantineCount, health.uptimeSeconds.

Audit Database

All receipts are persisted to audit.sqlite (auto-created on first run). Query it with:

sqlite3 audit.sqlite "SELECT id, timestamp, status, file_path FROM receipts ORDER BY id"

Schema:

Column Type Description
id INTEGER Auto-increment primary key
timestamp TEXT ISO 8601 UTC
file_path TEXT Absolute path of the scanned file
status TEXT Green or Red
receipt_json TEXT Full JSON-LD receipt
violation_log JSON Structured violation list (NULL for Green)

Verifying Signatures

The watcher prints its session public key on startup. Use verify_receipt(data_dict, signature_hex) to check any receipt:

from agent_xray_watcher import verify_receipt
import json

with open("sample_red_receipt.json") as f:
    receipt = json.load(f)

ok = verify_receipt(receipt["credentialSubject"], receipt["Causal_Filter_Signature"])
print("Valid" if ok else "Invalid")

Project Structure

agent_xray_watcher.py    # Watcher + Causal Filter + Signer + Interlock + Heartbeat
sample_red_receipt.json   # Example Red receipt for demos / audit trail
audit.sqlite              # Auto-created SQLite audit DB (gitignored)
README.md

Links

License

MIT — Copyright (c) 2026 Ashura Joseph Holeyfield — Aletheia Sovereign Systems

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aletheia_core-1.7.5.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aletheia_core-1.7.5-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file aletheia_core-1.7.5.tar.gz.

File metadata

  • Download URL: aletheia_core-1.7.5.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aletheia_core-1.7.5.tar.gz
Algorithm Hash digest
SHA256 11894c7aa8b5f5269e7c96254a006237235d34b115f7a5fc10b3d9e67b599cc2
MD5 2cc17cbd4a979003e81fb1145cded7da
BLAKE2b-256 fa0f18f39a68a2cc576cfa69277806e1d933141d1849bf20b83f4cd12439893e

See more details on using hashes here.

File details

Details for the file aletheia_core-1.7.5-py3-none-any.whl.

File metadata

  • Download URL: aletheia_core-1.7.5-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aletheia_core-1.7.5-py3-none-any.whl
Algorithm Hash digest
SHA256 715cee84a738f1584a85c4e66831eb344c274e62fe047a78d9c9eb4b4bb5c389
MD5 0c8d8aec127b2f9ede89abea6de3cff6
BLAKE2b-256 ea3bce22e8fa19ccb287b3601912137e0e24cd294f62f761474307ff2a1011d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page