secpol-audit 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. secpol_audit/__init__.py +5 -0
  2. secpol_audit/__main__.py +8 -0
  3. secpol_audit/api_server.py +137 -0
  4. secpol_audit/assets/fallback_dashboard.html +42 -0
  5. secpol_audit/bench.py +741 -0
  6. secpol_audit/blast.py +1533 -0
  7. secpol_audit/blast_html.py +1186 -0
  8. secpol_audit/build_doctor/__init__.py +481 -0
  9. secpol_audit/checks.py +976 -0
  10. secpol_audit/cli.py +1004 -0
  11. secpol_audit/compile_wrap.py +137 -0
  12. secpol_audit/demo.py +416 -0
  13. secpol_audit/diff.py +352 -0
  14. secpol_audit/equiv.py +107 -0
  15. secpol_audit/events.py +920 -0
  16. secpol_audit/explain.py +442 -0
  17. secpol_audit/extras.py +19 -0
  18. secpol_audit/firmware.py +776 -0
  19. secpol_audit/graph_html.py +1372 -0
  20. secpol_audit/ipc/__init__.py +215 -0
  21. secpol_audit/ir.py +430 -0
  22. secpol_audit/mcp_server/__init__.py +411 -0
  23. secpol_audit/mcp_server/__main__.py +4 -0
  24. secpol_audit/mkifs_conformance.py +234 -0
  25. secpol_audit/oracle_diff.py +246 -0
  26. secpol_audit/parser_ifs.py +1185 -0
  27. secpol_audit/parser_secpol.py +1086 -0
  28. secpol_audit/paths.py +653 -0
  29. secpol_audit/perf/__init__.py +94 -0
  30. secpol_audit/provenance/__init__.py +480 -0
  31. secpol_audit/prune.py +282 -0
  32. secpol_audit/remediate.py +846 -0
  33. secpol_audit/replay/__init__.py +157 -0
  34. secpol_audit/runtime.py +408 -0
  35. secpol_audit/sarif.py +237 -0
  36. secpol_audit/service.py +393 -0
  37. secpol_audit/target/__init__.py +339 -0
  38. secpol_audit/trace.py +389 -0
  39. secpol_audit/tui/__init__.py +57 -0
  40. secpol_audit/tui/__main__.py +4 -0
  41. secpol_audit-1.0.0.dist-info/METADATA +100 -0
  42. secpol_audit-1.0.0.dist-info/RECORD +46 -0
  43. secpol_audit-1.0.0.dist-info/WHEEL +5 -0
  44. secpol_audit-1.0.0.dist-info/entry_points.txt +5 -0
  45. secpol_audit-1.0.0.dist-info/licenses/LICENSE +21 -0
  46. secpol_audit-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,5 @@
