src/java.base/share/classes/java/security/cert/CertPathValidator.java
author jboes
Fri, 20 Sep 2019 11:07:52 +0100
changeset 58242 94bb65cb37d3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8230648: Replace @exception tag with @throws in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: prappo, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2019, 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;
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
    35
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.jca.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.jca.GetInstance.Instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A class for validating certification paths (also known as certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * chains).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * This class uses a provider-based architecture.
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    45
 * To create a {@code CertPathValidator},
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    46
 * call 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
    47
 * algorithm name of the {@code CertPathValidator} desired and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * optionally the name of the provider desired.
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    49
 *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    50
 * <p>Once a {@code CertPathValidator} object has been created, it can
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * be used to validate certification paths by calling the {@link #validate
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    52
 * validate} method and passing it the {@code CertPath} to be validated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * and an algorithm-specific set of parameters. If successful, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * returned in an object that implements the
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    55
 * {@code CertPathValidatorResult} interface.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    56
 *
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    57
 * <p>The {@link #getRevocationChecker} method allows an application to specify
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    58
 * additional algorithm-specific parameters and options used by the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    59
 * {@code CertPathValidator} when checking the revocation status of
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    60
 * certificates. Here is an example demonstrating how it is used with the PKIX
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    61
 * algorithm:
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    62
 *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    63
 * <pre>
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    64
 * CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    65
 * PKIXRevocationChecker rc = (PKIXRevocationChecker)cpv.getRevocationChecker();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    66
 * rc.setOptions(EnumSet.of(Option.SOFT_FAIL));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    67
 * params.addCertPathChecker(rc);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    68
 * CertPathValidatorResult cpvr = cpv.validate(path, params);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    69
 * </pre>
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    70
 *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
    71
 * <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
    72
 * following standard {@code CertPathValidator} algorithm:
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    73
 * <ul>
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
    74
 * <li>{@code PKIX}</li>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    75
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    76
 * This algorithm is described in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
    77
 * "{@docRoot}/../specs/security/standard-names.html#certpathvalidator-algorithms">
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    78
 * CertPathValidator section</a> of the
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
    79
 * Java Security Standard Algorithm Names Specification.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    80
 * 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
    81
 * other algorithms are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    82
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <b>Concurrent Access</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * The static methods of this class are guaranteed to be thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Multiple threads may concurrently invoke the static methods defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * this class with no ill effects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * However, this is not true for the non-static methods defined by this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * 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
    92
 * access a single {@code CertPathValidator} instance concurrently should
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * 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
    94
 * threads each manipulating a different {@code CertPathValidator}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * instance need not synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @see CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * @author      Yassir Elley
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
public class CertPathValidator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Constant to lookup in the Security properties file to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * the default certpathvalidator type. In the Security properties file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * the default certpathvalidator type is given as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * certpathvalidator.type=PKIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private static final String CPV_TYPE = "certpathvalidator.type";
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   113
    private final CertPathValidatorSpi validatorSpi;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   114
    private final Provider provider;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   115
    private final String algorithm;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   118
     * Creates a {@code CertPathValidator} object of the given algorithm,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * and encapsulates the given provider implementation (SPI object) in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param validatorSpi the provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param algorithm the algorithm name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    protected CertPathValidator(CertPathValidatorSpi validatorSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        Provider provider, String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this.validatorSpi = validatorSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   134
     * Returns a {@code CertPathValidator} object that implements the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * A new CertPathValidator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * CertPathValidatorSpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32649
diff changeset
   146
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32649
diff changeset
   147
     * The JDK Reference Implementation additionally uses the
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   148
     * {@code jdk.security.provider.preferred}
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   149
     * {@link Security#getProperty(String) Security} property to determine
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32649
diff changeset
   150
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32649
diff changeset
   151
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32649
diff changeset
   152
     * {@link Security#getProviders() Security.getProviders()}.
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 32649
diff changeset
   153
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   154
     * @param algorithm the name of the requested {@code CertPathValidator}
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   155
     * algorithm. See the CertPathValidator section in the <a href=
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   156
     * "{@docRoot}/../specs/security/standard-names.html#certpathvalidator-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   157
     * Java Security Standard Algorithm Names Specification</a>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   158
     * for information about standard algorithm names.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   160
     * @return a {@code CertPathValidator} object that implements the
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   161
     *         specified algorithm
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   163
     * @throws NoSuchAlgorithmException if no {@code Provider} supports a
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   164
     *         {@code CertPathValidatorSpi} implementation for the
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   165
     *         specified algorithm
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   166
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   167
     * @throws NullPointerException if {@code algorithm} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public static CertPathValidator getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            throws NoSuchAlgorithmException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   173
        Objects.requireNonNull(algorithm, "null algorithm name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        Instance instance = GetInstance.getInstance("CertPathValidator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            CertPathValidatorSpi.class, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return new CertPathValidator((CertPathValidatorSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   181
     * Returns a {@code CertPathValidator} object that implements the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * specified algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <p> A new CertPathValidator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * CertPathValidatorSpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   192
     * @param algorithm the name of the requested {@code CertPathValidator}
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   193
     * algorithm. See the CertPathValidator section in the <a href=
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   194
     * "{@docRoot}/../specs/security/standard-names.html#certpathvalidator-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   195
     * Java Security Standard Algorithm Names Specification</a>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   196
     * for information about standard algorithm names.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   200
     * @return a {@code CertPathValidator} object that implements the
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   201
     *         specified algorithm
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   203
     * @throws IllegalArgumentException if the {@code provider} is
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   204
     *         {@code null} or empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   206
     * @throws NoSuchAlgorithmException if a {@code CertPathValidatorSpi}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   207
     *         implementation for the specified algorithm is not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   208
     *         available from the specified provider
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   210
     * @throws NoSuchProviderException if the specified provider is not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   211
     *         registered in the security provider list
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   212
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   213
     * @throws NullPointerException if {@code algorithm} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public static CertPathValidator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            String provider) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            NoSuchProviderException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   220
        Objects.requireNonNull(algorithm, "null algorithm name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        Instance instance = GetInstance.getInstance("CertPathValidator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            CertPathValidatorSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return new CertPathValidator((CertPathValidatorSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
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
     * Returns a {@code CertPathValidator} 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
     * <p> A new CertPathValidator object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * CertPathValidatorSpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   236
     * @param algorithm the name of the requested {@code CertPathValidator}
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   237
     * algorithm. See the CertPathValidator section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   238
     * "{@docRoot}/../specs/security/standard-names.html#certpathvalidator-algorithms">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   239
     * Java Security Standard Algorithm Names Specification</a>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   240
     * for information about standard algorithm names.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   244
     * @return a {@code CertPathValidator} object that implements the
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   245
     *          specified algorithm
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   246
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   247
     * @throws IllegalArgumentException if the {@code provider} is
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   248
     *         {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   250
     * @throws NoSuchAlgorithmException if a {@code CertPathValidatorSpi}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   251
     *         implementation for the specified algorithm is not available
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   252
     *         from the specified Provider object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   254
     * @throws NullPointerException if {@code algorithm} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public static CertPathValidator getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            Provider provider) throws NoSuchAlgorithmException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   260
        Objects.requireNonNull(algorithm, "null algorithm name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        Instance instance = GetInstance.getInstance("CertPathValidator",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            CertPathValidatorSpi.class, algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return new CertPathValidator((CertPathValidatorSpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   268
     * Returns the {@code Provider} of this
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   269
     * {@code CertPathValidator}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   271
     * @return the {@code Provider} of this {@code CertPathValidator}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   278
     * Returns the algorithm name of this {@code CertPathValidator}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   280
     * @return the algorithm name of this {@code CertPathValidator}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Validates the specified certification path using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * algorithm parameter set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * <p>
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   290
     * The {@code CertPath} specified must be of a type that is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * supported by the validation algorithm, otherwise an
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   292
     * {@code InvalidAlgorithmParameterException} will be thrown. For
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   293
     * example, a {@code CertPathValidator} that implements the PKIX
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   294
     * algorithm validates {@code CertPath} objects of type X.509.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   296
     * @param certPath the {@code CertPath} to be validated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @param params the algorithm parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @return the result of the validation algorithm
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   299
     * @throws    CertPathValidatorException if the {@code CertPath}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * does not validate
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   301
     * @throws    InvalidAlgorithmParameterException if the specified
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   302
     * parameters or the type of the specified {@code CertPath} are
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 14775
diff changeset
   303
     * inappropriate for this {@code CertPathValidator}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public final CertPathValidatorResult validate(CertPath certPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        CertPathParameters params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        throws CertPathValidatorException, InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return validatorSpi.engineValidate(certPath, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   313
     * Returns the default {@code CertPathValidator} type as specified by
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   314
     * the {@code certpathvalidator.type} security property, or the string
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   315
     * {@literal "PKIX"} if no such property exists.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   317
     * <p>The default {@code CertPathValidator} type can be used by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * 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
   319
     * of the {@code getInstance} methods, and want to provide a default
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * type in case a user does not specify its own.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   322
     * <p>The default {@code CertPathValidator} type can be changed by
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   323
     * setting the value of the {@code certpathvalidator.type} security
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   324
     * property to the desired type.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   326
     * @see java.security.Security security properties
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   327
     * @return the default {@code CertPathValidator} type as specified
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   328
     * by the {@code certpathvalidator.type} security property, or the string
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14402
diff changeset
   329
     * {@literal "PKIX"} if no such property exists.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 30033
diff changeset
   331
    public static final String getDefaultType() {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   332
        String cpvtype =
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
   333
            AccessController.doPrivileged(new PrivilegedAction<>() {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   334
                public String run() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   335
                    return Security.getProperty(CPV_TYPE);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   336
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   337
            });
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   338
        return (cpvtype == null) ? "PKIX" : cpvtype;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   339
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   340
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   341
    /**
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   342
     * Returns a {@code CertPathChecker} that the encapsulated
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   343
     * {@code CertPathValidatorSpi} implementation uses to check the revocation
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   344
     * status of certificates. A PKIX implementation returns objects of
14402
424f3f23f1da 7171570: JEP 124 Potential API Changes
mullan
parents: 12860
diff changeset
   345
     * type {@code PKIXRevocationChecker}. Each invocation of this method
424f3f23f1da 7171570: JEP 124 Potential API Changes
mullan
parents: 12860
diff changeset
   346
     * returns a new instance of {@code CertPathChecker}.
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   347
     *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   348
     * <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
   349
     * additional input parameters and options specific to revocation checking.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   350
     * See the class description for an example.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   351
     *
14402
424f3f23f1da 7171570: JEP 124 Potential API Changes
mullan
parents: 12860
diff changeset
   352
     * @return a {@code CertPathChecker}
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   353
     * @throws UnsupportedOperationException if the service provider does not
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   354
     *         support this method
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   355
     * @since 1.8
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   356
     */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   357
    public final CertPathChecker getRevocationChecker() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 9035
diff changeset
   358
        return validatorSpi.engineGetRevocationChecker();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
}