|
| 1 | +# ############################################################################## |
| 2 | +# apps/netutils/dropbear/CMakeLists.txt |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# |
| 6 | +# Licensed to the Apache Software Foundation (ASF) under one or more contributor |
| 7 | +# license agreements. See the NOTICE file distributed with this work for |
| 8 | +# additional information regarding copyright ownership. The ASF licenses this |
| 9 | +# file to you under the Apache License, Version 2.0 (the "License"); you may not |
| 10 | +# use this file except in compliance with the License. You may obtain a copy of |
| 11 | +# the License at |
| 12 | +# |
| 13 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +# |
| 15 | +# Unless required by applicable law or agreed to in writing, software |
| 16 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 18 | +# License for the specific language governing permissions and limitations under |
| 19 | +# the License. |
| 20 | +# |
| 21 | +# ############################################################################## |
| 22 | + |
| 23 | +if(CONFIG_NETUTILS_DROPBEAR) |
| 24 | + |
| 25 | + set(DROPBEAR_COMMIT "${CONFIG_NETUTILS_DROPBEAR_COMMIT}") |
| 26 | + string(REPLACE "\"" "" DROPBEAR_COMMIT "${DROPBEAR_COMMIT}") |
| 27 | + |
| 28 | + set(DROPBEAR_ZIP "${DROPBEAR_COMMIT}.zip") |
| 29 | + set(DROPBEAR_URL "https://github.com/mkj/dropbear/archive") |
| 30 | + set(DROPBEAR_UNPACKNAME "dropbear") |
| 31 | + |
| 32 | + if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_UNPACKNAME}") |
| 33 | + if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_ZIP}") |
| 34 | + message(STATUS "Downloading Dropbear: ${DROPBEAR_URL}/${DROPBEAR_ZIP}") |
| 35 | + file(DOWNLOAD "${DROPBEAR_URL}/${DROPBEAR_ZIP}" |
| 36 | + "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_ZIP}") |
| 37 | + endif() |
| 38 | + message(STATUS "Unpacking Dropbear: ${DROPBEAR_ZIP}") |
| 39 | + execute_process( |
| 40 | + COMMAND unzip -q -o "${DROPBEAR_ZIP}" |
| 41 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
| 42 | + RESULT_VARIABLE result) |
| 43 | + if(result EQUAL 0) |
| 44 | + file(RENAME "${CMAKE_CURRENT_SOURCE_DIR}/dropbear-${DROPBEAR_COMMIT}" |
| 45 | + "${CMAKE_CURRENT_SOURCE_DIR}/${DROPBEAR_UNPACKNAME}") |
| 46 | + execute_process( |
| 47 | + COMMAND |
| 48 | + patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i |
| 49 | + "${CMAKE_CURRENT_SOURCE_DIR}/patch/0001-use-nuttx-unused-macro.patch" |
| 50 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") |
| 51 | + execute_process( |
| 52 | + COMMAND |
| 53 | + patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i |
| 54 | + "${CMAKE_CURRENT_SOURCE_DIR}/patch/0002-use-nuttx-ecdsa-hostkey-sign.patch" |
| 55 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") |
| 56 | + execute_process( |
| 57 | + COMMAND |
| 58 | + patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i |
| 59 | + "${CMAKE_CURRENT_SOURCE_DIR}/patch/0003-guard-environ-declaration-for-nuttx.patch" |
| 60 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") |
| 61 | + execute_process( |
| 62 | + COMMAND |
| 63 | + patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i |
| 64 | + "${CMAKE_CURRENT_SOURCE_DIR}/patch/0004-fix-nuttx-compile-warnings.patch" |
| 65 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") |
| 66 | + execute_process( |
| 67 | + COMMAND |
| 68 | + patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i |
| 69 | + "${CMAKE_CURRENT_SOURCE_DIR}/patch/0005-use-nuttx-sha256-hmac.patch" |
| 70 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") |
| 71 | + execute_process( |
| 72 | + COMMAND |
| 73 | + patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i |
| 74 | + "${CMAKE_CURRENT_SOURCE_DIR}/patch/0006-use-nuttx-chachapoly-state.patch" |
| 75 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") |
| 76 | + execute_process( |
| 77 | + COMMAND |
| 78 | + patch -s -N -l -p1 -d "${DROPBEAR_UNPACKNAME}" -i |
| 79 | + "${CMAKE_CURRENT_SOURCE_DIR}/patch/0007-use-nuttx-passwd-auth.patch" |
| 80 | + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}") |
| 81 | + endif() |
| 82 | + endif() |
| 83 | + |
| 84 | + set(PROGNAME "${CONFIG_NETUTILS_DROPBEAR_PROGNAME}") |
| 85 | + string(REPLACE "\"" "" PROGNAME "${PROGNAME}") |
| 86 | + |
| 87 | + set(DROPBEAR_SRCS |
| 88 | + dropbear_nshsession.c |
| 89 | + port/nuttx_auth.c |
| 90 | + port/nuttx_compat.c |
| 91 | + port/dropbear_chachapoly.c |
| 92 | + port/dropbear_crypto.c |
| 93 | + port/dropbear_curve25519.c |
| 94 | + port/dropbear_ltc_aes.c |
| 95 | + port/dropbear_ltc_hmac_sha256.c |
| 96 | + port/dropbear_ltc_sha256.c |
| 97 | + port/dropbear_utils.c |
| 98 | + port/nuttx_hostkey.c |
| 99 | + dropbear/src/dbutil.c |
| 100 | + dropbear/src/buffer.c |
| 101 | + dropbear/src/dbhelpers.c |
| 102 | + dropbear/src/bignum.c |
| 103 | + dropbear/src/signkey.c |
| 104 | + dropbear/src/dbrandom.c |
| 105 | + dropbear/src/queue.c |
| 106 | + dropbear/src/atomicio.c |
| 107 | + dropbear/src/compat.c |
| 108 | + dropbear/src/fake-rfc2553.c |
| 109 | + dropbear/src/ltc_prng.c |
| 110 | + dropbear/src/ecc.c |
| 111 | + dropbear/src/ecdsa.c |
| 112 | + dropbear/src/crypto_desc.c |
| 113 | + dropbear/src/dbmalloc.c |
| 114 | + dropbear/src/gensignkey.c |
| 115 | + dropbear/src/common-session.c |
| 116 | + dropbear/src/packet.c |
| 117 | + dropbear/src/common-algo.c |
| 118 | + dropbear/src/common-kex.c |
| 119 | + dropbear/src/common-channel.c |
| 120 | + dropbear/src/common-chansession.c |
| 121 | + dropbear/src/termcodes.c |
| 122 | + dropbear/src/tcp-accept.c |
| 123 | + dropbear/src/listener.c |
| 124 | + dropbear/src/process-packet.c |
| 125 | + dropbear/src/common-runopts.c |
| 126 | + dropbear/src/circbuffer.c |
| 127 | + dropbear/src/list.c |
| 128 | + dropbear/src/netio.c |
| 129 | + dropbear/src/gcm.c |
| 130 | + dropbear/src/kex-x25519.c |
| 131 | + dropbear/src/svr-kex.c |
| 132 | + dropbear/src/svr-auth.c |
| 133 | + dropbear/src/svr-authpasswd.c |
| 134 | + dropbear/src/svr-session.c |
| 135 | + dropbear/src/svr-service.c |
| 136 | + dropbear/src/svr-runopts.c |
| 137 | + dropbear/src/svr-tcpfwd.c |
| 138 | + dropbear/src/svr-authpam.c) |
| 139 | + |
| 140 | + file(GLOB LIBTOMMATH_SRCS CONFIGURE_DEPENDS |
| 141 | + "${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtommath/*.c") |
| 142 | + list(APPEND DROPBEAR_SRCS ${LIBTOMMATH_SRCS}) |
| 143 | + |
| 144 | + file(GLOB_RECURSE LIBTOMCRYPT_SRCS CONFIGURE_DEPENDS |
| 145 | + "${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtomcrypt/src/*.c") |
| 146 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_make_key\\.c$") |
| 147 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_encrypt_key\\.c$") |
| 148 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_decrypt_key\\.c$") |
| 149 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_shared_secret\\.c$") |
| 150 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_sign_hash\\.c$") |
| 151 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_verify_hash\\.c$") |
| 152 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/pk/ecc/ecc_test\\.c$") |
| 153 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/ciphers/aes/aes\\.c$") |
| 154 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/ciphers/aes/aes_tab\\.c$") |
| 155 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/hmac/hmac_done\\.c$") |
| 156 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/hmac/hmac_init\\.c$") |
| 157 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/hmac/hmac_process\\.c$") |
| 158 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/mac/poly1305/.*\\.c$") |
| 159 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/encauth/chachapoly/.*\\.c$") |
| 160 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/prngs/chacha20\\.c$") |
| 161 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/stream/chacha/.*\\.c$") |
| 162 | + list(FILTER LIBTOMCRYPT_SRCS EXCLUDE REGEX ".*/hashes/sha2/sha256\\.c$") |
| 163 | + list(APPEND DROPBEAR_SRCS ${LIBTOMCRYPT_SRCS}) |
| 164 | + |
| 165 | + nuttx_add_application( |
| 166 | + NAME |
| 167 | + ${PROGNAME} |
| 168 | + SRCS |
| 169 | + ${DROPBEAR_SRCS} |
| 170 | + dropbear_main.c |
| 171 | + STACKSIZE |
| 172 | + ${CONFIG_NETUTILS_DROPBEAR_STACKSIZE} |
| 173 | + PRIORITY |
| 174 | + ${CONFIG_NETUTILS_DROPBEAR_PRIORITY} |
| 175 | + DEPENDS |
| 176 | + ${DROPBEAR_UNPACKNAME}) |
| 177 | + |
| 178 | + target_include_directories( |
| 179 | + ${PROGNAME} |
| 180 | + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} |
| 181 | + ${CMAKE_CURRENT_SOURCE_DIR}/port |
| 182 | + ${CMAKE_CURRENT_SOURCE_DIR}/dropbear |
| 183 | + ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/src |
| 184 | + ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtomcrypt/src/headers |
| 185 | + ${CMAKE_CURRENT_SOURCE_DIR}/dropbear/libtommath |
| 186 | + ${CMAKE_CURRENT_SOURCE_DIR}/../../nshlib) |
| 187 | + |
| 188 | + if(CONFIG_NETUTILS_DROPBEAR_COMPRESSION) |
| 189 | + target_include_directories( |
| 190 | + ${PROGNAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../system/zlib/zlib) |
| 191 | + endif() |
| 192 | + |
| 193 | + target_compile_definitions( |
| 194 | + ${PROGNAME} |
| 195 | + PRIVATE LOCALOPTIONS_H_EXISTS=1 DROPBEAR_NUTTX=1 |
| 196 | + DROPBEAR_NUTTX_CHACHAPOLY=1 DROPBEAR_NUTTX_HMAC_SHA256=1 |
| 197 | + DROPBEAR_NUTTX_PASSWD=1 DROPBEAR_NUTTX_SHA256=1) |
| 198 | + |
| 199 | + set_source_files_properties( |
| 200 | + dropbear_nshsession.c |
| 201 | + PROPERTIES COMPILE_DEFINITIONS |
| 202 | + "Channel=dropbear_channel;ChanType=dropbear_chantype") |
| 203 | + |
| 204 | + # LTC_SOURCE must be set only for libtomcrypt sources. |
| 205 | + set_source_files_properties(${LIBTOMCRYPT_SRCS} PROPERTIES COMPILE_DEFINITIONS |
| 206 | + LTC_SOURCE=1) |
| 207 | + |
| 208 | + target_compile_options(${PROGNAME} PRIVATE -Wno-pointer-sign -Wno-format) |
| 209 | + |
| 210 | + target_sources(apps PRIVATE ${DROPBEAR_SRCS}) |
| 211 | + |
| 212 | +endif() |
0 commit comments