Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/javax/security/cert/Certificate.java
41159 views
1
/*
2
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
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
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
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
*
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.
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
*
52
* <p><em>Note: The classes in the package {@code javax.security.cert}
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
56
* {@code java.security.cert}.</em></p>
57
*
58
* @since 1.4
59
* @see X509Certificate
60
* @deprecated Use the classes in {@code java.security.cert} instead.
61
*
62
* @author Hemma Prafullchandra
63
*/
64
@SuppressWarnings("removal")
65
@Deprecated(since="9", forRemoval=true)
66
public abstract class Certificate {
67
68
/**
69
* Constructor for subclasses to call.
70
*/
71
public Certificate() {}
72
73
/**
74
* Compares this certificate for equality with the specified
75
* object. If the {@code other} object is an
76
* {@code instanceof} {@code Certificate}, then
77
* its encoded form is retrieved and compared with the
78
* encoded form of this certificate.
79
*
80
* @param other the object to test for equality with this certificate.
81
* @return true if the encoded forms of the two certificates
82
* match, false otherwise.
83
*/
84
public boolean equals(Object other) {
85
if (this == other)
86
return true;
87
if (!(other instanceof Certificate))
88
return false;
89
try {
90
byte[] thisCert = this.getEncoded();
91
byte[] otherCert = ((Certificate)other).getEncoded();
92
93
if (thisCert.length != otherCert.length)
94
return false;
95
for (int i = 0; i < thisCert.length; i++)
96
if (thisCert[i] != otherCert[i])
97
return false;
98
return true;
99
} catch (CertificateException e) {
100
return false;
101
}
102
}
103
104
/**
105
* Returns a hashcode value for this certificate from its
106
* encoded form.
107
*
108
* @return the hashcode value.
109
*/
110
public int hashCode() {
111
int retval = 0;
112
try {
113
byte[] certData = this.getEncoded();
114
for (int i = 1; i < certData.length; i++) {
115
retval += certData[i] * i;
116
}
117
return (retval);
118
} catch (CertificateException e) {
119
return (retval);
120
}
121
}
122
123
/**
124
* Returns the encoded form of this certificate. It is
125
* assumed that each certificate type would have only a single
126
* form of encoding; for example, X.509 certificates would
127
* be encoded as ASN.1 DER.
128
*
129
* @return encoded form of this certificate
130
* @exception CertificateEncodingException on internal certificate
131
* encoding failure
132
*/
133
public abstract byte[] getEncoded() throws CertificateEncodingException;
134
135
/**
136
* Verifies that this certificate was signed using the
137
* private key that corresponds to the specified public key.
138
*
139
* @param key the PublicKey used to carry out the verification.
140
*
141
* @exception NoSuchAlgorithmException on unsupported signature
142
* algorithms.
143
* @exception InvalidKeyException on incorrect key.
144
* @exception NoSuchProviderException if there's no default provider.
145
* @exception SignatureException on signature errors.
146
* @exception CertificateException on encoding errors.
147
*/
148
public abstract void verify(PublicKey key)
149
throws CertificateException, NoSuchAlgorithmException,
150
InvalidKeyException, NoSuchProviderException,
151
SignatureException;
152
153
/**
154
* Verifies that this certificate was signed using the
155
* private key that corresponds to the specified public key.
156
* This method uses the signature verification engine
157
* supplied by the specified provider.
158
*
159
* @param key the PublicKey used to carry out the verification.
160
* @param sigProvider the name of the signature provider.
161
* @exception NoSuchAlgorithmException on unsupported signature algorithms.
162
* @exception InvalidKeyException on incorrect key.
163
* @exception NoSuchProviderException on incorrect provider.
164
* @exception SignatureException on signature errors.
165
* @exception CertificateException on encoding errors.
166
*/
167
public abstract void verify(PublicKey key, String sigProvider)
168
throws CertificateException, NoSuchAlgorithmException,
169
InvalidKeyException, NoSuchProviderException,
170
SignatureException;
171
172
/**
173
* Returns a string representation of this certificate.
174
*
175
* @return a string representation of this certificate.
176
*/
177
public abstract String toString();
178
179
/**
180
* Gets the public key from this certificate.
181
*
182
* @return the public key.
183
*/
184
public abstract PublicKey getPublicKey();
185
}
186
187