2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / security / cert / X509CRL.java
blob6794ccb43adcc6104fd051dddfe9a2c9dea17f82
1 /* X509CRL.java --- X.509 Certificate Revocation List
2 Copyright (C) 1999 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.security.cert;
40 import java.math.BigInteger;
41 import java.security.Principal;
42 import java.security.PublicKey;
43 import java.security.NoSuchAlgorithmException;
44 import java.security.InvalidKeyException;
45 import java.security.NoSuchProviderException;
46 import java.security.SignatureException;
47 import java.util.Date;
48 import java.util.Set;
50 import javax.security.auth.x500.X500Principal;
52 /**
53 The X509CRL class is the abstract class used to manage
54 X.509 Certificate Revocation Lists. The CRL is a list of
55 time stamped entries which indicate which lists have been
56 revoked. The list is signed by a Certificate Authority (CA)
57 and made publically available in a repository.
59 Each revoked certificate in the CRL is identified by its
60 certificate serial number. When a piece of code uses a
61 certificate, the certificates validity is checked by
62 validating its signature and determing that it is not
63 only a recently acquired CRL. The recently aquired CRL
64 is depends on the local policy in affect. The CA issues
65 a new CRL periodically and entries are removed as the
66 certificate expiration date is reached
69 A description of the X.509 v2 CRL follows below from rfc2459.
71 "The X.509 v2 CRL syntax is as follows. For signature calculation,
72 the data that is to be signed is ASN.1 DER encoded. ASN.1 DER
73 encoding is a tag, length, value encoding system for each element.
75 CertificateList ::= SEQUENCE {
76 tbsCertList TBSCertList,
77 signatureAlgorithm AlgorithmIdentifier,
78 signatureValue BIT STRING }
80 TBSCertList ::= SEQUENCE {
81 version Version OPTIONAL,
82 -- if present, shall be v2
83 signature AlgorithmIdentifier,
84 issuer Name,
85 thisUpdate Time,
86 nextUpdate Time OPTIONAL,
87 revokedCertificates SEQUENCE OF SEQUENCE {
88 userCertificate CertificateSerialNumber,
89 revocationDate Time,
90 crlEntryExtensions Extensions OPTIONAL
91 -- if present, shall be v2
92 } OPTIONAL,
93 crlExtensions [0] EXPLICIT Extensions OPTIONAL
94 -- if present, shall be v2
97 @author Mark Benvenuto
99 @since JDK 1.2
101 public abstract class X509CRL extends CRL implements X509Extension
105 Constructs a new X509CRL.
107 protected X509CRL()
109 super("X.509");
113 Compares this X509CRL to other. It checks if the
114 object if instanceOf X509CRL and then checks if
115 the encoded form matches.
117 @param other An Object to test for equality
119 @return true if equal, false otherwise
121 public boolean equals(Object other)
123 if( other instanceof X509CRL ) {
124 try {
125 X509CRL x = (X509CRL) other;
126 if( getEncoded().length != x.getEncoded().length )
127 return false;
129 byte b1[] = getEncoded();
130 byte b2[] = x.getEncoded();
132 for( int i = 0; i < b1.length; i++ )
133 if( b1[i] != b2[i] )
134 return false;
136 } catch( CRLException crle ) {
137 return false;
139 return true;
141 return false;
145 Returns a hash code for this X509CRL in its encoded
146 form.
148 @return A hash code of this class
150 public int hashCode()
152 return super.hashCode();
156 Gets the DER ASN.1 encoded format for this X.509 CRL.
158 @return byte array containg encoded form
160 @throws CRLException if an error occurs
162 public abstract byte[] getEncoded() throws CRLException;
165 Verifies that this CRL was properly signed with the
166 PublicKey that corresponds to its private key.
168 @param key PublicKey to verify with
170 @throws CRLException encoding error
171 @throws NoSuchAlgorithmException unsupported algorithm
172 @throws InvalidKeyException incorrect key
173 @throws NoSuchProviderException no provider
174 @throws SignatureException signature error
176 public abstract void verify(PublicKey key)
177 throws CRLException,
178 NoSuchAlgorithmException,
179 InvalidKeyException,
180 NoSuchProviderException,
181 SignatureException;
184 Verifies that this CRL was properly signed with the
185 PublicKey that corresponds to its private key and uses
186 the signature engine provided by the provider.
188 @param key PublicKey to verify with
189 @param sigProvider Provider to use for signature algorithm
191 @throws CRLException encoding error
192 @throws NoSuchAlgorithmException unsupported algorithm
193 @throws InvalidKeyException incorrect key
194 @throws NoSuchProviderException incorrect provider
195 @throws SignatureException signature error
197 public abstract void verify(PublicKey key,
198 String sigProvider)
199 throws CRLException,
200 NoSuchAlgorithmException,
201 InvalidKeyException,
202 NoSuchProviderException,
203 SignatureException;
206 Gets the version of this CRL.
208 The ASN.1 encoding is:
210 version Version OPTIONAL,
211 -- if present, shall be v2
213 Version ::= INTEGER { v1(0), v2(1), v3(2) }
215 Consult rfc2459 for more information.
217 @return the version number, Ex: 1 or 2
219 public abstract int getVersion();
222 Returns the issuer (issuer distinguished name) of the CRL.
223 The issuer is the entity who signed and issued the
224 Certificate Revocation List.
226 The ASN.1 DER encoding is:
228 issuer Name,
230 Name ::= CHOICE {
231 RDNSequence }
233 RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
235 RelativeDistinguishedName ::=
236 SET OF AttributeTypeAndValue
238 AttributeTypeAndValue ::= SEQUENCE {
239 type AttributeType,
240 value AttributeValue }
242 AttributeType ::= OBJECT IDENTIFIER
244 AttributeValue ::= ANY DEFINED BY AttributeType
246 DirectoryString ::= CHOICE {
247 teletexString TeletexString (SIZE (1..MAX)),
248 printableString PrintableString (SIZE (1..MAX)),
249 universalString UniversalString (SIZE (1..MAX)),
250 utf8String UTF8String (SIZE (1.. MAX)),
251 bmpString BMPString (SIZE (1..MAX)) }
253 Consult rfc2459 for more information.
255 @return the issuer in the Principal class
257 public abstract Principal getIssuerDN();
260 Returns the thisUpdate date of the CRL.
262 The ASN.1 DER encoding is:
264 thisUpdate Time,
266 Time ::= CHOICE {
267 utcTime UTCTime,
268 generalTime GeneralizedTime }
270 Consult rfc2459 for more information.
272 @return the thisUpdate date
274 public abstract Date getThisUpdate();
277 Gets the nextUpdate field
279 The ASN.1 DER encoding is:
281 nextUpdate Time OPTIONAL,
283 Time ::= CHOICE {
284 utcTime UTCTime,
285 generalTime GeneralizedTime }
287 Consult rfc2459 for more information.
289 @return the nextUpdate date
291 public abstract Date getNextUpdate();
294 Gets the requeste dX509Entry for the specified
295 certificate serial number.
297 @return a X509CRLEntry representing the X.509 CRL entry
299 public abstract X509CRLEntry getRevokedCertificate(BigInteger serialNumber);
302 Returns a Set of revoked certificates.
304 @return a set of revoked certificates.
306 public abstract Set getRevokedCertificates();
309 Returns the DER ASN.1 encoded tbsCertList which is
310 the basic information of the list and associated certificates
311 in the encoded state. See top for more information.
313 The ASN.1 DER encoding is:
315 tbsCertList TBSCertList,
317 Consult rfc2459 for more information.
319 @return byte array representing tbsCertList
321 public abstract byte[] getTBSCertList() throws CRLException;
325 Returns the signature for the CRL.
327 The ASN.1 DER encoding is:
329 signatureValue BIT STRING
331 Consult rfc2459 for more information.
333 public abstract byte[] getSignature();
336 Returns the signature algorithm used to sign the CRL.
337 An examples is "SHA-1/DSA".
339 The ASN.1 DER encoding is:
341 signatureAlgorithm AlgorithmIdentifier,
343 AlgorithmIdentifier ::= SEQUENCE {
344 algorithm OBJECT IDENTIFIER,
345 parameters ANY DEFINED BY algorithm OPTIONAL }
347 Consult rfc2459 for more information.
349 The algorithm name is determined from the OID.
351 @return a string with the signature algorithm name
353 public abstract String getSigAlgName();
356 Returns the OID for the signature algorithm used.
357 Example "1.2.840.10040.4.3" is return for SHA-1 with DSA.\
359 The ASN.1 DER encoding for the example is:
361 id-dsa-with-sha1 ID ::= {
362 iso(1) member-body(2) us(840) x9-57 (10040)
363 x9cm(4) 3 }
365 Consult rfc2459 for more information.
367 @return a string containing the OID.
369 public abstract String getSigAlgOID();
372 Returns the AlgorithmParameters in the encoded form
373 for the signature algorithm used.
375 If access to the parameters is need, create an
376 instance of AlgorithmParameters.
378 @return byte array containing algorithm parameters, null
379 if no parameters are present in CRL
381 public abstract byte[] getSigAlgParams();
383 // 1.4 instance methods.
384 // ------------------------------------------------------------------------
387 * Returns the X.500 distinguished name of this CRL's issuer.
389 * @return The issuer's X.500 distinguished name.
390 * @since JDK 1.4
392 public X500Principal getIssuerX500Principal()
394 throw new UnsupportedOperationException();