Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/classes/sun/security/x509/CertException.java
41159 views
1
/*
2
* Copyright (c) 1996, 2019, 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
package sun.security.x509;
27
28
/**
29
* CertException indicates one of a variety of certificate problems.
30
*
31
* @deprecated use one of Exceptions defined in the java.security.cert
32
* package.
33
*
34
* @see java.security.Certificate
35
*
36
*
37
* @author David Brownell
38
*/
39
@Deprecated
40
public class CertException extends SecurityException {
41
42
@java.io.Serial
43
private static final long serialVersionUID = 6930793039696446142L;
44
45
// Zero is reserved.
46
47
/** Indicates that the signature in the certificate is not valid. */
48
public static final int verf_INVALID_SIG = 1;
49
50
/** Indicates that the certificate was revoked, and so is invalid. */
51
public static final int verf_INVALID_REVOKED = 2;
52
53
/** Indicates that the certificate is not yet valid. */
54
public static final int verf_INVALID_NOTBEFORE = 3;
55
56
/** Indicates that the certificate has expired and so is not valid. */
57
public static final int verf_INVALID_EXPIRED = 4;
58
59
/** Indicates that a certificate authority in the certification
60
* chain is not trusted. */
61
public static final int verf_CA_UNTRUSTED = 5;
62
63
/** Indicates that the certification chain is too long. */
64
public static final int verf_CHAIN_LENGTH = 6;
65
66
/** Indicates an error parsing the ASN.1/DER encoding of the certificate. */
67
public static final int verf_PARSE_ERROR = 7;
68
69
/** Indicates an error constructing a certificate or certificate chain. */
70
public static final int err_CONSTRUCTION = 8;
71
72
/** Indicates a problem with the public key */
73
public static final int err_INVALID_PUBLIC_KEY = 9;
74
75
/** Indicates a problem with the certificate version */
76
public static final int err_INVALID_VERSION = 10;
77
78
/** Indicates a problem with the certificate format */
79
public static final int err_INVALID_FORMAT = 11;
80
81
/** Indicates a problem with the certificate encoding */
82
public static final int err_ENCODING = 12;
83
84
// Private data members
85
private int verfCode;
86
private String moreData;
87
88
89
/**
90
* Constructs a certificate exception using an error code
91
* (<code>verf_*</code>) and a string describing the context
92
* of the error.
93
*/
94
public CertException(int code, String moredata)
95
{
96
verfCode = code;
97
moreData = moredata;
98
}
99
100
/**
101
* Constructs a certificate exception using just an error code,
102
* without a string describing the context.
103
*/
104
public CertException(int code)
105
{
106
verfCode = code;
107
}
108
109
/**
110
* Returns the error code with which the exception was created.
111
*/
112
public int getVerfCode() { return verfCode; }
113
114
/**
115
* Returns a string describing the context in which the exception
116
* was reported.
117
*/
118
public String getMoreData() { return moreData; }
119
120
/**
121
* Return a string corresponding to the error code used to create
122
* this exception.
123
*/
124
public String getVerfDescription()
125
{
126
switch (verfCode) {
127
case verf_INVALID_SIG:
128
return "The signature in the certificate is not valid.";
129
case verf_INVALID_REVOKED:
130
return "The certificate has been revoked.";
131
case verf_INVALID_NOTBEFORE:
132
return "The certificate is not yet valid.";
133
case verf_INVALID_EXPIRED:
134
return "The certificate has expired.";
135
case verf_CA_UNTRUSTED:
136
return "The Authority which issued the certificate is not trusted.";
137
case verf_CHAIN_LENGTH:
138
return "The certificate path to a trusted authority is too long.";
139
case verf_PARSE_ERROR:
140
return "The certificate could not be parsed.";
141
case err_CONSTRUCTION:
142
return "There was an error when constructing the certificate.";
143
case err_INVALID_PUBLIC_KEY:
144
return "The public key was not in the correct format.";
145
case err_INVALID_VERSION:
146
return "The certificate has an invalid version number.";
147
case err_INVALID_FORMAT:
148
return "The certificate has an invalid format.";
149
case err_ENCODING:
150
return "Problem encountered while encoding the data.";
151
152
default:
153
return "Unknown code: " + verfCode;
154
}
155
}
156
157
/**
158
* Returns a string describing the certificate exception.
159
*/
160
public String toString()
161
{
162
return "[Certificate Exception: " + getMessage() + ']';
163
}
164
165
/**
166
* Returns a string describing the certificate exception.
167
*/
168
public String getMessage()
169
{
170
return getVerfDescription()
171
+ ( (moreData != null)
172
? ( "\n (" + moreData + ')' ) : "" );
173
}
174
}
175
176