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

Consistently load OpenSSL libraries among different platforms. #884

Open
wants to merge 1 commit into
base: openj9
Choose a base branch
from
Open
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
84 changes: 0 additions & 84 deletions closed/src/java.base/aix/native/libjncrypto/NativeCrypto_md.c

This file was deleted.

75 changes: 0 additions & 75 deletions closed/src/java.base/macosx/native/libjncrypto/NativeCrypto_md.c

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,18 @@ public class NativeCrypto {

private static final Cleaner ECKeyCleaner = CleanerFactory.cleaner();

private static final String javaHome =
GetPropertyAction.privilegedGetProperty("java.home");

private static final boolean useNativeCrypto = Boolean.parseBoolean(
GetPropertyAction.privilegedGetProperty("jdk.nativeCrypto", "true"));

private static final boolean traceEnabled = Boolean.parseBoolean(
GetPropertyAction.privilegedGetProperty("jdk.nativeCryptoTrace", "false"));

private static String nativeLibName =
GetPropertyAction.privilegedGetProperty("jdk.native.openssl.lib");

private static final class InstanceHolder {
private static final NativeCrypto instance = new NativeCrypto();
}
Expand All @@ -85,20 +91,32 @@ private static long loadCryptoLibraries() {
long osslVersion;

try {
// load jncrypto JNI library
// Initialize null string before passing it to JNI.
if (nativeLibName == null){
nativeLibName = "";
}

// Load jncrypto JNI library.
System.loadLibrary("jncrypto");
// load OpenSSL crypto library dynamically
osslVersion = loadCrypto(traceEnabled);
if (traceEnabled && (osslVersion != -1)) {
System.err.println("Native crypto library load succeeded - using native crypto library.");

// Load OpenSSL crypto library dynamically.
osslVersion = loadCrypto(traceEnabled, nativeLibName, javaHome);
if (osslVersion != -1) {
if (traceEnabled) {
System.err.println("Native crypto library load succeeded - using native crypto library.");
}
} else {
if (!nativeLibName.isEmpty()) {
throw new RuntimeException(nativeLibName + " is not available, Crypto libraries are not loaded.");
}
}
} catch (UnsatisfiedLinkError usle) {
if (traceEnabled) {
System.err.println("UnsatisfiedLinkError: Failure attempting to load jncrypto JNI library");
System.err.println("Warning: Native crypto library load failed." +
" Using Java crypto implementation.");
}
// signal load failure
// Signal load failure.
osslVersion = -1;
}
return osslVersion;
Expand Down Expand Up @@ -253,14 +271,18 @@ public void run() {
});
}

/* Native digest interfaces */
/* OpenSSL utility interfaces */

private static final native long loadCrypto(boolean trace);
private static final native long loadCrypto(boolean trace,
String libname,
String javaHome);

public static final native boolean isMD5Available();

private static final native boolean isOpenSSLFIPS();

/* Native digest interfaces */

public final native long DigestCreateContext(long nativeBuffer,
int algoIndex);

Expand Down
Loading