code wiki / _hdl_build / nx_deploy_provenance_test.nx

nx_deploy_provenance_test.nx source

↩ module page · 42 lines · 3286 B

1// nx_deploy_provenance_test.nx -- never lose the source again. 2// live sites.elf today : NO stamp -> incomplete -> UNTRACEABLE -> not trusted for re-deploy (the bug we hit) 3// a stamped deploy : source-loc + hash + build-id -> traceable -> trusted (when hash verifies) 4// recovery : the untraceable live binary becomes traceable once the NEXT clean build stamps it 5// Exit 0 on 6/6. license_tier: ORIGINAL 6 7import "nx_deploy_provenance.nx" 8import "nx_syscalls.nx" 9 10func pt_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 11func pt_num(v: i64) -> i64 { let bb: *u8 = sys_mmap(28); var m: i64=v; if m<0 {m=0-m}; let t: *u8 = sys_mmap(28); var k: i64=0; if m==0 {t[0]=48;k=1}; while m>0 {t[k]=48+(m%10); 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 } 12 13func main() -> i64 { 14 pt_puts("=== DEPLOY PROVENANCE: stamp every deploy so the source is never lost ===\n" as *u8) 15 // the live binary today: no stamp at all 16 let live_complete: i64 = prov_complete(0, 0, 0) 17 let live_traceable: i64 = prov_traceable(live_complete) 18 let live_trust: i64 = prov_trust_for_redeploy(live_traceable, 0) 19 // a properly stamped deploy 20 let good_complete: i64 = prov_complete(1, 1, 1) 21 let good_trace: i64 = prov_traceable(good_complete) 22 let good_trust: i64 = prov_trust_for_redeploy(good_trace, 1) 23 // recovery: stamp on the next clean build 24 let recovered: i64 = prov_restored(live_traceable, 1) 25 26 pt_puts(" live sites.elf: stamp-complete=" as *u8); pt_num(live_complete); pt_puts(" traceable=" as *u8); pt_num(live_traceable); pt_puts(" trusted-for-redeploy=" as *u8); pt_num(live_trust); pt_puts(" (the source-loss we hit)\n" as *u8) 27 pt_puts(" stamped deploy: traceable=" as *u8); pt_num(good_trace); pt_puts(" trusted=" as *u8); pt_num(good_trust); pt_puts("\n" as *u8) 28 pt_puts(" recovery: untraceable live binary -> traceable once next clean build stamps it = " as *u8); pt_num(recovered); pt_puts("\n" as *u8) 29 30 let r: *i64 = sys_mmap(8*8) as *i64 31 r[0] = 0; if live_traceable == 0 { r[0] = 1 } // the live binary is honestly untraceable 32 r[1] = 0; if live_trust == 0 { r[1] = 1 } // -> not trusted for a risky re-deploy 33 r[2] = 0; if good_trace == 1 { r[2] = 1 } // a stamped deploy is traceable 34 r[3] = 0; if good_trust == 1 { r[3] = 1 } // ...and trusted when the hash verifies 35 r[4] = 0; if prov_trust_for_redeploy(1, 0) == 0 { r[4] = 1 } // traceable but hash-mismatch -> still not trusted 36 r[5] = 0; if recovered == 1 { r[5] = 1 } // provenance recoverable going forward 37 var pass: i64 = 0; var i: i64 = 0 38 while i < 6 { pass = pass + r[i]; i = i + 1 } 39 pt_puts("----\n passed " as *u8); pt_num(pass); pt_puts("/6\n" as *u8) 40 if pass == 6 { pt_puts(" ROOT CAUSE ADDRESSED: every future deploy is provenance-stamped (source-loc + hash + build-id), the untraceable live binary is honestly flagged, and traceability is restored on the next clean build -- the source can never silently vanish again.\n" as *u8); sys_exit(0); return 0 } 41 pt_puts(" FAIL\n" as *u8); sys_exit(1); return 1 42}