code wiki / _hdl_build / nx_vault_gateway.nx
nx_vault_gateway.nx
buildroot/runtime/_hdl_build/nx_vault_gateway.nx
about
nx_vault_gateway.nx -- OPAQUE-gated /vault media browser (M0 product surface) per the family-suite spec.
Reuses the gallery opaque realm (argv keys/store) so existing creds log in. Renders the SPEC'd shallow-
faceted VISUAL browse: MAJOR=gen/real, GROUP=type, SOURCE=badge, thumbnails served from the record `ref`
(DSM layout /volume1/vault/<class>/<type>/<shard>/<cid>_<source>.<ext>). Gated: no valid session -> 401,
never a public byte (private-media cardinal rule). Cookie-auth (ngs, HttpOnly, Path=/vault).
argv: [1]=port [2]=keys_path [3]=store_path [4]=budget [5]=allow_register [6]=m [7]=t [8]=p [9]=ttl
license_tier: ORIGINAL No hw writes (Rule 26).
dependencies 5 imports · 0 importers
imports: nx_opaque_login.nxnx_http_form.nxnx_registry.nxnx_mvault_record.nxnx_mvault_coll.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 13 | const VGW_MAGIC_262144: i64 = 262144 |
| 14 | const VGW_MAGIC_2048: i64 = 2048 |
| 15 | const VGW_MAGIC_8388608: i64 = 8388608 |
| 16 | const VGW_MAGIC_16777216: i64 = 16777216 |
| 17 | const VGW_MAGIC_131072: i64 = 131072 |
| 18 | const VGW_MAGIC_131071: i64 = 131071 |
| 19 | const VGW_MAGIC_8192: i64 = 8192 |
| 21 | const VGW_PROD_M: i64 = 65536 |
| 22 | const VGW_SESSION_TTL: i64 = 86400 |
| 23 | const VGW_MVAULT_STORE: *u8 = "/volume1/homes/elderwesto/nishihost/knowledge/store/mvault-" as *u8 |
| 24 | const VGW_MAX_ITEMS: i64 = 3000 |
| 25 | const VGW_MEDIA_CAP: i64 = 25165824 // 24 MiB serve cap -- OOM guard; images/thumbnails only |
| 31 | const VGW_MEDIA_ROOT: *u8 = "/volume1/homes/elderwesto/vaultfs" as *u8 |
| 32 | const VGW_REF_ROOT_LEN: i64 = 14 // len("/volume1/vault") |
| 34 | const VGW_COLLBUF: i64 = 1048576 // buffer for the collection id index feeding the groupings facet |
| 130 | const VGW_LOGIN_HTML: *u8 = "<!doctype html><html><head><meta charset=utf-8><meta name=viewport content=\"width=device-width,initial-scale=1\"><title>Nishi Vault</title><style>body{font-family:system-ui,sans-serif;max-width:420px;margin:8vh auto;padding:0 18px;color:#cdd7e6;background:#0b1019}h1{font-size:1.2rem;color:#e8eef7}p{color:#7c8aa5;font-size:.86rem}input{width:100%;padding:9px;margin:5px 0;box-sizing:border-box;border:1px solid #2a3550;border-radius:5px;background:#121a28;color:#e8eef7}button{padding:9px 16px;margin:6px 6px 0 0;background:#2d6cdf;color:#fff;border:0;border-radius:5px;cursor:pointer}#m{margin:14px 0;padding:12px;background:#121a28;border-left:3px solid #2d6cdf;color:#cdd7e6;min-height:1.2em}</style></head><body><h1>Nishi Vault — private</h1><p>OPAQUE aPAKE (RFC 9807). Same credentials as the gallery. The session rides an HttpOnly cookie, path-scoped to /vault.</p><div id=m>Log in to view the vault.</div><input id=h placeholder=handle autocomplete=username><input id=p type=password placeholder=passphrase autocomplete=current-password><button onclick=login()>Login</button><script>function $(i){return document.getElementById(i)}function M(t){$('m').textContent=t}async function login(){M('Logging in...');try{var r=await fetch('/vault/auth/login',{method:'POST',headers:{'Content-Type':'application/x-www-form-urlencoded'},body:'handle='+encodeURIComponent($('h').value)+'&pw='+encodeURIComponent($('p').value)});var j=await r.json();if(!r.ok){M('Login failed: '+(j.error||r.status));return}M('Logged in. Opening vault...');location.href='/vault/'}catch(e){M('error: '+e)}}</script></body></html>" as *u8 |
functions
| 35 | func gw_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 36 | func gw_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ let c: i64=s[i] as i64; if c<48{return v} if c>57{return v} v=v*10+(c-48); i=i+1 } return v } |
| 37 | func gw_starts(buf: *u8, n: i64, pre: *u8) -> i64 { var i: i64=0; while pre[i]!=(0 as u8){ if i>=n {return 0} if buf[i]!=pre[i]{return 0} i=i+1 } return 1 } |
| 38 | func gw_find(buf: *u8, n: i64, needle: *u8, nl: i64) -> i64 |
| 44 | func gw_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var i: i64=0; while s[i]!=(0 as u8){dst[o]=s[i]; o=o+1; i=i+1} return o } |
| 45 | func gw_catb(dst: *u8, off: i64, src: *u8, n: i64) -> i64 { var o: i64=off; var i: i64=0; while i<n {dst[o]=src[i]; o=o+1; i=i+1} return o } |
| 46 | func gw_itoa(dst: *u8, off: i64, v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var o: i64=off; var q: i64=k-1; while q>=0{dst[o]=t[q];o=o+1;q=q-1} return o } |
| 48 | func gw_send(cfd: i64, status: *u8, ctype: *u8, body: *u8, blen: i64) -> i64 |
| 57 | func gw_send_big(cfd: i64, body: *u8, blen: i64) -> i64 |
| 64 | func gw_401(cfd: i64) -> i64 |
| 68 | func gw_is_nav(req: *u8, n: i64) -> i64 { if gw_find(req, n, "Sec-Fetch-Mode: navigate" as *u8, 24) >= 0 { return 1 } return 0 } |
| 69 | func gw_302_login(cfd: i64) -> i64 |
| 73 | func gw_send_ck(cfd: i64, ctype: *u8, body: *u8, blen: i64, ckval: *u8, ckvallen: i64, ttl: i64) -> i64 |
| 83 | func gw_cookie_val(req: *u8, hend: i64, out: *u8, cap: i64) -> i64 |
| 90 | func gw_hdr_val(req: *u8, hend: i64, name: *u8, nl: i64, out: *u8, cap: i64) -> i64 |
| 99 | func gw_reqpath(req: *u8, rn: i64, out: *u8, cap: i64) -> i64 called by 1: main |
| 107 | func gw_read_full(cfd: i64, req: *u8, cap: i64) -> i64 |
| 132 | func vgw_nl(buf: *u8, from: i64, n: i64) -> i64 { var i: i64=from; var r: i64=n; while i<n { if buf[i]==(10 as u8) { r=i; i=n } else { i=i+1 } } return r } called by 1: vgw_serve_catalog |
| 134 | func vgw_field(rec: *u8, rl: i64, key: *u8, kl: i64, dst: *u8, o0: i64) -> i64 |
| 146 | func vgw_ref_of(cid: *u8, out: *u8, cap: i64) -> i64 |
| 160 | func vgw_jail_ok(p: *u8) -> i64 called by 1: vgw_serve_media |
| 168 | func vgw_ctype_for(p: *u8) -> *u8 |
| 183 | func vgw_serve_media(cfd: i64, path: *u8, plen: i64) -> i64 |
| 216 | func vgw_serve_catalog(cfd: i64) -> i64 |
| 321 | func main(argc: i64, argv: *i64) -> i64 |