|
34 | 34 | import java.util.ArrayList; |
35 | 35 | import java.util.List; |
36 | 36 | import java.util.Set; |
37 | | - |
38 | 37 | import java.security.GeneralSecurityException; |
39 | 38 | import java.security.PrivateKey; |
40 | 39 | import java.security.PublicKey; |
41 | 40 | import java.security.cert.CRLException; |
42 | 41 | import java.security.cert.CertificateFactory; |
43 | 42 | import java.security.cert.X509CRLEntry; |
44 | | -import java.security.interfaces.DSAParams; |
45 | | -import java.security.interfaces.DSAPublicKey; |
46 | | -import java.security.interfaces.RSAPublicKey; |
47 | 43 | import java.util.Arrays; |
48 | 44 | import java.util.Collection; |
49 | 45 | import java.util.Comparator; |
|
59 | 55 | import org.bouncycastle.asn1.x500.X500Name; |
60 | 56 | import org.bouncycastle.asn1.x509.Extension; |
61 | 57 | import org.bouncycastle.asn1.x509.Extensions; |
62 | | -import org.bouncycastle.cert.CertException; |
63 | 58 | import org.bouncycastle.cert.X509CRLHolder; |
64 | 59 | import org.bouncycastle.cert.X509v2CRLBuilder; |
65 | | -import org.bouncycastle.crypto.params.AsymmetricKeyParameter; |
66 | | -import org.bouncycastle.crypto.params.DSAParameters; |
67 | | -import org.bouncycastle.crypto.params.DSAPublicKeyParameters; |
68 | | -import org.bouncycastle.crypto.params.RSAKeyParameters; |
69 | 60 | import org.bouncycastle.operator.ContentSigner; |
70 | | -import org.bouncycastle.operator.ContentVerifierProvider; |
71 | | -import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder; |
72 | | -import org.bouncycastle.operator.DigestAlgorithmIdentifierFinder; |
73 | | -import org.bouncycastle.operator.OperatorException; |
74 | | -import org.bouncycastle.operator.bc.BcDSAContentVerifierProviderBuilder; |
75 | | -import org.bouncycastle.operator.bc.BcRSAContentVerifierProviderBuilder; |
76 | 61 | import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; |
77 | | - |
78 | 62 | import org.joda.time.DateTime; |
79 | 63 | import org.jruby.Ruby; |
80 | 64 | import org.jruby.RubyArray; |
@@ -700,42 +684,10 @@ public IRubyObject verify(final ThreadContext context, final IRubyObject key) { |
700 | 684 | if ( changed ) return context.runtime.getFalse(); |
701 | 685 | final PublicKey publicKey = ((PKey) key).getPublicKey(); |
702 | 686 | try { |
703 | | - // NOTE: with BC 1.49 this seems to need BC provider installed ;( |
704 | | - // java.security.NoSuchProviderException: no such provider: BC |
705 | | - // at sun.security.jca.GetInstance.getService(GetInstance.java:83) |
706 | | - // at sun.security.jca.GetInstance.getInstance(GetInstance.java:206) |
707 | | - // at java.security.Signature.getInstance(Signature.java:355) |
708 | | - // at org.bouncycastle.jcajce.provider.asymmetric.x509.X509CRLObject.verify(Unknown Source) |
709 | | - // at org.bouncycastle.jcajce.provider.asymmetric.x509.X509CRLObject.verify(Unknown Source) |
710 | | - // at org.jruby.ext.openssl.SecurityHelper.verify(SecurityHelper.java:564) |
711 | | - // at org.jruby.ext.openssl.X509CRL.verify(X509CRL.java:717) |
712 | | - //boolean valid = SecurityHelper.verify(getCRL(), publicKey, true); |
713 | | - |
714 | | - final DigestAlgorithmIdentifierFinder digestAlgFinder = new DefaultDigestAlgorithmIdentifierFinder(); |
715 | | - final ContentVerifierProvider verifierProvider; |
716 | | - if ( isDSA( (PKey) key ) ) { |
717 | | - BigInteger y = ((DSAPublicKey) publicKey).getY(); |
718 | | - DSAParams params = ((DSAPublicKey) publicKey).getParams(); |
719 | | - DSAParameters parameters = new DSAParameters(params.getP(), params.getQ(), params.getG()); |
720 | | - AsymmetricKeyParameter dsaKey = new DSAPublicKeyParameters(y, parameters); |
721 | | - verifierProvider = new BcDSAContentVerifierProviderBuilder(digestAlgFinder).build(dsaKey); |
722 | | - } |
723 | | - else { |
724 | | - BigInteger mod = ((RSAPublicKey) publicKey).getModulus(); |
725 | | - BigInteger exp = ((RSAPublicKey) publicKey).getPublicExponent(); |
726 | | - AsymmetricKeyParameter rsaKey = new RSAKeyParameters(false, mod, exp); |
727 | | - verifierProvider = new BcRSAContentVerifierProviderBuilder(digestAlgFinder).build(rsaKey); |
728 | | - } |
729 | | - //final X509CRLHolder crl = getCRLHolder(); |
730 | | - //final AlgorithmIdentifier algId = crl.toASN1Structure().getSignatureAlgorithm(); |
731 | | - boolean valid = getCRLHolder(false).isSignatureValid( verifierProvider ); |
| 687 | + boolean valid = SecurityHelper.verify(getCRL(), publicKey, true); |
732 | 688 | return context.runtime.newBoolean(valid); |
733 | 689 | } |
734 | | - catch (OperatorException e) { |
735 | | - debug("CRL#verify() failed:", e); |
736 | | - return context.runtime.getFalse(); |
737 | | - } |
738 | | - catch (CertException e) { |
| 690 | + catch (GeneralSecurityException e) { |
739 | 691 | debug("CRL#verify() failed:", e); |
740 | 692 | return context.runtime.getFalse(); |
741 | 693 | } |
|
0 commit comments