src/java.base/share/classes/sun/security/x509/CertException.java
author igerasim
Tue, 02 Oct 2018 10:19:07 -0700
changeset 51986 c1db377f6300
parent 47216 71c04702a3d5
child 57950 4612a3cfb927
permissions -rw-r--r--
8200381: Typos in javadoc - missing verb "be" and alike Reviewed-by: lancea, darcy, wetmore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.x509;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * CertException indicates one of a variety of certificate problems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @deprecated use one of Exceptions defined in the java.security.cert
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @see java.security.Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author David Brownell
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
@Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class CertException extends SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    private static final long serialVersionUID = 6930793039696446142L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    // Zero is reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /** Indicates that the signature in the certificate is not valid. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static final int verf_INVALID_SIG = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /** Indicates that the certificate was revoked, and so is invalid. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static final int verf_INVALID_REVOKED = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /** Indicates that the certificate is not yet valid. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final int verf_INVALID_NOTBEFORE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /** Indicates that the certificate has expired and so is not valid. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static final int verf_INVALID_EXPIRED = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /** Indicates that a certificate authority in the certification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * chain is not trusted. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static final int verf_CA_UNTRUSTED = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /** Indicates that the certification chain is too long. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static final int verf_CHAIN_LENGTH = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /** Indicates an error parsing the ASN.1/DER encoding of the certificate. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public static final int verf_PARSE_ERROR = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /** Indicates an error constructing a certificate or certificate chain. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final int err_CONSTRUCTION = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /** Indicates a problem with the public key */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static final int err_INVALID_PUBLIC_KEY = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /** Indicates a problem with the certificate version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final int err_INVALID_VERSION = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /** Indicates a problem with the certificate format */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int err_INVALID_FORMAT = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /** Indicates a problem with the certificate encoding */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final int err_ENCODING = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // Private data members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private int         verfCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private String      moreData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Constructs a certificate exception using an error code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * (<code>verf_*</code>) and a string describing the context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * of the error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public CertException(int code, String moredata)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        verfCode = code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        moreData = moredata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Constructs a certificate exception using just an error code,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * without a string describing the context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public CertException(int code)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        verfCode = code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Returns the error code with which the exception was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public int getVerfCode() { return verfCode; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Returns a string describing the context in which the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * was reported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public String getMoreData() { return moreData; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Return a string corresponding to the error code used to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * this exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public String getVerfDescription()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        switch (verfCode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        case verf_INVALID_SIG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            return "The signature in the certificate is not valid.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        case verf_INVALID_REVOKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            return "The certificate has been revoked.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        case verf_INVALID_NOTBEFORE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            return "The certificate is not yet valid.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        case verf_INVALID_EXPIRED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            return "The certificate has expired.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        case verf_CA_UNTRUSTED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return "The Authority which issued the certificate is not trusted.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        case verf_CHAIN_LENGTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return "The certificate path to a trusted authority is too long.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        case verf_PARSE_ERROR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            return "The certificate could not be parsed.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        case err_CONSTRUCTION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return "There was an error when constructing the certificate.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        case err_INVALID_PUBLIC_KEY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            return "The public key was not in the correct format.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        case err_INVALID_VERSION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return "The certificate has an invalid version number.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        case err_INVALID_FORMAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            return "The certificate has an invalid format.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        case err_ENCODING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            return "Problem encountered while encoding the data.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            return "Unknown code:  " + verfCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Returns a string describing the certificate exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public String toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    {
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 25859
diff changeset
   161
        return "[Certificate Exception: " + getMessage() + ']';
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Returns a string describing the certificate exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public String getMessage()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return getVerfDescription()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                + ( (moreData != null)
30649
e7cc8f48f616 8080522: Optimize string operations in java.base/share/classes/sun/security/x509/
igerasim
parents: 25859
diff changeset
   171
                    ? ( "\n  (" + moreData + ')' ) : "" );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}