jdk/src/share/classes/java/security/cert/PKIXCertPathChecker.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 5506 202f599c92aa
child 12860 9ffbd4e43413
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
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) 2000, 2003, 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 java.security.cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * An abstract class that performs one or more checks on an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <code>X509Certificate</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>A concrete implementation of the <code>PKIXCertPathChecker</code> class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * can be created to extend the PKIX certification path validation algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * For example, an implementation may check for and process a critical private
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * extension of each certificate in a certification path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>Instances of <code>PKIXCertPathChecker</code> are passed as parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * using the {@link PKIXParameters#setCertPathCheckers setCertPathCheckers}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * or {@link PKIXParameters#addCertPathChecker addCertPathChecker} methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * of the <code>PKIXParameters</code> and <code>PKIXBuilderParameters</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * class. Each of the <code>PKIXCertPathChecker</code>s {@link #check check}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * methods will be called, in turn, for each certificate processed by a PKIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <code>CertPathValidator</code> or <code>CertPathBuilder</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>A <code>PKIXCertPathChecker</code> may be called multiple times on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * successive certificates in a certification path. Concrete subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * are expected to maintain any internal state that may be necessary to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * check successive certificates. The {@link #init init} method is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * to initialize the internal state of the checker so that the certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * of a new certification path may be checked. A stateful implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <b>must</b> override the {@link #clone clone} method if necessary in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * order to allow a PKIX <code>CertPathBuilder</code> to efficiently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * backtrack and try other paths. In these situations, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <code>CertPathBuilder</code> is able to restore prior path validation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * states by restoring the cloned <code>PKIXCertPathChecker</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>The order in which the certificates are presented to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <code>PKIXCertPathChecker</code> may be either in the forward direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * (from target to most-trusted CA) or in the reverse direction (from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * most-trusted CA to target). A <code>PKIXCertPathChecker</code> implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <b>must</b> support reverse checking (the ability to perform its checks when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * it is presented with certificates in the reverse direction) and <b>may</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * support forward checking (the ability to perform its checks when it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * presented with certificates in the forward direction). The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * {@link #isForwardCheckingSupported isForwardCheckingSupported} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * indicates whether forward checking is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Additional input parameters required for executing the check may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * specified through constructors of concrete implementations of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <b>Concurrent Access</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Unless otherwise specified, the methods defined in this class are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * thread-safe. Multiple threads that need to access a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * object concurrently should synchronize amongst themselves and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * provide the necessary locking. Multiple threads each manipulating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * separate objects need not synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see PKIXParameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @see PKIXBuilderParameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * @author      Yassir Elley
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @author      Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
public abstract class PKIXCertPathChecker implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Default constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected PKIXCertPathChecker() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Initializes the internal state of this <code>PKIXCertPathChecker</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * The <code>forward</code> flag specifies the order that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * certificates will be passed to the {@link #check check} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * (forward or reverse). A <code>PKIXCertPathChecker</code> <b>must</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * support reverse checking and <b>may</b> support forward checking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param forward the order that certificates are presented to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * the <code>check</code> method. If <code>true</code>, certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * are presented from target to most-trusted CA (forward); if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <code>false</code>, from most-trusted CA to target (reverse).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @throws CertPathValidatorException if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <code>PKIXCertPathChecker</code> is unable to check certificates in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * the specified order; it should never be thrown if the forward flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * is false since reverse checking must be supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public abstract void init(boolean forward)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        throws CertPathValidatorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Indicates if forward checking is supported. Forward checking refers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * to the ability of the <code>PKIXCertPathChecker</code> to perform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * its checks when certificates are presented to the <code>check</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * method in the forward direction (from target to most-trusted CA).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return <code>true</code> if forward checking is supported,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public abstract boolean isForwardCheckingSupported();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Returns an immutable <code>Set</code> of X.509 certificate extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * that this <code>PKIXCertPathChecker</code> supports (i.e. recognizes, is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * able to process), or <code>null</code> if no extensions are supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Each element of the set is a <code>String</code> representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Object Identifier (OID) of the X.509 extension that is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * The OID is represented by a set of nonnegative integers separated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * periods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * All X.509 certificate extensions that a <code>PKIXCertPathChecker</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * might possibly be able to process should be included in the set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @return an immutable <code>Set</code> of X.509 extension OIDs (in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <code>String</code> format) supported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <code>PKIXCertPathChecker</code>, or <code>null</code> if no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * extensions are supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public abstract Set<String> getSupportedExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Performs the check(s) on the specified certificate using its internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * state and removes any critical extensions that it processes from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * specified collection of OID strings that represent the unresolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * critical extensions. The certificates are presented in the order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * specified by the <code>init</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param cert the <code>Certificate</code> to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param unresolvedCritExts a <code>Collection</code> of OID strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * representing the current set of unresolved critical extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @exception CertPathValidatorException if the specified certificate does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * not pass the check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public abstract void check(Certificate cert,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            Collection<String> unresolvedCritExts)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            throws CertPathValidatorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Returns a clone of this object. Calls the <code>Object.clone()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * All subclasses which maintain state must support and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * override this method, if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @return a copy of this <code>PKIXCertPathChecker</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            /* Cannot happen */
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   178
            throw new InternalError(e.toString(), e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
}