code wiki / (root) / nx_cert_debug.nx

nx_cert_debug.nx source

↩ module page · 52 lines · 2596 B

1// nx_cert_debug.nx -- debug why nx_cert_monitor misparsed the real fullchain cert. Prints x509_parse's 2// validity_off/len, the raw validity bytes, and the parsed notBefore/notAfter epochs, for the real 3// fullchain + leaf. Oracle: openssl says notAfter = Aug 26 2026 15:35:00 UTC ~= epoch 1787758500. 4import "nx_x509.nx" 5import "nx_x509_validity.nx" 6import "nx_cert_monitor.nx" // cm_read, cm_p, cm_n 7 8func dbg_hex(b: *u8, off: i64, n: i64) -> i64 { 9 let hx: *u8 = "0123456789abcdef" as *u8 10 var i: i64 = 0 11 while i < n { 12 let c: i64 = (b[off+i] as i64) & 0xff 13 let o: *u8 = sys_mmap(2); o[0]=hx[(c>>4)&15]; o[1]=hx[c&15]; sys_write(1,o,2) 14 i = i + 1 15 } 16 return 0 17} 18// also dump as ASCII (Time TLVs are printable digits) 19func dbg_ascii(b: *u8, off: i64, n: i64) -> i64 { 20 var i: i64 = 0 21 while i < n { let c: i64 = (b[off+i] as i64) & 0xff; let o: *u8 = sys_mmap(1); if c>=32{if c<127{o[0]=c as u8}else{o[0]=46 as u8}}else{o[0]=46 as u8}; sys_write(1,o,1); i=i+1 } 22 return 0 23} 24 25func dbg_cert(path: *u8) -> i64 { 26 let buf: *u8 = sys_mmap(65536); let n: i64 = cm_read(path, buf, 65536) 27 cm_p("\n--- " as *u8); cm_p(path); cm_p(" bytes=" as *u8); cm_n(n); cm_p("\n" as *u8) 28 let cert: *X509Cert = sys_mmap(1024) as *X509Cert 29 let prc: i64 = x509_parse(buf, n, cert) 30 cm_p(" x509_parse rc=" as *u8); cm_n(prc) 31 cm_p(" validity_off=" as *u8); cm_n(cert.validity_off) 32 cm_p(" validity_len=" as *u8); cm_n(cert.validity_len); cm_p("\n" as *u8) 33 if cert.validity_len > 0 { 34 if cert.validity_len < 80 { 35 cm_p(" validity HEX: " as *u8); dbg_hex(buf, cert.validity_off, cert.validity_len); cm_p("\n" as *u8) 36 cm_p(" validity ASCII: " as *u8); dbg_ascii(buf, cert.validity_off, cert.validity_len); cm_p("\n" as *u8) 37 } 38 } 39 let nb: *i64 = sys_mmap(16) as *i64; let na: *i64 = sys_mmap(16) as *i64 40 let vrc: i64 = x509_validity_get(buf, cert, nb, na) 41 cm_p(" validity_get rc=" as *u8); cm_n(vrc); cm_p(" (OK==" as *u8); cm_n(NX_X509_VALID_OK); cm_p(")\n" as *u8) 42 cm_p(" notBefore_epoch=" as *u8); cm_n(nb[0]); cm_p("\n" as *u8) 43 cm_p(" notAfter_epoch =" as *u8); cm_n(na[0]); cm_p(" (oracle Aug26 ~= 1787758500)\n" as *u8) 44 return 0 45} 46 47func main() -> i64 { 48 cm_p("=== CERT PARSE DEBUG (oracle: notAfter = Aug 26 2026 = epoch ~1787758500) ===\n" as *u8) 49 dbg_cert("/mnt/c/Users/elder/nishi-core/nxc2/knowledge/status/real_leaf.der" as *u8) 50 dbg_cert("/mnt/c/Users/elder/nishi-core/nxc2/knowledge/status/real_fullchain.der" as *u8) 51 sys_exit(0); return 0 52}