Path: blob/master/src/java.base/share/classes/sun/security/x509/CertException.java
41159 views
/*1* Copyright (c) 1996, 2019, 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 {4041@java.io.Serial42private static final long serialVersionUID = 6930793039696446142L;4344// Zero is reserved.4546/** Indicates that the signature in the certificate is not valid. */47public static final int verf_INVALID_SIG = 1;4849/** Indicates that the certificate was revoked, and so is invalid. */50public static final int verf_INVALID_REVOKED = 2;5152/** Indicates that the certificate is not yet valid. */53public static final int verf_INVALID_NOTBEFORE = 3;5455/** Indicates that the certificate has expired and so is not valid. */56public static final int verf_INVALID_EXPIRED = 4;5758/** Indicates that a certificate authority in the certification59* chain is not trusted. */60public static final int verf_CA_UNTRUSTED = 5;6162/** Indicates that the certification chain is too long. */63public static final int verf_CHAIN_LENGTH = 6;6465/** Indicates an error parsing the ASN.1/DER encoding of the certificate. */66public static final int verf_PARSE_ERROR = 7;6768/** Indicates an error constructing a certificate or certificate chain. */69public static final int err_CONSTRUCTION = 8;7071/** Indicates a problem with the public key */72public static final int err_INVALID_PUBLIC_KEY = 9;7374/** Indicates a problem with the certificate version */75public static final int err_INVALID_VERSION = 10;7677/** Indicates a problem with the certificate format */78public static final int err_INVALID_FORMAT = 11;7980/** Indicates a problem with the certificate encoding */81public static final int err_ENCODING = 12;8283// Private data members84private int verfCode;85private String moreData;868788/**89* Constructs a certificate exception using an error code90* (<code>verf_*</code>) and a string describing the context91* of the error.92*/93public CertException(int code, String moredata)94{95verfCode = code;96moreData = moredata;97}9899/**100* Constructs a certificate exception using just an error code,101* without a string describing the context.102*/103public CertException(int code)104{105verfCode = code;106}107108/**109* Returns the error code with which the exception was created.110*/111public int getVerfCode() { return verfCode; }112113/**114* Returns a string describing the context in which the exception115* was reported.116*/117public String getMoreData() { return moreData; }118119/**120* Return a string corresponding to the error code used to create121* this exception.122*/123public String getVerfDescription()124{125switch (verfCode) {126case verf_INVALID_SIG:127return "The signature in the certificate is not valid.";128case verf_INVALID_REVOKED:129return "The certificate has been revoked.";130case verf_INVALID_NOTBEFORE:131return "The certificate is not yet valid.";132case verf_INVALID_EXPIRED:133return "The certificate has expired.";134case verf_CA_UNTRUSTED:135return "The Authority which issued the certificate is not trusted.";136case verf_CHAIN_LENGTH:137return "The certificate path to a trusted authority is too long.";138case verf_PARSE_ERROR:139return "The certificate could not be parsed.";140case err_CONSTRUCTION:141return "There was an error when constructing the certificate.";142case err_INVALID_PUBLIC_KEY:143return "The public key was not in the correct format.";144case err_INVALID_VERSION:145return "The certificate has an invalid version number.";146case err_INVALID_FORMAT:147return "The certificate has an invalid format.";148case err_ENCODING:149return "Problem encountered while encoding the data.";150151default:152return "Unknown code: " + verfCode;153}154}155156/**157* Returns a string describing the certificate exception.158*/159public String toString()160{161return "[Certificate Exception: " + getMessage() + ']';162}163164/**165* Returns a string describing the certificate exception.166*/167public String getMessage()168{169return getVerfDescription()170+ ( (moreData != null)171? ( "\n (" + moreData + ')' ) : "" );172}173}174175176