jdk/src/share/classes/java/security/cert/CertPathBuilder.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 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.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    55
 *
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    56
 * <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
    57
 * following standard <code>CertPathBuilder</code> algorithm:
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    58
 * <ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    59
 * <li><tt>PKIX</tt></li>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    60
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    61
 * This algorithm is described in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    62
 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathBuilder">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    63
 * CertPathBuilder section</a> of the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    64
 * Java Cryptography Architecture Standard Algorithm Name Documentation.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    65
 * 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
    66
 * other algorithms are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    67
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <b>Concurrent Access</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * The static methods of this class are guaranteed to be thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Multiple threads may concurrently invoke the static methods defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * this class with no ill effects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * However, this is not true for the non-static methods defined by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Unless otherwise documented by a specific provider, threads that need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * access a single <code>CertPathBuilder</code> instance concurrently should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * synchronize amongst themselves and provide the necessary locking. Multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * threads each manipulating a different <code>CertPathBuilder</code> instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * need not synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @author      Sean Mullan
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 CertPathBuilder {
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 certpathbuilder type. In the Security properties file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * the default certpathbuilder type is given as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * certpathbuilder.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 CPB_TYPE = "certpathbuilder.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 CertPathBuilderSpi builderSpi;
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>CertPathBuilder</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 builderSpi 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 CertPathBuilder(CertPathBuilderSpi builderSpi, Provider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        this.builderSpi = builderSpi;
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>CertPathBuilder</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 CertPathBuilder object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * CertPathBuilderSpi 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>CertPathBuilder</code>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   134
     *  algorithm.  See the CertPathBuilder 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#CertPathBuilder">
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>CertPathBuilder</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
     * @throws NoSuchAlgorithmException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *          CertPathBuilderSpi 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 CertPathBuilder 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("CertPathBuilder",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            CertPathBuilderSpi.class, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return new CertPathBuilder((CertPathBuilderSpi)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>CertPathBuilder</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 CertPathBuilder object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * CertPathBuilderSpi 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>CertPathBuilder</code>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   169
     *  algorithm.  See the CertPathBuilder 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#CertPathBuilder">
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>CertPathBuilder</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
     * @throws NoSuchAlgorithmException if a CertPathBuilderSpi
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
     * @throws 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 CertPathBuilder getInstance(String algorithm, String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
           throws NoSuchAlgorithmException, NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        Instance instance = GetInstance.getInstance("CertPathBuilder",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            CertPathBuilderSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return new CertPathBuilder((CertPathBuilderSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * Returns a <code>CertPathBuilder</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * <p> A new CertPathBuilder object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * CertPathBuilderSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @param algorithm the name of the requested <code>CertPathBuilder</code>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   209
     *  algorithm.  See the CertPathBuilder section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   210
     *  "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathBuilder">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   211
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   212
     * for information about standard algorithm names.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @return a <code>CertPathBuilder</code> object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @exception NoSuchAlgorithmException if a CertPathBuilderSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @exception IllegalArgumentException if the <code>provider</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *          null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public static CertPathBuilder getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        Instance instance = GetInstance.getInstance("CertPathBuilder",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            CertPathBuilderSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return new CertPathBuilder((CertPathBuilderSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Returns the provider of this <code>CertPathBuilder</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @return the provider of this <code>CertPathBuilder</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Returns the name of the algorithm of this <code>CertPathBuilder</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @return the name of the algorithm of this <code>CertPathBuilder</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Attempts to build a certification path using the specified algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * parameter set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param params the algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @return the result of the build algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @throws CertPathBuilderException if the builder is unable to construct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *  a certification path that satisfies the specified parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @throws InvalidAlgorithmParameterException if the specified parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * are inappropriate for this <code>CertPathBuilder</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public final CertPathBuilderResult build(CertPathParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        throws CertPathBuilderException, InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        return builderSpi.engineBuild(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Returns the default <code>CertPathBuilder</code> type as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * the Java security properties file, or the string &quot;PKIX&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * if no such property exists. The Java security properties file is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * located in the file named &lt;JAVA_HOME&gt;/lib/security/java.security.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * &lt;JAVA_HOME&gt; refers to the value of the java.home system property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * and specifies the directory where the JRE is installed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <p>The default <code>CertPathBuilder</code> type can be used by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * applications that do not want to use a hard-coded type when calling one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * of the <code>getInstance</code> methods, and want to provide a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * type in case a user does not specify its own.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <p>The default <code>CertPathBuilder</code> type can be changed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * setting the value of the "certpathbuilder.type" security property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * (in the Java security properties file) to the desired type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @return the default <code>CertPathBuilder</code> type as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * in the Java security properties file, or the string &quot;PKIX&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * if no such property exists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public final static String getDefaultType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        String cpbtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        cpbtype = AccessController.doPrivileged(new PrivilegedAction<String>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            public String run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                return Security.getProperty(CPB_TYPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (cpbtype == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            cpbtype = "PKIX";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return cpbtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
}