author | xuelei |
Wed, 13 Mar 2019 07:14:50 -0700 | |
changeset 54099 | fd332722014c |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
54099
fd332722014c
8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
||
27 |
package javax.security.cert; |
|
28 |
||
29 |
import java.security.PublicKey; |
|
30 |
import java.security.NoSuchAlgorithmException; |
|
31 |
import java.security.NoSuchProviderException; |
|
32 |
import java.security.InvalidKeyException; |
|
33 |
import java.security.SignatureException; |
|
34 |
||
35 |
/** |
|
36 |
* <p>Abstract class for managing a variety of identity certificates. |
|
37 |
* An identity certificate is a guarantee by a principal that |
|
38 |
* a public key is that of another principal. (A principal represents |
|
39 |
* an entity such as an individual user, a group, or a corporation.) |
|
40 |
*<p> |
|
41 |
* This class is an abstraction for certificates that have different |
|
42 |
* formats but important common uses. For example, different types of |
|
43 |
* certificates, such as X.509 and PGP, share general certificate |
|
44 |
* functionality (like encoding and verifying) and |
|
45 |
* some types of information (like a public key). |
|
46 |
* <p> |
|
47 |
* X.509, PGP, and SDSI certificates can all be implemented by |
|
48 |
* subclassing the Certificate class, even though they contain different |
|
49 |
* sets of information, and they store and retrieve the information in |
|
50 |
* different ways. |
|
51 |
* |
|
18830 | 52 |
* <p><em>Note: The classes in the package {@code javax.security.cert} |
2 | 53 |
* exist for compatibility with earlier versions of the |
54 |
* Java Secure Sockets Extension (JSSE). New applications should instead |
|
55 |
* use the standard Java SE certificate classes located in |
|
18830 | 56 |
* {@code java.security.cert}.</em></p> |
2 | 57 |
* |
58 |
* @since 1.4 |
|
59 |
* @see X509Certificate |
|
29377
d3f457ce9c48
8073430: Deprecate security APIs that have been superseded
juh
parents:
25859
diff
changeset
|
60 |
* @deprecated Use the classes in {@code java.security.cert} instead. |
2 | 61 |
* |
62 |
* @author Hemma Prafullchandra |
|
63 |
*/ |
|
54099
fd332722014c
8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents:
47216
diff
changeset
|
64 |
@SuppressWarnings("removal") |
fd332722014c
8160247: Mark deprecated javax.security.cert APIs with forRemoval=true
xuelei
parents:
47216
diff
changeset
|
65 |
@Deprecated(since="9", forRemoval=true) |
2 | 66 |
public abstract class Certificate { |
67 |
||
68 |
/** |
|
69 |
* Compares this certificate for equality with the specified |
|
18830 | 70 |
* object. If the {@code other} object is an |
71 |
* {@code instanceof} {@code Certificate}, then |
|
2 | 72 |
* its encoded form is retrieved and compared with the |
73 |
* encoded form of this certificate. |
|
74 |
* |
|
75 |
* @param other the object to test for equality with this certificate. |
|
76 |
* @return true if the encoded forms of the two certificates |
|
77 |
* match, false otherwise. |
|
78 |
*/ |
|
79 |
public boolean equals(Object other) { |
|
80 |
if (this == other) |
|
81 |
return true; |
|
82 |
if (!(other instanceof Certificate)) |
|
83 |
return false; |
|
84 |
try { |
|
85 |
byte[] thisCert = this.getEncoded(); |
|
86 |
byte[] otherCert = ((Certificate)other).getEncoded(); |
|
87 |
||
88 |
if (thisCert.length != otherCert.length) |
|
89 |
return false; |
|
90 |
for (int i = 0; i < thisCert.length; i++) |
|
91 |
if (thisCert[i] != otherCert[i]) |
|
92 |
return false; |
|
93 |
return true; |
|
94 |
} catch (CertificateException e) { |
|
95 |
return false; |
|
96 |
} |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Returns a hashcode value for this certificate from its |
|
101 |
* encoded form. |
|
102 |
* |
|
103 |
* @return the hashcode value. |
|
104 |
*/ |
|
105 |
public int hashCode() { |
|
106 |
int retval = 0; |
|
107 |
try { |
|
108 |
byte[] certData = this.getEncoded(); |
|
109 |
for (int i = 1; i < certData.length; i++) { |
|
110 |
retval += certData[i] * i; |
|
111 |
} |
|
112 |
return (retval); |
|
113 |
} catch (CertificateException e) { |
|
114 |
return (retval); |
|
115 |
} |
|
116 |
} |
|
117 |
||
118 |
/** |
|
119 |
* Returns the encoded form of this certificate. It is |
|
120 |
* assumed that each certificate type would have only a single |
|
121 |
* form of encoding; for example, X.509 certificates would |
|
122 |
* be encoded as ASN.1 DER. |
|
123 |
* |
|
124 |
* @return encoded form of this certificate |
|
125 |
* @exception CertificateEncodingException on internal certificate |
|
126 |
* encoding failure |
|
127 |
*/ |
|
128 |
public abstract byte[] getEncoded() throws CertificateEncodingException; |
|
129 |
||
130 |
/** |
|
131 |
* Verifies that this certificate was signed using the |
|
132 |
* private key that corresponds to the specified public key. |
|
133 |
* |
|
134 |
* @param key the PublicKey used to carry out the verification. |
|
135 |
* |
|
136 |
* @exception NoSuchAlgorithmException on unsupported signature |
|
137 |
* algorithms. |
|
138 |
* @exception InvalidKeyException on incorrect key. |
|
139 |
* @exception NoSuchProviderException if there's no default provider. |
|
140 |
* @exception SignatureException on signature errors. |
|
141 |
* @exception CertificateException on encoding errors. |
|
142 |
*/ |
|
143 |
public abstract void verify(PublicKey key) |
|
144 |
throws CertificateException, NoSuchAlgorithmException, |
|
145 |
InvalidKeyException, NoSuchProviderException, |
|
146 |
SignatureException; |
|
147 |
||
148 |
/** |
|
149 |
* Verifies that this certificate was signed using the |
|
150 |
* private key that corresponds to the specified public key. |
|
151 |
* This method uses the signature verification engine |
|
152 |
* supplied by the specified provider. |
|
153 |
* |
|
154 |
* @param key the PublicKey used to carry out the verification. |
|
155 |
* @param sigProvider the name of the signature provider. |
|
156 |
* @exception NoSuchAlgorithmException on unsupported signature algorithms. |
|
157 |
* @exception InvalidKeyException on incorrect key. |
|
158 |
* @exception NoSuchProviderException on incorrect provider. |
|
159 |
* @exception SignatureException on signature errors. |
|
160 |
* @exception CertificateException on encoding errors. |
|
161 |
*/ |
|
162 |
public abstract void verify(PublicKey key, String sigProvider) |
|
163 |
throws CertificateException, NoSuchAlgorithmException, |
|
164 |
InvalidKeyException, NoSuchProviderException, |
|
165 |
SignatureException; |
|
166 |
||
167 |
/** |
|
168 |
* Returns a string representation of this certificate. |
|
169 |
* |
|
170 |
* @return a string representation of this certificate. |
|
171 |
*/ |
|
172 |
public abstract String toString(); |
|
173 |
||
174 |
/** |
|
175 |
* Gets the public key from this certificate. |
|
176 |
* |
|
177 |
* @return the public key. |
|
178 |
*/ |
|
179 |
public abstract PublicKey getPublicKey(); |
|
180 |
} |