Skip to content

Commit 780045e

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 b642b20 commit 780045e

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
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: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,17 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath)
662662
#endif /* defined(_AIX) */
663663
};
664664

665+
/** OpenSSL library names associated with bundled library. */
666+
#if defined(_AIX)
667+
static const char bundledLibName[] = "libcrypto-semeru.so";
668+
#elif defined(__APPLE__) /* defined(_AIX) */
669+
static const char bundledLibName[] = "libcrypto-semeru.dylib";
670+
#elif defined(_WIN32) /* defined(__APPLE__) */
671+
static const char bundledLibName[] = "crypto-semeru.dll";
672+
#else /* defined(_WIN32) */
673+
static const char bundledLibName[] = "libcrypto-semeru.so";
674+
#endif /* defined(_AIX) */
675+
665676
const size_t numOfLibs = sizeof(libNames) / sizeof(libNames[0]);
666677
void *result = NULL;
667678
size_t i = 0;
@@ -675,7 +686,7 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath)
675686
static const char pathSuffix[] = "/lib/";
676687
#endif /* defined(_WIN32) */
677688

678-
size_t path_len = strlen(chomepath) + sizeof(pathSuffix) - 1;
689+
size_t path_len = strlen(chomepath) + sizeof(pathSuffix) - 1 + sizeof(bundledLibName) - 1;
679690
char *libPath = malloc(path_len + 1);
680691

681692
if (NULL == libPath) {
@@ -693,33 +704,17 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath)
693704
fprintf(stdout, "Attempting to load library bundled with JDK from: %s\n", libPath);
694705
}
695706

696-
for (i = 0; i < numOfLibs; i++) {
697-
size_t file_len = strlen(libNames[i]);
698-
/* Allocate memory for the new file name with the path. */
699-
char *libNameWithPath = (char *)malloc(path_len + file_len + 1);
700-
701-
if (NULL == libNameWithPath) {
702-
if (traceEnabled) {
703-
fprintf(stderr, "\tFailed to allocate memory for file name with path.\n");
704-
}
705-
continue;
706-
}
707+
strcat(libPath, bundledLibName);
707708

708-
strcpy(libNameWithPath, libPath);
709-
strcat(libNameWithPath, libNames[i]);
710-
711-
/* Load OpenSSL Crypto library bundled with JDK. */
712-
if (traceEnabled) {
713-
fprintf(stdout, "\tAttempting to load: %s\n", libNames[i]);
714-
}
715-
result = load_crypto_library(traceEnabled, libNameWithPath);
716-
717-
free(libNameWithPath);
709+
/* Load OpenSSL Crypto library bundled with JDK. */
710+
if (traceEnabled) {
711+
fprintf(stdout, "\tAttempting to load: %s\n", bundledLibName);
712+
}
713+
result = load_crypto_library(traceEnabled, libPath);
718714

719-
if (NULL == result) {
720-
continue;
721-
}
715+
free(libPath);
722716

717+
if (NULL != result) {
723718
/* Identify and load the latest version from the potential libraries.
724719
* This logic depends upon the order in which libnames are defined.
725720
* Libraries are listed in descending order w.r.t version.
@@ -728,11 +723,9 @@ find_crypto_library(jboolean traceEnabled, const char *chomepath)
728723
*/
729724
tempVersion = get_crypto_library_version(traceEnabled, result, "\t\tLoaded OpenSSL version");
730725
if (tempVersion > 0) {
731-
free(libPath);
732726
return result;
733727
}
734728
}
735-
free(libPath);
736729
}
737730

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

0 commit comments

Comments
 (0)