Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crypto 174 #268

Merged
merged 3 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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