jdk/src/share/classes/java/security/cert/X509Extension.java
author xuelei
Wed, 20 Jan 2010 21:38:37 +0800
changeset 4807 2521b7dcf505
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6862064: incorrect implementation of PKIXParameters.clone() Reviewed-by: weijun, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security.cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * Interface for an X.509 extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <p>The extensions defined for X.509 v3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * {@link X509Certificate Certificates} and v2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * {@link X509CRL CRLs} (Certificate Revocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Lists) provide methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * for associating additional attributes with users or public keys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * for managing the certification hierarchy, and for managing CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * distribution. The X.509 extensions format also allows communities
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * to define private extensions to carry information unique to those
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * communities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>Each extension in a certificate/CRL may be designated as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * critical or non-critical.  A certificate/CRL-using system (an application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * validating a certificate/CRL) must reject the certificate/CRL if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * encounters a critical extension it does not recognize.  A non-critical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * extension may be ignored if it is not recognized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The ASN.1 definition for this is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Extensions  ::=  SEQUENCE SIZE (1..MAX) OF Extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Extension  ::=  SEQUENCE  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     extnId        OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *     critical      BOOLEAN DEFAULT FALSE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *     extnValue     OCTET STRING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *                   -- contains a DER encoding of a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *                   -- of the type registered for use with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *                   -- the extnId object identifier value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Since not all extensions are known, the <code>getExtensionValue</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * method returns the DER-encoded OCTET STRING of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * extension value (i.e., the <code>extnValue</code>). This can then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * be handled by a <em>Class</em> that understands the extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public interface X509Extension {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Check if there is a critical extension that is not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @return <tt>true</tt> if a critical extension is found that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * not supported, otherwise <tt>false</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public boolean hasUnsupportedCriticalExtension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Gets a Set of the OID strings for the extension(s) marked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * CRITICAL in the certificate/CRL managed by the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * implementing this interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Here is sample code to get a Set of critical extensions from an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * X509Certificate and print the OIDs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * InputStream inStrm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * X509Certificate cert = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *     inStrm = new FileInputStream("DER-encoded-Cert");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *     CertificateFactory cf = CertificateFactory.getInstance("X.509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *     cert = (X509Certificate)cf.generateCertificate(inStrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *     if (inStrm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *         inStrm.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * }<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Set<String> critSet = cert.getCriticalExtensionOIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * if (critSet != null && !critSet.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *     System.out.println("Set of critical extensions:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *     for (String oid : critSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *         System.out.println(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @return a Set (or an empty Set if none are marked critical) of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * the extension OID strings for extensions that are marked critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * If there are no extensions present at all, then this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public Set<String> getCriticalExtensionOIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Gets a Set of the OID strings for the extension(s) marked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * NON-CRITICAL in the certificate/CRL managed by the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * implementing this interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Here is sample code to get a Set of non-critical extensions from an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * X509CRL revoked certificate entry and print the OIDs:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * InputStream inStrm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * CertificateFactory cf = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * X509CRL crl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *     inStrm = new FileInputStream("DER-encoded-CRL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *     cf = CertificateFactory.getInstance("X.509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *     crl = (X509CRL)cf.generateCRL(inStrm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *     if (inStrm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *         inStrm.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * }<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * byte[] certData = &lt;DER-encoded certificate data&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * ByteArrayInputStream bais = new ByteArrayInputStream(certData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * X509Certificate cert = (X509Certificate)cf.generateCertificate(bais);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * bais.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * X509CRLEntry badCert =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *              crl.getRevokedCertificate(cert.getSerialNumber());<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * if (badCert != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *     Set<String> nonCritSet = badCert.getNonCriticalExtensionOIDs();<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *     if (nonCritSet != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *         for (String oid : nonCritSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *             System.out.println(oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return a Set (or an empty Set if none are marked non-critical) of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * the extension OID strings for extensions that are marked non-critical.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * If there are no extensions present at all, then this method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public Set<String> getNonCriticalExtensionOIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Gets the DER-encoded OCTET string for the extension value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * (<em>extnValue</em>) identified by the passed-in <code>oid</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * The <code>oid</code> string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * represented by a set of nonnegative whole numbers separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * by periods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <p>For example:<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <table border=groove summary="Examples of OIDs and extension names">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <th>OID <em>(Object Identifier)</em></th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <th>Extension Name</th></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <tr><td>2.5.29.14</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * <td>SubjectKeyIdentifier</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <tr><td>2.5.29.15</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * <td>KeyUsage</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * <tr><td>2.5.29.16</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <td>PrivateKeyUsage</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <tr><td>2.5.29.17</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * <td>SubjectAlternativeName</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <tr><td>2.5.29.18</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * <td>IssuerAlternativeName</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <tr><td>2.5.29.19</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * <td>BasicConstraints</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <tr><td>2.5.29.30</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * <td>NameConstraints</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * <tr><td>2.5.29.33</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * <td>PolicyMappings</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <tr><td>2.5.29.35</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <td>AuthorityKeyIdentifier</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <tr><td>2.5.29.36</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <td>PolicyConstraints</td></tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param oid the Object Identifier value for the extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @return the DER-encoded octet string of the extension value or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * null if it is not present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public byte[] getExtensionValue(String oid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}