code wiki / (root) / nx_edgeprobe_diag.nx

nx_edgeprobe_diag.nx source

↩ module page · 61 lines · 3277 B

1// nx_edgeprobe_diag.nx -- ONE-SHOT diagnostic. v2: send a MODERN TLS 1.3 ClientHello (supported_versions 2// + key_share, SNI=nishifamily.com) to 127.0.0.1:8443 and dump the reply. v1 proved the LEGACY 1.2 hello 3// gets read_r=0 (clean close) from the edge. If v2 yields a TLS record (byte 20..23) the edge ServerHellos 4// a modern hello and this is the exact hex to transplant into hp_build_ch. Throwaway; retire after. 5import "nx_syscalls.nx" 6const K_MAGIC_8443: i64 = 8443 7const K_MAGIC_4096: i64 = 4096 8const K_MAGIC_4095: i64 = 4095 9 10func ep_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func ep_n(v: i64) -> i64 { 12 let t: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} 13 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} 14 let b: *u8=sys_mmap(28); var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 15} 16func ep_hexv(c: i64) -> i64 { if c >= 97 { return c - 87 } return c - 48 } 17func ep_sockaddr(buf: *u8, port: i64) -> i64 { 18 var i: i64 = 0; while i < 16 { buf[i] = 0 as u8; i = i + 1 } 19 buf[0] = 2 as u8 20 buf[2] = ((port >> 8) & 0xff) as u8; buf[3] = (port & 0xff) as u8 21 buf[4] = 127 as u8; buf[5] = 0 as u8; buf[6] = 0 as u8; buf[7] = 1 as u8 22 return 0 23} 24func main() -> i64 { 25 let hx: *u8 = "160301009a0100009603034e582d544c532d50524f42452d323032362d30372d31362d6e6973686921212100000813011302130300ff0100006500000014001200000f6e6973686966616d696c792e636f6d000a00060004001d0017000d00080006040308040401002b0003020304003300260024001d00204242424242424242424242424242424242424242424242424242424242424242000b00020100" as *u8 26 let ch: *u8 = sys_mmap(512) 27 var i: i64 = 0; var go: i64 = 1 28 while go == 1 { 29 let j: i64 = i * 2 30 if hx[j] == (0 as u8) { go = 0 } 31 else { ch[i] = ((ep_hexv(hx[j] as i64) * 16) + ep_hexv(hx[j+1] as i64)) as u8; i = i + 1 } 32 } 33 ep_p("hello_len=" as *u8); ep_n(i); ep_p("\n" as *u8) 34 let fd: i64 = sys_socket(AF_INET, SOCK_STREAM, 0) 35 if fd < 0 { ep_p("SOCKET-FAIL\n" as *u8); return 1 } 36 sys_set_socket_timeout(fd, 3) 37 let dest: *u8 = sys_mmap(16); ep_sockaddr(dest, K_MAGIC_8443) 38 if sys_connect(fd, dest, 16) != 0 { ep_p("CONNECT-FAIL (REFUSED)\n" as *u8); sys_close(fd); return 0 } 39 ep_p("CONNECT-OK\n" as *u8) 40 let w: i64 = sys_write(fd, ch, i) 41 ep_p("wrote=" as *u8); ep_n(w); ep_p("\n" as *u8) 42 let buf: *u8 = sys_mmap(K_MAGIC_4096) 43 let r: i64 = sys_read(fd, buf, K_MAGIC_4095) 44 ep_p("read_r=" as *u8); ep_n(r); ep_p("\n" as *u8) 45 if r > 0 { 46 ep_p("first_bytes_dec=" as *u8) 47 var k: i64 = 0; var lim: i64 = r; if lim > 12 { lim = 12 } 48 while k < lim { ep_n(buf[k] as i64); ep_p(" " as *u8); k = k + 1 } 49 ep_p("\n" as *u8) 50 let b0: i64 = buf[0] as i64 51 if b0 >= 20 { if b0 <= 23 { ep_p("VERDICT=SERVING (TLS record type in 20..23)\n" as *u8) } } 52 if b0 < 20 { ep_p("VERDICT=BADRESP (first byte below 20)\n" as *u8) } 53 if b0 > 23 { ep_p("VERDICT=BADRESP (first byte above 23)\n" as *u8) } 54 } 55 else { 56 if r == 0 { ep_p("VERDICT=BADRESP-via-CLEAN-CLOSE\n" as *u8) } 57 else { ep_p("VERDICT=HUNG\n" as *u8) } 58 } 59 sys_close(fd) 60 return 0 61}