|
23 | 23 | */
|
24 | 24 | package org.jruby.ext.openssl;
|
25 | 25 |
|
| 26 | +import static org.jruby.ext.openssl.OpenSSL.debugStackTrace; |
| 27 | + |
26 | 28 | import java.lang.reflect.Constructor;
|
27 | 29 | import java.lang.reflect.Field;
|
28 | 30 | import java.lang.reflect.InvocationTargetException;
|
29 | 31 | import java.lang.reflect.Method;
|
30 |
| -import java.util.Locale; |
31 |
| - |
32 | 32 | import java.security.InvalidKeyException;
|
33 | 33 | import java.security.KeyFactory;
|
34 | 34 | import java.security.KeyFactorySpi;
|
|
39 | 39 | import java.security.MessageDigest;
|
40 | 40 | import java.security.MessageDigestSpi;
|
41 | 41 | import java.security.NoSuchAlgorithmException;
|
42 |
| -import java.security.NoSuchProviderException; |
43 | 42 | import java.security.Provider;
|
44 | 43 | import java.security.PublicKey;
|
45 | 44 | import java.security.SecureRandom;
|
|
53 | 52 | import java.security.cert.CertificateFactory;
|
54 | 53 | import java.security.cert.CertificateFactorySpi;
|
55 | 54 | import java.security.cert.X509CRL;
|
| 55 | +import java.util.LinkedList; |
| 56 | +import java.util.List; |
| 57 | +import java.util.Locale; |
56 | 58 | import java.util.Map;
|
57 | 59 | import java.util.StringTokenizer;
|
58 | 60 | import java.util.concurrent.ConcurrentHashMap;
|
|
72 | 74 | import org.bouncycastle.asn1.x509.CertificateList;
|
73 | 75 | import org.bouncycastle.jce.provider.X509CRLObject;
|
74 | 76 |
|
75 |
| -import static org.jruby.ext.openssl.OpenSSL.debugStackTrace; |
76 |
| - |
77 | 77 | /**
|
78 | 78 | * Java Security (and JCE) helpers.
|
79 | 79 | *
|
@@ -563,26 +563,28 @@ static boolean verify(final X509CRL crl, final PublicKey publicKey, final boolea
|
563 | 563 | return true;
|
564 | 564 | }
|
565 | 565 |
|
566 |
| - try { |
567 |
| - crl.verify(publicKey); |
568 |
| - return true; |
569 |
| - } |
570 |
| - catch (NoSuchAlgorithmException ex) { |
571 |
| - if ( silent ) return false; throw ex; |
572 |
| - } |
573 |
| - catch (CRLException ex) { |
574 |
| - if ( silent ) return false; throw ex; |
575 |
| - } |
576 |
| - catch (InvalidKeyException ex) { |
577 |
| - if ( silent ) return false; throw ex; |
578 |
| - } |
579 |
| - catch (SignatureException ex) { |
580 |
| - if ( silent ) return false; throw ex; |
| 566 | + // since we are using JCE here and BC might not be registered as Provider |
| 567 | + // we need to find a provider which supports such CRL verification |
| 568 | + // if we find a provider we will ignore the collected errors |
| 569 | + // otherwise the errors get displayed |
| 570 | + // TODO use BC directly for verifing CRL (probably needs quite some refactoring) |
| 571 | + List<Exception> errors = new LinkedList<Exception>(); |
| 572 | + for(Provider p: Security.getProviders()) { |
| 573 | + try { |
| 574 | + crl.verify(publicKey, p.getName()); |
| 575 | + return true; |
| 576 | + } |
| 577 | + catch(SignatureException e) { |
| 578 | + return false; |
| 579 | + } |
| 580 | + catch(Exception e) { |
| 581 | + errors.add(e); |
| 582 | + } |
581 | 583 | }
|
582 |
| - catch (NoSuchProviderException e) { |
| 584 | + for(Exception e: errors) { |
583 | 585 | debugStackTrace(e);
|
584 |
| - throw new RuntimeException(e); // unexpected - might hide a bug |
585 |
| - } |
| 586 | + } |
| 587 | + return false; |
586 | 588 | }
|
587 | 589 |
|
588 | 590 | private static Object getCertificateList(final Object crl) { // X509CRLObject
|
|
0 commit comments