1. /*
  2. * @(#)PKIXCertPathChecker.java 1.5 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security.cert;
  8. import java.util.Collection;
  9. import java.util.Set;
  10. /**
  11. * An abstract class that performs one or more checks on an
  12. * <code>X509Certificate</code>.
  13. *
  14. * <p>A concrete implementation of the <code>PKIXCertPathChecker</code> class
  15. * can be created to extend the PKIX certification path validation algorithm.
  16. * For example, an implementation may check for and process a critical private
  17. * extension of each certificate in a certification path.
  18. *
  19. * <p>Instances of <code>PKIXCertPathChecker</code> are passed as parameters
  20. * using the {@link PKIXParameters#setCertPathCheckers setCertPathCheckers}
  21. * or {@link PKIXParameters#addCertPathChecker addCertPathChecker} methods
  22. * of the <code>PKIXParameters</code> and <code>PKIXBuilderParameters</code>
  23. * class. Each of the <code>PKIXCertPathChecker</code>s {@link #check check}
  24. * methods will be called, in turn, for each certificate processed by a PKIX
  25. * <code>CertPathValidator</code> or <code>CertPathBuilder</code>
  26. * implementation.
  27. *
  28. * <p>A <code>PKIXCertPathChecker</code> may be called multiple times on
  29. * successive certificates in a certification path. Concrete subclasses
  30. * are expected to maintain any internal state that may be necessary to
  31. * check successive certificates. The {@link #init init} method is used
  32. * to initialize the internal state of the checker so that the certificates
  33. * of a new certification path may be checked. A stateful implementation
  34. * <b>must</b> override the {@link #clone clone} method if necessary in
  35. * order to allow a PKIX <code>CertPathBuilder</code> to efficiently
  36. * backtrack and try other paths. In these situations, the
  37. * <code>CertPathBuilder</code> is able to restore prior path validation
  38. * states by restoring the cloned <code>PKIXCertPathChecker</code>s.
  39. *
  40. * <p>The order in which the certificates are presented to the
  41. * <code>PKIXCertPathChecker</code> may be either in the forward direction
  42. * (from target to most-trusted CA) or in the reverse direction (from
  43. * most-trusted CA to target). A <code>PKIXCertPathChecker</code> implementation
  44. * <b>must</b> support reverse checking (the ability to perform its checks when
  45. * it is presented with certificates in the reverse direction) and <b>may</b>
  46. * support forward checking (the ability to perform its checks when it is
  47. * presented with certificates in the forward direction). The
  48. * {@link #isForwardCheckingSupported isForwardCheckingSupported} method
  49. * indicates whether forward checking is supported.
  50. * <p>
  51. * Additional input parameters required for executing the check may be
  52. * specified through constructors of concrete implementations of this class.
  53. * <p>
  54. * <b>Concurrent Access</b>
  55. * <p>
  56. * Unless otherwise specified, the methods defined in this class are not
  57. * thread-safe. Multiple threads that need to access a single
  58. * object concurrently should synchronize amongst themselves and
  59. * provide the necessary locking. Multiple threads each manipulating
  60. * separate objects need not synchronize.
  61. *
  62. * @see PKIXParameters
  63. * @see PKIXBuilderParameters
  64. *
  65. * @version 1.5 01/23/03
  66. * @since 1.4
  67. * @author Yassir Elley
  68. * @author Sean Mullan
  69. */
  70. public abstract class PKIXCertPathChecker implements Cloneable {
  71. /**
  72. * Default constructor.
  73. */
  74. protected PKIXCertPathChecker() {}
  75. /**
  76. * Initializes the internal state of this <code>PKIXCertPathChecker</code>.
  77. * <p>
  78. * The <code>forward</code> flag specifies the order that
  79. * certificates will be passed to the {@link #check check} method
  80. * (forward or reverse). A <code>PKIXCertPathChecker</code> <b>must</b>
  81. * support reverse checking and <b>may</b> support forward checking.
  82. *
  83. * @param forward the order that certificates are presented to
  84. * the <code>check</code> method. If <code>true</code>, certificates
  85. * are presented from target to most-trusted CA (forward); if
  86. * <code>false</code>, from most-trusted CA to target (reverse).
  87. * @throws CertPathValidatorException if this
  88. * <code>PKIXCertPathChecker</code> is unable to check certificates in
  89. * the specified order; it should never be thrown if the forward flag
  90. * is false since reverse checking must be supported
  91. */
  92. public abstract void init(boolean forward)
  93. throws CertPathValidatorException;
  94. /**
  95. * Indicates if forward checking is supported. Forward checking refers
  96. * to the ability of the <code>PKIXCertPathChecker</code> to perform
  97. * its checks when certificates are presented to the <code>check</code>
  98. * method in the forward direction (from target to most-trusted CA).
  99. *
  100. * @return <code>true</code> if forward checking is supported,
  101. * <code>false</code> otherwise
  102. */
  103. public abstract boolean isForwardCheckingSupported();
  104. /**
  105. * Returns an immutable <code>Set</code> of X.509 certificate extensions
  106. * that this <code>PKIXCertPathChecker</code> supports (i.e. recognizes, is
  107. * able to process), or <code>null</code> if no extensions are supported.
  108. * <p>
  109. * Each element of the set is a <code>String</code> representing the
  110. * Object Identifier (OID) of the X.509 extension that is supported.
  111. * The OID is represented by a set of nonnegative integers separated by
  112. * periods.
  113. * <p>
  114. * All X.509 certificate extensions that a <code>PKIXCertPathChecker</code>
  115. * might possibly be able to process should be included in the set.
  116. *
  117. * @return an immutable <code>Set</code> of X.509 extension OIDs (in
  118. * <code>String</code> format) supported by this
  119. * <code>PKIXCertPathChecker</code>, or <code>null</code> if no
  120. * extensions are supported
  121. */
  122. public abstract Set getSupportedExtensions();
  123. /**
  124. * Performs the check(s) on the specified certificate using its internal
  125. * state and removes any critical extensions that it processes from the
  126. * specified collection of OID strings that represent the unresolved
  127. * critical extensions. The certificates are presented in the order
  128. * specified by the <code>init</code> method.
  129. *
  130. * @param cert the <code>Certificate</code> to be checked
  131. * @param unresolvedCritExts a <code>Collection</code> of OID strings
  132. * representing the current set of unresolved critical extensions
  133. * @exception CertPathValidatorException if the specified certificate does
  134. * not pass the check
  135. */
  136. public abstract void check(Certificate cert, Collection unresolvedCritExts)
  137. throws CertPathValidatorException;
  138. /**
  139. * Returns a clone of this object. Calls the <code>Object.clone()</code>
  140. * method.
  141. * All subclasses which maintain state must support and
  142. * override this method, if necessary.
  143. *
  144. * @return a copy of this <code>PKIXCertPathChecker</code>
  145. */
  146. public Object clone() {
  147. try {
  148. return super.clone();
  149. } catch (CloneNotSupportedException e) {
  150. /* Cannot happen */
  151. throw new InternalError(e.toString());
  152. }
  153. }
  154. }