Skip to content

Commit

Permalink
Implement OpenSSL_version_num for JNA
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Dec 2, 2023
1 parent 2c1d130 commit 05dd7ec
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump commons-parent from 56 to 64 #225.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump com.sun.xml.bind:jaxb-impl from 2.3.7 to 2.3.8.</action>
<!-- ADD -->
<action type="add" dev="sebb">Implement OpenSSL_version_num for JNA</action>
<action issue="CRYPTO-177" type="add" dev="sebb">Cipher and Random Factory classes don't include JNA</action>
<action issue="CRYPTO-172" type="add" dev="sebb" due-to="Ludovic Henry">Add support for Linux-riscv64 #264</action>
<action issue="CRYPTO-174" type="add" dev="sebb">Allow override of SSL library name for Windows</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ public static native int EVP_CipherUpdate(PointerByReference ctx, ByteBuffer bou
public static native PointerByReference RAND_SSLeay();

/**
* TODO (does not appear to be used yet)
* @return OPENSSL_VERSION_NUMBER which is a numeric release version identifier
*/
public static native NativeLong SSLeay();
Expand Down Expand Up @@ -429,6 +428,11 @@ public String _OpenSSL_version(final int i) {
return SSLeay_version(i);
}

@Override
public long _OpenSSL_version_num() {
return SSLeay().longValue();
}

@Override
public int _RAND_bytes(final ByteBuffer buf, final int length) {
return RAND_bytes(buf, length) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ public static native int EVP_CipherUpdate(PointerByReference ctx, ByteBuffer bou
*/
public static native String OpenSSL_version(int type);

/**
* @return OPENSSL_VERSION_NUMBER which is a numeric release version identifier
*/
public static native NativeLong OpenSSL_version_num();

/**
* Generates random data
*
Expand Down Expand Up @@ -385,6 +390,11 @@ public String _OpenSSL_version(final int i) {
return OpenSSL_version(i);
}

@Override
public long _OpenSSL_version_num() {
return OpenSSL_version_num().longValue();
}

@Override
public int _RAND_bytes(final ByteBuffer buf, final int length) {
return RAND_bytes(buf, length) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,11 @@ public static native int EVP_CipherUpdate(PointerByReference ctx, ByteBuffer bou
*/
public static native String OpenSSL_version(int type);

/**
* @return OPENSSL_VERSION_NUMBER which is a numeric release version identifier
*/
public static native NativeLong OpenSSL_version_num();

/**
* Generates random data
*
Expand Down Expand Up @@ -387,6 +392,11 @@ public String _OpenSSL_version(final int i) {
return OpenSSL_version(i);
}

@Override
public long _OpenSSL_version_num() {
return OpenSSL_version_num().longValue();
}

@Override
public int _RAND_bytes(final ByteBuffer buf, final int length) {
return RAND_bytes(buf, length) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ int _EVP_CipherUpdate(final PointerByReference context, final ByteBuffer outBuff

String _OpenSSL_version(final int i);

long _OpenSSL_version_num();

int _RAND_bytes(final ByteBuffer buf, final int length);

PointerByReference _RAND_get_rand_method();
Expand Down
14 changes: 2 additions & 12 deletions src/main/java/org/apache/commons/crypto/jna/OpenSslJna.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,25 +106,15 @@ public static void main(final String[] args) throws Throwable {
System.err.flush(); // helpful for stack traces to not mix in other output.
throw initialisationError; // propagate to make error obvious
}
info("OpenSSL library loaded OK, version: 0x%s", Long.toHexString(OpenSslNativeJna.OpenSSL_version_num()));
for (int i = 0; i <= Utils.OPENSSL_VERSION_MAX_INDEX; i++) {
String data = OpenSSLVersion(i);
String data = OpenSslNativeJna.OpenSSLVersion(i);
if (!"not available".equals(data)) {
info("OpenSSLVersion(%d): %s", i, data);
}
}
}

/**
* Retrieves version/build information about OpenSSL library.
*
* @param type type can be OPENSSL_VERSION, OPENSSL_CFLAGS, OPENSSL_BUILT_ON...
* @return A pointer to a constant string describing the version of the
* OpenSSL library or giving information about the library build.
*/
static String OpenSSLVersion(final int type) {
return OpenSslNativeJna.OpenSSLVersion(type);
}

/**
* Constructs a new instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public static String OpenSSLVersion(final int i) {
return JnaImplementation._OpenSSL_version(i);
}

public static long OpenSSL_version_num() {
return JnaImplementation._OpenSSL_version_num();
}

public static int RAND_bytes(final ByteBuffer buf, final int length) {
return JnaImplementation._RAND_bytes(buf, length);
}
Expand Down

0 comments on commit 05dd7ec

Please sign in to comment.