!boards/nsh: Replace reversible TEA password storage in /etc/passwd with one-way PBKDF2-HMAC-SHA256 hashing #19209
Conversation
|
@acassis, Checks are failing because the password is currently empty, and CI expects some passwd value. |
f4a6ce2 to
aeec705
Compare
aeec705 to
084e043
Compare
Add apps/crypto/pbkdf2, migrate passwd encrypt/verify to modular crypt format with complexity validation, share base64url helpers, and add pbkdf2_test for RFC 6070 vector coverage. Change NSH_LOGIN_USERNAME default to root and remove fixed-login password defaults. BREAKING CHANGE: TEA-encoded /etc/passwd entries no longer verify. Regenerate each entry after upgrading. Pair with the nuttx host mkpasswd changes in apache/nuttx#19209. When CONFIG_NSH_LOGIN_FIXED=y, set CONFIG_NSH_LOGIN_PASSWORD in the board defconfig or menuconfig; there is no default password. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Add apps/crypto/pbkdf2, migrate passwd encrypt/verify to modular crypt format with complexity validation, share base64url helpers, and add pbkdf2_test for RFC 6070 vector coverage. Change NSH_LOGIN_USERNAME default to root and remove fixed-login password defaults. BREAKING CHANGE: TEA-encoded /etc/passwd entries no longer verify. Regenerate each entry after upgrading. Pair with the nuttx host mkpasswd changes in apache/nuttx#19209. When CONFIG_NSH_LOGIN_FIXED=y, set CONFIG_NSH_LOGIN_PASSWORD in the board defconfig or menuconfig; there is no default password. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
There was a problem hiding this comment.
Hi @Abhishekmishra2808 Is this a cross-platform solution (board_romfs_mkpasswd.sh)?
There was a problem hiding this comment.
Yes, on supported NuttX host environments
There was a problem hiding this comment.
This shell script (board_romfs_mkpasswd.sh) used in CMake (cmake/nuttx_add_romfs.cmake ) is not a cross-platform solution
COMMAND
${NUTTX_DIR}/tools/board_romfs_mkpasswd.sh ${NUTTX_DIR}
${ROMFS_PASSWD_FILE} ${MKPASSWD_BIN} ${GENPASSWD_OUTPUT} --user
"${CONFIG_BOARD_ETC_ROMFS_PASSWD_USER}" --uid
${CONFIG_BOARD_ETC_ROMFS_PASSWD_UID} --gid
${CONFIG_BOARD_ETC_ROMFS_PASSWD_GID} --home
"${CONFIG_BOARD_ETC_ROMFS_PASSWD_HOME}"
DEPENDS ${MKPASSWD_BIN} ${NUTTX_DIR}/.config
COMMENT "Generating /etc/passwd from Kconfig values")
There was a problem hiding this comment.
I mixed up "works on supported NuttX Unix hosts" with "cross-platform in CMake," which isn't the same thing :(
Now I have updated cmake/nuttx_add_romfs.cmake to call the host mkpasswd binary directly again, reading the passwd and iterations from Kconfig
Replace TEA based build time hashing with PBKDF2-HMAC-SHA256, add promptpasswd and board_romfs_mkpasswd helpers, require a root password when ROMFS passwd autogen is enabled, and enforce password complexity at build time. BREAKING CHANGE: TEA-encoded /etc/passwd entries no longer verify. Regenerate each entry with tools/mkpasswd or NSH passwd/useradd after upgrading nuttx-apps. Builds with CONFIG_BOARD_ETC_ROMFS_PASSWD_ENABLE=y fail until CONFIG_BOARD_ETC_ROMFS_PASSWD_PASSWORD is set in menuconfig (Board Selection -> Auto-generate /etc/passwd at build time -> Root password) or entered when make prompts. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
Document PBKDF2-HMAC-SHA256 passwd format, build-time ROMFS flow, password complexity rules, and remove obsolete TEA references. Signed-off-by: Abhishek Mishra <mishra.abhishek2808@gmail.com>
084e043 to
6671871
Compare
Summary
Replace reversible TEA password storage in
/etc/passwdwith one-way PBKDF2-HMAC-SHA256 hashing in modular crypt format (MCF):$pbkdf2-sha256$<iterations>$<base64url-salt>$<base64url-hash>BREAKING CHANGE: TEA-encoded /etc/passwd entries no longer verify.
Regenerate with tools/mkpasswd or NSH passwd/useradd after upgrading nuttx-apps.
Changes:
apps/crypto/pbkdf2(PBKDF2-HMAC-SHA256; Mbed TLS backend when available, self-contained SHA-256 fallback otherwise)passwd_encrypt.c/passwd_verify.cto use PBKDF2 andtimingsafe_bcmp()for verificationpasswd_base64.cfor base64url encode/decodetesting/pbkdf2(RFC 6070 vectors + passwd round-trip test)Companion nuttx PR (host
mkpasswdtool and ROMFS build integration): apache/nuttx-apps#3557Impact
Security
/etc/passwd.Compatibility (breaking)
/etc/passwdentries will not verify. Users must regenerate passwords with NSHpasswd/useraddor build-timemkpasswdafter upgrading.Build
CRYPTO_PBKDF2automatically whenFSUTILS_PASSWDis enabled.Runtime
CONFIG_FSUTILS_PASSWD_PBKDF2_ITERATIONS).Testing
Host: WSL2 Linux, x86_64
Sim (
sim:nshor login-enabled config)FSUTILS_PASSWDandTESTING_PBKDF2ESP32-C3 (
esp32c3-devkit:login, local test config, not in this PR)/etc/passwdwith PBKDF2 hash/dev/ttyACM0) succeeds with configured password; wrong password rejectedManual verification
useradd/passwdreject weak passwords (no special char, too short)$pbkdf2-sha256$...hash in/etc/passwd