From 7767343f269b5761380d293b8419f4a5748cf201 Mon Sep 17 00:00:00 2001 From: kares Date: Wed, 9 Oct 2024 19:18:57 +0200 Subject: [PATCH] [fix] have a useful OPENSSL_VERSION_NUMBER some gems such as ruby-jwt check this to detect 3.0.0 https://github.com/jwt/ruby-jwt/blob/v2.9.3/lib/jwt/version.rb#L27 --- src/main/java/org/jruby/ext/openssl/OpenSSL.java | 11 ++++++++--- src/test/ruby/test_openssl.rb | 5 +++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jruby/ext/openssl/OpenSSL.java b/src/main/java/org/jruby/ext/openssl/OpenSSL.java index 4247d943..7330f650 100644 --- a/src/main/java/org/jruby/ext/openssl/OpenSSL.java +++ b/src/main/java/org/jruby/ext/openssl/OpenSSL.java @@ -89,7 +89,7 @@ public static void createOpenSSL(final Ruby runtime) { runtime.getLoadService().require("jopenssl/version"); - final byte[] version = { '2','.','2','.','3' }; + final byte[] version = { '2','.','2','.','3' }; // C OpenSSL gem version _OpenSSL.setConstant("VERSION", StringHelper.newString(runtime, version)); @@ -97,13 +97,18 @@ public static void createOpenSSL(final Ruby runtime) { final RubyString jVERSION = JOpenSSL.getConstantAt("VERSION").asString(); final byte[] JRuby_OpenSSL_ = { 'J','R','u','b','y','-','O','p','e','n','S','S','L',' ' }; - final int OPENSSL_VERSION_NUMBER = 999999999; // NOTE: smt more useful? - ByteList OPENSSL_VERSION = new ByteList( jVERSION.getByteList().getRealSize() + JRuby_OpenSSL_.length ); OPENSSL_VERSION.setEncoding( jVERSION.getEncoding() ); OPENSSL_VERSION.append( JRuby_OpenSSL_ ); OPENSSL_VERSION.append( jVERSION.getByteList() ); + // < 3.0.0 until we have decent (full) compatibility + final byte OPENSSL_VERSION_MAJOR = 2; + final byte OPENSSL_VERSION_MINOR = 9; + final byte OPENSSL_VERSION_PATCH = 9; + final byte OPENSSL_VERSION_PRE_RELEASE = 0; + final int OPENSSL_VERSION_NUMBER = OPENSSL_VERSION_MAJOR << 28 | OPENSSL_VERSION_MINOR << 20 | OPENSSL_VERSION_PATCH << 4 | OPENSSL_VERSION_PRE_RELEASE; + final RubyString VERSION; _OpenSSL.setConstant("OPENSSL_VERSION", VERSION = runtime.newString(OPENSSL_VERSION)); _OpenSSL.setConstant("OPENSSL_VERSION_NUMBER", runtime.newFixnum(OPENSSL_VERSION_NUMBER)); diff --git a/src/test/ruby/test_openssl.rb b/src/test/ruby/test_openssl.rb index 9b4cf8a2..cda69766 100644 --- a/src/test/ruby/test_openssl.rb +++ b/src/test/ruby/test_openssl.rb @@ -27,6 +27,11 @@ def test_version assert /\AOpenSSL +0\./ !~ OpenSSL::OPENSSL_LIBRARY_VERSION end + # some gems check this - better to be conservative until 3.0.0 APIs are fully supported + def test_version_lt_3_0_0 + assert OpenSSL::OPENSSL_VERSION_NUMBER < 3 * 0x10000000 + end + def test_debug debug = OpenSSL.debug assert (OpenSSL.debug == true || OpenSSL.debug == false)