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