1. /*
  2. * @(#)PKIXCertPathValidatorResult.java 1.8 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.security.PublicKey;
  9. /**
  10. * This class represents the successful result of the PKIX certification
  11. * path validation algorithm.
  12. *
  13. * <p>Instances of <code>PKIXCertPathValidatorResult</code> are returned by the
  14. * {@link CertPathValidator#validate validate} method of
  15. * <code>CertPathValidator</code> objects implementing the PKIX algorithm.
  16. *
  17. * <p> All <code>PKIXCertPathValidatorResult</code> objects contain the
  18. * valid policy tree and subject public key resulting from the
  19. * validation algorithm, as well as a <code>TrustAnchor</code> describing
  20. * the certification authority (CA) that served as a trust anchor for the
  21. * certification path.
  22. * <p>
  23. * <b>Concurrent Access</b>
  24. * <p>
  25. * Unless otherwise specified, the methods defined in this class are not
  26. * thread-safe. Multiple threads that need to access a single
  27. * object concurrently should synchronize amongst themselves and
  28. * provide the necessary locking. Multiple threads each manipulating
  29. * separate objects need not synchronize.
  30. *
  31. * @see CertPathValidatorResult
  32. *
  33. * @version 1.8 01/23/03
  34. * @since 1.4
  35. * @author Yassir Elley
  36. * @author Sean Mullan
  37. */
  38. public class PKIXCertPathValidatorResult implements CertPathValidatorResult {
  39. private TrustAnchor trustAnchor;
  40. private PolicyNode policyTree;
  41. private PublicKey subjectPublicKey;
  42. /**
  43. * Creates an instance of <code>PKIXCertPathValidatorResult</code>
  44. * containing the specified parameters.
  45. *
  46. * @param trustAnchor a <code>TrustAnchor</code> describing the CA that
  47. * served as a trust anchor for the certification path
  48. * @param policyTree the immutable valid policy tree, or <code>null</code>
  49. * if there are no valid policies
  50. * @param subjectPublicKey the public key of the subject
  51. * @throws NullPointerException if the <code>subjectPublicKey</code> or
  52. * <code>trustAnchor</code> parameters are <code>null</code>
  53. */
  54. public PKIXCertPathValidatorResult(TrustAnchor trustAnchor,
  55. PolicyNode policyTree, PublicKey subjectPublicKey)
  56. {
  57. if (subjectPublicKey == null)
  58. throw new NullPointerException("subjectPublicKey must be non-null");
  59. if (trustAnchor == null)
  60. throw new NullPointerException("trustAnchor must be non-null");
  61. this.trustAnchor = trustAnchor;
  62. this.policyTree = policyTree;
  63. this.subjectPublicKey = subjectPublicKey;
  64. }
  65. /**
  66. * Returns the <code>TrustAnchor</code> describing the CA that served
  67. * as a trust anchor for the certification path.
  68. *
  69. * @return the <code>TrustAnchor</code> (never <code>null</code>)
  70. */
  71. public TrustAnchor getTrustAnchor() {
  72. return trustAnchor;
  73. }
  74. /**
  75. * Returns the root node of the valid policy tree resulting from the
  76. * PKIX certification path validation algorithm. The
  77. * <code>PolicyNode</code> object that is returned and any objects that
  78. * it returns through public methods are immutable.
  79. *
  80. * <p>Most applications will not need to examine the valid policy tree.
  81. * They can achieve their policy processing goals by setting the
  82. * policy-related parameters in <code>PKIXParameters</code>. However, more
  83. * sophisticated applications, especially those that process policy
  84. * qualifiers, may need to traverse the valid policy tree using the
  85. * {@link PolicyNode#getParent PolicyNode.getParent} and
  86. * {@link PolicyNode#getChildren PolicyNode.getChildren} methods.
  87. *
  88. * @return the root node of the valid policy tree, or <code>null</code>
  89. * if there are no valid policies
  90. */
  91. public PolicyNode getPolicyTree() {
  92. return policyTree;
  93. }
  94. /**
  95. * Returns the public key of the subject (target) of the certification
  96. * path, including any inherited public key parameters if applicable.
  97. *
  98. * @return the public key of the subject (never <code>null</code>)
  99. */
  100. public PublicKey getPublicKey() {
  101. return subjectPublicKey;
  102. }
  103. /**
  104. * Returns a copy of this object.
  105. *
  106. * @return the copy
  107. */
  108. public Object clone() {
  109. try {
  110. return super.clone();
  111. } catch (CloneNotSupportedException e) {
  112. /* Cannot happen */
  113. throw new InternalError(e.toString());
  114. }
  115. }
  116. /**
  117. * Return a printable representation of this
  118. * <code>PKIXCertPathValidatorResult</code>.
  119. *
  120. * @return a <code>String</code> describing the contents of this
  121. * <code>PKIXCertPathValidatorResult</code>
  122. */
  123. public String toString() {
  124. StringBuffer sb = new StringBuffer();
  125. sb.append("PKIXCertPathValidatorResult: [\n");
  126. sb.append(" Trust Anchor: " + trustAnchor.toString() + "\n");
  127. sb.append(" Policy Tree: " + String.valueOf(policyTree) + "\n");
  128. sb.append(" Subject Public Key: " + subjectPublicKey + "\n");
  129. sb.append("]");
  130. return sb.toString();
  131. }
  132. }