home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / security / cert / X509Extension.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  5.8 KB  |  158 lines

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