From c3e6195da5ccb9c2c9e63eeaa35c7435210faccf Mon Sep 17 00:00:00 2001 From: Elms Date: Fri, 19 Mar 2021 16:25:08 -0700 Subject: [PATCH] INTIME: add support for directory file search Directory support allows CRL use with undefining `NO_WOLFSSL_DIR` Also increase stack size to avoid page fault and add `_USE_64BIT_TIME_T` to example project to pass ASN test --- IDE/INTIME-RTOS/user_settings.h | 4 +- IDE/INTIME-RTOS/wolfExamples.vcxproj | 2 +- wolfcrypt/src/wc_port.c | 55 ++++++++++++++++++++++++++++ wolfssl/wolfcrypt/wc_port.h | 2 + 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/IDE/INTIME-RTOS/user_settings.h b/IDE/INTIME-RTOS/user_settings.h index 8458f3814..529dad4d1 100644 --- a/IDE/INTIME-RTOS/user_settings.h +++ b/IDE/INTIME-RTOS/user_settings.h @@ -14,7 +14,7 @@ extern "C" { #define INTIME_RTOS #undef WOLF_EXAMPLES_STACK -#define WOLF_EXAMPLES_STACK 65536 +#define WOLF_EXAMPLES_STACK (1<<17) #undef WOLFSSL_GENERAL_ALIGNMENT #define WOLFSSL_GENERAL_ALIGNMENT 4 @@ -27,7 +27,7 @@ extern "C" { /* disable directory support */ #undef NO_WOLFSSL_DIR -#define NO_WOLFSSL_DIR +//#define NO_WOLFSSL_DIR /* disable writev */ #undef NO_WRITEV diff --git a/IDE/INTIME-RTOS/wolfExamples.vcxproj b/IDE/INTIME-RTOS/wolfExamples.vcxproj index 81b1e6d4f..f650244c0 100755 --- a/IDE/INTIME-RTOS/wolfExamples.vcxproj +++ b/IDE/INTIME-RTOS/wolfExamples.vcxproj @@ -66,7 +66,7 @@ Async - WOLFSSL_USER_SETTINGS;%(PreprocessorDefinitions) + WOLFSSL_USER_SETTINGS;_USE_64BIT_TIME_T;%(PreprocessorDefinitions) $(ProjectDir);$(ProjectDir)..\..\;%(AdditionalIncludeDirectories) diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 2e6dc17ac..08a567433 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -464,6 +464,37 @@ int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name) return 0; } } while (FindNextFileA(ctx->hFind, &ctx->FindFileData)); + +#elif defined(INTIME_RTOS) + if (pathLen > MAX_FILENAME_SZ - 3) + return BAD_PATH_ERROR; + + XSTRNCPY(ctx->name, path, MAX_FILENAME_SZ - 3); + XSTRNCPY(ctx->name + pathLen, "\\*", MAX_FILENAME_SZ - pathLen); + + if (!FindFirstRtFile(ctx->name, &ctx->FindFileData, 0)) { + WOLFSSL_MSG("FindFirstFile for path verify locations failed"); + return BAD_PATH_ERROR; + } + + do { + if (!(ctx->FindFileData.dwFileAttributes & FILE_ATTR_DIRECTORY)) { + dnameLen = (int)XSTRLEN(ctx->FindFileData.cFileName); + + if (pathLen + dnameLen + 2 > MAX_FILENAME_SZ) { + return BAD_PATH_ERROR; + } + XSTRNCPY(ctx->name, path, pathLen + 1); + ctx->name[pathLen] = '\\'; + XSTRNCPY(ctx->name + pathLen + 1, + ctx->FindFileData.cFileName, + MAX_FILENAME_SZ - pathLen - 1); + if (name) + *name = ctx->name; + return 0; + } + } while (FindNextRtFile(&ctx->FindFileData)); + #elif defined(WOLFSSL_ZEPHYR) if (fs_opendir(&ctx->dir, path) != 0) { WOLFSSL_MSG("opendir path verify locations failed"); @@ -600,6 +631,26 @@ int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name) return 0; } } + +#elif defined(INTIME_RTOS) +while (FindNextRtFile(&ctx->FindFileData)) { + if (!(ctx->FindFileData.dwFileAttributes & FILE_ATTR_DIRECTORY)) { + dnameLen = (int)XSTRLEN(ctx->FindFileData.cFileName); + + if (pathLen + dnameLen + 2 > MAX_FILENAME_SZ) { + return BAD_PATH_ERROR; + } + XSTRNCPY(ctx->name, path, pathLen + 1); + ctx->name[pathLen] = '\\'; + XSTRNCPY(ctx->name + pathLen + 1, + ctx->FindFileData.cFileName, + MAX_FILENAME_SZ - pathLen - 1); + if (name) + *name = ctx->name; + return 0; + } +} + #elif defined(WOLFSSL_ZEPHYR) while ((fs_readdir(&ctx->dir, &ctx->entry)) != 0) { dnameLen = (int)XSTRLEN(ctx->entry.name); @@ -695,6 +746,10 @@ void wc_ReadDirClose(ReadDirCtx* ctx) FindClose(ctx->hFind); ctx->hFind = INVALID_HANDLE_VALUE; } + +#elif defined(INTIME_RTOS) + FindRtFileClose(&ctx->FindFileData); + #elif defined(WOLFSSL_ZEPHYR) if (ctx->dirp) { fs_closedir(ctx->dirp); diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 8a41f4b99..3c1021534 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -729,6 +729,8 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); M2MB_DIR_T* dir; struct M2MB_DIRENT* entry; struct M2MB_STAT s; + #elif defined(INTIME_RTOS) + FIND_FILE_DATA FindFileData; #else struct dirent* entry; DIR* dir;