From db28432515cf8c59541ad17deb6ddb79e6139dd9 Mon Sep 17 00:00:00 2001 From: sebbASF Date: Wed, 8 Nov 2023 00:57:15 +0000 Subject: [PATCH] Crypto 174 (#268) * Don't try to convert libraryPath * Fix up Windows defines --- .github/workflows/maven.yml | 16 +++++++--------- .../org/apache/commons/crypto/DynamicLoader.c | 5 +---- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 4fe5c7488..22f02cf2c 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -91,22 +91,20 @@ jobs: - name: OpenSSL engine (windows) # need to override the libarary on windows if: ${{ matrix.os == 'windows-latest' }} - # e.g. ENGINESDIR: "C:\Program Files\OpenSSL\lib\engines-1_1" - # The code below extracts "C:\Program Files\OpenSSL\lib", as expected - # but this does not seem to be the correct setting to override system library - # To avoid failing tests unnecessarily, skip the check for OpenSSL in the library name - # To be resolved... - # N.B. This must *not* be run under the bash shell, as that changes the default openssl library + # e.g. NAME: "libcrypto-1_1-x64.dll" + # Not sure how to derive this automatically run: | openssl version -a - chcp 65001 #set code page to utf-8 - echo ((openssl version -e) -replace ': "','=' -replace '\\engines-.*','') >> $env:GITHUB_ENV + echo "NAME=libcrypto-1_1-x64.dll" >> $env:GITHUB_ENV echo "CHECK_SKIP=skip" >> $env:GITHUB_ENV # N.B. '-V -B -ntp' is shorthand for '--show-version --batch-mode --no-transfer-progress' # # The bash shell under Windows changes the openssl default library, so is not used for running tests # Unfortunately that means separate steps for Windows, as it uses a different syntax for referrring to # environment variables: $env:VARNAME instead of $VARNAME + # Also, note that Windows stores all the DLLs in the same directory. + # Instead of defining jni.library.path and jna.library.path we need to define + # jni.library.name and commons.crypto.OpenSslNativeJna to override the file names - name: Build with Maven (Windows) if: ${{ matrix.os == 'windows-latest' }} # OPENSSL_HOME is needed for Windows build to find some header files @@ -119,7 +117,7 @@ jobs: env: OPENSSL_HOME: "C:\\Miniconda\\Library" run: | - mvn -V -B -ntp -DtrimStackTrace=false -D"jni.library.path=$env:ENGINESDIR" -D"jna.library.path=$env:ENGINESDIR" -D"commons.crypto.openssl.check=$env:CHECK_SKIP" + mvn -V -B -ntp -DtrimStackTrace=false -D"jni.library.name=$env:NAME" -D"commons.crypto.OpenSslNativeJna=$env:NAME" -D"commons.crypto.openssl.check=$env:CHECK_SKIP" - name: Build with Maven (not Windows) if: ${{ matrix.os != 'windows-latest' }} run: | diff --git a/src/main/native/org/apache/commons/crypto/DynamicLoader.c b/src/main/native/org/apache/commons/crypto/DynamicLoader.c index 57fff14ad..1f2656276 100644 --- a/src/main/native/org/apache/commons/crypto/DynamicLoader.c +++ b/src/main/native/org/apache/commons/crypto/DynamicLoader.c @@ -44,10 +44,7 @@ HMODULE open_library(JNIEnv *env) #endif #ifdef WINDOWS - size_t liblen = strlen(libraryPath) + 1; - wchar_t* lib = (wchar_t *)malloc(liblen); - mbstowcs(lib, libraryPath, liblen); // convert for Windows call - openssl = LoadLibrary(lib); + openssl = LoadLibraryA(libraryPath); // use the non-generic method; assume libraryPath is suitable #endif // Did we succeed?