001/* X509Certificate.java -- base class of X.509 certificates.
002   Copyright (C) 2004 Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038
039package javax.security.cert;
040
041import java.io.ByteArrayInputStream;
042import java.io.InputStream;
043
044import java.math.BigInteger;
045
046import java.security.Principal;
047import java.security.cert.CertificateFactory;
048
049import java.util.Date;
050
051/**
052 * <p>The base class of all X.509 certificates.</p>
053 *
054 * <p><b>This class is deprecated in favor of the {@link
055 * java.security.cert.X509Certificate} class. It should not be used in new
056 * applications.</b></p>
057 */
058public abstract class X509Certificate extends Certificate
059{
060
061  // Class methods.
062  // -------------------------------------------------------------------------
063
064  /**
065   * <p>Get an instance of X509Certificate for the given encoded bytes.</p>
066   *
067   * @param encoded The encoded certificate.
068   * @return An instance of X509Certificate.
069   * @throws CertificateException If the encoded certificate cannot be parsed.
070   */
071  public static X509Certificate getInstance(byte[] encoded)
072    throws CertificateException
073  {
074    return getInstance(new ByteArrayInputStream(encoded));
075  }
076
077  /**
078   * <p>Get an instance of X509Certificate for the given encoded stream.</p>
079   *
080   * @param encoded The encoded certificate stream..
081   * @return An instance of X509Certificate.
082   * @throws CertificateException If the encoded certificate cannot be parsed.
083   */
084  public static X509Certificate getInstance(InputStream encoded)
085    throws CertificateException
086  {
087    try
088      {
089        CertificateFactory cf = CertificateFactory.getInstance("X.509");
090        return new X509CertBridge((java.security.cert.X509Certificate)
091                                  cf.generateCertificate(encoded));
092      }
093    catch (java.security.cert.CertificateException ce)
094      {
095        throw new CertificateException(ce.getMessage());
096      }
097  }
098
099  // Abstract methods.
100  // -------------------------------------------------------------------------
101
102  /**
103   * <p>Check if this certificate is valid now.</p>
104   *
105   * @throws CertificateExpiredException If the certificate has expired.
106   * @throws CertificateNotYetValidException If the certificate is not yet valid.
107   * @see #checkValidity(java.util.Date)
108   */
109  public abstract void checkValidity()
110    throws CertificateExpiredException, CertificateNotYetValidException;
111
112  /**
113   * <p>Check if this certificate is valid for the given date.</p>
114   *
115   * @param date The date to check.
116   * @throws CertificateExpiredException If the certificate has expired.
117   * @throws CertificateNotYetValidException If the certificate is not yet valid.
118   */
119  public abstract void checkValidity(Date date)
120    throws CertificateExpiredException, CertificateNotYetValidException;
121
122  /**
123   * <p>Returns the X.509 version number.</p>
124   *
125   * @return The version number.
126   */
127  public abstract int getVersion();
128
129  /**
130   * <p>Returns this certificate's serial number.</p>
131   *
132   * @return The serial number.
133   */
134  public abstract BigInteger getSerialNumber();
135
136  /**
137   * <p>Returns the distinguished name of this certificate's issuer.</p>
138   *
139   * @return The issuer's distinguished name.
140   */
141  public abstract Principal getIssuerDN();
142
143  /**
144   * <p>Returns the distinguished name of this certificate's subject.</p>
145   *
146   * @return The subject's distinguished name.
147   */
148  public abstract Principal getSubjectDN();
149
150  /**
151   * <p>Returns the <i>not before</i> portion of this certificate's validity
152   * period.</p>
153   *
154   * @return The not before date.
155   */
156  public abstract Date getNotBefore();
157
158  /**
159   * <p>Returns the <i>not after</i> portion of this certificate's validity
160   * period.</p>
161   *
162   * @return The not after date.
163   */
164  public abstract Date getNotAfter();
165
166  /**
167   * <p>Returns the name of this certificate's signature algorithm.</p>
168   *
169   * @return The name of the signature algorithm.
170   */
171  public abstract String getSigAlgName();
172
173  /**
174   * <p>Returns the object identifier (OID) of this certificate's signature
175   * algorithm. The returned string is a sequence of integers separated by
176   * periods.</p>
177   *
178   * @return The signature OID.
179   */
180  public abstract String getSigAlgOID();
181
182  /**
183   * <p>Returns the signature parameters. The returned byte array contains the
184   * raw DER-encoded parameters.</p>
185   *
186   * @return The signature parameters.
187   */
188  public abstract byte[] getSigAlgParams();
189}