From 1dfc10ef3588f86ab3a44e278002c1eb1c679eba Mon Sep 17 00:00:00 2001 From: gojimmypi Date: Tue, 12 Nov 2024 10:39:55 -0800 Subject: [PATCH] Add Windows build support --- .gitignore | 9 ++ README.md | 313 +++++++++++++++++++++++++++++++++++++ addon/wolfcrypt/ecc.cpp | 70 +++++++-- addon/wolfcrypt/h/pbkdf2.h | 4 +- binding.gyp | 44 ++++-- lib/README.md | 8 + lib/user_settings.h | 151 ++++++++++++++++++ my_test.ps1 | 5 + setup_env.bat | 2 + setup_env.ps1 | 87 +++++++++++ test.js | 2 + 11 files changed, 671 insertions(+), 24 deletions(-) create mode 100644 lib/README.md create mode 100644 lib/user_settings.h create mode 100644 my_test.ps1 create mode 100644 setup_env.bat create mode 100644 setup_env.ps1 diff --git a/.gitignore b/.gitignore index 4e92739..8c7a01e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,12 @@ node_modules/* build/* package-lock.json + +# Ignore directories +**/.vs +**/bin +**/obj +**/node_modules + +# Ignore files +*.bak diff --git a/README.md b/README.md index a48b66e..9d8802d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # wolfCrypt Node.JS support +## Requirements + +[Node.js](https://nodejs.org/en/download/package-manager) + + +[npx](https://docs.npmjs.com/cli/v8/commands/npx) + + ## Description This Node.js module exposes various wolfCrypt native C functions to Node.js using the Napi library. It makes wolfCrypt functions for ECC, EVP, HMAC, PBKDF2, PKCS7, RSA and SHA available within Nodejs and also provides interface classes that streamline a lot of the tedious actions required when using these functions. @@ -217,6 +225,311 @@ const { wolfcrypt, WolfSSLEncryptionStream } = require( 'wolfcrypt_nodejs' ) ... ``` +## Visual Studio + +Use the local [./lib/user_settings.h](./lib/user_settings.h); Copy it to your `/IDE/Win` directory (or wherever your wolfssl binaries will be). +See the `wolfssl-VS2022.vcxproj` Project File in the root of your wolfSSL source. + +The [setup_env.ps1](./setup_env.ps1) or [setup_env.bat](./setup_env.bat) script can be used to setup the NodeJS/NPM environment. + +## wolfSSL Source Code + +The Windows Visual Studio environment assumes that wolfSSL source code repository is available. If not: + +From DOS: + +```dos +cd C:\workspace + +:: Fetch this repo from your fork: +git lone https://github.com/%USERNAME%/wolfcrypt_nodejs.git + +:: Fetch wolfssl from your fork: +git clone https://github.com/%USERNAME%/wolfssl.git "wolfssl-%USERNAME%" + +cd "wolfssl-%USERNAME%" +git remote add upstream https://github.com/wolfSSL/wolfssl.git +``` + +From Powershell: + +``` Powershell +cd C:\workspace +$USERNAME = $env:USERNAME + +# Fetch this repo from your fork: +git lone https://github.com/$USERNAME/wolfcrypt_nodejs.git + +# Fetch wolfssl from your fork: +git clone "https://github.com/$USERNAME/wolfssl.git" "wolfssl-$USERNAME" + +cd "wolfssl-$USERNAME" +git remote add upstream https://github.com/wolfSSL/wolfssl.git +``` + +Script preference will be given first for the directory name `wolfssl-`, then `wolfssl` + +### Environment Variable Settings + +For the `binding.gyp`: + +* `WOLFSSL_LIB_PATH` location of the wolfSSL compiled lib file, default: `C:/workspace/wolfssl/DLL Release/x64` +* `WOLFSSL_INCLUDE_PATH` location of wolfssl include directory, default: `C:/workspace/wolfssl` +* `WOLFSSL_USER_SETTINGS_PATH` location of wolfssl `user_settings.h` default: `C:/workspace/wolfssl/IDE/WIN` + +Important: Ensure the same `user_settings.h` used to compile wolfSSL is referenced from this NodeJS module! + +DOS + +```dos +set WOLFSSL_LIB_PATH=C:/workspace/wolfssl-%USERNAME%/DLL Release/x64 +set WOLFSSL_INCLUDE_PATH=C:/workspace/wolfssl-%USERNAME% +set WOLFSSL_USER_SETTINGS_PATH=C:/workspace/wolfssl-%USERNAME%/IDE/WIN + +set PATH=%PATH%;%WOLFSSL_LIB_PATH% +``` + +PowerShell + +```ps +$env:WOLFSSL_LIB_PATH = "C:/workspace/wolfssl-$env:USERNAME/DLL Release/x64" +$env:WOLFSSL_INCLUDE_PATH = "C:/workspace/wolfssl-$env:USERNAME" +$env:WOLFSSL_USER_SETTINGS_PATH = "C:/workspace/wolfssl-$env:USERNAME/IDE/WIN" + +$env:PATH += ";$env:WOLFSSL_LIB_PATH" +``` + +## Visual Studio 2022 + +See: + +* [Tutorial: Node.js for Beginners](https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-nodejs?view=vs-2022) +* [Tutorial: Create a Node.js and Express app in Visual Studio](https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-nodejs?view=vs-2022) + +```powershell +winget install Schniz.fnm +``` + +Ensure the architecture compiled in Visual Studio matches that in `node`: see `node -p "process.arch"` + +```powershell +fnm env --use-on-cd | Out-String | Invoke-Expression +fnm use --install-if-missing 20 +node -v # should print `v20.18.0` +npx -v # should print `10.8.2` + +# Launch VS2022 from the same shell: +& "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe" +``` + +Use the [IDE/WIN10/user_settings.h](https://github.com/wolfSSL/wolfssl/blob/master/IDE/WIN10/user_settings.h) file and +ensure these items are defined: + +```c +/* npm */ +#define NPM_WOLFCRYPT +#ifdef NPM_WOLFCRYPT + #undef HAVE_PKCS7 + #define HAVE_PKCS7 + #define HAVE_AES_KEYWRAP + #define WOLFSSL_AES_DIRECT + #define HAVE_X963_KDF + #define WOLFSSL_SHA224 + #define WOLFSSL_KEY_GEN + #define HAVE_ECC + #define ECC_MAX_BITS 521 + #define WC_ECC256 + #define WC_ECC384 + #define WC_ECC521 + #define HAVE_ECC_ENCRYPT + #define WOLFSSL_UINT128_T_DEFINED + /* #define WC_RNG_SEED_CB */ +#endif +``` + +There's also a reference file included in the [./lib](./lib) directory [here](./lib/user_settings.h). + +See [wolfssl PR #8090](https://github.com/wolfSSL/wolfssl/pull/8090) that adds Visual Studio 2022 project files. + +Build wolfssl using Visual Studio and see the resulting files as noted in output: + +``` +1> Creating library C:\workspace\wolfssl-gojimmypi-win\DLL Release\x64\wolfssl-VS2022.lib and object C:\workspace\wolfssl-gojimmypi-win\DLL Release\x64\wolfssl-VS2022.exp +1>Generating code +1>0 of 3869 functions ( 0.0%) were compiled, the rest were copied from previous compilation. +1> 0 functions were new in current compilation +1> 0 functions had inline decision re-evaluated but remain unchanged +1>Finished generating code +1>wolfssl-VS2022.vcxproj -> C:\workspace\wolfssl-gojimmypi-win\DLL Release\x64\wolfssl-VS2022.dll +========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== +========== Build completed at 3:32 PM and took 12.825 seconds ========== +``` + +In the above case, using the [root level project `wolfssl-VS2022.vcxproj`](https://github.com/wolfSSL/wolfssl/blob/master/wolfssl-VS2022.vcxproj), +select "DLL Release" build option; upon building the output binaries files should be found in +`C:\workspace\wolfssl-%USERNAME%\DLL Release\x64\wolfssl-VS2022.lib`. + +It is best to convert the Windows `\` to `/`. + +If instead conpiled with the `wolfcrypt/test` app, the lib file will be in: + +`C:/workspace/wolfssl-%USERNAME%/wolfcrypt/test/DLL Release/x64/wolfssl-VS2022.lib` + +if this ` error C2065: 'TI': undeclared identifier` is encountered, ensure the `user_settings.h` mentioned above is used, +in particular the `#define WOLFSSL_UINT128_T_DEFINED`. + +``` + nothing.vcxproj -> C:\workspace\wolfcrypt_nodejs-gojimmypi\build\Release\\nothing.lib + main.cpp +C:\workspace\wolfssl-gojimmypi-win\wolfssl\wolfcrypt\sp_int.h(257,44): error C2146: syntax error: missing ';' before identifier '__attribute__' [C:\workspace\wolfcrypt_ +nodejs-gojimmypi\build\wolfcrypt.vcxproj] + (compiling source file '../addon/wolfcrypt/main.cpp') + +C:\workspace\wolfssl-gojimmypi-win\wolfssl\wolfcrypt\sp_int.h(257,65): error C2065: 'TI': undeclared identifier [C:\workspace\wolfcrypt_nodejs-gojimmypi\build\wolfcrypt +.vcxproj] + (compiling source file '../addon/wolfcrypt/main.cpp') +``` + + +If this error is observed (missing `wolfssl/options.h`), see [wolfSSL install](https://github.com/wolfSSL/wolfssl/blob/master/INSTALL). +Determine if the `WOLFSSL_USER_SETTINGS` preprocessor directive has been defined. + +```text +gyp info spawn args ] + + nothing.c + win_delay_load_hook.cc + nothing.vcxproj -> C:\workspace\wolfcrypt_nodejs-gojimmypi\build\Release\\nothing.lib + main.cpp +C:\workspace\wolfcrypt_nodejs-gojimmypi\addon\wolfcrypt\h\evp.h(25,10): error C1083: Cannot open include file: 'wolfssl/options.h': No such file or directory [C +:\workspace\wolfcrypt_nodejs-gojimmypi\build\wolfcrypt.vcxproj] + (compiling source file '../addon/wolfcrypt/main.cpp') + +gyp ERR! build error +gyp ERR! stack Error: `C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1 +gyp +``` + +If this `Error: The specified module could not be found.` is observed: + +```text +C:\workspace\wolfcrypt_nodejs-gojimmypi>npm run test + +> wolfcrypt@1.0.3 test +> node test.js + +node:internal/modules/cjs/loader:1586 + return process.dlopen(module, path.toNamespacedPath(filename)); + ^ + +Error: The specified module could not be found. +\\?\C:\workspace\wolfcrypt_nodejs-gojimmypi\build\Release\wolfcrypt.node + at Module._extensions..node (node:internal/modules/cjs/loader:1586:18) + at Module.load (node:internal/modules/cjs/loader:1288:32) + at Module._load (node:internal/modules/cjs/loader:1104:12) + at Module.require (node:internal/modules/cjs/loader:1311:19) + at require (node:internal/modules/helpers:179:18) + at Object. (C:\workspace\wolfcrypt_nodejs-gojimmypi\interfaces\ecc.js:21:19) + at Module._compile (node:internal/modules/cjs/loader:1469:14) + at Module._extensions..js (node:internal/modules/cjs/loader:1548:10) + at Module.load (node:internal/modules/cjs/loader:1288:32) + at Module._load (node:internal/modules/cjs/loader:1104:12) { + code: 'ERR_DLOPEN_FAILED' +} + +Node.js v20.18.0 +``` + +Ensure the DLL can be found, either copied locally or in the DOS path: + +```dos +:: set your location of the wolfSSL root directory: +set WOLFSSL_ROOT=C:\workspace\wolfssl-%USERNAME% + +:: if using the DLL Release from an example, such as the wolfcrypt test: +set PATH=%PATH%;%WOLFSSL_ROOT%\wolfcrypt\test\DLL Release\x64\ + +:: otherwise set to root-level project; Be sure DLL Release was successfuly built and the file exists: +set PATH=%PATH%;%WOLFSSL_ROOT%\DLL Release\x64\ +``` + +Or when using PowerShell: + +```ps +# set WOLFSSL_ROOT to c:\workspace\wolfssl-[your login name] + +$env:WOLFSSL_ROOT = "C:\workspace\wolfssl-$env:USERNAME" +$env:PATH += ";$env:WOLFSSL_ROOT\DLL Release\x64" + +# Check the current path +$env:PATH -split ";" +``` + +When encountering `cannot open input file... wolfssl[-VS2022].lib` like this: + +``` +LINK : fatal error LNK1181: cannot open input file 'C:\workspace\wolfssl\DLL Released\wolfssl-VS2022.lib' [C:\workspace\wolfcrypt_nodejs\build\wolfcrypt.vcxproj] +``` + +Ensure the `DLL Release` build was selected and that the `[wolfssl root]\DLL Release\x64\wolfssl-VS2022.lib` file exists; build with the wolfSSL project and confirm build was successful: + +``` +1>Finished generating code +1>wolfssl-VS2022.vcxproj -> C:\workspace\wolfssl\DLL Release\x64\wolfssl-VS2022.dll +========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ========== +========== Rebuild completed at 6:08 PM and took 17.377 seconds ========== +``` + +For the error: `LINK : fatal error LNK1181: cannot open input file '\DLL Release\x64\wolfssl.lib' ` like this: + +``` + win_delay_load_hook.cc +LINK : fatal error LNK1181: cannot open input file 'C:\workspace\wolfssl-gojimmypi\DLL Release\x64\wolfssl.lib' [C:\workspace\wolfcrypt_nodejs-gojimmypi\build\wolfcrypt.vcxproj] +gyp ERR! build error +gyp ERR! stack Error: `C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1 +gyp ERR! stack at ChildProcess.onExit (C:\workspace\wolfcrypt_nodejs-gojimmypi\node_modules\node-gyp\lib\build.js:203:23) +gyp ERR! stack at ChildProcess.emit (node:events:519:28) +gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:294:12) +``` + +Ensure wolfSSL has been build with the `DLL Release` build option and that the files exist in `\DLL Release\x64\`. + + +Also ensure the `binding.gyp` file uses _forward slashes_, (or double backslashes). Not just a single backslash. + +``` + ['OS=="win"', { + "libraries": [ + "C:/workspace/wolfssl-gojimmypi-win/DLL Release/x64/wolfssl-VS2022.lib", +``` + +### wolfSSL Configuration Notes + +Note that the `options.h` definition should match those from the compiled lib file that used the respective +Windows [user_settings.h](https://github.com/gojimmypi/wolfssl/blob/master/IDE/WIN10/user_settings.h). + + +Clean build: + +```powershell +npm run clean +node-gyp clean +node-gyp rebuild +``` + +See the `my_test.ps1` script that also includes: + +``` +npm i +npm run test +``` + +Run it like this: + +``` +powershell -ExecutionPolicy Bypass -File .\my_test.ps1 +``` + ## Tests Output ``` diff --git a/addon/wolfcrypt/ecc.cpp b/addon/wolfcrypt/ecc.cpp index 047a7a4..9ecf850 100644 --- a/addon/wolfcrypt/ecc.cpp +++ b/addon/wolfcrypt/ecc.cpp @@ -19,6 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ #include "./h/ecc.h" +#include +#include Napi::Number sizeof_ecc_key(const Napi::CallbackInfo& info) { @@ -64,7 +66,13 @@ Napi::Number bind_wc_ecc_make_key(const Napi::CallbackInfo& info) int ret; int key_size = info[0].As().Int32Value(); ecc_key* ecc = (ecc_key*)( info[1].As().Data() ); - + WC_RNG rng; + ret = wc_InitRng(&rng); + if (ret < 0) { + printf("Failed to bind_wc_ecc_make_key wc_InitRng ret = %d\n", ret); + return Napi::Number::New(env, ret); // Return error code + } + printf("wc_ecc_make_key..."); ret = wc_ecc_make_key( ecc->rng, key_size, ecc ); return Napi::Number::New( env, ret ); @@ -250,25 +258,61 @@ Napi::Number bind_wc_ecc_set_curve(const Napi::CallbackInfo& info) return Napi::Number::New( env, ret ); } +void print_hex(const char* label, const uint8_t* data, size_t len) +{ + int n = 0; + printf("%s:\n", label); + for (size_t i = 0; i < len; i++) { + printf("%02X ", data[i]); + n++; + if (n > 15) { + printf("\n"); + n = 0; + } + } + printf("\n"); +} + + Napi::Number bind_wc_ecc_shared_secret(const Napi::CallbackInfo& info) { - Napi::Env env = info.Env(); - int ret; - ecc_key* private_key = (ecc_key*)( info[0].As().Data() ); - ecc_key* public_key = (ecc_key*)( info[1].As().Data() ); - uint8_t* out = info[2].As().Data(); - unsigned int out_len = info[3].As().Uint32Value(); + Napi::Env env = info.Env(); + int ret; + ecc_key* private_key = (ecc_key*)( info[0].As().Data() ); + ecc_key* public_key = (ecc_key*)( info[1].As().Data() ); + + int key_len = 255; +#ifdef DEBUG_WOLFSSL + print_hex("\n\nPrivate Key", (const uint8_t*)private_key, key_len); + + print_hex("\n\nPublic Key ", (const uint8_t*)public_key, key_len); +#endif + /* Alternatively call wolfSSL_Init() or comparable API */ + /* Mandatory with FIPS, will also trigger DRBG CAST */ +#ifdef WC_RNG_SEED_CB + wc_SetSeed_Cb(wc_GenerateSeed); +#endif + uint8_t* out = info[2].As().Data(); + unsigned int out_len = info[3].As().Uint32Value(); PRIVATE_KEY_UNLOCK(); ret = wc_ecc_shared_secret( private_key, public_key, out, &out_len ); PRIVATE_KEY_LOCK(); - if ( ret < 0 ) - { - out_len = ret; - } - - return Napi::Number::New( env, (int)out_len ); + if ( ret < 0 ) + { + out_len = ret; +#ifdef DEBUG_WOLFSSL + printf("\n\nwc_ecc_shared_secret error %d\n", ret); +#endif + } + else + { +#ifdef DEBUG_WOLFSSL + printf("\n\nwc_ecc_shared_secret success"); +#endif + } + return Napi::Number::New(env, (int)out_len); } Napi::Number bind_wc_ecc_sig_size(const Napi::CallbackInfo& info) diff --git a/addon/wolfcrypt/h/pbkdf2.h b/addon/wolfcrypt/h/pbkdf2.h index 9e30645..b439528 100644 --- a/addon/wolfcrypt/h/pbkdf2.h +++ b/addon/wolfcrypt/h/pbkdf2.h @@ -19,7 +19,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ #include -#include "wolfssl/options.h" +#ifndef WOLFSSL_USER_SETTINGS + #include +#endif #include #include diff --git a/binding.gyp b/binding.gyp index 20ac163..aed3f8a 100644 --- a/binding.gyp +++ b/binding.gyp @@ -14,20 +14,44 @@ "addon/wolfcrypt/pkcs7.cpp", "addon/wolfcrypt/pkcs12.cpp" ], - 'include_dirs': [ + "include_dirs": [ "\IDE\WIN`. + +See PR [#8090](https://github.com/wolfSSL/wolfssl/pull/8090) and +the [VS2022 project file](https://github.com/gojimmypi/wolfssl/blob/pr-visual-studio-2022/wolfssl-VS2022.vcxproj). diff --git a/lib/user_settings.h b/lib/user_settings.h new file mode 100644 index 0000000..af333af --- /dev/null +++ b/lib/user_settings.h @@ -0,0 +1,151 @@ +#ifndef _WIN_USER_SETTINGS_H_ +#define _WIN_USER_SETTINGS_H_ + +/* Verify this is Windows */ +#ifndef _WIN32 +#error This user_settings.h header is only designed for Windows +#endif + +#define USE_WOLFSSL_IO +#define HAVE_AESGCM +#define WOLFSSL_TLS13 +#define HAVE_HKDF +#define HAVE_FFDHE_4096 +#define WC_RSA_PSS +#define WOLFSSL_DTLS +#define WOLFSSL_DTLS13 +#define WOLFSSL_SEND_HRR_COOKIE +#define WOLFSSL_DTLS_CID + +/* npm */ +#define NPM_WOLFCRYPT +#ifdef NPM_WOLFCRYPT + /* Optional debug */ + /* #define DEBUG_WOLFSSL */ + + /* Optional RNG */ + /* #define WC_RNG_SEED_CB */ + + #define HAVE_PKCS7 + #define HAVE_AES_KEYWRAP + #define WOLFSSL_AES_DIRECT + #define HAVE_X963_KDF + #define WOLFSSL_SHA224 + #define WOLFSSL_KEY_GEN + #define HAVE_ECC + #define ECC_MAX_BITS 521 + #define WC_ECC256 + #define WC_ECC384 + #define WC_ECC521 + #define HAVE_ECC_ENCRYPT + #define WOLFSSL_UINT128_T_DEFINED + #define WOLFSSL_SHA512 + #define WOLFSSL_SHA384 + #define WOLFSSL_SHA3 + + #define NO_OLD_RNGNAME + #define TFM_TIMING_RESISTANT + #define ECC_TIMING_RESISTANT + #define WC_RSA_BLINDING + #define TFM_ECC256 + #define ECC_SHAMIR + #define ECC_MIN_KEY_SZ 224 + #define HAVE_ECC_BRAINPOOL + #define HAVE_CURVE25519 + #define FP_ECC + #define HAVE_ECC_ENCRYPT + #define WOLFCRYPT_HAVE_ECCSI + #define WOLFSSL_CUSTOM_CURVES +#endif + +/* Configurations */ +#if defined(HAVE_FIPS) + /* FIPS */ + #define OPENSSL_EXTRA + #define HAVE_THREAD_LS + #define WOLFSSL_KEY_GEN + #define HAVE_HASHDRBG + #define WOLFSSL_SHA384 + #define WOLFSSL_SHA512 + #define NO_PSK + #define NO_RC4 + #define NO_DSA + #define NO_MD4 + + #define GCM_NONCE_MID_SZ 12 +#else + /* Enables blinding mode, to prevent timing attacks */ + #define WC_RSA_BLINDING + #define NO_MULTIBYTE_PRINT + + #define HAVE_CRL + #define HAVE_CRL_MONITOR + + #if defined(WOLFSSL_LIB) + /* The lib */ + #define OPENSSL_EXTRA + #define WOLFSSL_RIPEMD + #define NO_PSK + #define HAVE_EXTENDED_MASTER + #define WOLFSSL_SNIFFER + #define HAVE_SECURE_RENEGOTIATION + + #define HAVE_AESGCM + #define WOLFSSL_AESGCM_STREAM + #define WOLFSSL_SHA384 + #define WOLFSSL_SHA512 + + #define HAVE_SUPPORTED_CURVES + #define HAVE_TLS_EXTENSIONS + + #define HAVE_ECC + #define ECC_SHAMIR + #define ECC_TIMING_RESISTANT + + #define WOLFSSL_SP_X86_64 + #define SP_INT_BITS 4096 + + /* Optional Performance Speedups */ + #if 0 + /* AESNI on x64 */ + #ifdef _WIN64 + #define HAVE_INTEL_RDSEED + #define WOLFSSL_AESNI + #define HAVE_INTEL_AVX1 + #if 0 + #define HAVE_INTEL_AVX2 + #endif + + #define USE_INTEL_CHACHA_SPEEDUP + #define USE_INTEL_POLY1305_SPEEDUP + #endif + + /* Single Precision Support for RSA/DH 1024/2048/3072 and + * ECC P-256/P-384 */ + #define WOLFSSL_SP + #define WOLFSSL_HAVE_SP_ECC + #define WOLFSSL_HAVE_SP_DH + #define WOLFSSL_HAVE_SP_RSA + + #ifdef _WIN64 + /* Old versions of MASM compiler do not recognize newer + * instructions. */ + #if 0 + #define NO_AVX2_SUPPORT + #define NO_MOVBE_SUPPORT + #endif + #define WOLFSSL_SP_ASM + #define WOLFSSL_SP_X86_64_ASM + #endif + #endif + #else + /* The servers and clients */ + #define OPENSSL_EXTRA + #define NO_PSK + #endif +#endif /* HAVE_FIPS */ + + + + +#endif /* _WIN_USER_SETTINGS_H_ */ diff --git a/my_test.ps1 b/my_test.ps1 new file mode 100644 index 0000000..7dedd53 --- /dev/null +++ b/my_test.ps1 @@ -0,0 +1,5 @@ +npm run clean +node-gyp clean +node-gyp rebuild +npm i +npm run test \ No newline at end of file diff --git a/setup_env.bat b/setup_env.bat new file mode 100644 index 0000000..d520db5 --- /dev/null +++ b/setup_env.bat @@ -0,0 +1,2 @@ +@echo "Running .\setup_env.ps1 and staying in the powershell environment..." +powershell -NoExit -ExecutionPolicy Bypass -File .\setup_env.ps1 diff --git a/setup_env.ps1 b/setup_env.ps1 new file mode 100644 index 0000000..bf29d98 --- /dev/null +++ b/setup_env.ps1 @@ -0,0 +1,87 @@ +$ErrorActionPreference = "Stop" + +# Predefined Community, Professional, Enterprise versions of Visual Studio 2022 +$vsPathCommunity = "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe" +$vsPathProfessional = "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\devenv.exe" +$vsPathEnterprise = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\devenv.exe" + +if (Test-Path "C:/workspace/wolfssl-$env:USERNAME") { + $env:WOLFSSL_ROOT = "C:/workspace/wolfssl-$env:USERNAME" + $env:PATH += ";$env:WOLFSSL_ROOT\DLL Release\x64" + + Write-Output "Found wolfSSL at $env:WOLFSSL_ROOT" + $env:WOLFSSL_LIB_PATH = "$env:WOLFSSL_ROOT/DLL Release/x64" + $env:WOLFSSL_INCLUDE_PATH = "$env:WOLFSSL_ROOT" + $env:WOLFSSL_USER_SETTINGS_PATH = "$env:WOLFSSL_ROOT/IDE/WIN" + +} elseif (Test-Path "C:/workspace/wolfssl") { + $env:WOLFSSL_ROOT = "C:/workspace/wolfssl" + $env:PATH += ";$env:WOLFSSL_ROOT\DLL Release\x64" + + Write-Output "Found wolfSSL at $env:WOLFSSL_ROOT" + $env:WOLFSSL_LIB_PATH = "$env:WOLFSSL_ROOT/DLL Release/x64" + $env:WOLFSSL_INCLUDE_PATH = "$env:WOLFSSL_ROOT" + $env:WOLFSSL_USER_SETTINGS_PATH = "$env:WOLFSSL_ROOT/IDE/WIN" + +} else { + Write-Output "Could not find wolfSSL source directory." +} + + +Write-Output "WOLFSSL_LIB_PATH: $($env:WOLFSSL_LIB_PATH)" +Write-Output "WOLFSSL_INCLUDE_PATH: $($env:WOLFSSL_INCLUDE_PATH)" +Write-Output "WOLFSSL_USER_SETTINGS_PATH: $($env:WOLFSSL_USER_SETTINGS_PATH)" + +fnm env --use-on-cd | Out-String | Invoke-Expression +fnm use --install-if-missing 20 +node -v # should print `v20.18.0` +npx -v # should print `10.8.2` + +# Launch VS2022 from the same shell: +# Check if the file exists +if (Test-Path $vsPathEnterprise) { + # Run the file + Write-Output "Launching Visual Studio 2022 Enterprise at: $vsPathEnterprise" + Start-Process $vsPathEnterprise + +} elseif (Test-Path $vsPathProfessional) { + # Run the file + Write-Output "Launching Visual Studio 2022 Professional at: $vsPathProfessional" + Start-Process $vsPathProfessional + +} elseif (Test-Path $vsPathCommunity) { + # Run the file + Write-Output "Launching Visual Studio 2022 Community at: $vsPathCommunity" + Start-Process $vsPathCommunity + +} else { + Write-Output "Visual Studio 2022 executable not found." +} + +Write-Output "Clean..." +npm run clean +npx node-gyp clean + +Write-Output "Rebuild..." +npx node-gyp rebuild + +Write-Output "Install..." +npm install + +Write-Output "Test..." +npm run test + + +# One final check if the user_settings.h match +$File1 = Get-Content "$($env:WOLFSSL_USER_SETTINGS_PATH)/user_settings.h" +$File2 = Get-Content "./lib/user_settings.h" + +$diff = Compare-Object $File1 $File2 + +if ($diff) { + Write-Host "Warning: " + Write-Host "./lib/user_settings.h does not match" + Write-Host "$($env:WOLFSSL_USER_SETTINGS_PATH)/user_settings.h" +} else { + Write-Host "Confirmed reference ./lib/user_settings.h matches wolfSSL source." +} diff --git a/test.js b/test.js index a962490..458077e 100644 --- a/test.js +++ b/test.js @@ -23,6 +23,8 @@ const tests = require( './tests' ); (async function() { for ( const key of Object.keys( tests ) ) { + console.log("Running test: ", key) await tests[key]() + console.log("") } })()