From 379e1fb630edb6b89a9cea3aa7bc1b2517dc8d48 Mon Sep 17 00:00:00 2001 From: Elms Date: Thu, 1 Apr 2021 10:21:45 -0700 Subject: [PATCH 1/3] INTIME: support CRL for INTIME version < 6 --- wolfcrypt/src/wc_port.c | 20 ++++++++++---------- wolfssl/wolfcrypt/wc_port.h | 28 +++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 02a98b767..41616f887 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -508,14 +508,14 @@ int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name) XSTRNCPY(ctx->name, path, MAX_FILENAME_SZ - 3); XSTRNCPY(ctx->name + pathLen, "\\*", MAX_FILENAME_SZ - pathLen); - if (!FindFirstRtFile(ctx->name, &ctx->FindFileData, 0)) { + if (!IntimeFindFirst(ctx->name, &ctx->FindFileData)) { 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 (IntimeNormalFile(ctx)) { + dnameLen = (int)XSTRLEN(IntimeFilename(ctx)); if (pathLen + dnameLen + 2 > MAX_FILENAME_SZ) { return BAD_PATH_ERROR; @@ -523,13 +523,13 @@ int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name) XSTRNCPY(ctx->name, path, pathLen + 1); ctx->name[pathLen] = '\\'; XSTRNCPY(ctx->name + pathLen + 1, - ctx->FindFileData.cFileName, + IntimeFilename(ctx), MAX_FILENAME_SZ - pathLen - 1); if (name) *name = ctx->name; return 0; } - } while (FindNextRtFile(&ctx->FindFileData)); + } while (IntimeFindNext(&ctx->FindFileData)); #elif defined(WOLFSSL_ZEPHYR) if (fs_opendir(&ctx->dir, path) != 0) { @@ -656,9 +656,9 @@ int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name) } #elif defined(INTIME_RTOS) - while (FindNextRtFile(&ctx->FindFileData)) { - if (!(ctx->FindFileData.dwFileAttributes & FILE_ATTR_DIRECTORY)) { - dnameLen = (int)XSTRLEN(ctx->FindFileData.cFileName); + while (IntimeFindNext(&ctx->FindFileData)) { + if (IntimeNormalFile(ctx)) { + dnameLen = (int)XSTRLEN(IntimeFilename(ctx)); if (pathLen + dnameLen + 2 > MAX_FILENAME_SZ) { return BAD_PATH_ERROR; @@ -666,7 +666,7 @@ int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name) XSTRNCPY(ctx->name, path, pathLen + 1); ctx->name[pathLen] = '\\'; XSTRNCPY(ctx->name + pathLen + 1, - ctx->FindFileData.cFileName, + IntimeFilename(ctx), MAX_FILENAME_SZ - pathLen - 1); if (name) *name = ctx->name; @@ -758,7 +758,7 @@ void wc_ReadDirClose(ReadDirCtx* ctx) } #elif defined(INTIME_RTOS) - FindRtFileClose(&ctx->FindFileData); + IntimeFindClose(&ctx->FindFileData); #elif defined(WOLFSSL_ZEPHYR) if (ctx->dirp) { diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 291ff4d40..7dd98358a 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -699,6 +699,16 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); #define XSTAT _stat #define XS_ISREG(s) (s & _S_IFREG) #define SEPARATOR_CHAR ';' + + #elif defined(INTIME_RTOS) + #include + #define XSTAT _stat64 + #define XS_ISREG(s) S_ISREG(s) + #define SEPARATOR_CHAR ';' + #define XWRITE write + #define XREAD read + #define XCLOSE close + #elif defined(WOLFSSL_ZEPHYR) #define XSTAT fs_stat #define XS_ISREG(s) (s == FS_DIR_ENTRY_FILE) @@ -765,7 +775,23 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); struct M2MB_DIRENT* entry; struct M2MB_STAT s; #elif defined(INTIME_RTOS) - FIND_FILE_DATA FindFileData; + struct stat64 s; + #if defined(INTIMEVER) && INTIMEVER > 0x0600 + FIND_FILE_DATA FindFileData; + #define IntimeFindFirst(name, data) FindFirstRtFile(name, data, 0) + #define IntimeFindNext(data) FindNextRtFile(data) + #define IntimeFindClose(data) FindRtFileClose(data) + #define IntimeFilename(ctx) ctx->FindFileData.cFileName + #define IntimeNormalFile(ctx) (ctx->FindFileData.dwFileAttributes \ + & FILE_ATTR_NORMAL) + #else + struct _find64 FindFileData; + #define IntimeFindFirst(name, data) _findfirst64(name, data) + #define IntimeFindNext(data) _findnext64(data) + #define IntimeFindClose(data) _findclose64(data) + #define IntimeFilename(ctx) ctx->FindFileData.f_filename + #define IntimeNormalFile(ctx) (0 == wc_FileExists(IntimeFilename(ctx))) + #endif #else struct dirent* entry; DIR* dir; From 18eca4deffb9ec68e4a40ecfb205853fc7627625 Mon Sep 17 00:00:00 2001 From: Elms Date: Thu, 8 Apr 2021 10:23:26 -0700 Subject: [PATCH 2/3] INTIME: fix check returns Find{First,Next,Close} for version <6 --- wolfssl/wolfcrypt/wc_port.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 7dd98358a..0b41c3410 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -786,9 +786,9 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); & FILE_ATTR_NORMAL) #else struct _find64 FindFileData; - #define IntimeFindFirst(name, data) _findfirst64(name, data) - #define IntimeFindNext(data) _findnext64(data) - #define IntimeFindClose(data) _findclose64(data) + #define IntimeFindFirst(name, data) (0 == _findfirst64(name, data)) + #define IntimeFindNext(data) (0 == _findnext64(data)) + #define IntimeFindClose(data) (0 == _findclose64(data)) #define IntimeFilename(ctx) ctx->FindFileData.f_filename #define IntimeNormalFile(ctx) (0 == wc_FileExists(IntimeFilename(ctx))) #endif From 9dd5768ecc2605a4d6986f24e2ae56ed92f85464 Mon Sep 17 00:00:00 2001 From: Elms Date: Mon, 19 Apr 2021 22:34:31 -0700 Subject: [PATCH 3/3] Intime: simplify and fix stat on different directory --- wolfcrypt/src/wc_port.c | 40 ++++++++++++++++++------------------- wolfssl/wolfcrypt/wc_port.h | 21 +++++-------------- 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index 41616f887..79e742919 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -514,17 +514,17 @@ int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name) } do { - if (IntimeNormalFile(ctx)) { - dnameLen = (int)XSTRLEN(IntimeFilename(ctx)); + dnameLen = (int)XSTRLEN(IntimeFilename(ctx)); - 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, - IntimeFilename(ctx), - MAX_FILENAME_SZ - pathLen - 1); + 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, + IntimeFilename(ctx), + MAX_FILENAME_SZ - pathLen - 1); + if (0 == wc_FileExists(ctx->name)) { if (name) *name = ctx->name; return 0; @@ -657,17 +657,17 @@ int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name) #elif defined(INTIME_RTOS) while (IntimeFindNext(&ctx->FindFileData)) { - if (IntimeNormalFile(ctx)) { - dnameLen = (int)XSTRLEN(IntimeFilename(ctx)); + dnameLen = (int)XSTRLEN(IntimeFilename(ctx)); - 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, - IntimeFilename(ctx), - MAX_FILENAME_SZ - pathLen - 1); + 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, + IntimeFilename(ctx), + MAX_FILENAME_SZ - pathLen - 1); + if (0 == wc_FileExists(ctx->name)) { if (name) *name = ctx->name; return 0; diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index 0b41c3410..81616e3a7 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -776,22 +776,11 @@ WOLFSSL_API int wolfCrypt_Cleanup(void); struct M2MB_STAT s; #elif defined(INTIME_RTOS) struct stat64 s; - #if defined(INTIMEVER) && INTIMEVER > 0x0600 - FIND_FILE_DATA FindFileData; - #define IntimeFindFirst(name, data) FindFirstRtFile(name, data, 0) - #define IntimeFindNext(data) FindNextRtFile(data) - #define IntimeFindClose(data) FindRtFileClose(data) - #define IntimeFilename(ctx) ctx->FindFileData.cFileName - #define IntimeNormalFile(ctx) (ctx->FindFileData.dwFileAttributes \ - & FILE_ATTR_NORMAL) - #else - struct _find64 FindFileData; - #define IntimeFindFirst(name, data) (0 == _findfirst64(name, data)) - #define IntimeFindNext(data) (0 == _findnext64(data)) - #define IntimeFindClose(data) (0 == _findclose64(data)) - #define IntimeFilename(ctx) ctx->FindFileData.f_filename - #define IntimeNormalFile(ctx) (0 == wc_FileExists(IntimeFilename(ctx))) - #endif + struct _find64 FindFileData; + #define IntimeFindFirst(name, data) (0 == _findfirst64(name, data)) + #define IntimeFindNext(data) (0 == _findnext64(data)) + #define IntimeFindClose(data) (0 == _findclose64(data)) + #define IntimeFilename(ctx) ctx->FindFileData.f_filename #else struct dirent* entry; DIR* dir;