Skip to content

Commit

Permalink
Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Akila94 committed Jan 26, 2024
1 parent a543877 commit 6671e39
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public CertificateVerificationManager(Integer cacheAllocatedSize, Integer cacheD
&& cacheDelayMins < Constants.CACHE_MAX_DELAY_MINS) {
this.cacheDelayMins = cacheDelayMins;
}
log.warn("The cache delay is out of range. Hence, using the default cache delay value of "
+ Constants.CACHE_DEFAULT_DELAY_MINS + ".");
}

public CertificateVerificationManager(Integer cacheAllocatedSize, Integer cacheDelayMins,
Expand All @@ -81,6 +83,9 @@ public CertificateVerificationManager(Integer cacheAllocatedSize, Integer cacheD
&& cacheDelayMins < Constants.CACHE_MAX_DELAY_MINS) {
this.cacheDelayMins = cacheDelayMins;
}
log.warn("The cache delay is out of range. Hence, using the default cache delay value of "
+ Constants.CACHE_DEFAULT_DELAY_MINS + ".");

this.isFullCertChainValidationEnabled = isFullCertChainValidationEnabled;
this.isCertExpiryValidationEnabled = isCertExpiryValidationEnabled;
}
Expand Down Expand Up @@ -182,12 +187,8 @@ public void verifyCertificateValidity(javax.security.cert.X509Certificate[] peer
}
}

long start = System.currentTimeMillis();

OCSPCache ocspCache = OCSPCache.getCache();
ocspCache.init(cacheSize, cacheDelayMins);
CRLCache crlCache = CRLCache.getCache();
crlCache.init(cacheSize, cacheDelayMins);
OCSPCache ocspCache = OCSPCache.getCache(cacheSize, cacheDelayMins);
CRLCache crlCache = CRLCache.getCache(cacheSize, cacheDelayMins);

RevocationVerifier[] verifiers = {new OCSPVerifier(ocspCache), new CRLVerifier(crlCache)};

Expand All @@ -206,7 +207,6 @@ public void verifyCertificateValidity(javax.security.cert.X509Certificate[] peer
CertificatePathValidator pathValidator = new CertificatePathValidator(convertedCertificates,
verifier);
pathValidator.validatePath();
log.info("Path verification Successful. Took " + (System.currentTimeMillis() - start) + " ms.");
} else {

if (isCertExpiryValidationEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ public class CRLCache implements ManageableCache {
private CRLCache() {
}

public static CRLCache getCache() {
public static CRLCache getCache(int cacheSize, int cacheDelayMins) {
//Double checked locking
if (cache == null) {
synchronized (CRLCache.class) {
if (cache == null) {
cache = new CRLCache();
cacheManager = new CacheManager(cache, cacheSize, cacheDelayMins);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.commons.jmx.MBeanRegistrar;
import org.apache.synapse.transport.certificatevalidation.CertificateVerificationException;
import org.apache.synapse.transport.certificatevalidation.Constants;
import org.apache.synapse.transport.certificatevalidation.cache.CacheController;
import org.apache.synapse.transport.certificatevalidation.cache.CacheManager;
import org.apache.synapse.transport.certificatevalidation.cache.ManageableCache;
Expand Down Expand Up @@ -51,12 +52,14 @@ public class OCSPCache implements ManageableCache {

private OCSPCache() {}

public static OCSPCache getCache() {
public static OCSPCache getCache(int cacheSize, int cacheDelayMins) {
//Double checked locking
if (cache == null) {
synchronized (OCSPCache.class) {
if (cache == null)
if (cache == null) {
cache = new OCSPCache();
cacheManager = new CacheManager(cache, cacheSize, cacheDelayMins);
}
}
}
return cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public void testRevokedCertificate() throws Exception {
//Create a crl with fakeRevokedCertificate marked as revoked.
X509CRL x509CRL = createCRL(fakeCACert, caKeyPair.getPrivate(), revokedSerialNumber);

CRLCache cache = CRLCache.getCache();
cache.init(5, 5);
CRLCache cache = CRLCache.getCache(5, 5);
cache.setCacheValue(crlDistributionPointUrl, x509CRL);

CRLVerifier crlVerifier = new CRLVerifier(cache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public void testOCSPVerifier() throws Exception{
OCSPResp response = generateOCSPResponse(request, certificateHolder, caKeyPair.getPrivate(), caKeyPair.getPublic(), revokedID);
SingleResp singleResp = ((BasicOCSPResp)response.getResponseObject()).getResponses()[0];

OCSPCache cache = OCSPCache.getCache();
cache.init(5,5);
OCSPCache cache = OCSPCache.getCache(5, 5);
cache.setCacheValue(revokedSerialNumber,singleResp, request, null);

OCSPVerifier ocspVerifier= new OCSPVerifier(cache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,15 @@ public void testOCSPPathValidationWithFakeCerts() throws Exception {

private void crlPathValidation(X509Certificate[] certChain) throws Exception {

CRLCache crlCache = CRLCache.getCache();
crlCache.init(5, 5);
CRLCache crlCache = CRLCache.getCache(5, 5);
RevocationVerifier verifier = new CRLVerifier(crlCache);
CertificatePathValidator pathValidator = new CertificatePathValidator(certChain, verifier);
pathValidator.validatePath();
}

private void ocspPathValidation(X509Certificate[] certChain) throws Exception {

OCSPCache ocspCache = OCSPCache.getCache();
ocspCache.init(5, 5);
OCSPCache ocspCache = OCSPCache.getCache(5, 5);
RevocationVerifier verifier = new OCSPVerifier(ocspCache);
CertificatePathValidator pathValidator = new CertificatePathValidator(certChain, verifier);
pathValidator.validatePath();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
t-0-1705986523002.txt 23/01/2024/ 10:38:43

0 comments on commit 6671e39

Please sign in to comment.