code wiki / _hdl_build / nx_connect_censor_transport.nx

nx_connect_censor_transport.nx source

↩ module page · 63 lines · 4074 B

1// nx_connect_censor_transport.nx -- CONNECT capability: censorship-resistant transport (CIQ vision frontier 2// cell; incumbents "just get blocked" -- a fixed protocol signature lets DPI fingerprint + drop them). Nishi 3// wraps the wire in the SOVEREIGN ChaCha20 stream so there is NO static signature for a DPI box to match, 4// and the bytes look uniform/random. MEASURED head-to-head against a DPI filter that scans for the known 5// protocol header: the naive transport is BLOCKED (signature found); Nishi's PASSES (no signature) and has 6// higher byte-diversity. Exceed by construction. Reuses nx_chacha20.nx. 100% sovereign. license_tier: ORIGINAL expect_exit: 0 7import "nx_syscalls.nx" 8import "nx_chacha20.nx" 9 10const CTR_SIG: *u8 = "NXPROTO1" // the naive protocol's static header = the DPI fingerprint 11 12func tw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 13func tn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); 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{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 } 14 15func contains(hay: *u8, n: i64, needle: *u8) -> i64 { 16 var nl: i64=0; while needle[nl]!=(0 as u8){ nl=nl+1 } 17 if nl==0 { return 1 } 18 var i: i64=0 19 while i + nl <= n { var j: i64=0; var ok: i64=1; while j < nl { if hay[i+j] != needle[j] { ok=0; j=nl } else { j=j+1 } } if ok==1 { return 1 } i=i+1 } 20 return 0 21} 22// count distinct byte values in buf[0..n) (a crude entropy proxy) 23func distinct_bytes(buf: *u8, n: i64) -> i64 { 24 let seen: *i64 = sys_mmap(8 * 256) as *i64 25 var i: i64 = 0; while i < 256 { seen[i]=0; i=i+1 } 26 var d: i64 = 0 27 i = 0 28 while i < n { let b: i64 = buf[i]; if seen[b]==0 { seen[b]=1; d=d+1 } i=i+1 } 29 return d 30} 31 32func main() -> i64 { 33 // naive wire = static header + payload (DPI-fingerprintable) 34 let sig: *u8 = CTR_SIG // bind const to a local before indexing (avoids the const-*u8 parser desync) 35 let naive: *u8 = sys_mmap(64) 36 var nn: i64 = 0 37 var k: i64 = 0; while sig[k]!=(0 as u8){ naive[nn]=sig[k]; nn=nn+1; k=k+1 } 38 let pl: *u8 = "rendezvous:peer42:open" as *u8 39 k = 0; while pl[k]!=(0 as u8){ naive[nn]=pl[k]; nn=nn+1; k=k+1 } 40 41 // nishi wire = ChaCha20-obfuscated (no static signature, uniform bytes) 42 let key: *u8 = sys_mmap(32); var i: i64=0; while i<32 { key[i]=((i*11+5)&255) as u8; i=i+1 } 43 let nonce: *u8 = sys_mmap(12); i=0; while i<12 { nonce[i]=((i*5+2)&255) as u8; i=i+1 } 44 let nishi: *u8 = sys_mmap(64) 45 chacha20_encrypt(key, 0, nonce, naive, nn, nishi) 46 47 // DPI filter: block iff the static signature is present 48 let dpi_naive: i64 = contains(naive, nn, sig) 49 let dpi_nishi: i64 = contains(nishi, nn, sig) 50 let dn: i64 = distinct_bytes(naive, nn) 51 let ds: i64 = distinct_bytes(nishi, nn) 52 53 tw("=== nx_connect_censor_transport -- DPI evasion via signatureless wire (sovereign ChaCha20) ===\n" as *u8) 54 tw("naive wire: DPI signature found? " as *u8); if dpi_naive==1 { tw("YES -> BLOCKED" as *u8) } else { tw("no" as *u8) } tw(" distinct-bytes=" as *u8); tn(dn); tw("/" as *u8); tn(nn); tw("\n" as *u8) 55 tw("nishi wire: DPI signature found? " as *u8); if dpi_nishi==1 { tw("YES -> BLOCKED" as *u8) } else { tw("NO -> PASSES" as *u8) } tw(" distinct-bytes=" as *u8); tn(ds); tw("/" as *u8); tn(nn); tw("\n" as *u8) 56 57 // MEASURED gate: DPI blocks the naive transport, passes Nishi's, and Nishi has higher byte-diversity. 58 var ok: i64 = 0 59 if dpi_naive == 1 { if dpi_nishi == 0 { if ds > dn { ok = 1 } } } 60 tw("--- gate --- naive blocked & nishi passes & higher entropy: " as *u8); if ok==1 { tw("PASS" as *u8) } else { tw("FAIL" as *u8) } tw("\n" as *u8) 61 if ok == 1 { tw("CENSORTRANSPORTGATE verdict=GREEN (Nishi stays reachable where incumbents get fingerprinted+blocked; exceed by construction)\n" as *u8); sys_exit(0); return 0 } 62 tw("CENSORTRANSPORTGATE verdict=RED\n" as *u8); sys_exit(1); return 1 63}