Skip to content

Commit

Permalink
Handle JRuby NullPointerExceptions when getting the EC curve_name.
Browse files Browse the repository at this point in the history
JRuby 9.4.8.0 raises a NullPointerException when getting the curve_name
from the group. On MRI, the group is nil.
  • Loading branch information
philr committed Oct 16, 2024
1 parent 839dbd3 commit 83bf487
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/putty/key/openssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ module OpenSSL

private_constant :SSH_CURVES

# Either a real JRuby NullPointerException, or a fake class that won't be
# raised. Can be rescued to handle NullPointerException on jruby.
JavaNullPointerException = RUBY_ENGINE == 'jruby' ? Java::JavaLang::NullPointerException : Class.new(Exception)
private_constant :JavaNullPointerException

# OpenSSL version helper methods.
#
# @private
Expand Down Expand Up @@ -355,7 +360,12 @@ module EC
# @raise [UnsupportedCurveError] If the key uses a curve that is not
# supported by PuTTY.
def to_ppk
curve = group && group.curve_name
g = group
curve = g && begin
g.curve_name
rescue JavaNullPointerException
nil
end
raise InvalidStateError, 'The key has not been fully initialized (a curve name must be assigned)' unless curve
ssh_curve = SSH_CURVES[curve]
raise UnsupportedCurveError, "The curve '#{curve}' is not supported" unless ssh_curve
Expand Down

0 comments on commit 83bf487

Please sign in to comment.