src/java.base/share/classes/java/security/cert/Certificate.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58242 94bb65cb37d3
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
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 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.)
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
    44
 * <p>
2
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
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 45118
diff changeset
    60
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public abstract class Certificate implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
    65
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private static final long serialVersionUID = -3585440601605666277L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // the certificate type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private final String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
20177
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
    71
    /** Cache the hash code for the certiticate */
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
    72
    private int hash = -1; // Default to -1
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
    73
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Creates a certificate of the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param type the standard name of the certificate type.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    78
     * See the CertificateFactory section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 29492
diff changeset
    79
     * "{@docRoot}/../specs/security/standard-names.html#certificatefactory-types">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 29492
diff changeset
    80
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected Certificate(String type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Returns the type of this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @return the type of this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public final String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return this.type;
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
     * Compares this certificate for equality with the specified
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    98
     * object. If the {@code other} object is an
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
    99
     * {@code instanceof} {@code Certificate}, then
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * its encoded form is retrieved and compared with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * encoded form of this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param other the object to test for equality with this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @return true iff the encoded forms of the two certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * match, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public boolean equals(Object other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        if (this == other) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (!(other instanceof Certificate)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            byte[] thisCert = X509CertImpl.getEncodedInternal(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            byte[] otherCert = X509CertImpl.getEncodedInternal((Certificate)other);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            return Arrays.equals(thisCert, otherCert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Returns a hashcode value for this certificate from its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * encoded form.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return the hashcode value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public int hashCode() {
20177
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
   131
        int h = hash;
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
   132
        if (h == -1) {
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
   133
            try {
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
   134
                h = Arrays.hashCode(X509CertImpl.getEncodedInternal(this));
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
   135
            } catch (CertificateException e) {
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
   136
                h = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
20177
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
   138
            hash = h;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
20177
8ea486a4f36e 8011402: Move blacklisting certificate logic from hard code to data
weijun
parents: 18551
diff changeset
   140
        return h;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Returns the encoded form of this certificate. It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * assumed that each certificate type would have only a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * form of encoding; for example, X.509 certificates would
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * be encoded as ASN.1 DER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @return the encoded form of this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   151
     * @throws    CertificateEncodingException if an encoding error occurs.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public abstract byte[] getEncoded()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        throws CertificateEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Verifies that this certificate was signed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * private key that corresponds to the specified public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param key the PublicKey used to carry out the verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   162
     * @throws    NoSuchAlgorithmException on unsupported signature
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * algorithms.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   164
     * @throws    InvalidKeyException on incorrect key.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   165
     * @throws    NoSuchProviderException if there's no default provider.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   166
     * @throws    SignatureException on signature errors.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   167
     * @throws    CertificateException on encoding errors.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public abstract void verify(PublicKey key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        throws CertificateException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        InvalidKeyException, NoSuchProviderException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        SignatureException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Verifies that this certificate was signed using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * private key that corresponds to the specified public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * This method uses the signature verification engine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * supplied by the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param key the PublicKey used to carry out the verification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param sigProvider the name of the signature provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   183
     * @throws    NoSuchAlgorithmException on unsupported signature
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * algorithms.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   185
     * @throws    InvalidKeyException on incorrect key.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   186
     * @throws    NoSuchProviderException on incorrect provider.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   187
     * @throws    SignatureException on signature errors.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   188
     * @throws    CertificateException on encoding errors.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public abstract void verify(PublicKey key, String sigProvider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        throws CertificateException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        InvalidKeyException, NoSuchProviderException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        SignatureException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
13406
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   196
     * 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
   197
     * 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
   198
     * This method uses the signature verification engine
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   199
     * 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
   200
     * 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
   201
     *
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   202
     * <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
   203
     * Standard Edition. In order to maintain backwards compatibility with
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
   204
     * existing service providers, this method cannot be {@code abstract}
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14342
diff changeset
   205
     * and by default throws an {@code UnsupportedOperationException}.
13406
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   206
     *
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   207
     * @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
   208
     * @param sigProvider the signature provider.
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   209
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   210
     * @throws    NoSuchAlgorithmException on unsupported signature
13406
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   211
     * algorithms.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   212
     * @throws    InvalidKeyException on incorrect key.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   213
     * @throws    SignatureException on signature errors.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   214
     * @throws    CertificateException on encoding errors.
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57950
diff changeset
   215
     * @throws    UnsupportedOperationException if the method is not supported
13406
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   216
     * @since 1.8
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
    public void verify(PublicKey key, Provider sigProvider)
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   219
        throws CertificateException, NoSuchAlgorithmException,
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   220
        InvalidKeyException, SignatureException {
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   221
        throw new UnsupportedOperationException();
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   222
    }
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   223
33d7bf574b42 7026347: Certificate and X509CRL should have verify(PublicKey key, Provider sigProvider)
mullan
parents: 9035
diff changeset
   224
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Returns a string representation of this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return a string representation of this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public abstract String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Gets the public key from this certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @return the public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public abstract PublicKey getPublicKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Alternate Certificate class for serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    protected static class CertificateRep implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
   244
        @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        private static final long serialVersionUID = -8563758940495660020L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        private byte[] data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         * Construct the alternate Certificate class with the Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         * type and Certificate encoding bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         *
29492
a4bf9a570035 8028266: Tidy warnings cleanup for packages java.security/javax.security
avstepan
parents: 25859
diff changeset
   254
         * @param type the standard name of the Certificate type.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         * @param data the Certificate data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        protected CertificateRep(String type, byte[] data) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            this.data = data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
         * Resolve the Certificate Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         * @return the resolved Certificate Object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
         * @throws java.io.ObjectStreamException if the Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
         *      could not be resolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
         */
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
   271
        @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        protected Object readResolve() throws java.io.ObjectStreamException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                CertificateFactory cf = CertificateFactory.getInstance(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                return cf.generateCertificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                        (new java.io.ByteArrayInputStream(data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                throw new java.io.NotSerializableException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                ("java.security.cert.Certificate: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                                type +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                                ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                                e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
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
     * Replace the Certificate to be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @return the alternate Certificate object to be serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @throws java.io.ObjectStreamException if a new object representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * this Certificate could not be created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
57950
4612a3cfb927 8229999: Apply java.io.Serial annotations to security types in java.base
darcy
parents: 47216
diff changeset
   296
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    protected Object writeReplace() throws java.io.ObjectStreamException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            return new CertificateRep(type, getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        } catch (CertificateException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            throw new java.io.NotSerializableException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                ("java.security.cert.Certificate: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                type +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                                e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
}