jdk/src/share/classes/java/security/cert/CertPathBuilder.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
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 building certification paths (also known as certificate chains).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This class uses a provider-based architecture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * To create a <code>CertPathBuilder</code>, call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * one of the static <code>getInstance</code> methods, passing in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * algorithm name of the <code>CertPathBuilder</code> desired and optionally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the name of the provider desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * Once a <code>CertPathBuilder</code> object has been created, certification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * paths can be constructed by calling the {@link #build build} method and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * passing it an algorithm-specific set of parameters. If successful, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * result (including the <code>CertPath</code> that was built) is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * in an object that implements the <code>CertPathBuilderResult</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <b>Concurrent Access</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * The static methods of this class are guaranteed to be thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Multiple threads may concurrently invoke the static methods defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * this class with no ill effects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * However, this is not true for the non-static methods defined by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Unless otherwise documented by a specific provider, threads that need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * access a single <code>CertPathBuilder</code> instance concurrently should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * synchronize amongst themselves and provide the necessary locking. Multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * threads each manipulating a different <code>CertPathBuilder</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * need not synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @see CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @author      Sean Mullan
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 CertPathBuilder {
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 certpathbuilder type. In the Security properties file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * the default certpathbuilder type is given as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * certpathbuilder.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 CPB_TYPE = "certpathbuilder.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 CertPathBuilderSpi builderSpi;
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>CertPathBuilder</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 builderSpi 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 CertPathBuilder(CertPathBuilderSpi builderSpi, Provider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.builderSpi = builderSpi;
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>CertPathBuilder</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 CertPathBuilder object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * CertPathBuilderSpi 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>CertPathBuilder</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>CertPathBuilder</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
     * @throws NoSuchAlgorithmException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *          CertPathBuilderSpi 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 CertPathBuilder 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("CertPathBuilder",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            CertPathBuilderSpi.class, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return new CertPathBuilder((CertPathBuilderSpi)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>CertPathBuilder</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 CertPathBuilder object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * CertPathBuilderSpi 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>CertPathBuilder</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>CertPathBuilder</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
     * @throws NoSuchAlgorithmException if a CertPathBuilderSpi
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
     * @throws 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 CertPathBuilder getInstance(String algorithm, String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
           throws NoSuchAlgorithmException, NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        Instance instance = GetInstance.getInstance("CertPathBuilder",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            CertPathBuilderSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return new CertPathBuilder((CertPathBuilderSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Returns a <code>CertPathBuilder</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <p> A new CertPathBuilder object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * CertPathBuilderSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param algorithm the name of the requested <code>CertPathBuilder</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *  algorithm.  See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *  "../../../../technotes/guides/security/certpath/CertPathProgGuide.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *  Java Certification Path API Programmer's Guide </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *  for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return a <code>CertPathBuilder</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @exception NoSuchAlgorithmException if a CertPathBuilderSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @exception IllegalArgumentException if the <code>provider</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *          null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public static CertPathBuilder getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        Instance instance = GetInstance.getInstance("CertPathBuilder",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            CertPathBuilderSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return new CertPathBuilder((CertPathBuilderSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * Returns the provider of this <code>CertPathBuilder</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @return the provider of this <code>CertPathBuilder</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Returns the name of the algorithm of this <code>CertPathBuilder</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @return the name of the algorithm of this <code>CertPathBuilder</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Attempts to build a certification path using the specified algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * parameter set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param params the algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @return the result of the build algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @throws CertPathBuilderException if the builder is unable to construct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *  a certification path that satisfies the specified parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @throws InvalidAlgorithmParameterException if the specified parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * are inappropriate for this <code>CertPathBuilder</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public final CertPathBuilderResult build(CertPathParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        throws CertPathBuilderException, InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return builderSpi.engineBuild(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Returns the default <code>CertPathBuilder</code> type as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * the Java security properties file, or the string &quot;PKIX&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * if no such property exists. The Java security properties file is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * located in the file named &lt;JAVA_HOME&gt;/lib/security/java.security.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * &lt;JAVA_HOME&gt; refers to the value of the java.home system property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * and specifies the directory where the JRE is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * <p>The default <code>CertPathBuilder</code> type can be used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * applications that do not want to use a hard-coded type when calling one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * of the <code>getInstance</code> methods, and want to provide a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * type in case a user does not specify its own.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <p>The default <code>CertPathBuilder</code> type can be changed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * setting the value of the "certpathbuilder.type" security property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * (in the Java security properties file) to the desired type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return the default <code>CertPathBuilder</code> type as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * in the Java security properties file, or the string &quot;PKIX&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * if no such property exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public final static String getDefaultType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        String cpbtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        cpbtype = AccessController.doPrivileged(new PrivilegedAction<String>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            public String run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                return Security.getProperty(CPB_TYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (cpbtype == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            cpbtype = "PKIX";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return cpbtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}