@@ -218,19 +218,19 @@ public static X509AuxCertificate findByIssuerAndSerial(
218218 /* c: PKCS7_get0_signers
219219 *
220220 */
221- public List <X509AuxCertificate > getSigners (Collection <X509AuxCertificate > certs , List <SignerInfoWithPkey > sinfos , int flags ) throws PKCS7Exception {
222- List <X509AuxCertificate > signers = new ArrayList <X509AuxCertificate >();
223-
224- if (!isSigned ()) {
225- throw new PKCS7Exception (F_PKCS7_GET0_SIGNERS ,R_WRONG_CONTENT_TYPE );
221+ public List <X509AuxCertificate > getSigners (Collection <X509AuxCertificate > certs , Collection <SignerInfoWithPkey > infos , int flags ) throws PKCS7Exception {
222+ if ( ! isSigned () ) {
223+ throw new PKCS7Exception (F_PKCS7_GET0_SIGNERS , R_WRONG_CONTENT_TYPE );
226224 }
227225
228- if ( sinfos .size () == 0 ) {
229- throw new PKCS7Exception (F_PKCS7_GET0_SIGNERS ,R_NO_SIGNERS );
226+ if ( infos == null || infos .size () == 0 ) {
227+ throw new PKCS7Exception (F_PKCS7_GET0_SIGNERS , R_NO_SIGNERS );
230228 }
231229
232- for (SignerInfoWithPkey si : sinfos ) {
233- IssuerAndSerialNumber ias = si .getIssuerAndSerialNumber ();
230+ final ArrayList <X509AuxCertificate > signers = new ArrayList <X509AuxCertificate >(infos .size ());
231+
232+ for ( final SignerInfoWithPkey info : infos ) {
233+ final IssuerAndSerialNumber ias = info .getIssuerAndSerialNumber ();
234234 X509AuxCertificate signer = null ;
235235// System.err.println("looking for: " + ias.getName() + " and " + ias.getCertificateSerialNumber());
236236// System.err.println(" in: " + certs);
@@ -329,98 +329,90 @@ public void signatureVerify(BIO bio, SignerInfoWithPkey si, X509AuxCertificate x
329329 *
330330 */
331331 public void verify (Collection <X509AuxCertificate > certs , Store store , BIO indata , BIO out , int flags ) throws PKCS7Exception {
332- if (! isSigned ()) {
332+ if ( ! isSigned () ) {
333333 throw new PKCS7Exception (F_PKCS7_VERIFY , R_WRONG_CONTENT_TYPE );
334334 }
335335
336- if ( getDetached () != 0 && indata == null ) {
336+ if ( getDetached () != 0 && indata == null ) {
337337 throw new PKCS7Exception (F_PKCS7_VERIFY , R_NO_CONTENT );
338338 }
339339
340- List <SignerInfoWithPkey > sinfos = new ArrayList < SignerInfoWithPkey >( getSignerInfo () );
341- if ( sinfos .size () == 0 ) {
340+ Collection <SignerInfoWithPkey > infos = getSignerInfo ();
341+ if ( infos == null || infos .size () == 0 ) {
342342 throw new PKCS7Exception (F_PKCS7_VERIFY , R_NO_SIGNATURES_ON_DATA );
343343 }
344344
345- List <X509AuxCertificate > signers = getSigners (certs , sinfos , flags );
346- if ( signers == null ) {
345+ List <X509AuxCertificate > signers = getSigners (certs , infos , flags );
346+ if ( signers == null ) {
347347 throw new NotVerifiedPKCS7Exception ();
348348 }
349349
350350 /* Now verify the certificates */
351- if ( (flags & NOVERIFY ) == 0 ) {
352- for ( X509AuxCertificate signer : signers ) {
353- StoreContext cert_ctx = new StoreContext ();
354- if ( (flags & NOCHAIN ) == 0 ) {
355- if ( cert_ctx .init (store , signer , new ArrayList <X509AuxCertificate >(getSign ().getCert ())) == 0 ) {
351+ if ( (flags & NOVERIFY ) == 0 ) {
352+ for ( final X509AuxCertificate signer : signers ) {
353+ final StoreContext certContext = new StoreContext (store );
354+ if ( (flags & NOCHAIN ) == 0 ) {
355+ if ( certContext .init (signer , new ArrayList <X509AuxCertificate >(getSign ().getCert ())) == 0 ) {
356356 throw new PKCS7Exception (F_PKCS7_VERIFY , -1 );
357357 }
358- cert_ctx .setPurpose (X509Utils .X509_PURPOSE_SMIME_SIGN );
359- } else if (cert_ctx .init (store , signer , null ) == 0 ) {
358+ certContext .setPurpose (X509Utils .X509_PURPOSE_SMIME_SIGN );
359+ }
360+ else if ( certContext .init (signer , null ) == 0 ) {
360361 throw new PKCS7Exception (F_PKCS7_VERIFY , -1 );
361362 }
362- cert_ctx .setExtraData (1 , store .getExtraData (1 ));
363- if ( (flags & NOCRL ) == 0 ) {
364- cert_ctx .setCRLs ((List <X509CRL >)getSign ().getCrl ());
363+ certContext .setExtraData (1 , store .getExtraData (1 ));
364+ if ( (flags & NOCRL ) == 0 ) {
365+ certContext .setCRLs ((List <X509CRL >) getSign ().getCrl ());
365366 }
366367 try {
367- int i = cert_ctx .verifyCertificate ();
368+ int i = certContext .verifyCertificate ();
368369 int j = 0 ;
369- if (i <= 0 ) {
370- j = cert_ctx .getError ();
370+ if (i <= 0 ) {
371+ j = certContext .getError ();
371372 }
372- cert_ctx .cleanup ();
373- if ( i <= 0 ) {
373+ certContext .cleanup ();
374+ if ( i <= 0 ) {
374375 throw new PKCS7Exception (F_PKCS7_VERIFY , R_CERTIFICATE_VERIFY_ERROR , "Verify error:" + X509Utils .verifyCertificateErrorString (j ));
375376 }
376- } catch (PKCS7Exception e ) {
377+ }
378+ catch (PKCS7Exception e ) {
377379 throw e ;
378- } catch (Exception e ) {
380+ }
381+ catch (Exception e ) {
379382 throw new PKCS7Exception (F_PKCS7_VERIFY , R_CERTIFICATE_VERIFY_ERROR , e );
380383 }
381384 }
382385 }
383386
384387 BIO tmpin = indata ;
385388 BIO p7bio = dataInit (tmpin );
386- BIO tmpout ;
387- if ((flags & TEXT ) != 0 ) {
388- tmpout = BIO .mem ();
389- } else {
390- tmpout = out ;
391- }
389+ final BIO tmpout = ( flags & TEXT ) != 0 ? BIO .mem () : out ;
392390
393- byte [] buf = new byte [4096 ];
391+ final byte [] buf = new byte [4096 ];
394392 for (;;) {
395393 try {
396- int i = p7bio .read (buf , 0 , buf .length );
397- if (i <= 0 ) {
398- break ;
399- }
400- if (tmpout != null ) {
401- tmpout .write (buf , 0 , i );
402- }
403- } catch (IOException e ) {
394+ final int i = p7bio .read (buf , 0 , buf .length );
395+ if ( i <= 0 ) break ;
396+ if (tmpout != null ) tmpout .write (buf , 0 , i );
397+ }
398+ catch (IOException e ) {
404399 throw new PKCS7Exception (F_PKCS7_VERIFY , -1 , e );
405400 }
406401 }
407402
408- if ( (flags & TEXT ) != 0 ) {
403+ if ( (flags & TEXT ) != 0 ) {
409404 new SMIME (Mime .DEFAULT ).text (tmpout , out );
410405 }
411406
412- if ((flags & NOSIGS ) == 0 ) {
413- for (int i =0 ; i <sinfos .size (); i ++) {
414- SignerInfoWithPkey si = sinfos .get (i );
415- X509AuxCertificate signer = signers .get (i );
416- signatureVerify (p7bio , si , signer );
407+ if ( (flags & NOSIGS ) == 0 ) {
408+ int i = 0 ; for ( SignerInfoWithPkey info : infos ) {
409+ X509AuxCertificate signer = signers .get (i ++);
410+ signatureVerify (p7bio , info , signer );
417411 }
418412 }
419413
420- if (tmpin == indata ) {
421- if (indata != null ) {
422- p7bio .pop ();
423- }
414+ if ( tmpin == indata ) {
415+ if ( indata != null ) p7bio .pop ();
424416 }
425417 }
426418
0 commit comments