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