-
Notifications
You must be signed in to change notification settings - Fork 879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring CmsValidator (internal CRL resolution) #2635
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: Lucas Saldanha <lucascrsaldanha@gmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import java.security.cert.CertPathBuilder; | ||
import java.security.cert.CertPathBuilderException; | ||
import java.security.cert.CertStore; | ||
import java.security.cert.CollectionCertStoreParameters; | ||
import java.security.cert.PKIXBuilderParameters; | ||
import java.security.cert.PKIXRevocationChecker; | ||
import java.security.cert.PKIXRevocationChecker.Option; | ||
|
@@ -54,11 +55,9 @@ public class CmsValidator { | |
private static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
private final KeyStoreWrapper truststore; | ||
private final Optional<CertStore> crlCertStore; | ||
|
||
public CmsValidator(final KeyStoreWrapper truststore, final CertStore crlCertStore) { | ||
public CmsValidator(final KeyStoreWrapper truststore) { | ||
this.truststore = truststore; | ||
this.crlCertStore = Optional.ofNullable(crlCertStore); | ||
} | ||
|
||
/** | ||
|
@@ -146,17 +145,18 @@ private boolean isCertificateTrusted( | |
new PKIXBuilderParameters(truststore.getKeyStore(), targetConstraints); | ||
|
||
// Adding CertStore with CRLs (if present, otherwise disabling revocation check) | ||
crlCertStore.ifPresentOrElse( | ||
CRLs -> { | ||
params.addCertStore(CRLs); | ||
PKIXRevocationChecker rc = (PKIXRevocationChecker) cpb.getRevocationChecker(); | ||
rc.setOptions(EnumSet.of(Option.PREFER_CRLS)); | ||
params.addCertPathChecker(rc); | ||
}, | ||
() -> { | ||
LOGGER.warn("No CRL CertStore provided. CRL validation will be disabled."); | ||
params.setRevocationEnabled(false); | ||
}); | ||
loadCRLs(truststore) | ||
.ifPresentOrElse( | ||
CRLs -> { | ||
params.addCertStore(CRLs); | ||
PKIXRevocationChecker rc = (PKIXRevocationChecker) cpb.getRevocationChecker(); | ||
rc.setOptions(EnumSet.of(Option.PREFER_CRLS)); | ||
params.addCertPathChecker(rc); | ||
}, | ||
() -> { | ||
LOGGER.warn("No CRL CertStore provided. CRL validation will be disabled."); | ||
params.setRevocationEnabled(false); | ||
}); | ||
|
||
// Read certificates sent on the CMS message and adding it to the path building algorithm | ||
final CertStore cmsCertificates = | ||
|
@@ -178,4 +178,18 @@ private boolean isCertificateTrusted( | |
throw new RuntimeException("Error validating certificate chain", e); | ||
} | ||
} | ||
|
||
private Optional<CertStore> loadCRLs(final KeyStoreWrapper truststore) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noticed there is CRLUtil that does something similar to this function, should that be used instead or this replaces that one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CRLUtil is used when loading the CRL pem file. Not for the truststore. They are similar but not the same. |
||
if (truststore.getCRLs() != null) { | ||
try { | ||
return Optional.of( | ||
CertStore.getInstance( | ||
"Collection", new CollectionCertStoreParameters(truststore.getCRLs()))); | ||
} catch (final Exception e) { | ||
throw new RuntimeException("Error loading CRLs from Truststore", e); | ||
} | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really loading CRL as such, maybe createCertStore?