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

ECDSA JRuby fix #49

Merged
merged 1 commit into from
Aug 24, 2023
Merged
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
12 changes: 11 additions & 1 deletion lib/sshkey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,12 @@ def public_key_object
return nil unless key_object
return nil unless key_object.group

if OpenSSL::OPENSSL_VERSION_NUMBER >= 0x30000000
if OpenSSL::OPENSSL_VERSION_NUMBER >= 0x30000000 && RUBY_PLATFORM != "java"

# jruby-openssl does not currently support point_conversion_form
# (futureproofing for if/when JRuby requires this technique to determine public key)
jruby_not_implemented("point_conversion_form is not implemented")

# Avoid "OpenSSL::PKey::PKeyError: pkeys are immutable on OpenSSL 3.0"
# https://github.com/ruby/openssl/blob/master/History.md#version-300
# https://github.com/ruby/openssl/issues/498
Expand All @@ -451,6 +456,11 @@ def public_key_object
curve_name = key_object.group.curve_name
return nil unless curve_name

# Map to different curve_name for JRuby
# (futureproofing for if/when JRuby requires this technique to determine public key)
# https://github.com/jwt/ruby-jwt/issues/362#issuecomment-722938409
curve_name = "prime256v1" if curve_name == "secp256r1" && RUBY_PLATFORM == "java"

# Construct public key OpenSSL::PKey::EC from OpenSSL::PKey::EC::Point
public_key_point = key_object.public_key # => OpenSSL::PKey::EC::Point
return nil unless public_key_point
Expand Down