code wiki / (root) / nx_profile_backup.nx

nx_profile_backup.nx

buildroot/runtime/nx_profile_backup.nx

6367 B149 linesdepth 7pulls 13 transitivereach 2 importersview sourcekind librarytopic profile
docsdependenciesstructsconstsfunctions

about

nx_profile_backup.nx -- ENCRYPTED second-copy backup of the browser profile store (lib, no main). Operator 2026-07-02: "have it also create a backup so two is one one is none, on the os encrypted whether nishi os or windows or android". Blob = ChaCha20-Poly1305 AEAD under a key HKDF-derived from MACHINE IDENTITY (/etc/machine-id, 128-bit random) + a fresh random 32B salt PER BACKUP (fresh salt => fresh key => the (key,nonce) pair is never reused across snapshots -- the AEAD nonce-reuse hazard). Threat model (same as nx_machine_key/nx_vault): defeats offline theft of the backup file without the machine; NOT an attacker with local machine access. Destination = OS-level dir OUTSIDE the repo, from knowledge/hosting/profile_backup.conf (line 1) -- portable across NishiOS/Windows(drvfs)/Android paths. .nxpb v1 layout: "NXPB1\n"(6) | salt(32) | nonce(12) | ptlen(8 LE) | tag(16) | ct(ptlen). pb_backup_file WRITES then RE-READS + DECRYPTS + BYTE-COMPARES (a backup that doesn't restore is not a backup) -- returns 0 only on proven roundtrip. license_tier: ORIGINAL

dependencies 3 imports · 2 importers

nx_syscalls.nx nx_chacha20_poly1305.nx nx_hkdf.nx nx_profile_backup.nx nx_profile_backup_gate.nx nx_profile_backup_run.nx

imports: nx_syscalls.nxnx_chacha20_poly1305.nxnx_hkdf.nx

imported by: nx_profile_backup_gate.nxnx_profile_backup_run.nx

structs

none

consts

16const K_MAGIC_134217728: i64 = 134217728

functions

18func pb_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
21func pb_derive_key(ikm: *u8, ilen: i64, salt: *u8, key_out: *u8) -> i64
29func pb_rand(buf: *u8, n: i64) -> i64
43func pb_machine_ikm(out: *u8, cap: i64) -> i64
called by 1: main calls 2: sys_mmapsys_read_file
57func pb_restore_buf(blobpath: *u8, ikm: *u8, ilen: i64, out: *u8, cap: i64, lenbox: *i64) -> i64
86func pb_backup_file(src: *u8, dst: *u8, ikm: *u8, ilen: i64) -> i64
134func pb_restore_file(blobpath: *u8, dst: *u8, ikm: *u8, ilen: i64) -> i64