acassis commented on code in PR #18396: URL: https://github.com/apache/nuttx/pull/18396#discussion_r2942349773
########## tools/mkpasswd.c: ########## @@ -0,0 +1,587 @@ +/**************************************************************************** + * tools/mkpasswd.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. + * + ****************************************************************************/ + +/**************************************************************************** + * Description: + * Host build tool that generates a NuttX /etc/passwd entry with a + * TEA-encrypted password hash. This is a pure C replacement for the + * former tools/mkpasswd.py, removing the Python dependency from the build. + * + * The encryption algorithm and base64 encoding are identical to those + * used at runtime by: + * libs/libc/misc/lib_tea_encrypt.c + * apps/fsutils/passwd/passwd_encrypt.c + * + * Usage: + * mkpasswd --user <name> --password <pass> [options] [-o <output>] + * + * Options: + * --user <str> Username (required) + * --password <str> Plaintext password (required, not stored in output) + * --uid <int> User ID (default: 0) + * --gid <int> Group ID (default: 0) + * --home <str> Home directory (default: /) + * --key1 <hex> TEA key word 1 (default: 0x12345678) + * --key2 <hex> TEA key word 2 (default: 0x9abcdef0) + * --key3 <hex> TEA key word 3 (default: 0x12345678) + * --key4 <hex> TEA key word 4 (default: 0x9abcdef0) + * -o <path> Output file (default: stdout) + * + * Output format (matches NuttX passwd file format): + * username:encrypted_hash:uid:gid:home + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +/* Expose strdup(), mkdir() and other POSIX.1-2008 extensions when + * compiling with strict C99 mode (-std=c99). Has no effect on C11/GNU + * builds or MSVC. + */ + +#ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200809L +#endif + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <sys/stat.h> + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* TEA key schedule constant (derived from the golden ratio) */ + +#define TEA_KEY_SCHEDULE_CONSTANT 0x9e3779b9u + +/* Password size limits - must match apps/fsutils/passwd/passwd.h */ + +#define MAX_ENCRYPTED 48 /* Max size of encrypted password (ASCII) */ +#define MAX_PASSWORD (3 * MAX_ENCRYPTED / 4) /* Max plaintext length */ +#define MIN_PASSWORD 8 /* Minimum plaintext length for security */ + +/* Default TEA key values - must match CONFIG_FSUTILS_PASSWD_KEY1-4 defaults + * in apps/fsutils/passwd/Kconfig so that the generated hash verifies + * correctly at runtime when the user has not changed the key config. + */ + +#define DEFAULT_KEY1 0x12345678u +#define DEFAULT_KEY2 0x9abcdef0u +#define DEFAULT_KEY3 0x12345678u +#define DEFAULT_KEY4 0x9abcdef0u Review Comment: @Abhishekmishra2808 please use the CONFIG_FSUTILS_PASSWD_KEY1-4 instead. Also warn the user if these default values are used, so they need to change it. @also we need to avoid "make savedefconfig" to save these CONFIG_FSUTILS_PASSWD_KEYx otherwise the users can leak their password without been aware of it. @raiden00pl @simbit18 @xiaoxiang781216 what do you think? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
