code wiki / (root) / nx_sclass_ux_research_fetch.nx

nx_sclass_ux_research_fetch.nx source

↩ module page · 155 lines · 7589 B

1// nx_sclass_ux_research_fetch.nx -- SOVEREIGN S-class web-UX research fetch. 2// 3// Rung R-RESEARCH of the gallery S-class-exceed arc: ground the census of "how 4// world-class sites (Google etc.) achieve responsive design, fast file delivery, 5// fast logins, fast page loads, easy scrolling, and finding many files" on REAL 6// sourced facts (global Rule 4 -- no assumptions; every census cell must cite a 7// real fetch, not memory). Reuses the team's OWN proven sovereign HTTPS stack 8// (nx_tls13_client_session_run + nx_https_get_complete; no browser/node/curl), 9// validated against the real Mozilla CA store -- the IDENTICAL path proven live 10// in nx_gallery_auth_research_fetch (the gauth_* corpus, 2026-06-17). 11// 12// Fetches the fact-dense canonical OPEN pages (en.wikipedia.org / MDN; canonical, 13// parens-free titles -> no redirect) for the axes the operator named: 14// /wiki/Responsive_web_design -> sclass_rwd_wiki.raw (responsive design) 15// /wiki/Lazy_loading -> sclass_lazy_wiki.raw (defer offscreen media) 16// /wiki/Content_delivery_network -> sclass_cdn_wiki.raw (fast file delivery) 17// /wiki/WebAuthn -> sclass_webauthn_wiki.raw (fast/passkey login) 18// /wiki/AVIF -> sclass_avif_wiki.raw (modern image format) 19// /wiki/Web_performance -> sclass_perf_wiki.raw (page-load / Core Web Vitals) 20// /Web/API/Intersection_Observer_API-> sclass_io_mdn.raw (infinite scroll primitive) 21// /Web/CSS/content-visibility -> sclass_cv_mdn.raw (skip offscreen render cost) 22// 23// expect_exit: 0 24// license_tier: ORIGINAL (clone of nx_gallery_auth_research_fetch; only the URLs differ) 25 26import "nx_syscalls.nx" 27import "nx_csprng.nx" 28import "nx_x509_trust_store.nx" 29import "nx_trust_store_load_from_certdata.nx" 30import "nx_tls13_client_validate_certificate.nx" 31import "nx_tls13_client_session_run.nx" 32import "nx_https_url_for_fetch.nx" 33import "nx_https_url_connect.nx" 34import "nx_https_get.nx" 35import "nx_https_get_complete.nx" 36import "nx_http_response_parse.nx" 37const K_MAGIC_4194304: i64 = 4194304 38 39func sf_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 40func sf_putn(v: i64) -> i64 { 41 let bb: *u8 = sys_mmap(28); var m: i64 = v 42 if m < 0 { m = 0 - m; sys_write(1, "-" as *u8, 1) } 43 let t: *u8 = sys_mmap(28); var k: i64 = 0 44 if m == 0 { t[0] = 48 as u8; k = 1 } 45 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 46 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0 47} 48func sf_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 49 50// Fetch one page over the sovereign TLS1.3 client, save the raw response. 51// Returns the HTTP status (200 ok), or a negative error code. 52func fetch_page(store: *TrustStore, full_url: *u8, path: *u8, path_len: i64, out_path: *u8) -> i64 { 53 sf_puts("--- fetch "); sf_puts(full_url); sf_puts("\n") 54 55 let cr: *u8 = sys_mmap(32) 56 var i: i64 = 0 57 nx_csprng_fill(cr, 32) // CWE-330 (debt 1785970852): was the constant 0xC0..0xDF 58 let priv: *u8 = sys_mmap(32) 59 i = 0 60 nx_csprng_fill(priv, 32) // CWE-330: the X25519 scalar was the constant 0xA0..0xBF on EVERY session 61 62 let url_p: *NxUrl = nx_url_new() 63 let target_raw: *u8 = sys_mmap(32) 64 let target: *NxHttpsTarget = target_raw as *NxHttpsTarget 65 target.url = url_p 66 target.port = 0 67 if nx_https_url_for_fetch(full_url, target) != NX_HTTPS_URL_OK { return 0 - 41 } 68 69 let fd_p: *i64 = sys_mmap(16) as *i64 70 if nx_https_url_connect(target, full_url, sys_now_realtime_sec(), fd_p) != NX_HTTPS_CONNECT_OK { return 0 - 42 } 71 let fd: i64 = *fd_p 72 73 let val_ctx_raw: *u8 = sys_mmap(64) 74 let val_ctx: *TlsValidationContext = val_ctx_raw as *TlsValidationContext 75 val_ctx.store = store 76 val_ctx.sni_host = full_url + target.url.host_off 77 val_ctx.sni_host_len = target.url.host_len 78 val_ctx.now_epoch = sys_now_realtime_sec() 79 80 let sr: i64 = nx_tls13_client_session_run( 81 fd, full_url + target.url.host_off, target.url.host_len, 82 cr, priv, val_ctx 83 ) 84 if sr <= 0 { sys_close(fd); return 0 - (200 + (0 - sr)) } 85 86 let session: *Tls13ClientSession = sr as *Tls13ClientSession 87 let buf: *u8 = sys_mmap(K_MAGIC_4194304) 88 let gc: i64 = nx_https_get_complete( 89 session, fd, path, path_len, 90 full_url + target.url.host_off, target.url.host_len, 91 buf, K_MAGIC_4194304 92 ) 93 sys_close(fd) 94 if gc < 0 { return 0 - (100 + (0 - gc)) } 95 96 let rs: *i64 = sys_mmap(128) as *i64 97 nx_http_response_parse(buf, gc, rs) 98 let status: i64 = rs[1] 99 100 let ofd: i64 = sys_openat_wr(out_path, 0x1A4) 101 if ofd <= 0 { return 0 - 70 } 102 sys_write(ofd, buf, gc) 103 sys_close(ofd) 104 105 sf_puts(" ST="); sf_putn(status); sf_puts(" GC="); sf_putn(gc); sf_puts(" -> "); sf_puts(out_path); sf_puts("\n") 106 return status 107} 108 109func main() -> i64 { 110 let cpath: *u8 = "/tmp/mozilla_certdata.txt\x00" 111 let r: i64 = nx_trust_store_load_from_certdata(cpath, 512, K_MAGIC_4194304) 112 if r <= 0 { sf_puts("SCLASS-FETCH: certdata load failed\n"); return 1 } 113 let store: *TrustStore = r as *TrustStore 114 let n: i64 = trust_store_count(store) 115 if n < 50 { sf_puts("SCLASS-FETCH: too few CAs\n"); return 3 } 116 sf_puts("CA="); sf_putn(n); sf_puts("\n") 117 118 var ok: i64 = 0 119 120 let u1: *u8 = "https://en.wikipedia.org/wiki/Responsive_web_design\x00" 121 let p1: *u8 = "/wiki/Responsive_web_design\x00" 122 if fetch_page(store, u1, p1, sf_strlen(p1), "knowledge/fetched/sclass_rwd_wiki.raw\x00" as *u8) == 200 { ok = ok + 1 } 123 124 let u2: *u8 = "https://en.wikipedia.org/wiki/Lazy_loading\x00" 125 let p2: *u8 = "/wiki/Lazy_loading\x00" 126 if fetch_page(store, u2, p2, sf_strlen(p2), "knowledge/fetched/sclass_lazy_wiki.raw\x00" as *u8) == 200 { ok = ok + 1 } 127 128 let u3: *u8 = "https://en.wikipedia.org/wiki/Content_delivery_network\x00" 129 let p3: *u8 = "/wiki/Content_delivery_network\x00" 130 if fetch_page(store, u3, p3, sf_strlen(p3), "knowledge/fetched/sclass_cdn_wiki.raw\x00" as *u8) == 200 { ok = ok + 1 } 131 132 let u4: *u8 = "https://en.wikipedia.org/wiki/WebAuthn\x00" 133 let p4: *u8 = "/wiki/WebAuthn\x00" 134 if fetch_page(store, u4, p4, sf_strlen(p4), "knowledge/fetched/sclass_webauthn_wiki.raw\x00" as *u8) == 200 { ok = ok + 1 } 135 136 let u5: *u8 = "https://en.wikipedia.org/wiki/AVIF\x00" 137 let p5: *u8 = "/wiki/AVIF\x00" 138 if fetch_page(store, u5, p5, sf_strlen(p5), "knowledge/fetched/sclass_avif_wiki.raw\x00" as *u8) == 200 { ok = ok + 1 } 139 140 let u6: *u8 = "https://en.wikipedia.org/wiki/Web_performance\x00" 141 let p6: *u8 = "/wiki/Web_performance\x00" 142 if fetch_page(store, u6, p6, sf_strlen(p6), "knowledge/fetched/sclass_perf_wiki.raw\x00" as *u8) == 200 { ok = ok + 1 } 143 144 let u7: *u8 = "https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API\x00" 145 let p7: *u8 = "/en-US/docs/Web/API/Intersection_Observer_API\x00" 146 if fetch_page(store, u7, p7, sf_strlen(p7), "knowledge/fetched/sclass_io_mdn.raw\x00" as *u8) == 200 { ok = ok + 1 } 147 148 let u8: *u8 = "https://developer.mozilla.org/en-US/docs/Web/CSS/content-visibility\x00" 149 let p8: *u8 = "/en-US/docs/Web/CSS/content-visibility\x00" 150 if fetch_page(store, u8, p8, sf_strlen(p8), "knowledge/fetched/sclass_cv_mdn.raw\x00" as *u8) == 200 { ok = ok + 1 } 151 152 sf_puts("SCLASS-SOVEREIGN-FETCH-OK pages_200="); sf_putn(ok); sf_puts("/8\n") 153 if ok < 1 { return 51 } 154 return 0 155}