|
18 | 18 | */ |
19 | 19 | package org.apache.synapse.transport.certificatevalidation.ocsp; |
20 | 20 |
|
| 21 | +import org.apache.commons.lang.StringUtils; |
21 | 22 | import org.apache.commons.logging.Log; |
22 | 23 | import org.apache.commons.logging.LogFactory; |
23 | 24 | import org.apache.http.HttpResponse; |
|
27 | 28 | import org.apache.http.entity.ContentType; |
28 | 29 | import org.apache.http.impl.client.CloseableHttpClient; |
29 | 30 | import org.apache.http.impl.client.HttpClientBuilder; |
| 31 | +import org.apache.synapse.commons.crypto.CryptoConstants; |
30 | 32 | import org.apache.synapse.transport.certificatevalidation.CertificateVerificationException; |
31 | 33 | import org.apache.synapse.transport.certificatevalidation.Constants; |
32 | 34 | import org.apache.synapse.transport.certificatevalidation.RevocationStatus; |
@@ -79,7 +81,7 @@ public OCSPVerifier(OCSPCache cache) { |
79 | 81 | public static final String ACCEPT_TYPE = "Accept"; |
80 | 82 | public static final String OCSP_REQUEST_TYPE = "application/ocsp-request"; |
81 | 83 | public static final String OCSP_RESPONSE_TYPE = "application/ocsp-response"; |
82 | | - |
| 84 | + private static final String SECURITY_JCE_PROVIDER = "security.jce.provider"; |
83 | 85 |
|
84 | 86 | /** |
85 | 87 | * Gets the revocation status (Good, Revoked or Unknown) of the given peer certificate. |
@@ -201,20 +203,7 @@ protected OCSPResp getOCSPResponce(String serviceUrl, OCSPReq request) throws Ce |
201 | 203 | private OCSPReq generateOCSPRequest(X509Certificate issuerCert, BigInteger serialNumber) |
202 | 204 | throws CertificateVerificationException { |
203 | 205 | String jceProvider = getPreferredJceProvider(); |
204 | | - String providerClass; |
205 | | - if (jceProvider.equals(Constants.BOUNCY_CASTLE_PROVIDER)) { |
206 | | - providerClass = "org.bouncycastle.jce.provider.BouncyCastleProvider"; |
207 | | - } else if (jceProvider.equals(Constants.BOUNCY_CASTLE_FIPS_PROVIDER)) { |
208 | | - providerClass = "org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider"; |
209 | | - } else { |
210 | | - throw new CertificateVerificationException("Unsupported JCE provider: " + jceProvider); |
211 | | - } |
212 | | - try { |
213 | | - Security.addProvider((Provider) Class.forName(providerClass).getDeclaredConstructor().newInstance()); |
214 | | - } catch (Exception e) { |
215 | | - throw new CertificateVerificationException("Error while initializing the JCE provider: " |
216 | | - + providerClass, e); |
217 | | - } |
| 206 | + addProvider(jceProvider); |
218 | 207 |
|
219 | 208 | try { |
220 | 209 |
|
@@ -299,4 +288,21 @@ private static String getPreferredJceProvider() { |
299 | 288 | } |
300 | 289 | return Constants.BOUNCY_CASTLE_PROVIDER; |
301 | 290 | } |
| 291 | + |
| 292 | + public static void addProvider(String jceProvider) throws CertificateVerificationException { |
| 293 | + if (StringUtils.isEmpty(System.getProperty(SECURITY_JCE_PROVIDER))) { |
| 294 | + String providerClass; |
| 295 | + if (CryptoConstants.BOUNCY_CASTLE_FIPS_PROVIDER.equals(jceProvider)) { |
| 296 | + providerClass = "org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider"; |
| 297 | + } else { |
| 298 | + providerClass = "org.bouncycastle.jce.provider.BouncyCastleProvider"; |
| 299 | + } |
| 300 | + try { |
| 301 | + Security.addProvider((Provider) Class.forName(providerClass).getDeclaredConstructor().newInstance()); |
| 302 | + } catch (Exception e) { |
| 303 | + throw new CertificateVerificationException("Error while initializing the JCE provider: " + |
| 304 | + providerClass, e); |
| 305 | + } |
| 306 | + } |
| 307 | + } |
302 | 308 | } |
0 commit comments