001/* PKIXCertPathChecker.java -- checks X.509 certificate paths.
002   Copyright (C) 2003 Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package java.security.cert;
040
041import java.util.Collection;
042import java.util.Set;
043
044/**
045 * A validator for X.509 certificates when approving certificate chains.
046 *
047 * <p>Concrete subclasses can be passed to the {@link
048 * PKIXParameters#setCertPathCheckers(java.util.List)} and {@link
049 * PKIXParameters#addCertPathChecker(java.security.cert.PKIXCertPathChecker)}
050 * methods, which are then used to set up PKIX certificate chain
051 * builders or validators. These classes then call the {@link
052 * #check(java.security.cert.Certificate,java.util.Collection)} method
053 * of this class, performing whatever checks on the certificate,
054 * throwing an exception if any check fails.
055 *
056 * <p>Subclasses of this must be able to perform their checks in the
057 * backward direction -- from the most-trusted certificate to the target
058 * -- and may optionally support forward checking -- from the target to
059 * the most-trusted certificate.
060 *
061 * @see PKIXParameters
062 * @since 1.4
063 */
064public abstract class PKIXCertPathChecker implements Cloneable
065{
066
067  // Constructor.
068  // ------------------------------------------------------------------------
069
070  /** Default constructor. */
071  protected PKIXCertPathChecker()
072  {
073    super();
074  }
075
076  // Cloneable interface.
077  // ------------------------------------------------------------------------
078
079  public Object clone()
080  {
081    try
082      {
083        return super.clone();
084      }
085    catch (CloneNotSupportedException cnse)
086      {
087        throw new InternalError(cnse.getMessage());
088      }
089  }
090
091  // Abstract methods.
092  // ------------------------------------------------------------------------
093
094  /**
095   * Initialize this PKIXCertPathChecker. If subclasses support forward
096   * checking, a value of true can be passed to this method, and
097   * certificates can be validated from the target certificate to the
098   * most-trusted certifcate.
099   *
100   * @param forward The direction of this PKIXCertPathChecker.
101   * @throws CertPathValidatorException If <i>forward</i> is true and
102   *         this class does not support forward checking.
103   */
104  public abstract void init(boolean forward) throws CertPathValidatorException;
105
106  /**
107   * Returns whether or not this class supports forward checking.
108   *
109   * @return Whether or not this class supports forward checking.
110   */
111  public abstract boolean isForwardCheckingSupported();
112
113  /**
114   * Returns an immutable set of X.509 extension object identifiers (OIDs)
115   * supported by this PKIXCertPathChecker.
116   *
117   * @return An immutable set of Strings of the supported X.509 OIDs, or
118   *         null if no extensions are supported.
119   */
120  public abstract Set<String> getSupportedExtensions();
121
122  /**
123   * Checks a certificate, removing any critical extensions that are
124   * resolved in this check.
125   *
126   * @param cert               The certificate to check.
127   * @param unresolvedCritExts The (mutable) collection of as-of-yet
128   *        unresolved critical extensions, as OID strings.
129   * @throws CertPathValidatorException If this certificate fails this
130   *         check.
131   */
132  public abstract void check(Certificate cert, Collection<String> unresolvedCritExts)
133  throws CertPathValidatorException;
134}