Skip to content

!nshlib: Require explicit fixed login password at build time#3557

Open
Abhishekmishra2808 wants to merge 1 commit into
apache:masterfrom
Abhishekmishra2808:nsh-login-empty-password
Open

!nshlib: Require explicit fixed login password at build time#3557
Abhishekmishra2808 wants to merge 1 commit into
apache:masterfrom
Abhishekmishra2808:nsh-login-empty-password

Conversation

@Abhishekmishra2808

@Abhishekmishra2808 Abhishekmishra2808 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR is the nuttx-apps companion to apache/nuttx#19209, which adds the host mkpasswd tool and ROMFS /etc/passwd build integration. Here, runtime password handling moves from reversible TEA to one-way PBKDF2-HMAC-SHA256 using a modular crypt string stored in /etc/passwd. The change adds apps/crypto/pbkdf2 with a small self-contained SHA-256 and HMAC implementation (Mbed TLS PKCS5 is used when available), rewrites passwd_encrypt and passwd_verify with shared base64url helpers and password complexity checks, and adds pbkdf2_test for RFC 6070 SHA-256 vector coverage. The round-trip portion of that test is skipped automatically when the passwd file is read-only or when DEV_URANDOM is not enabled. NSH also changes the default fixed-login username to root and removes insecure fixed-login password defaults.

BREAKING CHANGE: TEA-encoded /etc/passwd entries no longer verify after this upgrade. Every entry must be regenerated with NSH passwd or useradd once both nuttx and nuttx-apps are updated. If CONFIG_NSH_LOGIN_FIXED=y is used, CONFIG_NSH_LOGIN_PASSWORD must be set explicitly in the board defconfig or menuconfig; there is no default password.

Impact

This change modifies existing password file behavior and is not backward compatible with TEA-encoded hashes. Users must regenerate stored passwords. The build flow itself is unchanged in nuttx-apps; the ROMFS build-time password prompt lives in the paired nuttx PR. Documentation updates are included in that nuttx PR rather than here.

Testing

Testing was done on sim:login with NSH console login against a build-time PBKDF2 hash, and login succeeded.
Login was also verified on ESP32-C3 using the esp32c3-devkit:login configuration over USB serial. Check- apache/nuttx#19209

pbkdf2_test passed the RFC 6070 SHA-256 vectors on sim:login, and the passwd encrypt/verify round-trip passed with a writable passwd path at /tmp/passwd, readonly disabled, and DEV_URANDOM enabled.
image

Comment thread nshlib/Kconfig Outdated
Comment thread nshlib/Makefile Outdated
@ThePassionate

Copy link
Copy Markdown
Contributor

Thanks for this work. One suggestion:

the NuttX kernel already provides CRYPTO_PBKDF2_HMAC_SHA256 (defined in
cryptodev.h) with a complete software implementation in cryptosoft.c (swcr_pbkdf2), accessible via /dev/crypto.

Would it be possible for fsutils/passwd to use the kernel capability directly via /dev/crypto ioctl, rather than introducing a new apps/crypto/pbkdf2 module? The PBKDF2 logic already lives in the kernel — the app layer only needs to open /dev/crypto, call CIOCGSESSION with CRYPTO_PBKDF2_HMAC_SHA256, then CIOCCRYPT. This would avoid duplicating the implementation and keep apps/crypto/ clean.

@Abhishekmishra2808

Abhishekmishra2808 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @ThePassionate
host build tool tools/mkpasswd.c (in the NuttX PR) will still keep a standalone PBKDF2 implementation since it runs on the build machine, not on the target, Right?

I'll remove apps/crypto/pbkdf2 and have fsutils/passwd use kernel PBKDF2 via /dev/crypto. The host build tool tools/mkpasswd.c (nuttx PR) will keep a standalone implementation since it runs on the build machine.

Migrate passwd encrypt/verify to PBKDF2 modular crypt format using
kernel cryptodev (CRYPTO_PBKDF2_HMAC_SHA256 via /dev/crypto).  Add
passwd_pbkdf2 wrapper, base64url helpers, complexity validation, and
pbkdf2_test for RFC 6070 vector coverage.  FSUTILS_PASSWD selects
CRYPTO, ALLOW_BSD_COMPONENTS, and CRYPTO_CRYPTODEV so existing sim
defconfigs keep building.  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.  Boards must enable the appropriate
software or hardware crypto backend for PBKDF2 at runtime.  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>
@Abhishekmishra2808 Abhishekmishra2808 force-pushed the nsh-login-empty-password branch from c507e40 to 98a4b57 Compare June 30, 2026 20:46
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

Thanks for the review @ThePassionate host build tool tools/mkpasswd.c (in the NuttX PR) will still keep a standalone PBKDF2 implementation since it runs on the build machine, not on the target, Right?

I'll remove apps/crypto/pbkdf2 and have fsutils/passwd use kernel PBKDF2 via /dev/crypto. The host build tool tools/mkpasswd.c (nuttx PR) will keep a standalone implementation since it runs on the build machine.

it's more simple to convert host tool from c to python, since we don't need compile the tool and could support more OS.

Comment thread fsutils/passwd/Kconfig
default n
select CRYPTO
select ALLOW_BSD_COMPONENTS
select CRYPTO_CRYPTODEV

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use depends on or skip PBKDF2-HMAC-SHA256 if crypto isn't enabled

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make NSH_CONSOLE_LOGIN depend on FSUTILS_PASSWD / cryptodev so login always uses PBKDF2, and treat NSH_LOGIN_FIXED as an explicit opt-in for legacy boards only?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep something like this:
image

Because if we use "depends on," the user might go for the fixed password most of the time, which is not recommended.

Comment thread fsutils/passwd/Kconfig
config FSUTILS_PASSWD_KEY4
hex "Encryption key value 4"
default 0x9abcdef0
config FSUTILS_PASSWD_PBKDF2_ITERATIONS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove indent

/* RFC 4648 section 5 base64url alphabet (no padding). */

#define RNG90_MAX_BYTES 32
static const char g_base64url[] =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we call netutils/codecs/base64.c?

0x3c, 0x69, 0x62, 0x26, 0x65, 0x0a, 0x86, 0x87
};

static const struct pbkdf2_vector_s g_vectors[] =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move pdkdf2 to testing/drivers/crypto/pbkdf2.c

@@ -0,0 +1,287 @@
/****************************************************************************
* apps/testing/pbkdf2/pbkdf2_test.c

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to testing/crypto/passwd

@Abhishekmishra2808

Copy link
Copy Markdown
Contributor Author

it's more simple to convert host tool from c to python, since we don't need compile the tool and could support more OS.

Previously C was chosen to avoid a Python dependency. If maintainers prefer Python for Windows/CI simplicity, I can switch the nuttx PR to mkpasswd.py before merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants