4242import org .bouncycastle .asn1 .ASN1Encoding ;
4343import org .bouncycastle .asn1 .ASN1Set ;
4444import org .bouncycastle .asn1 .ASN1ObjectIdentifier ;
45- import org .bouncycastle .asn1 .ASN1Sequence ;
4645import org .bouncycastle .asn1 .pkcs .Attribute ;
4746import org .bouncycastle .asn1 .x500 .X500Name ;
4847
6160import org .jruby .runtime .Visibility ;
6261
6362import org .jruby .ext .openssl .impl .PKCS10Request ;
63+
6464import static org .jruby .ext .openssl .OpenSSL .*;
6565import static org .jruby .ext .openssl .PKey ._PKey ;
6666import static org .jruby .ext .openssl .X509 ._X509 ;
@@ -319,7 +319,7 @@ public IRubyObject sign(final ThreadContext context,
319319 request = null ; getRequest ().sign ( privateKey , digAlg );
320320 }
321321 catch (InvalidKeyException e ) {
322- debug (runtime , "X509Request#sign failed " , e );
322+ debug (runtime , "X509Request#sign invalid key: " , e );
323323 throw newRequestError (runtime , e );
324324 }
325325 catch (Exception e ) {
@@ -344,23 +344,25 @@ private Attribute newAttributeImpl(final ThreadContext context,
344344
345345 @ JRubyMethod
346346 public IRubyObject verify (final ThreadContext context , IRubyObject key ) {
347- final Ruby runtime = context .runtime ; final PublicKey publicKey ;
347+ final Ruby runtime = context .runtime ;
348348 try {
349- publicKey = ( (PKey ) key .callMethod (context , "public_key" ) ).getPublicKey ();
350- return runtime .newBoolean ( getRequest ().verify (publicKey ) );
349+ if (!(key instanceof PKey )) { // due PKeyEC
350+ key = key .callMethod (context , "public_key" );
351+ if (!(key instanceof PKey )) {
352+ throw context .runtime .newTypeError (key , _PKey (runtime ));
353+ }
354+ }
355+ boolean signatureValid = getRequest ().verify ( ((PKey ) key ).getPublicKey () );
356+ return runtime .newBoolean (signatureValid );
351357 }
352358 catch (InvalidKeyException e ) {
353- debug (runtime , "X509::Request #verify invalid key" , e );
359+ debug (runtime , "X509Request #verify invalid key: " , e );
354360 throw newRequestError (runtime , "invalid key supplied" , e );
355361 }
356- //catch (IOException e) {
357- // debug(runtime, "X509::Request.verify failed", e);
358- // return runtime.getFalse();
359- //}
360- //catch (RuntimeException e) {
361- // debug(runtime, "X509::Request.verify failed", e);
362- // return runtime.getFalse();
363- //}
362+ catch (RuntimeException e ) {
363+ debugStackTrace (runtime , "X509Request#verify" , e );
364+ return context .nil ;
365+ }
364366 }
365367
366368 @ JRubyMethod
0 commit comments