code wiki / _hdl_build / nx_pwfile.nx
nx_pwfile.nx source
↩ module page · 23 lines · 1187 B
1// nx_pwfile.nx -- generic: write sha256(password) hex (64 chars, mode 0600) to <outpath>. Used to set
2// CMS role credentials (admin_pw.sha256 = lawyer/staff, client_pw.sha256 = client). Only the hash is
3// stored (vault doctrine). Usage: nx_pwfile.sov.elf <outpath> <password>. license_tier: ORIGINAL
4import "nx_sha256.nx"
5import "nx_syscalls.nx"
6func pf_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
7func main(argc: i64, argv: *i64) -> i64 {
8 if argc < 3 { sys_write(1, "usage: nx_pwfile <outpath> <password>\n" as *u8, 38); sys_exit(2); return 2 }
9 let outpath: *u8 = argv[1] as *u8
10 let pw: *u8 = argv[2] as *u8
11 let dig: *u8 = sys_mmap(32)
12 sha256_digest(pw, pf_len(pw), dig)
13 let hexs: *u8 = sys_mmap(80)
14 let hxc: *u8 = "0123456789abcdef" as *u8
15 var i: i64 = 0
16 while i < 32 { hexs[i*2] = hxc[((dig[i] as i64) >> 4) & 15]; hexs[i*2+1] = hxc[(dig[i] as i64) & 15]; i = i + 1 }
17 let fd: i64 = sys_openat_wr(outpath, 0x180)
18 if fd < 0 { sys_write(1, "WRITE-FAIL\n" as *u8, 11); sys_exit(1); return 1 }
19 sys_write(fd, hexs, 64)
20 sys_close(fd)
21 sys_write(1, "PWFILE-OK\n" as *u8, 10)
22 sys_exit(0); return 0
23}