001    /* X509Certificate.java -- base class of X.509 certificates.
002       Copyright (C) 2004 Free Software Foundation, Inc.
003    
004    This file is part of GNU Classpath.
005    
006    GNU Classpath is free software; you can redistribute it and/or modify
007    it under the terms of the GNU General Public License as published by
008    the Free Software Foundation; either version 2, or (at your option)
009    any later version.
010    
011    GNU Classpath is distributed in the hope that it will be useful, but
012    WITHOUT ANY WARRANTY; without even the implied warranty of
013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014    General Public License for more details.
015    
016    You should have received a copy of the GNU General Public License
017    along with GNU Classpath; see the file COPYING.  If not, write to the
018    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
019    02110-1301 USA.
020    
021    Linking this library statically or dynamically with other modules is
022    making a combined work based on this library.  Thus, the terms and
023    conditions of the GNU General Public License cover the whole
024    combination.
025    
026    As a special exception, the copyright holders of this library give you
027    permission to link this library with independent modules to produce an
028    executable, regardless of the license terms of these independent
029    modules, and to copy and distribute the resulting executable under
030    terms of your choice, provided that you also meet, for each linked
031    independent module, the terms and conditions of the license of that
032    module.  An independent module is a module which is not derived from
033    or based on this library.  If you modify this library, you may extend
034    this exception to your version of the library, but you are not
035    obligated to do so.  If you do not wish to do so, delete this
036    exception statement from your version. */
037    
038    
039    package javax.security.cert;
040    
041    import java.io.ByteArrayInputStream;
042    import java.io.InputStream;
043    
044    import java.math.BigInteger;
045    
046    import java.security.Principal;
047    import java.security.cert.CertificateFactory;
048    
049    import 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     */
058    public 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    }