1. /*
  2. * @(#)X509Extension.java 1.14 01/11/29
  3. *
  4. * Copyright 2002 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.Set;
  9. /**
  10. * Interface for an X.509 extension.
  11. *
  12. * <p>The extensions defined for X.509 v3
  13. * {@link X509Certificate Certificates} and v2
  14. * {@link X509CRL CRLs} (Certificate Revocation
  15. * Lists) provide methods
  16. * for associating additional attributes with users or public keys,
  17. * for managing the certification hierarchy, and for managing CRL
  18. * distribution. The X.509 extensions format also allows communities
  19. * to define private extensions to carry information unique to those
  20. * communities.
  21. *
  22. * <p>Each extension in a certificate/CRL may be designated as
  23. * critical or non-critical. A certificate/CRL-using system (an application
  24. * validating a certificate/CRL) must reject the certificate/CRL if it
  25. * encounters a critical extension it does not recognize. A non-critical
  26. * extension may be ignored if it is not recognized.
  27. * <p>
  28. * The ASN.1 definition for this is:
  29. * <pre>
  30. * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension
  31. *
  32. * Extension ::= SEQUENCE {
  33. * extnId OBJECT IDENTIFIER,
  34. * critical BOOLEAN DEFAULT FALSE,
  35. * extnValue OCTET STRING
  36. * -- contains a DER encoding of a value
  37. * -- of the type registered for use with
  38. * -- the extnId object identifier value
  39. * }
  40. * </pre>
  41. * Since not all extensions are known, the <code>getExtensionValue</code>
  42. * method returns the DER-encoded OCTET STRING of the
  43. * extension value (i.e., the <code>extnValue</code>). This can then
  44. * be handled by a <em>Class</em> that understands the extension.
  45. *
  46. * @author Hemma Prafullchandra
  47. * @version 1.14 01/11/29
  48. */
  49. public interface X509Extension {
  50. /**
  51. * Return true if a critical extension is found that is
  52. * not supported, otherwise return false.
  53. */
  54. public boolean hasUnsupportedCriticalExtension();
  55. /**
  56. * Gets a Set of the OID strings for the extension(s) marked
  57. * CRITICAL in the certificate/CRL managed by the object
  58. * implementing this interface.
  59. *
  60. * Here is sample code to get a Set of critical extensions from an
  61. * X509Certificate and print the OIDs:
  62. * <pre><code>
  63. * InputStream inStrm = new FileInputStream("DER-encoded-Cert");
  64. * CertificateFactory cf = CertificateFactory.getInstance("X.509");
  65. * X509Certificate cert = (X509Certificate)cf.generateCertificate(inStrm);
  66. * inStrm.close();<p>
  67. *
  68. * Set critSet = cert.getCriticalExtensionOIDs();
  69. * if (critSet != null && !critSet.isEmpty()) {
  70. * System.out.println("Set of critical extensions:");
  71. * for (Iterator i = critSet.iterator(); i.hasNext();) {
  72. * String oid = (String)i.next();
  73. * System.out.println(oid);
  74. * }
  75. * }
  76. * </code></pre>
  77. * @return a Set (or an empty Set if none are marked critical) of
  78. * the extension OID strings for extensions that are marked critical.
  79. * If there are no extensions present at all, then this method returns
  80. * null.
  81. */
  82. public Set getCriticalExtensionOIDs();
  83. /**
  84. * Gets a Set of the OID strings for the extension(s) marked
  85. * NON-CRITICAL in the certificate/CRL managed by the object
  86. * implementing this interface.
  87. *
  88. * Here is sample code to get a Set of non-critical extensions from an
  89. * X509CRL revoked certificate entry and print the OIDs:
  90. * <pre><code>
  91. * InputStream inStrm = new FileInputStream("DER-encoded-CRL");
  92. * CertificateFactory cf = CertificateFactory.getInstance("X.509");
  93. * X509CRL crl = (X509CRL)cf.generateCRL(inStrm);
  94. * inStrm.close();<p>
  95. *
  96. * byte[] certData = <DER-encoded certificate data>
  97. * ByteArrayInputStream bais = new ByteArrayInputStream(certData);
  98. * X509Certificate cert = (X509Certificate)cf.generateCertificate(bais);
  99. * bais.close();
  100. * X509CRLEntry badCert =
  101. * crl.getRevokedCertificate(cert.getSerialNumber());<p>
  102. *
  103. * if (badCert != null) {
  104. * Set nonCritSet = badCert.getNonCriticalExtensionOIDs();<p>
  105. * if (nonCritSet != null)
  106. * for (Iterator i = nonCritSet.iterator(); i.hasNext();) {
  107. * String oid = (String)i.next();
  108. * System.out.println(oid);
  109. * }
  110. * }
  111. * </code></pre>
  112. *
  113. * @return a Set (or an empty Set if none are marked non-critical) of
  114. * the extension OID strings for extensions that are marked non-critical.
  115. * If there are no extensions present at all, then this method returns
  116. * null.
  117. */
  118. public Set getNonCriticalExtensionOIDs();
  119. /**
  120. * Gets the DER-encoded OCTET string for the extension value
  121. * (<em>extnValue</em>) identified by the passed-in <code>oid</code>
  122. * String.
  123. * The <code>oid</code> string is
  124. * represented by a set of positive whole numbers separated
  125. * by periods.
  126. *
  127. * <p>For example:<br>
  128. * <table border=groove>
  129. * <tr>
  130. * <th>OID <em>(Object Identifier)</em></th>
  131. * <th>Extension Name</th></tr>
  132. * <tr><td>2.5.29.14</td>
  133. * <td>SubjectKeyIdentifier</td></tr>
  134. * <tr><td>2.5.29.15</td>
  135. * <td>KeyUsage</td></tr>
  136. * <tr><td>2.5.29.16</td>
  137. * <td>PrivateKeyUsage</td></tr>
  138. * <tr><td>2.5.29.17</td>
  139. * <td>SubjectAlternativeName</td></tr>
  140. * <tr><td>2.5.29.18</td>
  141. * <td>IssuerAlternativeName</td></tr>
  142. * <tr><td>2.5.29.19</td>
  143. * <td>BasicConstraints</td></tr>
  144. * <tr><td>2.5.29.30</td>
  145. * <td>NameConstraints</td></tr>
  146. * <tr><td>2.5.29.33</td>
  147. * <td>PolicyMappings</td></tr>
  148. * <tr><td>2.5.29.35</td>
  149. * <td>AuthorityKeyIdentifier</td></tr>
  150. * <tr><td>2.5.29.36</td>
  151. * <td>PolicyConstraints</td></tr>
  152. * </table>
  153. *
  154. * @param oid the Object Identifier value for the extension.
  155. * @return the DER-encoded octet string of the extension value or
  156. * null if it is not present.
  157. */
  158. public byte[] getExtensionValue(String oid);
  159. }