8383
8484import static org .jruby .ext .openssl .Digest ._Digest ;
8585import static org .jruby .ext .openssl .OCSP ._OCSP ;
86+ import static org .jruby .ext .openssl .OCSP .newOCSPError ;
8687import static org .jruby .ext .openssl .X509 ._X509 ;
8788
8889import java .io .IOException ;
105106 */
106107public class OCSPBasicResponse extends RubyObject {
107108 private static final long serialVersionUID = 8755480816625884227L ;
109+
108110 private static final String OCSP_NOCERTS = "NOCERTS" ;
109111 private static final String OCSP_NOCHAIN = "NOCHAIN" ;
110112 private static final String OCSP_NOCHECKS = "NOCHECKS" ;
@@ -121,9 +123,9 @@ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
121123 }
122124 };
123125
124- public static void createBasicResponse (final Ruby runtime , final RubyModule _OCSP ) {
125- RubyClass _BasicResponse = _OCSP .defineClassUnder ("BasicResponse" , runtime .getObject (), BASICRESPONSE_ALLOCATOR );
126- _BasicResponse .defineAnnotatedMethods (OCSPBasicResponse .class );
126+ public static void createBasicResponse (final Ruby runtime , final RubyModule OCSP ) {
127+ RubyClass BasicResponse = OCSP .defineClassUnder ("BasicResponse" , runtime .getObject (), BASICRESPONSE_ALLOCATOR );
128+ BasicResponse .defineAnnotatedMethods (OCSPBasicResponse .class );
127129 }
128130
129131 private byte [] nonce ;
@@ -371,7 +373,7 @@ public IRubyObject sign(final ThreadContext context, IRubyObject[] args) {
371373
372374 @ JRubyMethod (name = "verify" , rest = true )
373375 public IRubyObject verify (final ThreadContext context , IRubyObject [] args ) {
374- Ruby runtime = getRuntime () ;
376+ Ruby runtime = context . runtime ;
375377 int flags = 0 ;
376378 IRubyObject certificates = args [0 ];
377379 IRubyObject store = args [1 ];
@@ -385,7 +387,7 @@ public IRubyObject verify(final ThreadContext context, IRubyObject[] args) {
385387 jcacvpb .setProvider ("BC" );
386388 BasicOCSPResp basicOCSPResp = getBasicOCSPResp ();
387389
388- java .security .cert .Certificate signer = findSignerCert (asn1BCBasicOCSPResp , convertRubyCerts (certificates ), flags );
390+ java .security .cert .Certificate signer = findSignerCert (context , asn1BCBasicOCSPResp , convertRubyCerts (certificates ), flags );
389391 if ( signer == null ) return RubyBoolean .newBoolean (runtime , false );
390392 if ( (flags & RubyFixnum .fix2int ((RubyFixnum )_OCSP (runtime ).getConstant (OCSP_NOINTERN ))) == 0 &&
391393 (flags & RubyFixnum .fix2int ((RubyFixnum )_OCSP (runtime ).getConstant (OCSP_TRUSTOTHER ))) != 0 ) {
@@ -426,10 +428,9 @@ else if (basicOCSPResp.getCerts() != null && (certificates != null && !((RubyArr
426428 RubyArray rUntrustedCerts = RubyArray .newEmptyArray (runtime );
427429 if (untrustedCerts != null ) {
428430 X509Cert [] rubyCerts = new X509Cert [untrustedCerts .size ()];
429- untrustedCerts .toArray (rubyCerts );
430- rUntrustedCerts = RubyArray .newArray (runtime , rubyCerts );
431+ rUntrustedCerts = RubyArray .newArray (runtime , untrustedCerts .toArray (rubyCerts ));
431432 }
432- X509StoreContext ctx = null ;
433+ X509StoreContext ctx ;
433434 try {
434435 ctx = X509StoreContext .newStoreContext (context , (X509Store )store , X509Cert .wrap (runtime , signer ), rUntrustedCerts );
435436 }
@@ -438,7 +439,7 @@ else if (basicOCSPResp.getCerts() != null && (certificates != null && !((RubyArr
438439 }
439440
440441 ctx .set_purpose (context , _X509 (runtime ).getConstant ("PURPOSE_OCSP_HELPER" ));
441- ret = (( RubyBoolean ) ctx .verify (context ) ).isTrue ();
442+ ret = ctx .verify (context ).isTrue ();
442443 IRubyObject chain = ctx .chain (context );
443444
444445 if ((flags & RubyFixnum .fix2int ((RubyFixnum )_OCSP (runtime ).getConstant (OCSP_NOCHECKS ))) > 0 ) {
@@ -473,20 +474,21 @@ else if (basicOCSPResp.getCerts() != null && (certificates != null && !((RubyArr
473474 }
474475
475476 @ JRubyMethod (name = "status" )
476- public IRubyObject status () {
477- Ruby runtime = getRuntime () ;
478- RubyArray ret = RubyArray .newEmptyArray (runtime );
477+ public IRubyObject status (ThreadContext context ) {
478+ final Ruby runtime = context . runtime ;
479+ RubyArray ret = RubyArray .newArray (runtime , singleResponses . size () );
479480
480481 for (OCSPSingleResponse resp : singleResponses ) {
481- RubyArray respAry = RubyArray .newEmptyArray (runtime );
482+ RubyArray respAry = RubyArray .newArray (runtime , 7 );
482483
483- respAry .add (resp .certid ());
484- respAry .add (resp .cert_status ());
485- respAry .add (resp .revocation_reason ());
486- respAry .add (resp .revocation_time ());
487- respAry .add (resp .this_update ());
488- respAry .add (resp .next_update ());
489- respAry .add (resp .extensions ());
484+ respAry .append (resp .certid (context ));
485+ respAry .append (resp .cert_status ());
486+ respAry .append (resp .revocation_reason ());
487+ respAry .append (resp .revocation_time ());
488+ respAry .append (resp .this_update ());
489+ respAry .append (resp .next_update ());
490+ respAry .append (resp .extensions ());
491+
490492 ret .add (respAry );
491493 }
492494
@@ -496,7 +498,7 @@ public IRubyObject status() {
496498 @ JRubyMethod (name = "to_der" )
497499 public IRubyObject to_der () {
498500 Ruby runtime = getRuntime ();
499- IRubyObject ret = null ;
501+ IRubyObject ret ;
500502 try {
501503 ret = RubyString .newString (runtime , asn1BCBasicOCSPResp .getEncoded ());
502504 }
@@ -630,16 +632,12 @@ private List<java.security.cert.Certificate> convertRubyCerts(IRubyObject certif
630632
631633 return ret ;
632634 }
633-
634- private static RaiseException newOCSPError (Ruby runtime , Exception e ) {
635- return Utils .newError (runtime , _OCSP (runtime ).getClass ("OCSPError" ), e );
636- }
637635
638- private java .security .cert .Certificate findSignerCert (BasicOCSPResponse basicResp , List < java . security . cert . Certificate > certificates , int flags ) {
639- Ruby runtime = getRuntime ();
640- ThreadContext context = runtime . getCurrentContext () ;
636+ private java .security .cert .Certificate findSignerCert (final ThreadContext context ,
637+ BasicOCSPResponse basicResp , List < java . security . cert . Certificate > certificates , int flags ) {
638+ final Ruby runtime = context . runtime ;
641639 ResponderID respID = basicResp .getTbsResponseData ().getResponderID ();
642- java .security .cert .Certificate ret = null ;
640+ java .security .cert .Certificate ret ;
643641 ret = findSignerByRespId (context , certificates , respID );
644642
645643 if (ret == null && (flags & RubyFixnum .fix2int ((RubyFixnum )_OCSP (runtime ).getConstant (OCSP_NOINTERN ))) == 0 ) {
0 commit comments