jdk/src/share/classes/java/security/cert/CertPathValidator.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8152 94e5966bdf22
child 12860 9ffbd4e43413
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8152
diff changeset
     2
 * Copyright (c) 2000, 2011, 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.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.InvalidAlgorithmParameterException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.NoSuchAlgorithmException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.NoSuchProviderException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.Provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.Security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.util.Debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.jca.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.jca.GetInstance.Instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A class for validating certification paths (also known as certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * chains).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This class uses a provider-based architecture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * To create a <code>CertPathValidator</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * call one of the static <code>getInstance</code> methods, passing in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * algorithm name of the <code>CertPathValidator</code> desired and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * optionally the name of the provider desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Once a <code>CertPathValidator</code> object has been created, it can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * be used to validate certification paths by calling the {@link #validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * validate} method and passing it the <code>CertPath</code> to be validated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * and an algorithm-specific set of parameters. If successful, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * returned in an object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>CertPathValidatorResult</code> interface.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    56
 *
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    57
 * <p> Every implementation of the Java platform is required to support the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    58
 * following standard <code>CertPathValidator</code> algorithm:
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    59
 * <ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    60
 * <li><tt>PKIX</tt></li>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    61
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    62
 * This algorithm is described in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    63
 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    64
 * CertPathValidator section</a> of the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    65
 * Java Cryptography Architecture Standard Algorithm Name Documentation.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    66
 * Consult the release documentation for your implementation to see if any
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    67
 * other algorithms are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    68
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <b>Concurrent Access</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * The static methods of this class are guaranteed to be thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Multiple threads may concurrently invoke the static methods defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * this class with no ill effects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * However, this is not true for the non-static methods defined by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Unless otherwise documented by a specific provider, threads that need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * access a single <code>CertPathValidator</code> instance concurrently should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * synchronize amongst themselves and provide the necessary locking. Multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * threads each manipulating a different <code>CertPathValidator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * instance need not synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @author      Yassir Elley
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
public class CertPathValidator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Constant to lookup in the Security properties file to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * the default certpathvalidator type. In the Security properties file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * the default certpathvalidator type is given as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * certpathvalidator.type=PKIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static final String CPV_TYPE = "certpathvalidator.type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final Debug debug = Debug.getInstance("certpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private CertPathValidatorSpi validatorSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Creates a <code>CertPathValidator</code> object of the given algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * and encapsulates the given provider implementation (SPI object) in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param validatorSpi the provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param algorithm the algorithm name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    protected CertPathValidator(CertPathValidatorSpi validatorSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        Provider provider, String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        this.validatorSpi = validatorSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Returns a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * A new CertPathValidator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * CertPathValidatorSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param algorithm the name of the requested <code>CertPathValidator</code>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   134
     *  algorithm. See the CertPathValidator section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   135
     *  "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   136
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   137
     * for information about standard algorithm names.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @exception NoSuchAlgorithmException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *          CertPathValidatorSpi implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public static CertPathValidator getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        Instance instance = GetInstance.getInstance("CertPathValidator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            CertPathValidatorSpi.class, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return new CertPathValidator((CertPathValidatorSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            instance.provider, algorithm);
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 <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * <p> A new CertPathValidator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * CertPathValidatorSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param algorithm the name of the requested <code>CertPathValidator</code>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   169
     *  algorithm. See the CertPathValidator section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   170
     *  "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   171
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   172
     * for information about standard algorithm names.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @return a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @exception NoSuchAlgorithmException if a CertPathValidatorSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *          implementation for the specified algorithm is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *          available from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @exception NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @exception IllegalArgumentException if the <code>provider</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *          null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public static CertPathValidator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            String provider) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        Instance instance = GetInstance.getInstance("CertPathValidator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            CertPathValidatorSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return new CertPathValidator((CertPathValidatorSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Returns a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * <p> A new CertPathValidator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * CertPathValidatorSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   209
     * @param algorithm the name of the requested <code>CertPathValidator</code>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   210
     * algorithm. See the CertPathValidator section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   211
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathValidator">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   212
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   213
     * for information about standard algorithm names.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @return a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @exception NoSuchAlgorithmException if a CertPathValidatorSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @exception IllegalArgumentException if the <code>provider</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *          null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public static CertPathValidator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        Instance instance = GetInstance.getInstance("CertPathValidator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            CertPathValidatorSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return new CertPathValidator((CertPathValidatorSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Returns the <code>Provider</code> of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <code>CertPathValidator</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @return the <code>Provider</code> of this <code>CertPathValidator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Returns the algorithm name of this <code>CertPathValidator</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @return the algorithm name of this <code>CertPathValidator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Validates the specified certification path using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * algorithm parameter set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * The <code>CertPath</code> specified must be of a type that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * supported by the validation algorithm, otherwise an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <code>InvalidAlgorithmParameterException</code> will be thrown. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * example, a <code>CertPathValidator</code> that implements the PKIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * algorithm validates <code>CertPath</code> objects of type X.509.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param certPath the <code>CertPath</code> to be validated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param params the algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return the result of the validation algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @exception CertPathValidatorException if the <code>CertPath</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * does not validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @exception InvalidAlgorithmParameterException if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * parameters or the type of the specified <code>CertPath</code> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * inappropriate for this <code>CertPathValidator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public final CertPathValidatorResult validate(CertPath certPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        CertPathParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        throws CertPathValidatorException, InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return validatorSpi.engineValidate(certPath, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Returns the default <code>CertPathValidator</code> type as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * the Java security properties file, or the string &quot;PKIX&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * if no such property exists. The Java security properties file is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * located in the file named &lt;JAVA_HOME&gt;/lib/security/java.security.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * &lt;JAVA_HOME&gt; refers to the value of the java.home system property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * and specifies the directory where the JRE is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * <p>The default <code>CertPathValidator</code> type can be used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * applications that do not want to use a hard-coded type when calling one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * of the <code>getInstance</code> methods, and want to provide a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * type in case a user does not specify its own.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * <p>The default <code>CertPathValidator</code> type can be changed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * setting the value of the "certpathvalidator.type" security property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * (in the Java security properties file) to the desired type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @return the default <code>CertPathValidator</code> type as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * in the Java security properties file, or the string &quot;PKIX&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * if no such property exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public final static String getDefaultType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        String cpvtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        cpvtype = AccessController.doPrivileged(new PrivilegedAction<String>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            public String run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                return Security.getProperty(CPV_TYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (cpvtype == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            cpvtype = "PKIX";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return cpvtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}