Implementing a PKIXCertPathChecker Object
The PKIXCertPathChecker
class is abstract. It
has four methods (check
, getSupportedExtensions
, init
,
and isForwardCheckingSupported
) that all concrete
subclasses must implement.
Implementing a PKIXCertPathChecker
may be trivial
or complex. A PKIXCertPathChecker
implementation
can be stateless or stateful. A stateless implementation does not
maintain its state between successive calls of the check
method.
For example, a PKIXCertPathChecker
that checks that
each certificate contains a particular policy qualifier is stateless.
In contrast, a stateful implementation does maintain state between
successive calls of the check
method. The check
method
of a stateful implementation usually depends on the contents of prior
certificates in the certification path. For example, a PKIXCertPathChecker
that
processes the NameConstraints extension is stateful.
Also, the order in which the certificates processed by a service
provider implementation are presented (passed) to a PKIXCertPathChecker
is
very important, especially if the implementation is stateful. Depending
on the algorithm used by the service provider, the certificates may
be presented in reverse or forward order.
A reverse ordering means that the certificates are ordered from the
most trusted CA (if present) to the target subject, whereas a forward
ordering means that the certificates are ordered from the target subject
to the most trusted CA. The order must be made known to the PKIXCertPathChecker
implementation,
so that it knows how to process consecutive certificates.
Initializing a PKIXCertPathChecker Object
init
method initializes the internal state of the
checker:public abstract void init(boolean forward)
All stateful implementations should clear or initialize
any internal state in the checker. This prevents a service provider
implementation from calling a checker that is in an uninitialized
state. It also allows stateful checkers to be reused in subsequent
operations without reinstantiating them. The forward
parameter
indicates the order of the certificates presented to the PKIXCertPathChecker
.
If forward
is true
, the certificates
are presented from target to trust anchor; if false
,
from trust anchor to target.
Forward Checking
isForwardCheckingSupported
method returns a boolean
that
indicates if the PKIXCertPathChecker
supports forward
checking:public abstract boolean isForwardCheckingSupported()
All PKIXCertPathChecker
implementations must support
reverse checking. A PKIXCertPathChecker
implementation may support
forward checking.
Supporting forward checking improves the efficiency
of CertPathBuilder
s that build forward, because it
allows paths to be checked as they are built. However, some stateful PKIXCertPathChecker
s
may find it difficult or impossible to support forward checking.
Supported Extensions
getSupportedExtensions
method returns an immutable Set
of
OID String
s for the X.509 extensions that the PKIXCertPathChecker
implementation supports (that is, it recognizes and is able to process the
extensions):public abstract Set getSupportedExtensions()
The method should return null
if
no extensions are processed. All implementations should return the Set
of
OID String
s that the check
method
may process.
A CertPathBuilder
can use this
information to identify certificates with unrecognized critical extensions,
even when performing a forward build with a PKIXCertPathChecker that
does not support forward checking.
Executing the Check
public abstract void
check(Certificate cert, Collection unresolvedCritExts)
throws CertPathValidatorException
The unresolvedCritExts
parameter
contains a collection of OIDs as String
s. These OIDs
represent the set of critical extensions in the certificate that have
not yet been resolved by the certification path validation algorithm.
Concrete implementations of the check
method should
remove any critical extensions that it processes from the unresolvedCritExts
parameter.
If
the certificate does not pass the checks, a CertPathValidatorException
should
be thrown.
Cloning a PKIXCertPathChecker
The PKIXCertPathChecker
class
implements the Cloneable
interface. All stateful PKIXCertPathChecker
implementations
must override the clone
method if necessary. The
default implementation of the clone
method calls
the Object.clone
method, which performs a simple
clone by copying all fields of the original object to the new object.
A stateless implementation should not override the clone
method.
However, all stateful implementations must ensure that the default clone
method
is correct, and override it if necessary. For example, a PKIXCertPathChecker
that
stores state in an array must override the clone
method
to make a copy of the array, rather than just a reference to the array.
The
reason that PKIXCertPathChecker
objects are Cloneable
is
to allow a PKIX CertPathBuilder
implementation to
efficiently backtrack and try another path when a potential certification
path reaches a dead end or point of failure. In this case, the implementation
is able to restore prior path validation states by restoring the cloned
objects.