nx_zerodt_fetch.nx source
↩ module page · 132 lines · 6167 B
1// nx_zerodt_fetch.nx -- SOVEREIGN Nishi researcher fetch for ZERO-DOWNTIME / LIVE-UPDATE deployment.
2//
3// Operator 2026-06-18: "i dont get why the multiple streams crashing the daemon instead of our setup being
4// s class exceed allowing the daemon to receive updates and changes to live sites as they go like i asked,
5// nishi researcher this to see where all the gaps are happening." This grounds an HONEST, CITED gap analysis
6// of our F-class kill+respawn deploy vs the S-class live-update bar -- sourced facts, not opinion (the
7// evidence-cited, no-handwaving law). Same proven sovereign HTTPS path as nx_webpub_fetch.
8//
9// Fact-dense OPEN pages (en.wikipedia.org, canonical/parens-free -> no redirect):
10// /wiki/Blue-green_deployment -> zerodt_bluegreen.raw (the canonical zero-downtime cutover)
11// /wiki/Continuous_deployment -> zerodt_cd.raw (deploy-to-prod automation)
12// /wiki/Hot_swapping -> zerodt_hotswap.raw (replace a component while running)
13// /wiki/Graceful_exit -> zerodt_graceful.raw (drain + exit without dropping work)
14// /wiki/Rolling_release -> zerodt_rolling.raw (incremental live update)
15//
16// expect_exit: 0
17// license_tier: ORIGINAL
18
19import "nx_syscalls.nx"
20import "nx_csprng.nx"
21import "nx_x509_trust_store.nx"
22import "nx_trust_store_load_from_certdata.nx"
23import "nx_tls13_client_validate_certificate.nx"
24import "nx_tls13_client_session_run.nx"
25import "nx_https_url_for_fetch.nx"
26import "nx_https_url_connect.nx"
27import "nx_https_get.nx"
28import "nx_https_get_complete.nx"
29import "nx_http_response_parse.nx"
30const K_MAGIC_4194304: i64 = 4194304
31
32func zf_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
33func zf_putn(v: i64) -> i64 {
34 let bb: *u8 = sys_mmap(28); var m: i64 = v
35 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) }
36 let t: *u8 = sys_mmap(28); var k: i64 = 0
37 if m == 0 { t[0] = 48 as u8; k = 1 }
38 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
39 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
40}
41func zf_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
42
43func fetch_page(store: *TrustStore, full_url: *u8, path: *u8, path_len: i64, out_path: *u8) -> i64 {
44 zf_puts("--- fetch "); zf_puts(full_url); zf_puts("\n")
45 let cr: *u8 = sys_mmap(32)
46 var i: i64 = 0
47 nx_csprng_fill(cr, 32) // CWE-330 (debt 1785970852): was the constant 0xC0..0xDF
48 let priv: *u8 = sys_mmap(32)
49 i = 0
50 nx_csprng_fill(priv, 32) // CWE-330: the X25519 scalar was the constant 0xA0..0xBF on EVERY session
51
52 let url_p: *NxUrl = nx_url_new()
53 let target_raw: *u8 = sys_mmap(32)
54 let target: *NxHttpsTarget = target_raw as *NxHttpsTarget
55 target.url = url_p
56 target.port = 0
57 if nx_https_url_for_fetch(full_url, target) != NX_HTTPS_URL_OK { return 0 - 41 }
58
59 let fd_p: *i64 = sys_mmap(16) as *i64
60 if nx_https_url_connect(target, full_url, sys_now_realtime_sec(), fd_p) != NX_HTTPS_CONNECT_OK { return 0 - 42 }
61 let fd: i64 = *fd_p
62
63 let val_ctx_raw: *u8 = sys_mmap(64)
64 let val_ctx: *TlsValidationContext = val_ctx_raw as *TlsValidationContext
65 val_ctx.store = store
66 val_ctx.sni_host = full_url + target.url.host_off
67 val_ctx.sni_host_len = target.url.host_len
68 val_ctx.now_epoch = sys_now_realtime_sec()
69
70 let sr: i64 = nx_tls13_client_session_run(
71 fd, full_url + target.url.host_off, target.url.host_len,
72 cr, priv, val_ctx
73 )
74 if sr <= 0 { sys_close(fd); return 0 - (200 + (0 - sr)) }
75
76 let session: *Tls13ClientSession = sr as *Tls13ClientSession
77 let buf: *u8 = sys_mmap(K_MAGIC_4194304)
78 let gc: i64 = nx_https_get_complete(
79 session, fd, path, path_len,
80 full_url + target.url.host_off, target.url.host_len,
81 buf, K_MAGIC_4194304
82 )
83 sys_close(fd)
84 if gc < 0 { return 0 - (100 + (0 - gc)) }
85
86 let rs: *i64 = sys_mmap(128) as *i64
87 nx_http_response_parse(buf, gc, rs)
88 let status: i64 = rs[1]
89
90 let ofd: i64 = sys_openat_wr(out_path, 0x1A4)
91 if ofd <= 0 { return 0 - 70 }
92 sys_write(ofd, buf, gc)
93 sys_close(ofd)
94
95 zf_puts(" ST="); zf_putn(status); zf_puts(" GC="); zf_putn(gc); zf_puts(" -> "); zf_puts(out_path); zf_puts("\n")
96 return status
97}
98
99func main() -> i64 {
100 let cpath: *u8 = "/tmp/mozilla_certdata.txt\x00"
101 let r: i64 = nx_trust_store_load_from_certdata(cpath, 512, K_MAGIC_4194304)
102 if r <= 0 { zf_puts("ZERODT-FETCH: certdata load failed\n"); return 1 }
103 let store: *TrustStore = r as *TrustStore
104 let n: i64 = trust_store_count(store)
105 if n < 50 { zf_puts("ZERODT-FETCH: too few CAs\n"); return 3 }
106 zf_puts("CA="); zf_putn(n); zf_puts("\n")
107
108 var ok: i64 = 0
109 let u1: *u8 = "https://en.wikipedia.org/wiki/Blue-green_deployment\x00"
110 let p1: *u8 = "/wiki/Blue-green_deployment\x00"
111 if fetch_page(store, u1, p1, zf_strlen(p1), "knowledge/fetched/zerodt_bluegreen.raw\x00" as *u8) == 200 { ok = ok + 1 }
112
113 let u2: *u8 = "https://en.wikipedia.org/wiki/Continuous_deployment\x00"
114 let p2: *u8 = "/wiki/Continuous_deployment\x00"
115 if fetch_page(store, u2, p2, zf_strlen(p2), "knowledge/fetched/zerodt_cd.raw\x00" as *u8) == 200 { ok = ok + 1 }
116
117 let u3: *u8 = "https://en.wikipedia.org/wiki/Hot_swapping\x00"
118 let p3: *u8 = "/wiki/Hot_swapping\x00"
119 if fetch_page(store, u3, p3, zf_strlen(p3), "knowledge/fetched/zerodt_hotswap.raw\x00" as *u8) == 200 { ok = ok + 1 }
120
121 let u4: *u8 = "https://en.wikipedia.org/wiki/Graceful_exit\x00"
122 let p4: *u8 = "/wiki/Graceful_exit\x00"
123 if fetch_page(store, u4, p4, zf_strlen(p4), "knowledge/fetched/zerodt_graceful.raw\x00" as *u8) == 200 { ok = ok + 1 }
124
125 let u5: *u8 = "https://en.wikipedia.org/wiki/Rolling_release\x00"
126 let p5: *u8 = "/wiki/Rolling_release\x00"
127 if fetch_page(store, u5, p5, zf_strlen(p5), "knowledge/fetched/zerodt_rolling.raw\x00" as *u8) == 200 { ok = ok + 1 }
128
129 zf_puts("ZERODT-SOVEREIGN-FETCH-OK pages_200="); zf_putn(ok); zf_puts("/5\n")
130 if ok < 1 { return 51 }
131 return 0
132}