From 1dce0edf5e90f253857e77dd4cae2dbb3f5b1c05 Mon Sep 17 00:00:00 2001 From: kares Date: Wed, 16 Oct 2024 12:33:42 +0200 Subject: [PATCH] [fix] avoid PKey::EC.new failing with specific DER (#318) --- src/main/java/org/jruby/ext/openssl/PKeyEC.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jruby/ext/openssl/PKeyEC.java b/src/main/java/org/jruby/ext/openssl/PKeyEC.java index 5e4a8624..9c0330b8 100644 --- a/src/main/java/org/jruby/ext/openssl/PKeyEC.java +++ b/src/main/java/org/jruby/ext/openssl/PKeyEC.java @@ -171,7 +171,10 @@ public static RubyArray builtin_curves(ThreadContext context, IRubyObject self) return curves; } - private static Optional getCurveOID(final String curveName) { + private static Optional getCurveOID(String curveName) { + if (curveName == null) return Optional.empty(); + // work-around getNamedCurveOid not being able to handle "... " (assuming spacePos + 1 is valid index) + if (curveName.indexOf(' ') == curveName.length() - 1) return Optional.empty(); return Optional.ofNullable(ECUtil.getNamedCurveOid(curveName)); }