1
+ """secpol-audit: Deterministic static & runtime QNX Neutrino 8.0 security policy auditor."""
2
+
3
+ __version__ = "1.0.0"
4
+
5
+ __all__ = ["__version__"]
@@ -0,0 +1,8 @@
1
+ """Module entrypoint for `python3 -m secpol_audit`."""
2
+
3
+ import sys
4
+
5
+ from secpol_audit.cli import main
6
+
7
+ if __name__ == "__main__":
8
+ sys.exit(main())
@@ -0,0 +1,137 @@
1
+ """Live FastAPI backend server for secpol-audit Web Dashboard (Part M).
2
+
3
+ Binds strictly to 127.0.0.1 by default, enforces read-only workspace confinement
4
+ via `SecpolPlatformService`, and serves both live JSON endpoints and the
5
+ interactive systems-engineering dashboard.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ from importlib.resources import files
12
+ from pathlib import Path
13
+ from typing import Any
14
+
15
+ from fastapi import FastAPI, HTTPException, Query
16
+ from fastapi.responses import HTMLResponse
17
+
18
+ from secpol_audit.service import SecpolPlatformService, WorkspaceSecurityError
19
+
20
+
21
+ def create_app(workspace_root: str | Path) -> FastAPI:
22
+ svc = SecpolPlatformService(workspace_root)
23
+ app = FastAPI(title="secpol-audit QNX 8.0 API", version="1.0.0")
24
+
25
+ @app.get("/api/health")
26
+ def api_health() -> dict[str, Any]:
27
+ return {
28
+ "status": "ok",
29
+ "mode": "LIVE_API",
30
+ "workspace_root": str(svc.workspace_root),
31
+ "toolchain": svc.check_toolchain(),
32
+ }
33
+
34
+ @app.get("/api/policies")
35
+ def api_policies() -> dict[str, Any]:
36
+ return {"policies": svc.list_policies(), "build_files": svc.list_build_files()}
37
+
38
+ @app.get("/api/analyze")
39
+ def api_analyze(
40
+ policy_path: str = Query("qnx_demo/mutants/M3_blast_escalate.secpol"),
41
+ ifs_path: str | None = Query(None),
42
+ ) -> dict[str, Any]:
43
+ try:
44
+ return svc.analyze_policy(policy_path, ifs_path=ifs_path)
45
+ except (WorkspaceSecurityError, FileNotFoundError) as exc:
46
+ raise HTTPException(status_code=400, detail=str(exc)) from exc
47
+
48
+ @app.get("/api/blast")
49
+ def api_blast(
50
+ policy_path: str = Query("qnx_demo/mutants/M3_blast_escalate.secpol"),
51
+ ifs_path: str | None = Query("qnx_demo/build_blast.ifs.in"),
52
+ log_path: str | None = Query("evidence/blast/M3_blast_escalate.log"),
53
+ expected_probes_path: str | None = Query("qnx_demo/blast_expected_probes.json"),
54
+ ) -> dict[str, Any]:
55
+ try:
56
+ return svc.analyze_blast_radius(
57
+ policy_path,
58
+ ifs_path=ifs_path,
59
+ log_path=log_path,
60
+ expected_probes_path=expected_probes_path,
61
+ )
62
+ except (WorkspaceSecurityError, FileNotFoundError) as exc:
63
+ raise HTTPException(status_code=400, detail=str(exc)) from exc
64
+
65
+ @app.get("/api/remediate")
66
+ def api_remediate(
67
+ policy_path: str = Query("qnx_demo/mutants/M3_blast_escalate.secpol"),
68
+ ) -> dict[str, Any]:
69
+ try:
70
+ return svc.preview_remediation(policy_path)
71
+ except (WorkspaceSecurityError, FileNotFoundError) as exc:
72
+ raise HTTPException(status_code=400, detail=str(exc)) from exc
73
+
74
+ @app.get("/api/build-doctor")
75
+ def api_build_doctor(
76
+ build_path: str = Query("qnx_demo/build_blast.ifs.in"),
77
+ secpol_path: str | None = Query("qnx_demo/mutants/M3_blast_escalate.secpol"),
78
+ ) -> dict[str, Any]:
79
+ try:
80
+ return svc.run_build_doctor(build_path, secpol_path=secpol_path)
81
+ except (WorkspaceSecurityError, FileNotFoundError) as exc:
82
+ raise HTTPException(status_code=400, detail=str(exc)) from exc
83
+
84
+ @app.get("/api/target")
85
+ def api_target(
86
+ profile: str = Query("qemu-m3-capture"),
87
+ ) -> dict[str, Any]:
88
+ try:
89
+ return svc.inspect_target(profile)
90
+ except (ValueError, FileNotFoundError, WorkspaceSecurityError) as exc:
91
+ raise HTTPException(status_code=400, detail=str(exc)) from exc
92
+
93
+ @app.get("/api/ipc")
94
+ def api_ipc(
95
+ source: str = Query("qnx-adas-live"),
96
+ ) -> dict[str, Any]:
97
+ try:
98
+ return svc.analyze_ipc_scenario(source)
99
+ except (ValueError, FileNotFoundError, WorkspaceSecurityError) as exc:
100
+ raise HTTPException(status_code=400, detail=str(exc)) from exc
101
+
102
+ @app.get("/api/witness")
103
+ def api_witness(
104
+ target: str = Query("ADAS_12svc_blast"),
105
+ ) -> dict[str, Any]:
106
+ try:
107
+ return svc.build_e2e_witness(target)
108
+ except (ValueError, FileNotFoundError, WorkspaceSecurityError) as exc:
109
+ raise HTTPException(status_code=400, detail=str(exc)) from exc
110
+
111
+ @app.get("/", response_class=HTMLResponse)
112
+ def index() -> str:
113
+ dash = svc.workspace_root / "web-dashboard" / "index.html"
114
+ if dash.is_file():
115
+ return dash.read_text(encoding="utf-8")
116
+ try:
117
+ return files("secpol_audit").joinpath("assets", "fallback_dashboard.html").read_text(encoding="utf-8")
118
+ except (FileNotFoundError, ModuleNotFoundError) as exc:
119
+ raise HTTPException(status_code=404, detail="No workspace dashboard or packaged fallback is available") from exc
120
+
121
+ return app
122
+
123
+
124
+ def main(argv: list[str] | None = None) -> int:
125
+ import uvicorn
126
+
127
+ ap = argparse.ArgumentParser(description="secpol-audit local read-only web console")
128
+ ap.add_argument("--workspace", default=".")
129
+ ap.add_argument("--host", default="127.0.0.1")
130
+ ap.add_argument("--port", type=int, default=8765)
131
+ ns = ap.parse_args(argv)
132
+ uvicorn.run(create_app(ns.workspace), host=ns.host, port=ns.port)
133
+ return 0
134
+
135
+
136
+ if __name__ == "__main__":
137
+ raise SystemExit(main())
@@ -0,0 +1,42 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <title>secpol-audit · Workspace console</title>
7
+ <style>
8
+ :root{color-scheme:dark;--bg:#0b1115;--panel:#121c21;--line:#26373b;--text:#e6efeb;--muted:#91a39e;--lime:#c7ee78;--red:#ff8179}
9
+ *{box-sizing:border-box}body{margin:0;background:radial-gradient(ellipse at 80% 0%,#1c302b 0,transparent 45%),var(--bg);color:var(--text);font:15px/1.55 system-ui,sans-serif}
10
+ main{width:min(100% - 36px,980px);margin:56px auto}header{display:flex;justify-content:space-between;gap:20px;align-items:center;border-bottom:1px solid var(--line);padding-bottom:22px}
11
+ h1{font-size:clamp(30px,5vw,48px);line-height:1.05;letter-spacing:-.04em;margin:0}h1 span{color:var(--lime)}p{color:var(--muted)}
12
+ .pill{border:1px solid var(--line);border-radius:99px;padding:6px 12px;color:var(--muted);font-size:12px}
13
+ .grid{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin-top:24px}.card{background:rgba(18,28,33,.92);border:1px solid var(--line);border-radius:12px;padding:20px;min-width:0}
14
+ h2{font-size:16px;margin:0 0 12px}label{display:block;color:var(--muted);font-size:12px;margin:12px 0 5px}
15
+ select,input,button{font:inherit;color:var(--text);background:#0d1519;border:1px solid var(--line);border-radius:7px;padding:10px;width:100%}
16
+ button{cursor:pointer;background:rgba(199,238,120,.12);border-color:rgba(199,238,120,.35);color:var(--lime);font-weight:650;margin-top:12px}
17
+ pre{white-space:pre-wrap;overflow-wrap:anywhere;background:#091014;border:1px solid var(--line);border-radius:8px;padding:14px;min-height:100px;color:#d5e4dd;font:12px/1.55 ui-monospace,monospace}
18
+ .notice{border-left:3px solid var(--lime);padding:10px 14px;background:rgba(199,238,120,.06);margin:22px 0;color:var(--muted)}
19
+ footer{margin-top:24px;color:var(--muted);font-size:12px}
20
+ @media(max-width:680px){main{margin:30px auto}.grid{grid-template-columns:1fr}header{align-items:flex-start;flex-direction:column}}
21
+ </style>
22
+ </head>
23
+ <body>
24
+ <main>
25
+ <header><div><h1>secpol<span>-audit</span></h1><p>QNX Neutrino 8.0 · Read-only workspace console</p></div><span class="pill" id="status">Checking API…</span></header>
26
+ <div class="notice">The full visual workbench is not present in this workspace. This packaged console provides safe API access without returning a 404. To generate the full workbench in a source checkout, run <code>python harness/generate_dashboard.py</code>.</div>
27
+ <div class="grid">
28
+ <section class="card"><h2>Workspace health</h2><p>API and toolchain availability.</p><button id="refresh">Refresh status</button><pre id="health">Waiting for API…</pre></section>
29
+ <section class="card"><h2>Policy analysis</h2><label for="policy">Policy file</label><select id="policy"><option value="">Loading policies…</option></select><label for="ifs">Optional buildfile</label><select id="ifs"><option value="">No buildfile</option></select><button id="analyze">Analyze selected files</button><pre id="result">Select a policy and run analysis.</pre></section>
30
+ </div>
31
+ <footer>Static findings are not compiler confirmation. QNX mkifs and secpolcompile remain the target-side authorities. The server is read-only and should remain bound to loopback unless authenticated deployment controls are added.</footer>
32
+ </main>
33
+ <script>
34
+ 'use strict';
35
+ const $=id=>document.getElementById(id);
36
+ async function get(path){const r=await fetch(path,{headers:{Accept:'application/json'}});if(!r.ok)throw new Error('HTTP '+r.status+' '+r.statusText);return r.json();}
37
+ async function refresh(){try{const d=await get('/api/health');$('status').textContent='API ONLINE';$('health').textContent=JSON.stringify(d,null,2);const f=await get('/api/policies');$('policy').replaceChildren();for(const p of f.policies){const o=document.createElement('option');o.value=p;o.textContent=p;$('policy').append(o);}if(!f.policies.length){const o=document.createElement('option');o.textContent='No .secpol files found';o.value='';$('policy').append(o);} $('ifs').replaceChildren();const none=document.createElement('option');none.value='';none.textContent='No buildfile';$('ifs').append(none);for(const p of f.build_files){const o=document.createElement('option');o.value=p;o.textContent=p;$('ifs').append(o);}}catch(e){$('status').textContent='API UNAVAILABLE';$('health').textContent=String(e);}}
38
+ async function analyze(){const policy=$('policy').value;if(!policy){$('result').textContent='No policy selected.';return;}const q=new URLSearchParams({policy_path:policy});if($('ifs').value)q.set('ifs_path',$('ifs').value);$('result').textContent='Analyzing…';try{$('result').textContent=JSON.stringify(await get('/api/analyze?'+q.toString()),null,2);}catch(e){$('result').textContent=String(e);}}
39
+ $('refresh').addEventListener('click',refresh);$('analyze').addEventListener('click',analyze);refresh();
40
+ </script>
41
+ </body>
42
+ </html>