Skip to content

Commit 087ffa5

Browse files
committed
Rename bundled openssl libraries
OpenSSL libraries that are bundled within the runtime are being renamed to avoid conflicts with system libraries that may have the same name. Additional updates were made to the loading logic associated with native cryptography to make use of the correct bundled version by default. Signed-off-by: Jason Katonica <[email protected]>
1 parent eccd019 commit 087ffa5

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

closed/custom/modules/java.base/Copy.gmk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ ifneq ($(OPENSSL_BUNDLE_LIB_PATH), )
227227
$(error Cannot bundle OpenSSL - none of $(LIBCRYPTO_NAMES) are present in $(OPENSSL_BUNDLE_LIB_PATH))
228228
endif
229229

230-
LIBCRYPTO_TARGET_LIB := $(LIB_DST_DIR)/$(notdir $(LIBCRYPTO_PATH))
230+
LIBCRYPTO_TARGET_LIB := $(LIB_DST_DIR)/$(LIBRARY_PREFIX)crypto-semeru$(SHARED_LIBRARY_SUFFIX)
231231
TARGETS += $(LIBCRYPTO_TARGET_LIB)
232232
$(LIBCRYPTO_TARGET_LIB) : $(LIBCRYPTO_PATH)
233233
$(call install-file)
@@ -245,7 +245,7 @@ ifneq ($(OPENSSL_BUNDLE_LIB_PATH), )
245245
LIBSSL_PATH := $(firstword $(wildcard $(addprefix $(OPENSSL_BUNDLE_LIB_PATH)/, $(LIBSSL_NAMES))))
246246

247247
ifneq ($(LIBSSL_PATH), )
248-
LIBSSL_TARGET_LIB = $(LIB_DST_DIR)/$(notdir $(LIBSSL_PATH))
248+
LIBSSL_TARGET_LIB = $(LIB_DST_DIR)/$(LIBRARY_PREFIX)ssl-semeru$(SHARED_LIBRARY_SUFFIX)
249249
TARGETS += $(LIBSSL_TARGET_LIB)
250250
$(LIBSSL_TARGET_LIB) : $(LIBSSL_PATH)
251251
$(call install-file)

closed/src/java.base/share/native/libjncrypto/NativeCrypto.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,17 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath)
665665
#endif /* defined(_AIX) */
666666
};
667667

668+
/** OpenSSL library names associated with bundled library. */
669+
#if defined(_AIX)
670+
static const char * const bundledLibName = "libcrypto-semeru.so";
671+
#elif defined(__APPLE__) /* defined(_AIX) */
672+
static const char * const bundledLibName = "libcrypto-semeru.dylib";
673+
#elif defined(_WIN32) /* defined(__APPLE__) */
674+
static const char * const bundledLibName = "crypto-semeru.dll";
675+
#else /* defined(_WIN32) */
676+
static const char * const bundledLibName = "libcrypto-semeru.so";
677+
#endif /* defined(_AIX) */
678+
668679
const size_t numOfLibs = sizeof(libNames) / sizeof(libNames[0]);
669680
#if defined(_AIX)
670681
const size_t num_of_generic = 4;
@@ -706,33 +717,31 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath)
706717
fprintf(stdout, "Attempting to load library bundled with JDK from: %s\n", libPath);
707718
}
708719

709-
for (i = 0; i < numOfLibs; i++) {
710-
size_t file_len = strlen(libNames[i]);
711-
/* Allocate memory for the new file name with the path. */
712-
char *libNameWithPath = (char *)malloc(path_len + file_len + 1);
713-
714-
if (NULL == libNameWithPath) {
715-
if (traceEnabled) {
716-
fprintf(stderr, "\tFailed to allocate memory for file name with path.\n");
717-
}
718-
continue;
719-
}
720+
size_t file_len = strlen(bundledLibName);
721+
/* Allocate memory for the new file name with the path. */
722+
char *libNameWithPath = (char *)malloc(path_len + file_len + 1);
720723

721-
strcpy(libNameWithPath, libPath);
722-
strcat(libNameWithPath, libNames[i]);
723-
724-
/* Load OpenSSL Crypto library bundled with JDK. */
724+
if (NULL == libNameWithPath) {
725725
if (traceEnabled) {
726-
fprintf(stdout, "\tAttempting to load: %s\n", libNames[i]);
726+
fprintf(stderr, "\tFailed to allocate memory for file name with path.\n");
727727
}
728-
result = load_crypto_library(traceEnabled, libNameWithPath);
728+
free(libPath);
729+
return NULL;
730+
}
729731

730-
free(libNameWithPath);
732+
strcpy(libNameWithPath, libPath);
733+
strcat(libNameWithPath, bundledLibName);
731734

732-
if (NULL == result) {
733-
continue;
734-
}
735+
/* Load OpenSSL Crypto library bundled with JDK. */
736+
if (traceEnabled) {
737+
fprintf(stdout, "\tAttempting to load: %s\n", bundledLibName);
738+
}
739+
result = load_crypto_library(traceEnabled, libNameWithPath);
735740

741+
free(libNameWithPath);
742+
free(libPath);
743+
744+
if (NULL != result) {
736745
/* Identify and load the latest version from the potential libraries.
737746
* This logic depends upon the order in which libnames are defined.
738747
* Libraries are listed in descending order w.r.t version.
@@ -741,11 +750,9 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath)
741750
*/
742751
tempVersion = get_crypto_library_version(traceEnabled, result, "\t\tLoaded OpenSSL version");
743752
if (tempVersion > 0) {
744-
free(libPath);
745753
return result;
746754
}
747755
}
748-
free(libPath);
749756
}
750757

751758
/* The attempt to load from property and OpenSSL bundled with JDK failed.

0 commit comments

Comments
 (0)