code wiki / _hdl_build / nx_uiq_wire.nx

nx_uiq_wire.nx source

↩ module page · 36 lines · 2020 B

1// nx_uiq_wire.nx -- CLI: the FIRST-BYTE-UP response/header auditor (experiential wire layer). 2// Audits the HTTP response the edge emits from byte 0 -- status + the SOTA security-header posture. 3// usage: nx_uiq_wire --kat (self-test: bare=EXPOSED, hardened=5/5, xfo/frame-ancestors) 4// nx_uiq_wire audit <resp-file> (JSON: status, per-header presence, sec_score/5, verdict) 5// live: capture a page's response with nx_https_get -> file, then `nx_uiq_wire audit <file>`. 6// license_tier: ORIGINAL expect_exit: 0 genealogy: experiential wire layer; fetch=nx_https_get 7import "nx_uiq_wire_lib.nx" 8const K_MAGIC_262144: i64 = 262144 9 10func main(argc: i64, argv: *i64) -> i64 { 11 if argc>=2 { 12 let a1: *u8 = argv[1] as *u8 13 if a1[0]==(45 as u8) { 14 uw_w("=== nx_uiq_wire --kat (first-byte-up response security-header audit) ===\n" as *u8) 15 let f: i64 = uw_selftest() 16 uw_w("checks failed=" as *u8); uw_pn(f); uw_w(" (bare=EXPOSED 0/5, hardened=5/5, frame-ancestors + X-Frame-Options + case-insensitive)\n" as *u8) 17 if f==0 { uw_w("VERDICT=GREEN\n" as *u8); sys_exit(0); return 0 } 18 uw_w("VERDICT=RED\n" as *u8); sys_exit(1); return 1 19 } 20 let vl: i64 = uw_len(a1) 21 if vl==5 { if uw_lc(a1[0] as i64)==97 { if uw_lc(a1[1] as i64)==117 { 22 if argc<3 { uw_w("usage: nx_uiq_wire audit <response-file>\n" as *u8); sys_exit(2); return 2 } 23 let p: *u8 = argv[2] as *u8 24 let cap: i64 = K_MAGIC_262144 25 let buf: *u8 = sys_mmap(cap) 26 let n: i64 = uw_slurp(p, buf, cap) 27 if n<=0 { uw_w("{\"organ\":\"nx_uiq_wire\",\"error\":\"cannot read response file\"}\n" as *u8); sys_exit(2); return 2 } 28 let out: *i64 = sys_mmap(64) as *i64 29 uw_audit(buf, n, out) 30 uw_emit(p, out) 31 sys_exit(0); return 0 32 } } } 33 } 34 uw_w("usage: nx_uiq_wire --kat | audit <response-file>\n" as *u8) 35 sys_exit(2); return 2 36}