nx_hub_verify_gate.nx source
↩ module page · 87 lines · 4806 B
1// nx_hub_verify_gate.nx -- SOVEREIGN live verifier for nishifamily.com/hub/.
2// Real HTTPS GET via the Nishi TLS-1.3 client + Mozilla CA chain; asserts 200 and
3// that the hub body links CAD + is organ-authored. GREEN iff 6/6. expect_exit: 0.
4import "nx_syscalls.nx"
5import "nx_x509_trust_store.nx"
6import "nx_trust_store_load_from_certdata.nx"
7import "nx_tls13_client_validate_certificate.nx"
8import "nx_tls13_client_session_run.nx"
9import "nx_https_url_for_fetch.nx"
10import "nx_https_url_connect.nx"
11import "nx_https_get.nx"
12import "nx_https_get_complete.nx"
13import "nx_http_response_parse.nx"
14
15func vg_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
16func vg_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); 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 i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
17func vg_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
18func vg_contains(buf: *u8, lo: i64, hi: i64, needle: *u8) -> i64 {
19 let nl: i64=vg_strlen(needle); if nl==0 { return 0 }
20 var i: i64=lo
21 while i+nl<=hi { var j: i64=0; var ok: i64=1; while j<nl { if buf[i+j]!=needle[j] { ok=0; j=nl } else { j=j+1 } } if ok==1 { return 1 } i=i+1 }
22 return 0
23}
24func vg_row(id: i64, ok: i64, what: *u8) -> i64 {
25 vg_w(" R" as *u8); vg_num(id); vg_w(" " as *u8); vg_w(what); vg_w(": " as *u8)
26 if ok==1 { vg_w("YES PASS\n" as *u8) } else { vg_w("NO FAIL\n" as *u8) }
27 return ok
28}
29
30func main() -> i64 {
31 vg_w("=== HUB LIVE VERIFY GATE (sovereign HTTPS GET of nishifamily.com/hub/) ===\n" as *u8)
32 var pass: i64=0; let rows: i64=6
33
34 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 300, 4194304)
35 var caok: i64=0; var nca: i64=0
36 if r > 0 { let store0: *TrustStore = r as *TrustStore; nca = trust_store_count(store0); if nca >= 50 { caok=1 } }
37 pass=pass+vg_row(1, caok, "Mozilla CA store loads (>=50 anchors)" as *u8)
38 if caok==0 { vg_w("HUB-VERIFY abort: no CA store\n" as *u8); sys_exit(1); return 1 }
39 let store: *TrustStore = r as *TrustStore
40
41 let url: *u8 = "https://nishifamily.com/hub/" as *u8
42 let url_p: *NxUrl = nx_url_new()
43 let target: *NxHttpsTarget = sys_mmap(64) as *NxHttpsTarget
44 target.url = url_p
45 target.port = 0
46 var urlok: i64=0
47 if nx_https_url_for_fetch(url, target) == NX_HTTPS_URL_OK { urlok=1 }
48
49 let fd_p: *i64 = sys_mmap(16) as *i64
50 var conn: i64=0
51 if urlok==1 { if nx_https_url_connect(target, url, sys_now_realtime_sec(), fd_p) == NX_HTTPS_CONNECT_OK { conn=1 } }
52 let fd: i64 = fd_p[0]
53
54 let cr: *u8 = sys_mmap(32); var i: i64=0; while i<32 { cr[i]=(0xC0+i) as u8; i=i+1 }
55 let priv: *u8 = sys_mmap(32); i=0; while i<32 { priv[i]=(0xA0+i) as u8; i=i+1 }
56 let val_ctx: *TlsValidationContext = sys_mmap(64) as *TlsValidationContext
57 val_ctx.store = store
58 val_ctx.sni_host = ((url as i64) + target.url.host_off) as *u8
59 val_ctx.sni_host_len = target.url.host_len
60 val_ctx.now_epoch = sys_now_realtime_sec()
61
62 var sr: i64=0
63 if conn==1 { sr = nx_tls13_client_session_run(fd, ((url as i64)+target.url.host_off) as *u8, target.url.host_len, cr, priv, val_ctx) }
64 pass=pass+vg_row(2, (sr>0) as i64, "TLS-1.3 session connects + cert validates" as *u8)
65
66 var gc: i64=0
67 let buf: *u8 = sys_mmap(262144)
68 if sr>0 {
69 let session: *Tls13ClientSession = sr as *Tls13ClientSession
70 gc = nx_https_get_complete(session, fd, "/hub/" as *u8, 5, ((url as i64)+target.url.host_off) as *u8, target.url.host_len, buf, 262144)
71 sys_close(fd)
72 }
73 pass=pass+vg_row(3, (gc>0) as i64, "HTTPS GET returns response bytes" as *u8)
74
75 var status: i64=0; var body_off: i64=0
76 if gc>0 { let pr: *i64 = sys_mmap(128) as *i64; if nx_http_response_parse(buf, gc, pr)==0 { status=pr[1]; body_off=pr[6] } }
77 pass=pass+vg_row(4, (status==200) as i64, "HTTP status 200" as *u8)
78
79 var m1: i64=0; var m2: i64=0
80 if gc>0 { if vg_contains(buf, body_off, gc, "Nishi Family" as *u8)==1 { m1=1 } if vg_contains(buf, body_off, gc, "/cad/" as *u8)==1 { m2=1 } }
81 pass=pass+vg_row(5, m1, "served body is the Nishi Family hub" as *u8)
82 pass=pass+vg_row(6, m2, "hub links the CAD studio (/cad/)" as *u8)
83
84 vg_w("----\nHUB-VERIFY rows=" as *u8); vg_num(rows); vg_w(" pass=" as *u8); vg_num(pass); vg_w(" status=" as *u8); vg_num(status); vg_w(" bytes=" as *u8); vg_num(gc); vg_w("\n" as *u8)
85 if pass==rows { vg_w("HUB-VERIFY GREEN -- nishifamily.com/hub/ is LIVE and links CAD\n" as *u8); sys_exit(0); return 0 }
86 vg_w("HUB-VERIFY RED -- not fully verified live\n" as *u8); sys_exit(1); return 1
87}