jdk/src/java.base/share/classes/java/security/cert/CertPathBuilder.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 30033 b9c86c17164a
child 33241 27eb2d6abda9
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
     2
 * Copyright (c) 2000, 2013, 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.
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    44
 * To create a {@code CertPathBuilder}, call
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    45
 * one of the static {@code getInstance} methods, passing in the
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    46
 * algorithm name of the {@code CertPathBuilder} desired and optionally
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the name of the provider desired.
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    48
 *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    49
 * <p>Once a {@code CertPathBuilder} object has been created, certification
2
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
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    52
 * result (including the {@code CertPath} that was built) is returned
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    53
 * in an object that implements the {@code CertPathBuilderResult}
2
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
 *
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    56
 * <p>The {@link #getRevocationChecker} method allows an application to specify
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    57
 * additional algorithm-specific parameters and options used by the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    58
 * {@code CertPathBuilder} when checking the revocation status of certificates.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    59
 * Here is an example demonstrating how it is used with the PKIX algorithm:
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    60
 *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    61
 * <pre>
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    62
 * CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    63
 * PKIXRevocationChecker rc = (PKIXRevocationChecker)cpb.getRevocationChecker();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    64
 * rc.setOptions(EnumSet.of(Option.PREFER_CRLS));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    65
 * params.addCertPathChecker(rc);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    66
 * CertPathBuilderResult cpbr = cpb.build(params);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    67
 * </pre>
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    68
 *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    69
 * <p>Every implementation of the Java platform is required to support the
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    70
 * following standard {@code CertPathBuilder} algorithm:
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    71
 * <ul>
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    72
 * <li>{@code PKIX}</li>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    73
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    74
 * This algorithm is described in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    75
 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathBuilder">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    76
 * CertPathBuilder section</a> of the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    77
 * Java Cryptography Architecture Standard Algorithm Name Documentation.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    78
 * 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
    79
 * other algorithms are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    80
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <b>Concurrent Access</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * The static methods of this class are guaranteed to be thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Multiple threads may concurrently invoke the static methods defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * this class with no ill effects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * However, this is not true for the non-static methods defined by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * Unless otherwise documented by a specific provider, threads that need to
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    90
 * access a single {@code CertPathBuilder} instance concurrently should
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * synchronize amongst themselves and provide the necessary locking. Multiple
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    92
 * threads each manipulating a different {@code CertPathBuilder} instance
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * need not synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @see CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * @author      Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @author      Yassir Elley
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
public class CertPathBuilder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Constant to lookup in the Security properties file to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * the default certpathbuilder type. In the Security properties file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * the default certpathbuilder type is given as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * certpathbuilder.type=PKIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static final String CPB_TYPE = "certpathbuilder.type";
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   112
    private final CertPathBuilderSpi builderSpi;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   113
    private final Provider provider;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   114
    private final String algorithm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   117
     * Creates a {@code CertPathBuilder} object of the given algorithm,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * and encapsulates the given provider implementation (SPI object) in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param builderSpi the provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param algorithm the algorithm name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    protected CertPathBuilder(CertPathBuilderSpi builderSpi, Provider provider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        this.builderSpi = builderSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   133
     * Returns a {@code CertPathBuilder} object that implements the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * A new CertPathBuilder object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * CertPathBuilderSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   145
     * @param algorithm the name of the requested {@code CertPathBuilder}
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   146
     *  algorithm.  See the CertPathBuilder section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   147
     *  "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathBuilder">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   148
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   149
     * for information about standard algorithm names.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   151
     * @return a {@code CertPathBuilder} object that implements the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @throws NoSuchAlgorithmException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *          CertPathBuilderSpi implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public static CertPathBuilder getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        Instance instance = GetInstance.getInstance("CertPathBuilder",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            CertPathBuilderSpi.class, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return new CertPathBuilder((CertPathBuilderSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   169
     * Returns a {@code CertPathBuilder} object that implements the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <p> A new CertPathBuilder object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * CertPathBuilderSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   180
     * @param algorithm the name of the requested {@code CertPathBuilder}
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   181
     *  algorithm.  See the CertPathBuilder section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   182
     *  "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathBuilder">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   183
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   184
     * for information about standard algorithm names.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   188
     * @return a {@code CertPathBuilder} object that implements the
2
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
     * @throws NoSuchAlgorithmException if a CertPathBuilderSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *          implementation for the specified algorithm is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *          available from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @throws NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   198
     * @exception IllegalArgumentException if the {@code provider} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *          null or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public static CertPathBuilder getInstance(String algorithm, String provider)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
           throws NoSuchAlgorithmException, NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        Instance instance = GetInstance.getInstance("CertPathBuilder",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            CertPathBuilderSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return new CertPathBuilder((CertPathBuilderSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   212
     * Returns a {@code CertPathBuilder} object that implements the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <p> A new CertPathBuilder object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * CertPathBuilderSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   220
     * @param algorithm the name of the requested {@code CertPathBuilder}
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   221
     *  algorithm.  See the CertPathBuilder section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   222
     *  "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathBuilder">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   223
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   224
     * for information about standard algorithm names.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   228
     * @return a {@code CertPathBuilder} object that implements the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *          specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @exception NoSuchAlgorithmException if a CertPathBuilderSpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   235
     * @exception IllegalArgumentException if the {@code provider} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *          null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public static CertPathBuilder getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        Instance instance = GetInstance.getInstance("CertPathBuilder",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            CertPathBuilderSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return new CertPathBuilder((CertPathBuilderSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   249
     * Returns the provider of this {@code CertPathBuilder}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   251
     * @return the provider of this {@code CertPathBuilder}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   258
     * Returns the name of the algorithm of this {@code CertPathBuilder}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   260
     * @return the name of the algorithm of this {@code CertPathBuilder}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Attempts to build a certification path using the specified algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * parameter set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param params the algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @return the result of the build algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @throws CertPathBuilderException if the builder is unable to construct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *  a certification path that satisfies the specified parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @throws InvalidAlgorithmParameterException if the specified parameters
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   275
     * are inappropriate for this {@code CertPathBuilder}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public final CertPathBuilderResult build(CertPathParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        throws CertPathBuilderException, InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return builderSpi.engineBuild(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /**
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   284
     * Returns the default {@code CertPathBuilder} type as specified by
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   285
     * the {@code certpathbuilder.type} security property, or the string
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   286
     * {@literal "PKIX"} if no such property exists.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   288
     * <p>The default {@code CertPathBuilder} type can be used by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * applications that do not want to use a hard-coded type when calling one
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   290
     * of the {@code getInstance} methods, and want to provide a default
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * type in case a user does not specify its own.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   293
     * <p>The default {@code CertPathBuilder} type can be changed by
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   294
     * setting the value of the {@code certpathbuilder.type} security property
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   295
     * to the desired type.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   297
     * @see java.security.Security security properties
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   298
     * @return the default {@code CertPathBuilder} type as specified
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   299
     * by the {@code certpathbuilder.type} security property, or the string
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   300
     * {@literal "PKIX"} if no such property exists.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30033
diff changeset
   302
    public static final String getDefaultType() {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   303
        String cpbtype =
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   304
            AccessController.doPrivileged(new PrivilegedAction<>() {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   305
                public String run() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   306
                    return Security.getProperty(CPB_TYPE);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   307
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   308
            });
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   309
        return (cpbtype == null) ? "PKIX" : cpbtype;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   310
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   311
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   312
    /**
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   313
     * Returns a {@code CertPathChecker} that the encapsulated
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   314
     * {@code CertPathBuilderSpi} implementation uses to check the revocation
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   315
     * status of certificates. A PKIX implementation returns objects of
14402
424f3f23f1da 7171570: JEP 124 Potential API Changes
mullan
parents: 12860
diff changeset
   316
     * type {@code PKIXRevocationChecker}. Each invocation of this method
424f3f23f1da 7171570: JEP 124 Potential API Changes
mullan
parents: 12860
diff changeset
   317
     * returns a new instance of {@code CertPathChecker}.
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   318
     *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   319
     * <p>The primary purpose of this method is to allow callers to specify
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   320
     * additional input parameters and options specific to revocation checking.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   321
     * See the class description for an example.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   322
     *
14402
424f3f23f1da 7171570: JEP 124 Potential API Changes
mullan
parents: 12860
diff changeset
   323
     * @return a {@code CertPathChecker}
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   324
     * @throws UnsupportedOperationException if the service provider does not
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   325
     *         support this method
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   326
     * @since 1.8
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   327
     */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   328
    public final CertPathChecker getRevocationChecker() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   329
        return builderSpi.engineGetRevocationChecker();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
}