Showing the changes to java/pkg/sun/security/x509/CertException.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,173 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 1996, 2004, 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 | + private static final long serialVersionUID = 6930793039696446142L; | |
| 43 | + | |
| 44 | + // Zero is reserved. | |
| 45 | + | |
| 46 | + /** Indicates that the signature in the certificate is not valid. */ | |
| 47 | + public static final int verf_INVALID_SIG = 1; | |
| 48 | + | |
| 49 | + /** Indicates that the certificate was revoked, and so is invalid. */ | |
| 50 | + public static final int verf_INVALID_REVOKED = 2; | |
| 51 | + | |
| 52 | + /** Indicates that the certificate is not yet valid. */ | |
| 53 | + public static final int verf_INVALID_NOTBEFORE = 3; | |
| 54 | + | |
| 55 | + /** Indicates that the certificate has expired and so is not valid. */ | |
| 56 | + public static final int verf_INVALID_EXPIRED = 4; | |
| 57 | + | |
| 58 | + /** Indicates that a certificate authority in the certification | |
| 59 | + * chain is not trusted. */ | |
| 60 | + public static final int verf_CA_UNTRUSTED = 5; | |
| 61 | + | |
| 62 | + /** Indicates that the certification chain is too long. */ | |
| 63 | + public static final int verf_CHAIN_LENGTH = 6; | |
| 64 | + | |
| 65 | + /** Indicates an error parsing the ASN.1/DER encoding of the certificate. */ | |
| 66 | + public static final int verf_PARSE_ERROR = 7; | |
| 67 | + | |
| 68 | + /** Indicates an error constructing a certificate or certificate chain. */ | |
| 69 | + public static final int err_CONSTRUCTION = 8; | |
| 70 | + | |
| 71 | + /** Indicates a problem with the public key */ | |
| 72 | + public static final int err_INVALID_PUBLIC_KEY = 9; | |
| 73 | + | |
| 74 | + /** Indicates a problem with the certificate version */ | |
| 75 | + public static final int err_INVALID_VERSION = 10; | |
| 76 | + | |
| 77 | + /** Indicates a problem with the certificate format */ | |
| 78 | + public static final int err_INVALID_FORMAT = 11; | |
| 79 | + | |
| 80 | + /** Indicates a problem with the certificate encoding */ | |
| 81 | + public static final int err_ENCODING = 12; | |
| 82 | + | |
| 83 | + // Private data members | |
| 84 | + private int verfCode; | |
| 85 | + private String moreData; | |
| 86 | + | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * Constructs a certificate exception using an error code | |
| 90 | + * (<code>verf_*</code>) and a string describing the context | |
| 91 | + * of the error. | |
| 92 | + */ | |
| 93 | + public CertException(int code, String moredata) | |
| 94 | + { | |
| 95 | + verfCode = code; | |
| 96 | + moreData = moredata; | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * Constructs a certificate exception using just an error code, | |
| 101 | + * without a string describing the context. | |
| 102 | + */ | |
| 103 | + public CertException(int code) | |
| 104 | + { | |
| 105 | + verfCode = code; | |
| 106 | + } | |
| 107 | + | |
| 108 | + /** | |
| 109 | + * Returns the error code with which the exception was created. | |
| 110 | + */ | |
| 111 | + public int getVerfCode() { return verfCode; } | |
| 112 | + | |
| 113 | + /** | |
| 114 | + * Returns a string describing the context in which the exception | |
| 115 | + * was reported. | |
| 116 | + */ | |
| 117 | + public String getMoreData() { return moreData; } | |
| 118 | + | |
| 119 | + /** | |
| 120 | + * Return a string corresponding to the error code used to create | |
| 121 | + * this exception. | |
| 122 | + */ | |
| 123 | + public String getVerfDescription() | |
| 124 | + { | |
| 125 | + switch (verfCode) { | |
| 126 | + case verf_INVALID_SIG: | |
| 127 | + return "The signature in the certificate is not valid."; | |
| 128 | + case verf_INVALID_REVOKED: | |
| 129 | + return "The certificate has been revoked."; | |
| 130 | + case verf_INVALID_NOTBEFORE: | |
| 131 | + return "The certificate is not yet valid."; | |
| 132 | + case verf_INVALID_EXPIRED: | |
| 133 | + return "The certificate has expired."; | |
| 134 | + case verf_CA_UNTRUSTED: | |
| 135 | + return "The Authority which issued the certificate is not trusted."; | |
| 136 | + case verf_CHAIN_LENGTH: | |
| 137 | + return "The certificate path to a trusted authority is too long."; | |
| 138 | + case verf_PARSE_ERROR: | |
| 139 | + return "The certificate could not be parsed."; | |
| 140 | + case err_CONSTRUCTION: | |
| 141 | + return "There was an error when constructing the certificate."; | |
| 142 | + case err_INVALID_PUBLIC_KEY: | |
| 143 | + return "The public key was not in the correct format."; | |
| 144 | + case err_INVALID_VERSION: | |
| 145 | + return "The certificate has an invalid version number."; | |
| 146 | + case err_INVALID_FORMAT: | |
| 147 | + return "The certificate has an invalid format."; | |
| 148 | + case err_ENCODING: | |
| 149 | + return "Problem encountered while encoding the data."; | |
| 150 | + | |
| 151 | + default: | |
| 152 | + return "Unknown code: " + verfCode; | |
| 153 | + } | |
| 154 | + } | |
| 155 | + | |
| 156 | + /** | |
| 157 | + * Returns a string describing the certificate exception. | |
| 158 | + */ | |
| 159 | + public String toString() | |
| 160 | + { | |
| 161 | + return "[Certificate Exception: " + getMessage() + "]"; | |
| 162 | + } | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * Returns a string describing the certificate exception. | |
| 166 | + */ | |
| 167 | + public String getMessage() | |
| 168 | + { | |
| 169 | + return getVerfDescription() | |
| 170 | + + ( (moreData != null) | |
| 171 | + ? ( "\n (" + moreData + ")" ) : "" ); | |
| 172 | + } | |
| 173 | +} | |