From 5f462bdd4438d9e660ec0f8b925889c26eb0aaff Mon Sep 17 00:00:00 2001 From: kares Date: Mon, 27 May 2024 10:29:08 +0200 Subject: [PATCH] [fix] OpenSSL::PKey::DH#set_pqg regression (#300) introduced at: adcd03115f6906fad9424f3276b86c9c54f91c05 --- lib/jopenssl/_compat23.rb | 4 ++-- src/test/ruby/test_pkey.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/jopenssl/_compat23.rb b/lib/jopenssl/_compat23.rb index 8da642c6..78f9d0ef 100644 --- a/lib/jopenssl/_compat23.rb +++ b/lib/jopenssl/_compat23.rb @@ -14,9 +14,9 @@ def set_key(pub_key, priv_key) def set_pqg(p, q, g) self.p = p - if respond_to?(:q) + if respond_to?(:q=) self.q = q - else # TODO self.q = q + else OpenSSL.warn "JRuby-OpenSSL does not support setting q param on #{inspect}" if q end self.g = g diff --git a/src/test/ruby/test_pkey.rb b/src/test/ruby/test_pkey.rb index 30b83489..2a0f0e12 100644 --- a/src/test/ruby/test_pkey.rb +++ b/src/test/ruby/test_pkey.rb @@ -83,6 +83,20 @@ def test_pkey_pem_file_error end end + def test_pkey_dh + dh = OpenSSL::PKey::DH.new + assert_equal nil, dh.p + assert_equal nil, dh.priv_key + + # OpenSSL::PKey::PKeyError: dh#set_pqg= is incompatible with OpenSSL 3.0 + if defined? JRUBY_VERSION + dh.set_pqg(1_000_000, nil, 10) + assert_equal 1_000_000, dh.p + assert_equal 10, dh.g + end + assert_equal nil, dh.q + end + def test_to_java pkey = OpenSSL::PKey.read(KEY) assert_kind_of java.security.PublicKey, pkey.to_java