code wiki / (root) / nx_mfa.nx

nx_mfa.nx

buildroot/runtime/nx_mfa.nx

4196 B73 linesdepth 5pulls 6 transitivereach 4 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_mfa.nx -- ADMIN MFA / second factor (closes hosting_research gap #12 "mfa-admin", 2/0 CONFIRMED: admin login is single-factor password only). Sovereign TOTP verification (RFC 6238, HMAC-SHA1 -- the Google Authenticator / Authy / Microsoft Authenticator / Duo default) on top of the already-KAT'd nx_totp_sha1 + nx_base32. The login composes mfa_verify AFTER the argon2id password check, so a stolen password alone is not enough. Why SHA-1 (not nx_otp's SHA-256): authenticator apps default to and widely ONLY support HMAC-SHA1 TOTP; SHA-1's collision weakness is irrelevant to HMAC's PRF security (NIST + RFC 6238 both keep HMAC-SHA1 for OTP). Standard params: 6 digits, 30s step, +/-1 step skew window. module: nishi-core.auth.mfa capability: ACCESS_CONTROL / auth

dependencies 3 imports · 2 importers

nx_totp_sha1.nx nx_base32.nx nx_syscalls.nx nx_mfa.nx nx_cms_admin.nx nx_mfa_gate.nx

imports: nx_totp_sha1.nxnx_base32.nxnx_syscalls.nx

imported by: nx_cms_admin.nxnx_mfa_gate.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap mfa_gen_secret sys_mmap ↻ sys_openat_rd sys_read sys_close base32_encode b32_enc_char mfa_p sys_write sys_write ↻ sys_now_realtime_sec sys_mmap ↻ sys_clock_gettime_real base32_decode sys_mmap ↻ b32_dec_val totp_sha1_render hotp_sha1_value sys_mmap ↻ hmac_sha1 sys_mmap ↻ sha1 sys_mmap ↻ sha1_process_block if_ge sys_exit

structs

none

consts

14const MFA_STEP: i64 = 30 // RFC 6238 default time-step (seconds)
15const MFA_DIGITS: i64 = 6 // authenticator-app default
16const MFA_WINDOW: i64 = 1 // accept the code for step-1 / step / step+1 (RFC 6238 SS5.2 skew tolerance)
17const MFA_KEY_BYTES: i64 = 20 // 160-bit secret (RFC 4226 SS4 recommends >= 128 bits, 160 preferred)

functions

20func mfa_ct_eq(a: *u8, b: *u8, n: i64) -> i64
called by 1: mfa_verify
29func mfa_verify(secret_b32: *u8, b32_len: i64, code: *u8, code_len: i64, now_unix: i64, window: i64) -> i64
48func mfa_enrolled(secret_b32: *u8, b32_len: i64) -> i64 { if b32_len >= 16 { return 1 } return 0 }
called by 3: ca_mfa_okmainmain
52func mfa_gen_secret(out_b32: *u8) -> i64
61func mfa_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
63func main() -> i64