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 #429

Draft
wants to merge 1 commit into
base: openj9
Choose a base branch
from
Draft
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
@@ -1,6 +1,6 @@
/*
* ===========================================================================
* (c) Copyright IBM Corp. 2018, 2024 All Rights Reserved
* (c) Copyright IBM Corp. 2018, 2025 All Rights Reserved
* ===========================================================================
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -32,6 +32,7 @@
import jdk.internal.ref.CleanerFactory;
import jdk.internal.reflect.Reflection;
import jdk.internal.reflect.CallerSensitive;
import jdk.internal.util.StaticProperty;

import sun.security.action.GetPropertyAction;

Expand Down Expand Up @@ -81,24 +82,39 @@ private static final class InstanceHolder {

private final boolean isOpenSSLFIPS;

@SuppressWarnings("restricted")
private static long loadCryptoLibraries() {
long osslVersion;

try {
// load jncrypto JNI library
// 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.");

// Get user-specified OpenSSL library to use, if available.
String nativeLibName =
GetPropertyAction.privilegedGetProperty("jdk.native.openssl.lib", "");

// Get the JDK location.
String javaHome = StaticProperty.javaHome();

// 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 +269,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