Skip to content

Commit

Permalink
fixes for USE_WINDOWS_API && !NO_FILESYSTEM && !NO_WOLFSSL_DIR:
Browse files Browse the repository at this point in the history
* in wc_port.h, add XWRITE and XREAD definitions and include <io.h>;
* in wolfSSL_BIO_read(), implement Windows support for XREAD and XWRITE;
* in wolfSSL_BIO_write_filename(), add 'b' flag to XFOPEN flags;
* in wolfSSL_RAND_file_name(), add support for XALTHOMEVARNAME, and add Windows definition for it to wc_port.h alongside XWRITE and XREAD.

fixes test_wolfSSL_BIO, test_wolfSSL_X509_print, test_wolfSSL_RAND, test_wolfSSL_RSA_print in cross-mingw-all-crypto scenario.
  • Loading branch information
douzzer committed Jun 6, 2024
1 parent 71db561 commit ac5caba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/bio.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ int wolfSSL_BIO_read(WOLFSSL_BIO* bio, void* buf, int len)
ret = (int)XFREAD(buf, 1, (size_t)len, (XFILE)bio->ptr);
}
else {
#if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR) && \
#if defined(XREAD) && !defined(NO_WOLFSSL_DIR) && \
!defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
ret = (int)XREAD(bio->num, buf, (size_t)len);
#else
Expand Down Expand Up @@ -682,7 +682,7 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len)
ret = (int)XFWRITE(data, 1, (size_t)len, (XFILE)bio->ptr);
}
else {
#if !defined(USE_WINDOWS_API) && !defined(NO_WOLFSSL_DIR) && \
#if defined(XWRITE) && !defined(NO_WOLFSSL_DIR) && \
!defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
ret = (int)XWRITE(bio->num, data, (size_t)len);
#else
Expand Down Expand Up @@ -1617,7 +1617,12 @@ int wolfSSL_BIO_write_filename(WOLFSSL_BIO *bio, char *name)
XFCLOSE((XFILE)bio->ptr);
}

bio->ptr = XFOPEN(name, "w");
/* 'b' flag is ignored on POSIX targets, but on Windows it assures
* inhibition of LF<->CRLF rewriting, so that there is consistency
* between the size and contents of the representation in memory and on
* disk.
*/
bio->ptr = XFOPEN(name, "wb");
if (((XFILE)bio->ptr) == XBADFILE) {
return WOLFSSL_FAILURE;
}
Expand Down
11 changes: 10 additions & 1 deletion src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -23701,9 +23701,18 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
const char ap[] = "/.rnd";

WOLFSSL_MSG("Environment variable RANDFILE not set");

if ((rt = XGETENV("HOME")) == NULL) {
#ifdef XALTHOMEVARNAME
if ((rt = XGETENV(XALTHOMEVARNAME)) == NULL) {
WOLFSSL_MSG("Environment variable HOME and " XALTHOMEVARNAME
" not set");
return NULL;
}
#else
WOLFSSL_MSG("Environment variable HOME not set");
return NULL;
#endif
}

if (len > XSTRLEN(rt) + XSTRLEN(ap)) {
Expand All @@ -23713,7 +23722,7 @@ const char* wolfSSL_RAND_file_name(char* fname, unsigned long len)
return fname;
}
else {
WOLFSSL_MSG("HOME too large for buffer");
WOLFSSL_MSG("Path too large for buffer");
return NULL;
}
}
Expand Down
4 changes: 4 additions & 0 deletions wolfssl/wolfcrypt/wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,16 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void);
#if !defined(NO_WOLFSSL_DIR)\
&& !defined(WOLFSSL_NUCLEUS) && !defined(WOLFSSL_NUCLEUS_1_2)
#if defined(USE_WINDOWS_API)
#include <io.h>
#include <sys/stat.h>
#ifndef XSTAT
#define XSTAT _stat
#endif
#define XS_ISREG(s) (s & _S_IFREG)
#define SEPARATOR_CHAR ';'
#define XWRITE _write
#define XREAD _read
#define XALTHOMEVARNAME "USERPROFILE"

#elif defined(ARDUINO)
#ifndef XSTAT
Expand Down

0 comments on commit ac5caba

Please sign in to comment.