jdk/src/share/classes/java/security/cert/Certificate.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8152 94e5966bdf22
child 13406 33d7bf574b42
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8152
diff changeset
     2
 * Copyright (c) 1997, 2011, 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 java.security.cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.PublicKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.NoSuchAlgorithmException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.NoSuchProviderException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.InvalidKeyException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.SignatureException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.x509.X509CertImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>Abstract class for managing a variety of identity certificates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * An identity certificate is a binding of a principal to a public key which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * is vouched for by another principal.  (A principal represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * an entity such as an individual user, a group, or a corporation.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This class is an abstraction for certificates that have different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * formats but important common uses.  For example, different types of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * certificates, such as X.509 and PGP, share general certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * functionality (like encoding and verifying) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * some types of information (like a public key).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * X.509, PGP, and SDSI certificates can all be implemented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * subclassing the Certificate class, even though they contain different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * sets of information, and they store and retrieve the information in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * different ways.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @see X509Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @see CertificateFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public abstract class Certificate implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    private static final long serialVersionUID = -3585440601605666277L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // the certificate type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private final String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Creates a certificate of the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param type the standard name of the certificate type.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    72
     * See the CertificateFactory section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    73
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    74
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected Certificate(String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Returns the type of this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @return the type of this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public final String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return this.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Compares this certificate for equality with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * object. If the <code>other</code> object is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * <code>instanceof</code> <code>Certificate</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * its encoded form is retrieved and compared with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * encoded form of this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param other the object to test for equality with this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @return true iff the encoded forms of the two certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * match, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (!(other instanceof Certificate)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            byte[] thisCert = X509CertImpl.getEncodedInternal(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            byte[] otherCert = X509CertImpl.getEncodedInternal((Certificate)other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return Arrays.equals(thisCert, otherCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Returns a hashcode value for this certificate from its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * encoded form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @return the hashcode value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        int retval = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            byte[] certData = X509CertImpl.getEncodedInternal(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            for (int i = 1; i < certData.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                 retval += certData[i] * i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Returns the encoded form of this certificate. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * assumed that each certificate type would have only a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * form of encoding; for example, X.509 certificates would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * be encoded as ASN.1 DER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return the encoded form of this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @exception CertificateEncodingException if an encoding error occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public abstract byte[] getEncoded()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        throws CertificateEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Verifies that this certificate was signed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * private key that corresponds to the specified public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param key the PublicKey used to carry out the verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @exception NoSuchAlgorithmException on unsupported signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @exception InvalidKeyException on incorrect key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @exception NoSuchProviderException if there's no default provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @exception SignatureException on signature errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @exception CertificateException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public abstract void verify(PublicKey key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        throws CertificateException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        InvalidKeyException, NoSuchProviderException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        SignatureException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Verifies that this certificate was signed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * private key that corresponds to the specified public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * This method uses the signature verification engine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * supplied by the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param key the PublicKey used to carry out the verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param sigProvider the name of the signature provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @exception NoSuchAlgorithmException on unsupported signature
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @exception InvalidKeyException on incorrect key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @exception NoSuchProviderException on incorrect provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @exception SignatureException on signature errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception CertificateException on encoding errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public abstract void verify(PublicKey key, String sigProvider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        throws CertificateException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        InvalidKeyException, NoSuchProviderException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        SignatureException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Returns a string representation of this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return a string representation of this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public abstract String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Gets the public key from this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return the public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public abstract PublicKey getPublicKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Alternate Certificate class for serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    protected static class CertificateRep implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        private static final long serialVersionUID = -8563758940495660020L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        private byte[] data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * Construct the alternate Certificate class with the Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         * type and Certificate encoding bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
         * @param type the standard name of the Certificate type. <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
         * @param data the Certificate data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        protected CertificateRep(String type, byte[] data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            this.data = data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
         * Resolve the Certificate Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         * @return the resolved Certificate Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         * @throws java.io.ObjectStreamException if the Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         *      could not be resolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        protected Object readResolve() throws java.io.ObjectStreamException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                CertificateFactory cf = CertificateFactory.getInstance(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                return cf.generateCertificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        (new java.io.ByteArrayInputStream(data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                throw new java.io.NotSerializableException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                ("java.security.cert.Certificate: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                type +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                                e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Replace the Certificate to be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @return the alternate Certificate object to be serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @throws java.io.ObjectStreamException if a new object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * this Certificate could not be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    protected Object writeReplace() throws java.io.ObjectStreamException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            return new CertificateRep(type, getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            throw new java.io.NotSerializableException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                                ("java.security.cert.Certificate: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                type +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
}