89
89
import static org .jruby .ext .openssl .X509CRL .extensions_to_text ;
90
90
import static org .jruby .ext .openssl .StringHelper .appendGMTDateTime ;
91
91
import static org .jruby .ext .openssl .StringHelper .appendLowerHexValue ;
92
- import static org .jruby .ext .openssl .StringHelper .gsub ;
93
92
import static org .jruby .ext .openssl .StringHelper .lowerHexBytes ;
93
+ import static org .jruby .ext .openssl .OpenSSL .debug ;
94
+ import static org .jruby .ext .openssl .OpenSSL .debugStackTrace ;
94
95
95
96
/**
96
97
* @author <a href="mailto:[email protected] ">Ola Bini</a>
@@ -412,7 +413,6 @@ public IRubyObject subject() {
412
413
@ JRubyMethod (name = "subject=" )
413
414
public IRubyObject set_subject (final IRubyObject subject ) {
414
415
if ( ! subject .equals (this .subject ) ) this .changed = true ;
415
- //generator.setSubjectDN( ((X509Name) subject).getRealName() );
416
416
return this .subject = subject ;
417
417
}
418
418
@@ -424,7 +424,6 @@ public IRubyObject issuer() {
424
424
@ JRubyMethod (name = "issuer=" )
425
425
public IRubyObject set_issuer (final IRubyObject issuer ) {
426
426
if ( ! issuer .equals (this .issuer ) ) this .changed = true ;
427
- //generator.setIssuerDN( ((X509Name) issuer).getRealName() );
428
427
return this .issuer = issuer ;
429
428
}
430
429
@@ -438,7 +437,6 @@ public IRubyObject set_not_before(final ThreadContext context, final IRubyObject
438
437
changed = true ;
439
438
not_before = (RubyTime ) time .callMethod (context , "getutc" );
440
439
not_before .setMicroseconds (0 );
441
- //generator.setNotBefore( not_before.getJavaDate() );
442
440
return time ;
443
441
}
444
442
@@ -456,7 +454,6 @@ public IRubyObject set_not_after(final ThreadContext context, final IRubyObject
456
454
changed = true ;
457
455
not_after = (RubyTime ) time .callMethod (context , "getutc" );
458
456
not_after .setMicroseconds (0 );
459
- //generator.setNotAfter( not_after.getJavaDate() );
460
457
return time ;
461
458
}
462
459
@@ -480,7 +477,6 @@ public IRubyObject set_public_key(IRubyObject public_key) {
480
477
if ( ! public_key .equals (this .public_key ) ) {
481
478
this .changed = true ;
482
479
}
483
- //generator.setPublicKey(((PKey) public_key).getPublicKey());
484
480
return this .public_key = (PKey ) public_key ;
485
481
}
486
482
@@ -547,21 +543,19 @@ public IRubyObject sign(final ThreadContext context, final IRubyObject key, fina
547
543
}
548
544
}
549
545
550
- builder .setSignatureAlgorithm (digAlg + "WITH" + keyAlg );
546
+ builder .setSignatureAlgorithm (digAlg + "WITH" + keyAlg ); // "SHA1WITHRSA"
551
547
552
548
try {
553
549
cert = builder .generate ( ((PKey ) key ).getPrivateKey () );
554
550
}
555
551
catch (GeneralSecurityException e ) {
556
- throw newCertificateError (getRuntime (), e );
557
- }
558
- if (cert == null ) {
559
- throw newCertificateError (runtime , (String ) null );
552
+ throw newCertificateError (runtime , e );
560
553
}
554
+
555
+ if (cert == null ) throw newCertificateError (runtime , (String ) null );
556
+
561
557
String name = ASN1Registry .o2a (cert .getSigAlgOID ());
562
- if (name == null ) {
563
- name = cert .getSigAlgOID ();
564
- }
558
+ if ( name == null ) name = cert .getSigAlgOID ();
565
559
this .sig_alg = runtime .newString (name );
566
560
this .changed = false ;
567
561
return this ;
@@ -587,36 +581,43 @@ private org.bouncycastle.x509.X509V3CertificateGenerator getCertificateBuilder()
587
581
//private transient org.bouncycastle.x509.X509V3CertificateGenerator generator;
588
582
589
583
@ JRubyMethod
590
- public IRubyObject verify (IRubyObject key ) {
591
- if ( changed ) return getRuntime ().getFalse ();
584
+ public RubyBoolean verify (final IRubyObject key ) {
585
+ final Ruby runtime = getRuntime ();
586
+
587
+ if ( changed ) return runtime .getFalse ();
592
588
593
589
try {
594
- cert .verify (((PKey )key ).getPublicKey ());
595
- return getRuntime () .getTrue ();
590
+ cert .verify (((PKey ) key ).getPublicKey ());
591
+ return runtime .getTrue ();
596
592
}
597
593
catch (CertificateException e ) {
598
- throw newCertificateError (getRuntime (), e );
594
+ debug (runtime , "Certificate#verify failed: " , e );
595
+ throw newCertificateError (runtime , e );
599
596
}
600
597
catch (NoSuchAlgorithmException e ) {
601
- throw newCertificateError (getRuntime (), e );
598
+ debugStackTrace (runtime , e );
599
+ throw newCertificateError (runtime , e );
602
600
}
603
601
catch (NoSuchProviderException e ) {
604
- throw newCertificateError (getRuntime (), e );
602
+ debugStackTrace (runtime , e );
603
+ throw newCertificateError (runtime , e );
605
604
}
606
605
catch (SignatureException e ) {
607
- return getRuntime ().getFalse ();
606
+ debug (runtime , "Certificate#verify failed: " , e );
607
+ return runtime .getFalse ();
608
608
}
609
609
catch (InvalidKeyException e ) {
610
- return getRuntime ().getFalse ();
610
+ debug (runtime , "Certificate#verify failed: " , e );
611
+ return runtime .getFalse ();
611
612
}
612
613
}
613
614
614
615
@ JRubyMethod
615
- public RubyBoolean check_private_key (IRubyObject arg ) {
616
- PKey key = ( PKey ) arg ;
617
- PublicKey pubKey = key .getPublicKey ();
618
- PublicKey certPubKey = getAuxCert ().getPublicKey ();
619
- if ( certPubKey . equals ( pubKey ) ) return getRuntime (). getTrue ();
616
+ public RubyBoolean check_private_key (final IRubyObject key ) {
617
+ final PublicKey certPublicKey = cert . getPublicKey () ;
618
+ if ( certPublicKey . equals ( (( PKey ) key ) .getPublicKey () ) ) {
619
+ return getRuntime ().getTrue ();
620
+ }
620
621
return getRuntime ().getFalse ();
621
622
}
622
623
@@ -628,7 +629,7 @@ public RubyArray extensions() {
628
629
}
629
630
630
631
@ SuppressWarnings ("unchecked" )
631
- @ JRubyMethod (name = "extensions=" )
632
+ @ JRubyMethod (name = "extensions=" )
632
633
public IRubyObject set_extensions (final IRubyObject array ) {
633
634
extensions .clear (); // RubyArray is a List :
634
635
extensions .addAll ( (List <X509Extension >) array );
0 commit comments