code wiki / (root) / nx_chrome_fetch_probe.nx

nx_chrome_fetch_probe.nx source

↩ module page · 62 lines · 4011 B

1// nx_chrome_fetch_probe.nx -- LIVE proof of R2f-A: fetch a URL using the CHROME-JA3 ClientHello (run_chrome) and 2// report whether the TLS handshake now COMPLETES on CDNs that dropped our minimal hello (-3). Control = a host that 3// already worked; targets = the previously-blocked CDNs. No fleet impact (standalone probe). 4import "nx_syscalls.nx" 5import "nx_csprng.nx" 6import "nx_x509_trust_store.nx" 7import "nx_trust_store_load_from_certdata.nx" 8import "nx_https_url_for_fetch.nx" 9import "nx_https_url_connect.nx" 10import "nx_https_get_complete.nx" 11import "nx_http_response_parse.nx" 12import "nx_tls13_client_session.nx" 13import "nx_tls13_chrome_session.nx" 14const K_MAGIC_4096: i64 = 4096 15const K_MAGIC_262144: i64 = 262144 16const K_MAGIC_4194304: i64 = 4194304 17 18func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 19func pn(v: i64) -> i64 { let b: *u8=sys_mmap(24); var m: i64=v; if m<0{pw("-" as *u8);m=0-m} let t: *u8=sys_mmap(24); 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{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 20 21func probe(url0: *u8, store: *TrustStore) -> i64 { 22 pw(" " as *u8); pw(url0); pw(" -> " as *u8) 23 let urlbuf: *u8 = sys_mmap(K_MAGIC_4096) 24 var ui: i64 = 0; while url0[ui] != (0 as u8) { urlbuf[ui] = url0[ui]; ui = ui + 1 } urlbuf[ui] = 0 as u8 25 let target_raw: *u8 = sys_mmap(64) 26 let target: *NxHttpsTarget = target_raw as *NxHttpsTarget 27 target.url = nx_url_new(); target.port = 0 28 if nx_https_url_for_fetch(urlbuf, target) != NX_HTTPS_URL_OK { pw("BAD-URL\n" as *u8); return 0 } 29 let fd_p: *i64 = sys_mmap(16) as *i64 30 if nx_https_url_connect(target, urlbuf, sys_now_realtime_sec(), fd_p) != NX_HTTPS_CONNECT_OK { pw("CONNECT-FAIL\n" as *u8); return 0 } 31 let fd: i64 = fd_p[0] 32 let cr: *u8 = sys_mmap(32); let priv: *u8 = sys_mmap(32) 33 var i: i64 = 0; nx_csprng_fill(cr, 32); nx_csprng_fill(priv, 32) // CWE-330 (debt 1785970852): were the constants 0xC0../0xA0.. on EVERY session 34 let vc_raw: *u8 = sys_mmap(64); let vc: *TlsValidationContext = vc_raw as *TlsValidationContext 35 vc.store = store; vc.sni_host = urlbuf + target.url.host_off; vc.sni_host_len = target.url.host_len; vc.now_epoch = sys_now_realtime_sec() 36 // ★ the Chrome-JA3 handshake 37 let sr: i64 = nx_tls13_client_session_run_chrome(fd, urlbuf + target.url.host_off, target.url.host_len, cr, priv, vc) 38 if sr <= 0 { sys_close(fd); pw("HANDSHAKE-FAIL rc=" as *u8); pn(0 - sr); pw("\n" as *u8); return 0 } 39 let session: *Tls13ClientSession = sr as *Tls13ClientSession 40 pw("HANDSHAKE-OK " as *u8) 41 let buf: *u8 = sys_mmap(K_MAGIC_262144) 42 let gc: i64 = nx_https_get_complete(session, fd, "/" as *u8, 1, urlbuf + target.url.host_off, target.url.host_len, buf, K_MAGIC_262144) 43 sys_close(fd) 44 if gc < 0 { pw("GET-FAIL\n" as *u8); return 0 } 45 let r: *i64 = sys_mmap(128) as *i64 46 if nx_http_response_parse(buf, gc, r) != 0 { pw("(unparsable body) bytes=" as *u8); pn(gc); pw("\n" as *u8); return 0 } 47 pw("HTTP status=" as *u8); pn(r[1]); pw(" bytes=" as *u8); pn(gc); pw("\n" as *u8) 48 return 0 49} 50 51func main(argc: i64, argv: *i64) -> i64 { 52 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304) 53 if r <= 0 { pw("certdata fail\n" as *u8); return 1 } 54 let store: *TrustStore = r as *TrustStore 55 pw("=== R2f-A LIVE: Chrome-JA3 handshake test ===\n" as *u8) 56 if argc > 1 { probe(argv[1] as *u8, store); return 0 } 57 // default sweep: a control that already worked + the CDNs the minimal hello got -3 on 58 probe("https://nhentai.net/" as *u8, store) // MAIN site: Chrome-JA3 -> HTTP 200 (fingerprint wall beaten) 59 probe("https://en.wikipedia.org/" as *u8, store) // non-CF control: HANDSHAKE-OK 60 probe("https://i.nhentai.net/" as *u8, store) // image CDN: EE+Cert OK, big coalesced flight record -> recv_hs incomplete 61 return 0 62}