-
Notifications
You must be signed in to change notification settings - Fork 747
!nshlib: Require explicit fixed login password at build time #3557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Abhishekmishra2808
wants to merge
1
commit into
apache:master
Choose a base branch
from
Abhishekmishra2808:nsh-login-empty-password
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,15 @@ | |
| config FSUTILS_PASSWD | ||
| bool "Password file support" | ||
| default n | ||
| select CRYPTO | ||
| select ALLOW_BSD_COMPONENTS | ||
| select CRYPTO_CRYPTODEV | ||
| ---help--- | ||
| Enables support for /etc/passwd file access routines | ||
| Enables support for /etc/passwd file access routines. | ||
|
|
||
| NOTE: Password hashes use PBKDF2-HMAC-SHA256 (modular crypt format). | ||
| Existing TEA-encrypted /etc/passwd entries are NOT compatible and | ||
| must be regenerated. | ||
|
|
||
| if FSUTILS_PASSWD | ||
|
|
||
|
|
@@ -23,20 +30,14 @@ config FSUTILS_PASSWD_IOBUFFER_SIZE | |
| int "Allocated I/O buffer size" | ||
| default 512 | ||
|
|
||
| config FSUTILS_PASSWD_KEY1 | ||
| hex "Encryption key value 1" | ||
| default 0x12345678 | ||
|
|
||
| config FSUTILS_PASSWD_KEY2 | ||
| hex "Encryption key value 2" | ||
| default 0x9abcdef0 | ||
|
|
||
| config FSUTILS_PASSWD_KEY3 | ||
| hex "Encryption key value 3" | ||
| default 0x12345678 | ||
|
|
||
| config FSUTILS_PASSWD_KEY4 | ||
| hex "Encryption key value 4" | ||
| default 0x9abcdef0 | ||
| config FSUTILS_PASSWD_PBKDF2_ITERATIONS | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove indent |
||
| int "Default PBKDF2 iteration count for new passwords" | ||
| default 10000 | ||
| range 1000 200000 | ||
| ---help--- | ||
| Number of PBKDF2-HMAC-SHA256 iterations applied when setting a new | ||
| password. Higher values slow brute-force attacks but also increase | ||
| login latency on low-MHz MCUs. The iteration count is stored in each | ||
| hash string, so changing this option only affects newly-set passwords. | ||
|
|
||
| endif # FSUTILS_PASSWD | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| /**************************************************************************** | ||
| * apps/fsutils/passwd/passwd_base64.c | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. The | ||
| * ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the | ||
| * License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| /**************************************************************************** | ||
| * Included Files | ||
| ****************************************************************************/ | ||
|
|
||
| #include <nuttx/config.h> | ||
|
|
||
| #include <errno.h> | ||
| #include <stdint.h> | ||
|
|
||
| #include "passwd_base64.h" | ||
|
|
||
| /**************************************************************************** | ||
| * Pre-processor Definitions | ||
| ****************************************************************************/ | ||
|
|
||
| /* RFC 4648 section 5 base64url alphabet (no padding). */ | ||
|
|
||
| static const char g_base64url[] = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we call netutils/codecs/base64.c? |
||
| "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; | ||
|
|
||
| /**************************************************************************** | ||
| * Private Functions | ||
| ****************************************************************************/ | ||
|
|
||
| static int passwd_base64url_val(char c) | ||
| { | ||
| if (c >= 'A' && c <= 'Z') | ||
| { | ||
| return c - 'A'; | ||
| } | ||
|
|
||
| if (c >= 'a' && c <= 'z') | ||
| { | ||
| return c - 'a' + 26; | ||
| } | ||
|
|
||
| if (c >= '0' && c <= '9') | ||
| { | ||
| return c - '0' + 52; | ||
| } | ||
|
|
||
| if (c == '-') | ||
| { | ||
| return 62; | ||
| } | ||
|
|
||
| if (c == '_') | ||
| { | ||
| return 63; | ||
| } | ||
|
|
||
| return -1; | ||
| } | ||
|
|
||
| /**************************************************************************** | ||
| * Public Functions | ||
| ****************************************************************************/ | ||
|
|
||
| /**************************************************************************** | ||
| * Name: passwd_base64url_encode | ||
| * | ||
| * Description: | ||
| * Encode binary data as unpadded base64url (RFC 4648 section 5). | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| int passwd_base64url_encode(FAR const uint8_t *in, size_t inlen, | ||
| FAR char *out, size_t outlen) | ||
| { | ||
| uint32_t acc = 0; | ||
| size_t i; | ||
| size_t o = 0; | ||
| int bits = 0; | ||
|
|
||
| for (i = 0; i < inlen; i++) | ||
| { | ||
| acc = (acc << 8) | in[i]; | ||
| bits += 8; | ||
|
|
||
| while (bits >= 6) | ||
| { | ||
| if (o + 1 >= outlen) | ||
| { | ||
| return -E2BIG; | ||
| } | ||
|
|
||
| bits -= 6; | ||
| out[o++] = g_base64url[(acc >> bits) & 0x3f]; | ||
| } | ||
| } | ||
|
|
||
| if (bits > 0) | ||
| { | ||
| if (o + 1 >= outlen) | ||
| { | ||
| return -E2BIG; | ||
| } | ||
|
|
||
| out[o++] = g_base64url[(acc << (6 - bits)) & 0x3f]; | ||
| } | ||
|
|
||
| if (o >= outlen) | ||
| { | ||
| return -E2BIG; | ||
| } | ||
|
|
||
| out[o] = '\0'; | ||
| return OK; | ||
| } | ||
|
|
||
| /**************************************************************************** | ||
| * Name: passwd_base64url_decode | ||
| * | ||
| * Description: | ||
| * Decode unpadded base64url (RFC 4648 section 5). | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| int passwd_base64url_decode(FAR const char *in, | ||
| FAR uint8_t *out, size_t outmax, | ||
| FAR size_t *outlen) | ||
| { | ||
| uint32_t acc = 0; | ||
| size_t o = 0; | ||
| int bits = 0; | ||
| int v; | ||
|
|
||
| *outlen = 0; | ||
|
|
||
| while (*in != '\0') | ||
| { | ||
| if (*in == '$' || *in == ':') | ||
| { | ||
| break; | ||
| } | ||
|
|
||
| v = passwd_base64url_val(*in++); | ||
| if (v < 0) | ||
| { | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| acc = (acc << 6) | (uint32_t)v; | ||
| bits += 6; | ||
|
|
||
| if (bits >= 8) | ||
| { | ||
| bits -= 8; | ||
| if (o >= outmax) | ||
| { | ||
| return -E2BIG; | ||
| } | ||
|
|
||
| out[o++] = (uint8_t)((acc >> bits) & 0xff); | ||
| } | ||
| } | ||
|
|
||
| if (bits >= 6) | ||
| { | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| *outlen = o; | ||
| return OK; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /**************************************************************************** | ||
| * apps/fsutils/passwd/passwd_base64.h | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. The | ||
| * ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance with the | ||
| * License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| * | ||
| ****************************************************************************/ | ||
|
|
||
| #ifndef __APPS_FSUTILS_PASSWD_PASSWD_BASE64_H | ||
| #define __APPS_FSUTILS_PASSWD_PASSWD_BASE64_H | ||
|
|
||
| /**************************************************************************** | ||
| * Included Files | ||
| ****************************************************************************/ | ||
|
|
||
| #include <nuttx/config.h> | ||
|
|
||
| #include <sys/types.h> | ||
| #include <stdint.h> | ||
|
|
||
| /**************************************************************************** | ||
| * Public Function Prototypes | ||
| ****************************************************************************/ | ||
|
|
||
| int passwd_base64url_encode(FAR const uint8_t *in, size_t inlen, | ||
| FAR char *out, size_t outlen); | ||
| int passwd_base64url_decode(FAR const char *in, | ||
| FAR uint8_t *out, size_t outmax, | ||
| FAR size_t *outlen); | ||
|
|
||
| #endif /* __APPS_FSUTILS_PASSWD_PASSWD_BASE64_H */ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:

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