code wiki / (root) / nx_webpub_fetch.nx

nx_webpub_fetch.nx source

↩ module page · 137 lines · 6498 B

1// nx_webpub_fetch.nx -- SOVEREIGN research fetch for WEB-PUBLISHING / hosting / deploy best practices. 2// 3// Operator 2026-06-17: "i feel if you used nishi researcher on our web publishing it wouldnt be s class and i 4// want that feedback." This grounds an HONEST measured assessment of our sovereign web-publishing stack 5// (sni_router + sites.elf + nx_aw_push deploy + the daemons) against the industry best-practice corpus -- not 6// an opinion, sourced facts (the evidence-cited, no-handwaving law). Same proven sovereign HTTPS path as 7// nx_library_fetch (nx_tls13_client_session_run + nx_https_get_complete; Mozilla-CA-validated; NishiBot UA). 8// 9// Six fact-dense OPEN pages (en.wikipedia.org, canonical/parens-free -> no redirect): 10// /wiki/Continuous_delivery -> webpub_cd.raw (deploy automation / zero-touch) 11// /wiki/Reverse_proxy -> webpub_revproxy.raw (the routing layer) 12// /wiki/High_availability -> webpub_ha.raw (uptime / failover / restart) 13// /wiki/DevOps -> webpub_devops.raw (the practice) 14// /wiki/Web_hosting_service -> webpub_hosting.raw (hosting baseline) 15// /wiki/Site_reliability_engineering -> webpub_sre.raw (observability / SLOs / toil) 16// 17// expect_exit: 0 18// license_tier: ORIGINAL 19 20import "nx_syscalls.nx" 21import "nx_csprng.nx" 22import "nx_x509_trust_store.nx" 23import "nx_trust_store_load_from_certdata.nx" 24import "nx_tls13_client_validate_certificate.nx" 25import "nx_tls13_client_session_run.nx" 26import "nx_https_url_for_fetch.nx" 27import "nx_https_url_connect.nx" 28import "nx_https_get.nx" 29import "nx_https_get_complete.nx" 30import "nx_http_response_parse.nx" 31const K_MAGIC_4194304: i64 = 4194304 32 33func wf_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 34func wf_putn(v: i64) -> i64 { 35 let bb: *u8 = sys_mmap(28); var m: i64 = v 36 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } 37 let t: *u8 = sys_mmap(28); var k: i64 = 0 38 if m == 0 { t[0] = 48 as u8; k = 1 } 39 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 40 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 41} 42func wf_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 43 44func fetch_page(store: *TrustStore, full_url: *u8, path: *u8, path_len: i64, out_path: *u8) -> i64 { 45 wf_puts("--- fetch "); wf_puts(full_url); wf_puts("\n") 46 let cr: *u8 = sys_mmap(32) 47 var i: i64 = 0 48 nx_csprng_fill(cr, 32) // CWE-330 (debt 1785970852): was the constant 0xC0..0xDF 49 let priv: *u8 = sys_mmap(32) 50 i = 0 51 nx_csprng_fill(priv, 32) // CWE-330: the X25519 scalar was the constant 0xA0..0xBF on EVERY session 52 53 let url_p: *NxUrl = nx_url_new() 54 let target_raw: *u8 = sys_mmap(32) 55 let target: *NxHttpsTarget = target_raw as *NxHttpsTarget 56 target.url = url_p 57 target.port = 0 58 if nx_https_url_for_fetch(full_url, target) != NX_HTTPS_URL_OK { return 0 - 41 } 59 60 let fd_p: *i64 = sys_mmap(16) as *i64 61 if nx_https_url_connect(target, full_url, sys_now_realtime_sec(), fd_p) != NX_HTTPS_CONNECT_OK { return 0 - 42 } 62 let fd: i64 = *fd_p 63 64 let val_ctx_raw: *u8 = sys_mmap(64) 65 let val_ctx: *TlsValidationContext = val_ctx_raw as *TlsValidationContext 66 val_ctx.store = store 67 val_ctx.sni_host = full_url + target.url.host_off 68 val_ctx.sni_host_len = target.url.host_len 69 val_ctx.now_epoch = sys_now_realtime_sec() 70 71 let sr: i64 = nx_tls13_client_session_run( 72 fd, full_url + target.url.host_off, target.url.host_len, 73 cr, priv, val_ctx 74 ) 75 if sr <= 0 { sys_close(fd); return 0 - (200 + (0 - sr)) } 76 77 let session: *Tls13ClientSession = sr as *Tls13ClientSession 78 let buf: *u8 = sys_mmap(K_MAGIC_4194304) 79 let gc: i64 = nx_https_get_complete( 80 session, fd, path, path_len, 81 full_url + target.url.host_off, target.url.host_len, 82 buf, K_MAGIC_4194304 83 ) 84 sys_close(fd) 85 if gc < 0 { return 0 - (100 + (0 - gc)) } 86 87 let rs: *i64 = sys_mmap(128) as *i64 88 nx_http_response_parse(buf, gc, rs) 89 let status: i64 = rs[1] 90 91 let ofd: i64 = sys_openat_wr(out_path, 0x1A4) 92 if ofd <= 0 { return 0 - 70 } 93 sys_write(ofd, buf, gc) 94 sys_close(ofd) 95 96 wf_puts(" ST="); wf_putn(status); wf_puts(" GC="); wf_putn(gc); wf_puts(" -> "); wf_puts(out_path); wf_puts("\n") 97 return status 98} 99 100func main() -> i64 { 101 let cpath: *u8 = "/tmp/mozilla_certdata.txt\x00" 102 let r: i64 = nx_trust_store_load_from_certdata(cpath, 512, K_MAGIC_4194304) 103 if r <= 0 { wf_puts("WEBPUB-FETCH: certdata load failed\n"); return 1 } 104 let store: *TrustStore = r as *TrustStore 105 let n: i64 = trust_store_count(store) 106 if n < 50 { wf_puts("WEBPUB-FETCH: too few CAs\n"); return 3 } 107 wf_puts("CA="); wf_putn(n); wf_puts("\n") 108 109 var ok: i64 = 0 110 let u1: *u8 = "https://en.wikipedia.org/wiki/Continuous_delivery\x00" 111 let p1: *u8 = "/wiki/Continuous_delivery\x00" 112 if fetch_page(store, u1, p1, wf_strlen(p1), "knowledge/fetched/webpub_cd.raw\x00" as *u8) == 200 { ok = ok + 1 } 113 114 let u2: *u8 = "https://en.wikipedia.org/wiki/Reverse_proxy\x00" 115 let p2: *u8 = "/wiki/Reverse_proxy\x00" 116 if fetch_page(store, u2, p2, wf_strlen(p2), "knowledge/fetched/webpub_revproxy.raw\x00" as *u8) == 200 { ok = ok + 1 } 117 118 let u3: *u8 = "https://en.wikipedia.org/wiki/High_availability\x00" 119 let p3: *u8 = "/wiki/High_availability\x00" 120 if fetch_page(store, u3, p3, wf_strlen(p3), "knowledge/fetched/webpub_ha.raw\x00" as *u8) == 200 { ok = ok + 1 } 121 122 let u4: *u8 = "https://en.wikipedia.org/wiki/DevOps\x00" 123 let p4: *u8 = "/wiki/DevOps\x00" 124 if fetch_page(store, u4, p4, wf_strlen(p4), "knowledge/fetched/webpub_devops.raw\x00" as *u8) == 200 { ok = ok + 1 } 125 126 let u5: *u8 = "https://en.wikipedia.org/wiki/Web_hosting_service\x00" 127 let p5: *u8 = "/wiki/Web_hosting_service\x00" 128 if fetch_page(store, u5, p5, wf_strlen(p5), "knowledge/fetched/webpub_hosting.raw\x00" as *u8) == 200 { ok = ok + 1 } 129 130 let u6: *u8 = "https://en.wikipedia.org/wiki/Site_reliability_engineering\x00" 131 let p6: *u8 = "/wiki/Site_reliability_engineering\x00" 132 if fetch_page(store, u6, p6, wf_strlen(p6), "knowledge/fetched/webpub_sre.raw\x00" as *u8) == 200 { ok = ok + 1 } 133 134 wf_puts("WEBPUB-SOVEREIGN-FETCH-OK pages_200="); wf_putn(ok); wf_puts("/6\n") 135 if ok < 1 { return 51 } 136 return 0 137}