in src/main/java/org/apache/commons/crypto/jna/OpenSslNativeJna.java [55:107]
static {
OpenSslJna.debug("OpenSslNativeJna static init start");
final String libraryName = System.getProperty(Crypto.JNA_LIBRARY_NAME_PROPERTY, Crypto.JNA_LIBRARY_NAME_DEFAULT);
OpenSslJna.debug("OpenSslNativeJna NativeLibrary.getInstance('%s')", libraryName);
// CRYPTO-179 - avoid crash
if ("Mac OS X".equals(System.getProperty("os.name"))
&& System.getProperty(Crypto.JNA_LIBRARY_NAME_PROPERTY, "").isEmpty()
&& System.getProperty(Crypto.JNA_LIBRARY_PATH_PROPERTY, "").isEmpty()
) {
final String ret = OpenSslMacOS.checkLibrary(Crypto.MACOS_LIBRARY_NAME_DEFAULT);
if (ret != null) {
throw new UnsatisfiedLinkError(
String.format("Cannot load default library '%s'; please define %s! (%s)",
Crypto.MACOS_LIBRARY_NAME_DEFAULT, Crypto.JNA_LIBRARY_PATH_PROPERTY, ret));
}
}
@SuppressWarnings("resource") // NativeLibrary.getInstance returns a singleton
final NativeLibrary crypto = NativeLibrary.getInstance(libraryName);
OpenSslJna.debug("OpenSslNativeJna NativeLibrary.getInstance('%s') -> %s", libraryName, crypto);
Function versionFunction = null;
try {
versionFunction = crypto.getFunction("OpenSSL_version_num"); // Used by OpenSSL 1.1 and 3.x, so more likely
} catch (final UnsatisfiedLinkError e) {
versionFunction = crypto.getFunction("SSLeay"); // Fallback only needed for LibreSSL 2.x
}
// Must find one of the above two functions; else give up with UnsatisfiedLinkError
VERSION = versionFunction.invokeLong(new Object[]{});
//CHECKSTYLE:OFF
VERSION_X_Y = VERSION & 0xffff0000; // keep only major.minor
//CHECKSTYLE:ON
OpenSslJna.debug(String.format("OpenSslNativeJna detected version 0x%x => 0x%x", VERSION, VERSION_X_Y));
if (VERSION_X_Y == VERSION_1_1_X) {
OpenSslJna.debug("Creating OpenSsl11XNativeJna");
JnaImplementation = new OpenSsl11XNativeJna();
} else if (VERSION_X_Y == VERSION_2_0_X) {
OpenSslJna.debug("Creating LibreSsl20XNativeJna");
JnaImplementation = new LibreSsl20XNativeJna();
} else if (VERSION_X_Y == VERSION_3_0_X || VERSION_X_Y == VERSION_3_1_X || VERSION_X_Y == VERSION_3_2_X) { // assume these are the same
OpenSslJna.debug("Creating OpenSsl30XNativeJna");
JnaImplementation = new OpenSsl30XNativeJna();
} else {
throw new UnsupportedOperationException(String.format("Unsupported Version: %x", VERSION_X_Y));
}
INIT_OK = JnaImplementation._INIT_OK();
INIT_ERROR = INIT_OK ? null : JnaImplementation._INIT_ERROR();
OpenSslJna.debug("OpenSslNativeJna INIT_OK = %s, INIT_ERROR = '%s', JnaImplementation = %s", INIT_OK, INIT_ERROR, JnaImplementation.getClass());
OpenSslJna.debug("OpenSslNativeJna static init end");
}