nx_fetchprobed.nx source
↩ module page · 38 lines · 1742 B
1// nx_fetchprobed.nx -- BISECT: does importing nx_sha256 break the fetch path?
2// nx_feedfetch fetches https://phzmapi.org/97202.json fine on the SAME lib, while nx_libdata
3// returns -2 NX_FF_CONNECT on the identical URL from its FIRST iteration. Only difference is the
4// import closure. expect_exit: 0 license_tier: ORIGINAL
5import "nx_syscalls.nx"
6import "nx_x509_trust_store.nx"
7import "nx_trust_store_load_from_certdata.nx"
8import "nx_https_fetch_follow.nx"
9import "nx_sha256.nx"
10const K_MAGIC_4194304: i64 = 4194304
11const K_MAGIC_16777216: i64 = 16777216
12func fp_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
13func fp_puts(s: *u8) -> i64 { sys_write(1, s, fp_len(s)); return 0 }
14func fp_putn(v: i64) -> i64 {
15 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
16 var m: i64 = v
17 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
18 let d: *u8 = sys_mmap(24)
19 var k: i64 = 0
20 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
21 var j: i64 = k - 1
22 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
23 return 0
24}
25func main() -> i64 {
26 let tr: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
27 if tr <= 0 { fp_puts("certdata FAIL\n" as *u8); return 1 }
28 let store: *TrustStore = tr as *TrustStore
29 let out: *u8 = sys_mmap(K_MAGIC_16777216)
30 let st: *i64 = sys_mmap(8) as *i64
31 let n: i64 = nx_https_fetch_follow_best("https://phzmapi.org/97202.json" as *u8, store, out, K_MAGIC_16777216, 6, st)
32 fp_puts("PROBEd bytes=" as *u8)
33 fp_putn(n)
34 fp_puts(" status=" as *u8)
35 fp_putn(st[0])
36 fp_puts("\n" as *u8)
37 return 0
38}