From 379e1fb630edb6b89a9cea3aa7bc1b2517dc8d48 Mon Sep 17 00:00:00 2001 From: Elms Date: Thu, 1 Apr 2021 10:21:45 -0700 Subject: [PATCH] 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;