src/java.base/share/classes/com/sun/security/cert/internal/x509/X509V1CertImpl.java
author xuelei
Wed, 13 Mar 2019 07:14:50 -0700
changeset 54099 fd332722014c
parent 47216 71c04702a3d5
child 57950 4612a3cfb927
permissions -rw-r--r--
8160247: Mark deprecated javax.security.cert APIs with forRemoval=true Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54099
fd332722014c 8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
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 com.sun.security.cert.internal.x509;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.Signature;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.security.cert.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.BitSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The X509V1CertImpl class is used as a conversion wrapper around
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * sun.security.x509.X509Cert certificates when running under JDK1.1.x.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
29377
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 25859
diff changeset
    48
 * @deprecated This is the implementation class for the deprecated
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 25859
diff changeset
    49
 *  {@code javax.security.cert.X509Certificate} class. The classes in the
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 25859
diff changeset
    50
 *  {@code java.security.cert} package should be used instead.
d3f457ce9c48 8073430: Deprecate security APIs that have been superseded
juh
parents: 25859
diff changeset
    51
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author Jeff Nisewanger
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
54099
fd332722014c 8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents: 47216
diff changeset
    54
@SuppressWarnings("removal")
fd332722014c 8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents: 47216
diff changeset
    55
@Deprecated(since="9", forRemoval=true)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class X509V1CertImpl extends X509Certificate implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static final long serialVersionUID = -2048442350420423405L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private java.security.cert.X509Certificate wrappedCert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 29377
diff changeset
    60
    private static synchronized java.security.cert.CertificateFactory
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    getFactory()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    throws java.security.cert.CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return java.security.cert.CertificateFactory.getInstance("X.509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Default constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    public X509V1CertImpl() { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Unmarshals a certificate from its encoded form, parsing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * encoded bytes.  This form of constructor is used by agents which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * need to examine and use certificate contents.  That is, this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * one of the more commonly used constructors.  Note that the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * must include only a certificate, and no "garbage" may be left at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * the end.  If you need to ignore data at the end of a certificate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * use another constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param certData the encoded bytes, with no trailing padding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @exception CertificateException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public X509V1CertImpl(byte[] certData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            ByteArrayInputStream bs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            bs = new ByteArrayInputStream(certData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            wrappedCert = (java.security.cert.X509Certificate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                getFactory().generateCertificate(bs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        } catch (java.security.cert.CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            throw new CertificateException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * unmarshals an X.509 certificate from an input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param in an input stream holding at least one certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @exception CertificateException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public X509V1CertImpl(InputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            wrappedCert = (java.security.cert.X509Certificate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                getFactory().generateCertificate(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        } catch (java.security.cert.CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            throw new CertificateException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Returns the encoded form of this certificate. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * assumed that each certificate type would have only a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * form of encoding; for example, X.509 certificates would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * be encoded as ASN.1 DER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public byte[] getEncoded() throws CertificateEncodingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            return wrappedCert.getEncoded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        } catch (java.security.cert.CertificateEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            throw new CertificateEncodingException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Throws an exception if the certificate was not signed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * verification key provided.  Successfully verifying a certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * does <em>not</em> indicate that one should trust the entity which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * it represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param key the public key used for verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public void verify(PublicKey key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        throws CertificateException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        InvalidKeyException, NoSuchProviderException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        SignatureException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            wrappedCert.verify(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } catch (java.security.cert.CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new CertificateException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Throws an exception if the certificate was not signed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * verification key provided.  Successfully verifying a certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * does <em>not</em> indicate that one should trust the entity which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * it represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @param key the public key used for verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param sigProvider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public void verify(PublicKey key, String sigProvider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        throws CertificateException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        InvalidKeyException, NoSuchProviderException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        SignatureException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            wrappedCert.verify(key, sigProvider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } catch (java.security.cert.CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            throw new CertificateException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Checks that the certificate is currently valid, i.e. the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * time is within the specified validity period.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public void checkValidity() throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      CertificateExpiredException, CertificateNotYetValidException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        checkValidity(new Date());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Checks that the specified date is within the certificate's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * validity period, or basically if the certificate would be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * valid at the specified date/time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param date the Date to check against to see if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *        is valid at that date/time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public void checkValidity(Date date) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      CertificateExpiredException, CertificateNotYetValidException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            wrappedCert.checkValidity(date);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        } catch (java.security.cert.CertificateNotYetValidException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new CertificateNotYetValidException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        } catch (java.security.cert.CertificateExpiredException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            throw new CertificateExpiredException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Returns a printable representation of the certificate.  This does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * contain all the information available to distinguish this from any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * other certificate.  The certificate must be fully constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * before this function may be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return wrappedCert.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Gets the publickey from this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @return the publickey.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public PublicKey getPublicKey() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        PublicKey key = wrappedCert.getPublicKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Gets the version number from the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return the version number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public int getVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return wrappedCert.getVersion() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Gets the serial number from the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return the serial number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public BigInteger getSerialNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return wrappedCert.getSerialNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Gets the subject distinguished name from the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @return the subject name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @exception CertificateException if a parsing error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public Principal getSubjectDN() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return wrappedCert.getSubjectDN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Gets the issuer distinguished name from the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @return the issuer name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @exception CertificateException if a parsing error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public Principal getIssuerDN() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return wrappedCert.getIssuerDN();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Gets the notBefore date from the validity period of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @return the start date of the validity period.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @exception CertificateException if a parsing error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public Date getNotBefore() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return wrappedCert.getNotBefore();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Gets the notAfter date from the validity period of the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return the end date of the validity period.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @exception CertificateException if a parsing error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public Date getNotAfter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return wrappedCert.getNotAfter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Gets the signature algorithm name for the certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * signature algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * For example, the string "SHA1/DSA".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return the signature algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @exception CertificateException if a parsing error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public String getSigAlgName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return wrappedCert.getSigAlgName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Gets the signature algorithm OID string from the certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * For example, the string "1.2.840.10040.4.3"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @return the signature algorithm oid string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @exception CertificateException if a parsing error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public String getSigAlgOID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return wrappedCert.getSigAlgOID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Gets the DER encoded signature algorithm parameters from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * certificate's signature algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @return the DER encoded signature algorithm parameters, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *         null if no parameters are present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @exception CertificateException if a parsing error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public byte[] getSigAlgParams() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        return wrappedCert.getSigAlgParams();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    private synchronized void writeObject(ObjectOutputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            stream.write(getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        } catch (CertificateEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            throw new IOException("getEncoded failed: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    private synchronized void readObject(ObjectInputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            wrappedCert = (java.security.cert.X509Certificate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                getFactory().generateCertificate(stream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        } catch (java.security.cert.CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            throw new IOException("generateCertificate failed: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public java.security.cert.X509Certificate getX509Certificate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return wrappedCert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
}