-
Notifications
You must be signed in to change notification settings - Fork 744
netutils/dropbear: initial Dropbear SSH server port for NuttX #3532
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
Draft
FelipeMdeO
wants to merge
1
commit into
apache:master
Choose a base branch
from
FelipeMdeO:feature/dropbear-esp32c3-port
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.
Draft
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
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,6 @@ | ||
| /dropbear | ||
| /*.zip | ||
| *.o | ||
| .built | ||
| .depend | ||
| Make.dep |
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,207 @@ | ||
| # ############################################################################## | ||
| # apps/netutils/dropbear/CMakeLists.txt | ||
| # | ||
| # 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. | ||
| # | ||
| # ############################################################################## | ||
|
|
||
| if(CONFIG_NETUTILS_DROPBEAR) | ||
|
|
||
| set(DROPBEAR_COMMIT "${CONFIG_NETUTILS_DROPBEAR_COMMIT}") | ||
| string(REPLACE "\"" "" DROPBEAR_COMMIT "${DROPBEAR_COMMIT}") | ||
|
|
||
| set(DROPBEAR_ZIP "${DROPBEAR_COMMIT}.zip") | ||
| set(DROPBEAR_URL "https://github.com/mkj/dropbear/archive") | ||
| set(DROPBEAR_UNPACKNAME "dropbear") | ||
|
|
||
| if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_UNPACKNAME}") | ||
| if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_ZIP}") | ||
| message(STATUS "Downloading Dropbear: ${DROPBEAR_URL}/${DROPBEAR_ZIP}") | ||
| file(DOWNLOAD "${DROPBEAR_URL}/${DROPBEAR_ZIP}" | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_ZIP}") | ||
| endif() | ||
| message(STATUS "Unpacking Dropbear: ${DROPBEAR_ZIP}") | ||
| execute_process( | ||
| COMMAND unzip -q -o "${DROPBEAR_ZIP}" | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" | ||
| RESULT_VARIABLE result) | ||
| if(result EQUAL 0) | ||
| file(RENAME "${CMAKE_CURRENT_SOURCE_DIR}/dropbear-${DROPBEAR_COMMIT}" | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_UNPACKNAME}") | ||
| execute_process( | ||
| COMMAND | ||
| patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/patch/0001-use-nuttx-unused-macro.patch" | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") | ||
| execute_process( | ||
| COMMAND | ||
| patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/patch/0002-use-nuttx-ecdsa-hostkey-sign.patch" | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") | ||
| execute_process( | ||
| COMMAND | ||
| patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/patch/0003-guard-environ-declaration-for-nuttx.patch" | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") | ||
| execute_process( | ||
| COMMAND | ||
| patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/patch/0004-fix-nuttx-compile-warnings.patch" | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") | ||
| execute_process( | ||
| COMMAND | ||
| patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/patch/0005-use-nuttx-sha256-hmac.patch" | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") | ||
| execute_process( | ||
| COMMAND | ||
| patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/patch/0006-use-nuttx-chachapoly-state.patch" | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") | ||
| execute_process( | ||
| COMMAND | ||
| patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/patch/0007-use-nuttx-passwd-auth.patch" | ||
| WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") | ||
| endif() | ||
| endif() | ||
|
|
||
| set(PROGNAME "${CONFIG_NETUTILS_DROPBEAR_PROGNAME}") | ||
| string(REPLACE "\"" "" PROGNAME "${PROGNAME}") | ||
|
|
||
| set(DROPBEAR_SRCS | ||
| dropbear_nshsession.c | ||
| port/nuttx_auth.c | ||
| port/nuttx_compat.c | ||
| port/dropbear_chachapoly.c | ||
| port/dropbear_crypto.c | ||
| port/dropbear_curve25519.c | ||
| port/dropbear_ltc_aes.c | ||
| port/dropbear_ltc_hmac_sha256.c | ||
| port/dropbear_ltc_sha256.c | ||
| port/dropbear_utils.c | ||
| port/nuttx_hostkey.c | ||
| dropbear/src/dbutil.c | ||
| dropbear/src/buffer.c | ||
| dropbear/src/dbhelpers.c | ||
| dropbear/src/bignum.c | ||
| dropbear/src/signkey.c | ||
| dropbear/src/dbrandom.c | ||
| dropbear/src/queue.c | ||
| dropbear/src/atomicio.c | ||
| dropbear/src/compat.c | ||
| dropbear/src/fake-rfc2553.c | ||
| dropbear/src/ltc_prng.c | ||
| dropbear/src/ecc.c | ||
| dropbear/src/ecdsa.c | ||
| dropbear/src/crypto_desc.c | ||
| dropbear/src/dbmalloc.c | ||
| dropbear/src/gensignkey.c | ||
| dropbear/src/common-session.c | ||
| dropbear/src/packet.c | ||
| dropbear/src/common-algo.c | ||
| dropbear/src/common-kex.c | ||
| dropbear/src/common-channel.c | ||
| dropbear/src/common-chansession.c | ||
| dropbear/src/termcodes.c | ||
| dropbear/src/tcp-accept.c | ||
| dropbear/src/listener.c | ||
| dropbear/src/process-packet.c | ||
| dropbear/src/common-runopts.c | ||
| dropbear/src/circbuffer.c | ||
| dropbear/src/list.c | ||
| dropbear/src/netio.c | ||
| dropbear/src/gcm.c | ||
| dropbear/src/kex-x25519.c | ||
| dropbear/src/svr-kex.c | ||
| dropbear/src/svr-auth.c | ||
| dropbear/src/svr-authpasswd.c | ||
| dropbear/src/svr-session.c | ||
| dropbear/src/svr-service.c | ||
| dropbear/src/svr-runopts.c | ||
| dropbear/src/svr-tcpfwd.c | ||
| dropbear/src/svr-authpam.c) | ||
|
|
||
| file(GLOB LIBTOMMATH_SRCS CONFIGURE_DEPENDS | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtommath/*.c") | ||
| list(APPEND DROPBEAR_SRCS ${LIBTOMMATH_SRCS}) | ||
|
|
||
| file(GLOB_RECURSE LIBTOMCRYPT_SRCS CONFIGURE_DEPENDS | ||
| "${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtomcrypt/src/*.c") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_make_key\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_encrypt_key\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_decrypt_key\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_shared_secret\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_sign_hash\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_verify_hash\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_test\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/ciphers/aes/aes\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/ciphers/aes/aes_tab\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/hmac/hmac_done\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/hmac/hmac_init\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/hmac/hmac_process\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/poly1305/.*\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/encauth/chachapoly/.*\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/prngs/chacha20\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/stream/chacha/.*\\.c$") | ||
| list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/hashes/sha2/sha256\\.c$") | ||
| list(APPEND DROPBEAR_SRCS ${LIBTOMCRYPT_SRCS}) | ||
|
|
||
| nuttx_add_application( | ||
| NAME | ||
| ${PROGNAME} | ||
| SRCS | ||
| ${DROPBEAR_SRCS} | ||
| dropbear_main.c | ||
| STACKSIZE | ||
| ${CONFIG_NETUTILS_DROPBEAR_STACKSIZE} | ||
| PRIORITY | ||
| ${CONFIG_NETUTILS_DROPBEAR_PRIORITY} | ||
| DEPENDS | ||
| ${DROPBEAR_UNPACKNAME}) | ||
|
|
||
| target_include_directories( | ||
| ${PROGNAME} | ||
| PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/port | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/dropbear | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/src | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtomcrypt/src/headers | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtommath | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/../../nshlib) | ||
|
|
||
| target_compile_definitions( | ||
| ${PROGNAME} | ||
| PRIVATE LOCALOPTIONS_H_EXISTS=1 DROPBEAR_NUTTX=1 | ||
| DROPBEAR_NUTTX_CHACHAPOLY=1 DROPBEAR_NUTTX_HMAC_SHA256=1 | ||
| DROPBEAR_NUTTX_PASSWD=1 DROPBEAR_NUTTX_SHA256=1) | ||
|
|
||
| set_source_files_properties( | ||
| dropbear_nshsession.c | ||
| PROPERTIES COMPILE_DEFINITIONS | ||
| "Channel=dropbear_channel;ChanType=dropbear_chantype") | ||
|
|
||
| # LTC_SOURCE must be set only for libtomcrypt sources. | ||
| set_source_files_properties(${LIBTOMCRYPT_SRCS} PROPERTIES COMPILE_DEFINITIONS | ||
| LTC_SOURCE=1) | ||
|
|
||
| target_compile_options(${PROGNAME} PRIVATE -Wno-pointer-sign -Wno-format) | ||
|
|
||
| target_sources(apps PRIVATE ${DROPBEAR_SRCS}) | ||
|
|
||
| endif() |
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,102 @@ | ||
| # | ||
| # For a description of the syntax of this configuration file, | ||
| # see the file kconfig-language.txt in the NuttX tools repository. | ||
| # | ||
|
|
||
| menuconfig NETUTILS_DROPBEAR | ||
| tristate "Dropbear SSH server" | ||
| default n | ||
| depends on NET && NET_TCP | ||
| depends on !DISABLE_PSEUDOFS_OPERATIONS | ||
| depends on !DISABLE_PTHREAD | ||
| depends on SCHED_WAITPID | ||
| depends on NSH_LIBRARY | ||
| depends on FSUTILS_PASSWD | ||
| depends on PSEUDOTERM | ||
| depends on SERIAL | ||
| depends on ARCH_HAVE_RNG | ||
| select CRYPTO | ||
| select CRYPTO_RANDOM_POOL | ||
| select DEV_RANDOM | ||
| select DEV_URANDOM | ||
| select LIBC_NETDB | ||
| select LIBC_GAISTRERROR | ||
|
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. change select to depends on |
||
| ---help--- | ||
| Enable a minimal Dropbear SSH server port for NuttX. This initial | ||
| port is based on the ESP-IDF MCU test port and provides a single | ||
| foreground SSH server process with SSH sessions backed by NSH. | ||
|
|
||
| if NETUTILS_DROPBEAR | ||
|
|
||
| config NETUTILS_DROPBEAR_STACKSIZE | ||
| int "Dropbear main stack size" | ||
| default 65536 if ARCH_CHIP_ESP32C3 | ||
| default 32768 | ||
|
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. why not fix to 65536 |
||
| ---help--- | ||
| Stack size for the Dropbear server built-in. The ESP32-C3 test | ||
| results showed key exchange needs more than 32 KiB on RISC-V, so | ||
| 64 KiB is the conservative default for ESP32-C3. | ||
|
|
||
| config NETUTILS_DROPBEAR_PRIORITY | ||
| int "Dropbear main priority" | ||
| default 100 | ||
|
|
||
| config NETUTILS_DROPBEAR_SHELL_PRIORITY | ||
| int "Dropbear NSH session priority" | ||
| default 100 | ||
|
|
||
| config NETUTILS_DROPBEAR_PROGNAME | ||
| string "Dropbear program name" | ||
| default "dropbear" | ||
| ---help--- | ||
| This is the name of the program that will be used when the NSH ELF | ||
| program is installed. | ||
|
|
||
| config NETUTILS_DROPBEAR_LISTEN_RETRIES | ||
| int "Dropbear listen retries" | ||
| default 0 | ||
| ---help--- | ||
| Number of times to retry listen setup when no listen socket could | ||
| be opened. Zero means to retry forever. | ||
|
|
||
| config NETUTILS_DROPBEAR_LISTEN_RETRY_MAX | ||
| int "Dropbear maximum listen retry interval" | ||
| default 120 | ||
| range 1 3600 | ||
| ---help--- | ||
| Maximum number of seconds to wait between listen setup retries. | ||
| The retry delay starts at one second and doubles until it reaches | ||
| this value. | ||
|
|
||
| config NETUTILS_DROPBEAR_SHELL_STACKSIZE | ||
| int "Dropbear NSH session task stack size" | ||
| default 8192 | ||
|
|
||
| config NETUTILS_DROPBEAR_PORT | ||
| int "Dropbear listen port" | ||
| default 2222 | ||
|
|
||
| config NETUTILS_DROPBEAR_HOSTKEY_PATH | ||
| string "Dropbear ECDSA P-256 host key path" | ||
| default "/etc/dropbear/dropbear_ecdsa_host_key" | ||
| ---help--- | ||
| Path to the persistent ECDSA P-256 host key used by the Dropbear | ||
| server. The file stores the private scalar and public point in a | ||
| NuttX-specific text format: | ||
| nuttx-ecdsa-p256-v1:d_hex:x_hex:y_hex | ||
|
|
||
| config NETUTILS_DROPBEAR_GENERATE_HOSTKEY | ||
| bool "Generate host key if missing" | ||
| default y | ||
| ---help--- | ||
| Generate an ECDSA P-256 host key with NuttX crypto on first boot | ||
| when NETUTILS_DROPBEAR_HOSTKEY_PATH does not exist. Product builds | ||
| can disable this and provision the host key externally. | ||
|
|
||
| config NETUTILS_DROPBEAR_COMMIT | ||
| string "Dropbear upstream commit" | ||
| default "75f699bfe2c234418056776c4d9f651a07a76de6" | ||
| ---help--- | ||
| Upstream Dropbear revision used by the ESP-IDF validation repo. | ||
|
|
||
| endif | ||
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,25 @@ | ||
| ############################################################################ | ||
| # apps/netutils/dropbear/Make.defs | ||
| # | ||
| # 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. | ||
| # | ||
| ############################################################################ | ||
|
|
||
| ifneq ($(CONFIG_NETUTILS_DROPBEAR),) | ||
| CONFIGURED_APPS += $(APPDIR)/netutils/dropbear | ||
| endif |
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.
why need open stream and close it immediately