Skip to content

Commit

Permalink
Merge pull request #683 from jasonkatonica/katonica/issue17577/openss…
Browse files Browse the repository at this point in the history
…l3libraries

Allow loading of OpenSSL 3.x native library for Mac, Windows and AIX
  • Loading branch information
pshipton authored Aug 21, 2023
2 parents 36ba274 + 1089383 commit f908ec9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2019, 2022 All Rights Reserved
* (c) Copyright IBM Corp. 2019, 2023 All Rights Reserved
* ===========================================================================
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -43,11 +43,16 @@ void * load_crypto_library(jboolean traceEnabled)
// Library names for OpenSSL 3.x, 1.1.1, 1.1.0, 1.0.2 and symbolic links
static const char * const libNames[] = {
#if defined(_AIX)
"libcrypto.a(libcrypto64.so.3)",
"libcrypto64.so.3",
"libcrypto.a(libcrypto.so.3)",
"libcrypto.so.3",
"libcrypto.a(libcrypto64.so.1.1)",
"libcrypto.so.1.1",
"libcrypto.so.1.0.0",
"libcrypto.a(libcrypto64.so)",
#elif defined(MACOSX)
"libcrypto.3.dylib",
"libcrypto.1.1.dylib",
"libcrypto.1.0.0.dylib",
"libcrypto.dylib"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2019, 2022 All Rights Reserved
* (c) Copyright IBM Corp. 2019, 2023 All Rights Reserved
* ===========================================================================
*/

Expand All @@ -46,36 +46,40 @@ static int JLI_Snprintf(char* buffer, size_t size, const char* format, ...);
/* Load the crypto library (return NULL on error) */
void * load_crypto_library(jboolean traceEnabled) {
void * result = NULL;
const char *libname;
const char *oldname = "libeay32.dll";
char opensslpath[MAX_PATH];

#if defined (_WIN64)
libname = "libcrypto-1_1-x64.dll";
static const char * const libNames[] = {
"libcrypto-3-x64.dll",
"libcrypto-1_1-x64.dll"
};
#else
libname = "libcrypto-1_1.dll";
static const char * const libNames[] = {
"libcrypto-3.dll",
"libcrypto-1_1.dll",
"libeay32.dll"
};
#endif

size_t i = 0;
if (GetJREPath(opensslpath, MAX_PATH)) {
char libpathname[MAX_PATH];
int rc;
struct stat s;

rc = JLI_Snprintf(libpathname, sizeof(libpathname), "%s\\bin\\%s", opensslpath, libname);
if ((rc > 0) && (rc <= MAX_PATH) && (stat(libpathname, &s) == 0)) {
result = LoadLibrary(libpathname);
}
if (result == NULL) {
rc = JLI_Snprintf(libpathname, sizeof(libpathname), "%s\\bin\\%s", opensslpath, oldname);
// Check to see if we can load the libraries in the order set out above
for (i = 0; (NULL == result) && (i < sizeof(libNames) / sizeof(libNames[0])); i++) {
const char * libraryName = libNames[i];
rc = JLI_Snprintf(libpathname, sizeof(libpathname), "%s\\bin\\%s", opensslpath, libraryName);
if ((rc > 0) && (rc <= MAX_PATH) && (stat(libpathname, &s) == 0)) {
result = LoadLibrary(libpathname);
}
}
} else {
result = LoadLibrary(libname);

if (result == NULL) {
result = LoadLibrary(oldname);
// Check to see if we can load the libraries in the order set out above
for (i = 0; (NULL == result) && (i < sizeof(libNames) / sizeof(libNames[0])); i++) {
const char * libraryName = libNames[i];
result = LoadLibrary(libraryName);
}
}
return result;
Expand Down
4 changes: 2 additions & 2 deletions jdk/make/CopyFiles.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#

# ===========================================================================
# (c) Copyright IBM Corp. 2018, 2022 All Rights Reserved
# (c) Copyright IBM Corp. 2018, 2023 All Rights Reserved
# ===========================================================================

INCLUDEDIR = $(JDK_OUTPUTDIR)/include
Expand Down Expand Up @@ -234,7 +234,7 @@ ifneq ($(OPENSSL_BUNDLE_LIB_PATH), )
# instead of 'libcrypto.so' files.
# For reference, corresponding OpenSSL PR is
# https://github.com/openssl/openssl/pull/6487
LIBCRYPTO_NAMES := libcrypto.so.3 libcrypto.so.1.1 libcrypto.so.1.0.0 libcrypto.a
LIBCRYPTO_NAMES := libcrypto64.so.3 libcrypto.so.3 libcrypto.so.1.1 libcrypto.so.1.0.0
else
LIBCRYPTO_NAMES := libcrypto.so
endif
Expand Down

0 comments on commit f908ec9

Please sign in to comment.