Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/x509/CertException.java
38831 views
/*1* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.x509;2627/**28* CertException indicates one of a variety of certificate problems.29*30* @deprecated use one of Exceptions defined in the java.security.cert31* package.32*33* @see java.security.Certificate34*35*36* @author David Brownell37*/38@Deprecated39public class CertException extends SecurityException {4041private static final long serialVersionUID = 6930793039696446142L;4243// Zero is reserved.4445/** Indicates that the signature in the certificate is not valid. */46public static final int verf_INVALID_SIG = 1;4748/** Indicates that the certificate was revoked, and so is invalid. */49public static final int verf_INVALID_REVOKED = 2;5051/** Indicates that the certificate is not yet valid. */52public static final int verf_INVALID_NOTBEFORE = 3;5354/** Indicates that the certificate has expired and so is not valid. */55public static final int verf_INVALID_EXPIRED = 4;5657/** Indicates that a certificate authority in the certification58* chain is not trusted. */59public static final int verf_CA_UNTRUSTED = 5;6061/** Indicates that the certification chain is too long. */62public static final int verf_CHAIN_LENGTH = 6;6364/** Indicates an error parsing the ASN.1/DER encoding of the certificate. */65public static final int verf_PARSE_ERROR = 7;6667/** Indicates an error constructing a certificate or certificate chain. */68public static final int err_CONSTRUCTION = 8;6970/** Indicates a problem with the public key */71public static final int err_INVALID_PUBLIC_KEY = 9;7273/** Indicates a problem with the certificate version */74public static final int err_INVALID_VERSION = 10;7576/** Indicates a problem with the certificate format */77public static final int err_INVALID_FORMAT = 11;7879/** Indicates a problem with the certificate encoding */80public static final int err_ENCODING = 12;8182// Private data members83private int verfCode;84private String moreData;858687/**88* Constructs a certificate exception using an error code89* (<code>verf_*</code>) and a string describing the context90* of the error.91*/92public CertException(int code, String moredata)93{94verfCode = code;95moreData = moredata;96}9798/**99* Constructs a certificate exception using just an error code,100* without a string describing the context.101*/102public CertException(int code)103{104verfCode = code;105}106107/**108* Returns the error code with which the exception was created.109*/110public int getVerfCode() { return verfCode; }111112/**113* Returns a string describing the context in which the exception114* was reported.115*/116public String getMoreData() { return moreData; }117118/**119* Return a string corresponding to the error code used to create120* this exception.121*/122public String getVerfDescription()123{124switch (verfCode) {125case verf_INVALID_SIG:126return "The signature in the certificate is not valid.";127case verf_INVALID_REVOKED:128return "The certificate has been revoked.";129case verf_INVALID_NOTBEFORE:130return "The certificate is not yet valid.";131case verf_INVALID_EXPIRED:132return "The certificate has expired.";133case verf_CA_UNTRUSTED:134return "The Authority which issued the certificate is not trusted.";135case verf_CHAIN_LENGTH:136return "The certificate path to a trusted authority is too long.";137case verf_PARSE_ERROR:138return "The certificate could not be parsed.";139case err_CONSTRUCTION:140return "There was an error when constructing the certificate.";141case err_INVALID_PUBLIC_KEY:142return "The public key was not in the correct format.";143case err_INVALID_VERSION:144return "The certificate has an invalid version number.";145case err_INVALID_FORMAT:146return "The certificate has an invalid format.";147case err_ENCODING:148return "Problem encountered while encoding the data.";149150default:151return "Unknown code: " + verfCode;152}153}154155/**156* Returns a string describing the certificate exception.157*/158public String toString()159{160return "[Certificate Exception: " + getMessage() + "]";161}162163/**164* Returns a string describing the certificate exception.165*/166public String getMessage()167{168return getVerfDescription()169+ ( (moreData != null)170? ( "\n (" + moreData + ")" ) : "" );171}172}173174175