Skip to content

Commit

Permalink
Crypto 174 (#268)
Browse files Browse the repository at this point in the history
* Don't try to convert libraryPath

* Fix up Windows defines
  • Loading branch information
sebbASF authored Nov 8, 2023
1 parent 7e6f540 commit db28432
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: |
Expand Down
5 changes: 1 addition & 4 deletions src/main/native/org/apache/commons/crypto/DynamicLoader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit db28432

Please sign in to comment.