jdk/src/share/classes/java/security/cert/CertPathValidator.java
author xuelei
Wed, 20 Jan 2010 21:38:37 +0800
changeset 4807 2521b7dcf505
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6862064: incorrect implementation of PKIXParameters.clone() Reviewed-by: weijun, mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <b>Concurrent Access</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * The static methods of this class are guaranteed to be thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Multiple threads may concurrently invoke the static methods defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * this class with no ill effects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * However, this is not true for the non-static methods defined by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * Unless otherwise documented by a specific provider, threads that need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * access a single <code>CertPathValidator</code> instance concurrently should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * synchronize amongst themselves and provide the necessary locking. Multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * threads each manipulating a different <code>CertPathValidator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * instance need not synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @see CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @author      Yassir Elley
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
public class CertPathValidator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Constant to lookup in the Security properties file to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * the default certpathvalidator type. In the Security properties file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * the default certpathvalidator type is given as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * certpathvalidator.type=PKIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final String CPV_TYPE = "certpathvalidator.type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static final Debug debug = Debug.getInstance("certpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private CertPathValidatorSpi validatorSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Creates a <code>CertPathValidator</code> object of the given algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * and encapsulates the given provider implementation (SPI object) in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param validatorSpi the provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param algorithm the algorithm name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected CertPathValidator(CertPathValidatorSpi validatorSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        Provider provider, String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.validatorSpi = validatorSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Returns a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * A new CertPathValidator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * CertPathValidatorSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param algorithm the name of the requested <code>CertPathValidator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *  algorithm.  See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *  "../../../../technotes/guides/security/certpath/CertPathProgGuide.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *  Java Certification Path API Programmer's Guide </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *  for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @exception NoSuchAlgorithmException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *          CertPathValidatorSpi implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static CertPathValidator getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        Instance instance = GetInstance.getInstance("CertPathValidator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            CertPathValidatorSpi.class, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return new CertPathValidator((CertPathValidatorSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Returns a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <p> A new CertPathValidator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * CertPathValidatorSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param algorithm the name of the requested <code>CertPathValidator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *  algorithm.  See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *  "../../../../technotes/guides/security/certpath/CertPathProgGuide.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *  Java Certification Path API Programmer's Guide </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *  for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @return a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @exception NoSuchAlgorithmException if a CertPathValidatorSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *          implementation for the specified algorithm is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *          available from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @exception NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @exception IllegalArgumentException if the <code>provider</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *          null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public static CertPathValidator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            String provider) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        Instance instance = GetInstance.getInstance("CertPathValidator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            CertPathValidatorSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return new CertPathValidator((CertPathValidatorSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Returns a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <p> A new CertPathValidator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * CertPathValidatorSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @param algorithm the name of the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *  <code>CertPathValidator</code> algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *  See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *  "../../../../technotes/guides/security/certpath/CertPathProgGuide.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *  Java Certification Path API Programmer's Guide </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *  for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @return a <code>CertPathValidator</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @exception NoSuchAlgorithmException if a CertPathValidatorSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @exception IllegalArgumentException if the <code>provider</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *          null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public static CertPathValidator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        Instance instance = GetInstance.getInstance("CertPathValidator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            CertPathValidatorSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return new CertPathValidator((CertPathValidatorSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Returns the <code>Provider</code> of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * <code>CertPathValidator</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return the <code>Provider</code> of this <code>CertPathValidator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Returns the algorithm name of this <code>CertPathValidator</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @return the algorithm name of this <code>CertPathValidator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Validates the specified certification path using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * algorithm parameter set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * The <code>CertPath</code> specified must be of a type that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * supported by the validation algorithm, otherwise an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * <code>InvalidAlgorithmParameterException</code> will be thrown. For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * example, a <code>CertPathValidator</code> that implements the PKIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * algorithm validates <code>CertPath</code> objects of type X.509.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @param certPath the <code>CertPath</code> to be validated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param params the algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return the result of the validation algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @exception CertPathValidatorException if the <code>CertPath</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * does not validate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @exception InvalidAlgorithmParameterException if the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * parameters or the type of the specified <code>CertPath</code> are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * inappropriate for this <code>CertPathValidator</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public final CertPathValidatorResult validate(CertPath certPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        CertPathParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        throws CertPathValidatorException, InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return validatorSpi.engineValidate(certPath, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Returns the default <code>CertPathValidator</code> type as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * the Java security properties file, or the string &quot;PKIX&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * if no such property exists. The Java security properties file is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * located in the file named &lt;JAVA_HOME&gt;/lib/security/java.security.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * &lt;JAVA_HOME&gt; refers to the value of the java.home system property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * and specifies the directory where the JRE is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <p>The default <code>CertPathValidator</code> type can be used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * applications that do not want to use a hard-coded type when calling one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * of the <code>getInstance</code> methods, and want to provide a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * type in case a user does not specify its own.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * <p>The default <code>CertPathValidator</code> type can be changed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * setting the value of the "certpathvalidator.type" security property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * (in the Java security properties file) to the desired type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @return the default <code>CertPathValidator</code> type as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * in the Java security properties file, or the string &quot;PKIX&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * if no such property exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    public final static String getDefaultType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        String cpvtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        cpvtype = AccessController.doPrivileged(new PrivilegedAction<String>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            public String run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                return Security.getProperty(CPV_TYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (cpvtype == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            cpvtype = "PKIX";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        return cpvtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
}