code wiki / _hdl_build / nx_media_access_gate.nx

nx_media_access_gate.nx source

↩ module page · 98 lines · 6034 B

1// nx_media_access_gate.nx -- proves the operator's media model (2026-06-17): "everything accessible EVERYWHERE 2// but with different LEVELS of access." Reachable from anywhere (an internet deploy behind the OPAQUE wall), 3// but always login-gated + level-gated. Two folders: 4// /library/ -> SFW (Zatoichi, Mr Bean ...) -> FAMILY level (1): you + family can watch, from anywhere 5// /recordings/ -> NSFW (our own recordings) -> OWNER level (3): ONLY you (elder), from anywhere, nobody else 6// catch-all "/" -> 1, so EVERYTHING needs at least a family login (reachable everywhere, but never public/open); 7// recordings need the OWNER level (only elder's account holds it). Owner sees all; family sees SFW only and 8// the recordings are NOT EVEN LISTED for them. Composes nx_authz (proven). license_tier: ORIGINAL 9import "nx_authz.nx" 10import "nx_syscalls.nx" 11 12const LVL_PUBLIC: i64 = 0 13const LVL_FAMILY: i64 = 1 14const LVL_OWNER: i64 = 3 15 16func mw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 17func mslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 18func mrow(id: i64, ok: i64, what: *u8) -> i64 { mw("MAROW " as *u8); let b: *u8=sys_mmap(8); b[0]=(48+id) as u8; sys_write(1,b,1); mw(" " as *u8); if ok==1 { mw("PASS " as *u8) } else { mw("FAIL " as *u8) } mw(what); mw("\n" as *u8); return ok } 19func mcontains(hay: *u8, hn: i64, needle: *u8) -> i64 { 20 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 21 if nl==0 { return 1 } if nl>hn { return 0 } 22 let last: i64=hn-nl; var i: i64=0 23 while i<=last { var j: i64=0; var hit: i64=1; while j<nl { if (hay[i+j] as i64)!=(needle[j] as i64){hit=0;j=nl} if hit==1{j=j+1} } if hit==1 { return 1 } i=i+1 } 24 return 0 25} 26func mallow(level: i64, pp: *i64, pl: *i64, pv: *i64, np: i64, req: *u8) -> i64 { 27 return authz_level_allow(level, pp, pl, pv, np, req, mslen(req)) 28} 29 30func main() -> i64 { 31 mw("media access gate: everything reachable everywhere, login+level gated; SFW=family, recordings=owner-only\n" as *u8) 32 33 // policy: family-login base; the recordings folder is OWNER-only 34 let pp: *i64=sys_mmap(8*8) as *i64 35 let pl: *i64=sys_mmap(8*8) as *i64 36 let pv: *i64=sys_mmap(8*8) as *i64 37 pp[0]="/" as *u8 as i64; pl[0]=mslen("/" as *u8); pv[0]=LVL_FAMILY 38 pp[1]="/recordings/" as *u8 as i64; pl[1]=mslen("/recordings/" as *u8); pv[1]=LVL_OWNER 39 let np: i64=2 40 41 // the media library's items: SFW under /library, NSFW recordings under /recordings 42 let items: *i64=sys_mmap(8*8) as *i64 43 let ilen: *i64=sys_mmap(8*8) as *i64 44 items[0]="/library/zatoichi.mkv" as *u8 as i64; ilen[0]=mslen("/library/zatoichi.mkv" as *u8) 45 items[1]="/library/mrbean.mkv" as *u8 as i64; ilen[1]=mslen("/library/mrbean.mkv" as *u8) 46 items[2]="/recordings/rec1.mp4" as *u8 as i64; ilen[2]=mslen("/recordings/rec1.mp4" as *u8) 47 items[3]="/recordings/rec2.mp4" as *u8 as i64; ilen[3]=mslen("/recordings/rec2.mp4" as *u8) 48 let nit: i64=4 49 50 var rows: i64=0 51 var pass: i64=0 52 var ok: i64=0 53 54 // R0: a FAMILY member's listing -> only the SFW library (recordings omitted) 55 let famout: *i64=sys_mmap(8*8) as *i64 56 let famn: i64=authz_filter(LVL_FAMILY, items, ilen, nit, pp, pl, pv, np, famout) 57 ok=0; if famn==2 { ok=1 } 58 rows=rows+1; pass=pass+mrow(0, ok, "family listing shows the 2 SFW library items, recordings omitted" as *u8) 59 60 // R1: NON-DISCLOSURE -- the family listing never mentions /recordings 61 ok=1 62 var k: i64=0 63 while k<famn { if mcontains(famout[k] as *u8, ilen[k], "/recordings/" as *u8)==1 { ok=0 } k=k+1 } 64 rows=rows+1; pass=pass+mrow(1, ok, "NON-DISCLOSURE: recordings never listed for family (nobody but owner knows)" as *u8) 65 66 // R2: family CAN watch the SFW library (Zatoichi) -- from anywhere 67 ok=0; if mallow(LVL_FAMILY, pp, pl, pv, np, "/library/zatoichi.mkv" as *u8)==AUTHZ_ALLOW { ok=1 } 68 rows=rows+1; pass=pass+mrow(2, ok, "family can watch the SFW library (Zatoichi/Mr Bean) anywhere" as *u8) 69 70 // R3: family CANNOT access the recordings (owner-only) 71 ok=0; if mallow(LVL_FAMILY, pp, pl, pv, np, "/recordings/rec1.mp4" as *u8)==AUTHZ_DENY { ok=1 } 72 rows=rows+1; pass=pass+mrow(3, ok, "family DENIED the recordings (owner-only: nobody but you)" as *u8) 73 74 // R4: the OWNER (elder) CAN access the recordings -- from anywhere 75 ok=0; if mallow(LVL_OWNER, pp, pl, pv, np, "/recordings/rec1.mp4" as *u8)==AUTHZ_ALLOW { ok=1 } 76 rows=rows+1; pass=pass+mrow(4, ok, "OWNER (you) can access the recordings, from anywhere" as *u8) 77 78 // R5: the owner's listing shows EVERYTHING (library + recordings) 79 let ownout: *i64=sys_mmap(8*8) as *i64 80 let ownn: i64=authz_filter(LVL_OWNER, items, ilen, nit, pp, pl, pv, np, ownout) 81 ok=0; if ownn==4 { ok=1 } 82 rows=rows+1; pass=pass+mrow(5, ok, "owner listing shows all 4 (library + recordings)" as *u8) 83 84 // R6: reachable everywhere but NEVER public -- a no-login (public, level 0) request is DENIED even for SFW 85 ok=0; if mallow(LVL_PUBLIC, pp, pl, pv, np, "/library/zatoichi.mkv" as *u8)==AUTHZ_DENY { ok=1 } 86 rows=rows+1; pass=pass+mrow(6, ok, "login required: a no-login (public) request is denied even for SFW (gated, not open)" as *u8) 87 88 mw("NX-MEDIA-ACCESS-GATE rows=" as *u8); let rb: *u8=sys_mmap(8); rb[0]=(48+rows) as u8; sys_write(1,rb,1); mw(" pass=" as *u8); let pb: *u8=sys_mmap(8); pb[0]=(48+pass) as u8; sys_write(1,pb,1); mw("\n" as *u8) 89 if pass==rows { 90 let line: *u8 = "CMSGATE row=nx_media_access library-sfw-family-recordings-owner-only rows=7 pass=7 verdict=PASS\n" as *u8 91 let gf: i64 = sys_openat_append("knowledge/status/cms_gate.log" as *u8, 0x1a4) 92 if gf >= 0 { sys_write(gf, line, mslen(line)); sys_close(gf) } 93 mw("NX-MEDIA-ACCESS-GATE GREEN 7/7 (reachable everywhere, login+level gated; SFW=family, recordings=owner-only)\n" as *u8) 94 sys_exit(0); return 0 95 } 96 mw("NX-MEDIA-ACCESS-GATE RED\n" as *u8) 97 sys_exit(1); return 1 98}