From 2b2337055a6d3e32e5c637c9227a336bc575037a Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Tue, 16 Apr 2024 16:27:51 +0200 Subject: [PATCH] Add NO_FILESYSTEM to Zephyr port --- .github/workflows/zephyr.yml | 4 +- src/port.c | 3 +- src/ssh.c | 6 +- src/wolfscp.c | 9 +- zephyr/samples/tests/prj_nofs.conf | 66 +++++++++ zephyr/samples/tests/sample.yaml | 6 + zephyr/samples/tests/tests.c | 11 +- .../tests/wolfssh_user_settings_nofs.h | 68 +++++++++ .../tests/wolfssl_user_settings_nofs.h | 137 ++++++++++++++++++ 9 files changed, 299 insertions(+), 11 deletions(-) create mode 100644 zephyr/samples/tests/prj_nofs.conf create mode 100644 zephyr/samples/tests/wolfssh_user_settings_nofs.h create mode 100644 zephyr/samples/tests/wolfssl_user_settings_nofs.h diff --git a/.github/workflows/zephyr.yml b/.github/workflows/zephyr.yml index 1221e120d..26750fcc6 100644 --- a/.github/workflows/zephyr.yml +++ b/.github/workflows/zephyr.yml @@ -16,7 +16,7 @@ jobs: zephyr-sdk: 0.16.1 runs-on: ubuntu-latest # This should be a safe limit for the tests to run. - timeout-minutes: 15 + timeout-minutes: 20 steps: - name: Install dependencies run: | @@ -77,6 +77,8 @@ jobs: run: | ./zephyr/scripts/twister --testsuite-root modules/lib/wolfssh --test zephyr/samples/tests/sample.lib.wolfssh_tests -vvv rm -rf zephyr/twister-out + ./zephyr/scripts/twister --testsuite-root modules/lib/wolfssh --test zephyr/samples/tests/sample.lib.wolfssh_nofs_tests -vvv + rm -rf zephyr/twister-out - name: Zip failure logs if: ${{ failure() && steps.wolfssh-test.outcome == 'failure' }} diff --git a/src/port.c b/src/port.c index f8bd43378..b38d498a1 100644 --- a/src/port.c +++ b/src/port.c @@ -476,7 +476,8 @@ int WS_DeleteFileA(const char* fileName, void* heap) #endif /* USE_WINDOWS_API WOLFSSH_SFTP WOLFSSH_SCP */ -#if defined(WOLFSSH_ZEPHYR) && (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) +#if !defined(NO_FILESYSTEM) && \ + defined(WOLFSSH_ZEPHYR) && (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) int wssh_z_fstat(const char *p, struct fs_dirent *b) { diff --git a/src/ssh.c b/src/ssh.c index 46e83f560..9f519ce47 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -75,7 +75,8 @@ int wolfSSH_Init(void) #ifdef WC_RNG_SEED_CB wc_SetSeed_Cb(wc_GenerateSeed); #endif -#if defined(WOLFSSH_ZEPHYR) && (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) +#if !defined(NO_FILESYSTEM) && defined(WOLFSSH_ZEPHYR) && \ + (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) if (wssh_z_fds_init() != 0) ret = WS_CRYPTO_FAILED; #endif @@ -93,7 +94,8 @@ int wolfSSH_Cleanup(void) if (wolfCrypt_Cleanup() != 0) ret = WS_CRYPTO_FAILED; -#if defined(WOLFSSH_ZEPHYR) && (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) +#if !defined(NO_FILESYSTEM) && defined(WOLFSSH_ZEPHYR) && \ + (defined(WOLFSSH_SFTP) || defined(WOLFSSH_SCP)) if (wssh_z_fds_cleanup() != 0) ret = WS_CRYPTO_FAILED; #endif diff --git a/src/wolfscp.c b/src/wolfscp.c index 1bbb89cd3..33a55580a 100644 --- a/src/wolfscp.c +++ b/src/wolfscp.c @@ -2845,9 +2845,10 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, recvBuffer->mode = fileMode; if (recvBuffer->status) { if (recvBuffer->status(ssh, fileName, WOLFSSH_SCP_NEW_FILE, - recvBuffer) != WS_SUCCESS) + recvBuffer) != WS_SUCCESS) { WLOG(WS_LOG_ERROR, "scp: status of new file failed, abort"); ret = WS_SCP_ABORT; + } } break; @@ -2869,9 +2870,10 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, recvBuffer->fileSz += sz; if (recvBuffer->status) { if (recvBuffer->status(ssh, recvBuffer->name, - WOLFSSH_SCP_FILE_PART, recvBuffer) != WS_SUCCESS) + WOLFSSH_SCP_FILE_PART, recvBuffer) != WS_SUCCESS) { WLOG(WS_LOG_ERROR, "scp: bad status, abort"); ret = WS_SCP_ABORT; + } } break; @@ -2880,9 +2882,10 @@ int wsScpRecvCallback(WOLFSSH* ssh, int state, const char* basePath, recvBuffer->mTime = 0; /* @TODO set time if wanted */ if (recvBuffer->status) { if (recvBuffer->status(ssh, recvBuffer->name, - WOLFSSH_SCP_FILE_DONE, recvBuffer) != WS_SUCCESS) + WOLFSSH_SCP_FILE_DONE, recvBuffer) != WS_SUCCESS) { WLOG(WS_LOG_ERROR, "scp: bad status, abort"); ret = WS_SCP_ABORT; + } } break; diff --git a/zephyr/samples/tests/prj_nofs.conf b/zephyr/samples/tests/prj_nofs.conf new file mode 100644 index 000000000..4b628e8e8 --- /dev/null +++ b/zephyr/samples/tests/prj_nofs.conf @@ -0,0 +1,66 @@ +# Kernel options +CONFIG_MAIN_STACK_SIZE=32768 +CONFIG_ENTROPY_GENERATOR=y +CONFIG_INIT_STACKS=y +CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072 + +# Enable wolfSSH +CONFIG_WOLFSSH=y +CONFIG_WOLFSSH_SETTINGS_FILE="samples/tests/wolfssh_user_settings_nofs.h" + +# Pthreads +CONFIG_PTHREAD_IPC=y + +# Clock for time() +CONFIG_POSIX_CLOCK=y + +# Networking +CONFIG_NETWORKING=y +CONFIG_NET_TEST=y +CONFIG_NET_IPV4=y +CONFIG_NET_IPV6=n +CONFIG_NET_TCP=y +CONFIG_NET_SOCKETS=y +CONFIG_NET_SOCKETS_POSIX_NAMES=y + +CONFIG_NET_TEST=y +CONFIG_NET_LOOPBACK=y + +# Network driver config +CONFIG_TEST_RANDOM_GENERATOR=y + +# Network address config +CONFIG_NET_CONFIG_SETTINGS=y +CONFIG_NET_CONFIG_NEED_IPV4=y +CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" +CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2" +CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" + +CONFIG_NET_PKT_TX_COUNT=10 + +# Logging +CONFIG_PRINTK=y +CONFIG_LOG=y +CONFIG_LOG_MODE_IMMEDIATE=y +#CONFIG_WOLFSSH_DEBUG=y +#CONFIG_WOLFSSL_DEBUG=y +#CONFIG_DEBUG=y + +# Enable logging using RTT and UART +#CONFIG_CBPRINTF_LIBC_SUBSTS=y +#CONFIG_CBPRINTF_FP_SUPPORT=y +#CONFIG_CONSOLE=y +#CONFIG_LOG_BACKEND_UART=y +#CONFIG_LOG_BUFFER_SIZE=15360 + +# TLS configuration +CONFIG_WOLFSSL=y +CONFIG_WOLFSSL_BUILTIN=y +CONFIG_WOLFSSL_SETTINGS_FILE="samples/tests/wolfssl_user_settings_nofs.h" + +CONFIG_WOLFSSL_TLS_VERSION_1_2=y +CONFIG_WOLFSSL_KEY_EXCHANGE_ALL_ENABLED=y +CONFIG_WOLFSSL_CIPHER_ALL_ENABLED=y +CONFIG_WOLFSSL_MAC_ALL_ENABLED=y +CONFIG_WOLFSSL_HMAC_DRBG_ENABLED=y + diff --git a/zephyr/samples/tests/sample.yaml b/zephyr/samples/tests/sample.yaml index 4f6f359cf..23abc38b9 100644 --- a/zephyr/samples/tests/sample.yaml +++ b/zephyr/samples/tests/sample.yaml @@ -13,3 +13,9 @@ tests: platform_allow: qemu_x86 integration_platforms: - qemu_x86 + sample.lib.wolfssh_nofs_tests: + timeout: 200 + platform_allow: qemu_x86 + extra_args: CONF_FILE="prj_nofs.conf" + integration_platforms: + - qemu_x86 diff --git a/zephyr/samples/tests/tests.c b/zephyr/samples/tests/tests.c index cd5e54356..69a8e3b26 100644 --- a/zephyr/samples/tests/tests.c +++ b/zephyr/samples/tests/tests.c @@ -37,14 +37,15 @@ #include #include #include -#include -#include -#include - +#ifndef NO_FILESYSTEM #ifndef CONFIG_FAT_FILESYSTEM_ELM #error "This test is designed for FAT FS" #endif +#include +#include +#include +#endif #define CHECK_TEST_RETURN(func) do { \ printf("\tRunning %s... ", #func); \ @@ -60,6 +61,7 @@ int main(void) { int ret = 0; +#ifndef NO_FILESYSTEM static FATFS fat_fs; static struct fs_mount_t mnt_point = { .type = FS_FATFS, @@ -89,6 +91,7 @@ int main(void) < 0); CHECK_TEST_RETURN(fs_close(&zfp)); +#endif CHECK_TEST_RETURN(wolfSSH_UnitTest(0, NULL)); CHECK_TEST_RETURN(wolfSSH_TestsuiteTest(0, NULL)); diff --git a/zephyr/samples/tests/wolfssh_user_settings_nofs.h b/zephyr/samples/tests/wolfssh_user_settings_nofs.h new file mode 100644 index 000000000..5df7f407c --- /dev/null +++ b/zephyr/samples/tests/wolfssh_user_settings_nofs.h @@ -0,0 +1,68 @@ +/* user_settings.h + * + * Copyright (C) 2014-2024 wolfSSL Inc. + * + * This file is part of wolfSSH. + * + * wolfSSH is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with wolfSSH. If not, see . + */ + +#ifndef WOLFSSH_USER_SETTINGS_H +#define WOLFSSH_USER_SETTINGS_H + + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#undef WOLFSSH_SCP +#define WOLFSSH_SCP + +#undef NO_APITEST_MAIN_DRIVER +#define NO_APITEST_MAIN_DRIVER + +#undef NO_TESTSUITE_MAIN_DRIVER +#define NO_TESTSUITE_MAIN_DRIVER + +#undef NO_UNITTEST_MAIN_DRIVER +#define NO_UNITTEST_MAIN_DRIVER + +#undef NO_MAIN_DRIVER +#define NO_MAIN_DRIVER + +#undef WS_NO_SIGNAL +#define WS_NO_SIGNAL + +#undef WS_USE_TEST_BUFFERS +#define WS_USE_TEST_BUFFERS + +#undef NO_WOLFSSL_DIR +#define NO_WOLFSSL_DIR + +#undef WOLFSSH_NO_NONBLOCKING +#define WOLFSSH_NO_NONBLOCKING + +#define DEFAULT_WINDOW_SZ (128 * 128) +#define WOLFSSH_MAX_SFTP_RW 8192 + +#undef NO_FILESYSTEM +#define NO_FILESYSTEM + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/zephyr/samples/tests/wolfssl_user_settings_nofs.h b/zephyr/samples/tests/wolfssl_user_settings_nofs.h new file mode 100644 index 000000000..881b6b689 --- /dev/null +++ b/zephyr/samples/tests/wolfssl_user_settings_nofs.h @@ -0,0 +1,137 @@ +/* wolfssl_user_settings.h + * + * Copyright (C) 2014-2024 wolfSSL Inc. + * + * This file is part of wolfSSH. + * + * wolfSSH is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * wolfSSH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with wolfSSH. If not, see . + */ + +#ifndef WOLFSSL_USER_SETTINGS_H +#define WOLFSSL_USER_SETTINGS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#undef WOLFSSL_ZEPHYR +#define WOLFSSL_ZEPHYR + +#undef TFM_TIMING_RESISTANT +#define TFM_TIMING_RESISTANT + +#undef ECC_TIMING_RESISTANT +#define ECC_TIMING_RESISTANT + +#undef WC_RSA_BLINDING +#define WC_RSA_BLINDING + +#undef HAVE_AESGCM +#define HAVE_AESGCM + +#undef WOLFSSL_SHA512 +#define WOLFSSL_SHA512 + +#undef WOLFSSL_SHA384 +#define WOLFSSL_SHA384 + +#undef NO_DSA +#define NO_DSA + +#undef HAVE_ECC +#define HAVE_ECC + +#undef TFM_ECC256 +#define TFM_ECC256 + +#undef WOLFSSL_BASE64_ENCODE +#define WOLFSSL_BASE64_ENCODE + +#undef NO_RC4 +#define NO_RC4 + +#undef WOLFSSL_SHA224 +#define WOLFSSL_SHA224 + +#undef WOLFSSL_SHA3 +#define WOLFSSL_SHA3 + +#undef HAVE_POLY1305 +#define HAVE_POLY1305 + +#undef HAVE_ONE_TIME_AUTH +#define HAVE_ONE_TIME_AUTH + +#undef HAVE_CHACHA +#define HAVE_CHACHA + +#undef HAVE_HASHDRBG +#define HAVE_HASHDRBG + +#undef HAVE_TLS_EXTENSIONS +#define HAVE_TLS_EXTENSIONS + +#undef HAVE_SUPPORTED_CURVES +#define HAVE_SUPPORTED_CURVES + +#undef HAVE_EXTENDED_MASTER +#define HAVE_EXTENDED_MASTER + +#undef NO_PSK +#define NO_PSK + +#undef NO_MD4 +#define NO_MD4 + +#undef NO_PWDBASED +#define NO_PWDBASED + +#undef USE_FAST_MATH +#define USE_FAST_MATH + +#undef WOLFSSL_NO_ASM +#define WOLFSSL_NO_ASM + +#undef WOLFSSL_X86_BUILD +#define WOLFSSL_X86_BUILD + +#undef WC_NO_ASYNC_THREADING +#define WC_NO_ASYNC_THREADING + +#undef NO_DES3 +#define NO_DES3 + +#undef WOLFSSL_STATIC_MEMORY +#define WOLFSSL_STATIC_MEMORY + +#undef WOLFSSL_TLS13 +#define WOLFSSL_TLS13 + +#undef HAVE_HKDF +#define HAVE_HKDF + +#undef WC_RSA_PSS +#define WC_RSA_PSS + +#undef HAVE_FFDHE_2048 +#define HAVE_FFDHE_2048 + +#undef NO_FILESYSTEM +#define NO_FILESYSTEM + +#ifdef __cplusplus +} +#endif + +#endif /* WOLFSSL_USER_SETTINGS_H */