|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnl.nikhef.slcshttps.trust.CertChainChecker
public class CertChainChecker
Static class to validate a X509Certificate
chain. It provides only
one public (and static) method, validate(X509Certificate[])
. The
class is static for performance reasons, it's only initialized at startup.
It uses either the Java truststore specified via the default security
settings in $JAVA_HOME/lib/security/ or via an external truststore which can
be specified by defining the system property
javax.net.ssl.trustStore
.
See JSSE
Reference Guide for details.
The code to find the correct truststore is roughly taken over from
the implementation dependent JDK1.6 class
sun.security.ssl.TrustManagerFactoryImpl
.
The CertPathValidator
uses BouncyCastle for stability and more human
readable error messages. BouncyCastle follows mostly RFC3280 which is now
superseded by RFC5280.
Field Summary | |
---|---|
private static CertificateFactory |
certFactory
certFactory is needed to make a CertPath object
from a . |
private static CertPathValidator |
certValidator
certValidator is doing the actual validation, initialized
at startup using initCertValidator() . |
private static PKIXBuilderParameters |
pkixParameters
PKIXParameters used by the certValidator , they use
the trustStore and are initialized at startup using initPKIXParameters() . |
private static KeyStore |
trustStore
KeyStore with trusted certificates, initialized at class
initialization using getCacertsKeyStore() . |
Constructor Summary | |
---|---|
CertChainChecker()
|
Method Summary | |
---|---|
static X509Certificate[] |
getAcceptedIssuers()
Method to get all the accepted issuers for certificate chain checking. |
private static KeyStore |
getCacertsKeyStore()
Method to find the correct truststore with trusted CA certificates. |
private static CertPath |
getCertPath(X509Certificate[] x509Chain)
Returns a CertPath object for the given array of X509Certificate . |
private static FileInputStream |
getFileInputStream(File file)
Checks whether a file exists and can be opened. |
private static CertificateFactory |
initCertFactory()
Static method creating a new CertificateFactory . |
private static CertPathValidator |
initCertValidator()
Static method creating a new CertPathValidator . |
private static PKIXBuilderParameters |
initPKIXParameters()
Static method to initialize the PKIXBuilderParameters for CertPathValidator . |
static void |
validate(X509Certificate[] x509Chain)
Validates a X509Certificate chain. |
static void |
validate(X509Certificate[] x509Chain,
Date date)
Validates a X509Certificate chain for given date. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static KeyStore trustStore
KeyStore
with trusted certificates, initialized at class
initialization using getCacertsKeyStore()
.
private static CertPathValidator certValidator
certValidator
is doing the actual validation, initialized
at startup using initCertValidator()
.
private static CertificateFactory certFactory
certFactory
is needed to make a CertPath
object
from a X509Certificate
[]
.
private static PKIXBuilderParameters pkixParameters
PKIXParameters
used by the certValidator
, they use
the trustStore
and are initialized at startup using initPKIXParameters()
.
Constructor Detail |
---|
public CertChainChecker()
Method Detail |
---|
public static void validate(X509Certificate[] x509Chain) throws CertPathValidatorException, CertificateException
X509Certificate
chain.
x509Chain
- array of certificates, they should be in the right
order.
CertPathValidatorException
- when chain validation fails.
Throwable.getMessage()
gives the reason.
CertificateException
- upon other error.validate(X509Certificate[],Date)
public static void validate(X509Certificate[] x509Chain, Date date) throws CertPathValidatorException, CertificateException
X509Certificate
chain for given date.
x509Chain
- array of certificates, they should be in the right
order.date
- at which to check the certificate chain, when
null
use now.
CertPathValidatorException
- when chain validation fails.
Throwable.getMessage()
gives the reason.
CertificateException
- upon other errorvalidate(X509Certificate[])
public static X509Certificate[] getAcceptedIssuers()
private static CertPath getCertPath(X509Certificate[] x509Chain) throws CertPathValidatorException
CertPath
object for the given array of X509Certificate
. It also strips off the root CA certificate, i.e. if the
first certificate is self-signed it will be stripped, this is necessary
to ensure that we don't get error messages from the validator if this is
a Version 1 cert (like many root CA certificates are).
x509Chain
- array of X509Certificate
certificates, note
that Java demands them to be in the correct order, see
RFC 5246 page 48.
CertPathValidatorException
- when creation failsprivate static CertPathValidator initCertValidator() throws RuntimeException
CertPathValidator
. Since this method
is intended to be called at class initialization it throws a
RuntimeException
since it cannot be caught.
RuntimeException
- in case of error.private static CertificateFactory initCertFactory() throws RuntimeException
CertificateFactory
. Since this
method is intended to be called at class initialization it throws a
RuntimeException
since it cannot be caught.
RuntimeException
- in case of error.private static PKIXBuilderParameters initPKIXParameters() throws RuntimeException
PKIXBuilderParameters
for CertPathValidator
. It uses PKIXBuilderParameters
and not PKIXParameters
since it allows us to raise the certificate chain length
to be checked to infinity (-1). Since this method is intended to be
called at class initialization it throws a RuntimeException
since it cannot be caught.
RuntimeException
- in case of error.private static KeyStore getCacertsKeyStore() throws RuntimeException
sun.security.ssl.TrustManagerFactoryImpl
.
Since this method is intended to be called at class initialization it
throws a RuntimeException
since it cannot be caught.
RuntimeException
- in case of error.private static FileInputStream getFileInputStream(File file)
file
- file to be checked.
null
when it could
not be opened or didn't exist.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
nl.nikhef.slcshttps | Mischa Sallé - msalle(AT)nikhef.nl |