Skip to content

Commit

Permalink
[fix] resolving EC key from X509::Request.new(pem)
Browse files Browse the repository at this point in the history
  • Loading branch information
kares committed Apr 10, 2024
1 parent 7bafbb5 commit ad67878
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/org/jruby/ext/openssl/X509Request.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,16 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
throw newRequestError(runtime, "invalid certificate request data", e);
}

final String algorithm; final byte[] encoded;
final String algorithm;
final byte[] encoded;
try {
final PublicKey pkey = request.generatePublicKey();
algorithm = pkey.getAlgorithm();
encoded = pkey.getEncoded();
}
catch (IOException e) { throw newRequestError(runtime, e); }
catch (GeneralSecurityException e) { throw newRequestError(runtime, e); }
catch (IOException|GeneralSecurityException e) {
throw newRequestError(runtime, e);
}

final RubyString enc = RubyString.newString(runtime, encoded);
if ( "RSA".equalsIgnoreCase(algorithm) ) {
Expand All @@ -127,6 +129,9 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
else if ( "DSA".equalsIgnoreCase(algorithm) ) {
this.public_key = newPKeyImplInstance(context, "DSA", enc);
}
else if ( "EC".equalsIgnoreCase(algorithm) ) {
this.public_key = newPKeyImplInstance(context, "EC", enc);
}
else {
throw runtime.newNotImplementedError("public key algorithm: " + algorithm);
}
Expand Down

0 comments on commit ad67878

Please sign in to comment.