public class CertPathValidator
extends Object
| java.lang.Object | |
| java.security.cert.CertPathValidator | |
用于验证认证路径的类(也称为证书链)。
这个类使用基于提供者的架构。 要创建CertPathValidator ,请调用其中一个静态getInstance方法,传递所需的CertPathValidator的算法名称以及可选的所需提供者的名称。
一旦创建了一个CertPathValidator对象,就可以通过调用validate方法并将其传递给CertPath进行验证,以及一组算法特定的参数来验证认证路径。 如果成功,结果将返回到实现CertPathValidatorResult接口的对象中。
该getRevocationChecker()方法允许应用程序指定用于由附加特定算法的参数和选项CertPathValidator检查证书的撤销状态时。 下面是一个演示PKIX算法如何使用的例子:
CertPathValidator cpv = CertPathValidator.getInstance("PKIX");
PKIXRevocationChecker rc = (PKIXRevocationChecker)cpv.getRevocationChecker();
rc.setOptions(EnumSet.of(Option.SOFT_FAIL));
params.addCertPathChecker(rc);
CertPathValidatorResult cpvr = cpv.validate(path, params);
Android提供了以下 CertPathValidator算法:
| Name | Supported (API Levels) |
|---|---|
| PKIX | 1+ |
并发访问
这个类的静态方法保证是线程安全的。 多线程可能会同时调用此类中定义的静态方法,而不会产生不良影响。
但是,对于由此类定义的非静态方法,这不是真的。 除非通过特定的供应商提供了其他凭证,需要线程访问单个CertPathValidator实例同时应该在它们之间实现同步并提供所需的锁定。 每个操作不同CertPathValidator实例的多个线程不需要同步。
也可以看看:
Protected constructors |
|
|---|---|
CertPathValidator(CertPathValidatorSpi validatorSpi, Provider provider, String algorithm) 创建给定算法的 |
|
公共方法(Public methods) |
|
|---|---|
final String |
getAlgorithm() 返回此 |
static final String |
getDefaultType() 返回 |
static CertPathValidator |
getInstance(String algorithm) 返回实现指定算法的 |
static CertPathValidator |
getInstance(String algorithm, String provider) 返回实现指定算法的 |
static CertPathValidator |
getInstance(String algorithm, Provider provider) 返回实现指定算法的 |
final Provider |
getProvider() 返回此 |
final CertPathChecker |
getRevocationChecker() 返回 |
final CertPathValidatorResult |
validate(CertPath certPath, CertPathParameters params) 使用指定的算法参数集验证指定的认证路径。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
CertPathValidator (CertPathValidatorSpi validatorSpi, Provider provider, String algorithm)
创建给定算法的 CertPathValidator对象,并封装给定的提供者实现(SPI对象)。
| 参数(Parameters) | |
|---|---|
validatorSpi |
CertPathValidatorSpi: the provider implementation |
provider |
Provider: the provider |
algorithm |
String: the algorithm name |
String getAlgorithm ()
返回此 CertPathValidator的算法名称。
| 返回(Returns) | |
|---|---|
String |
the algorithm name of this CertPathValidator |
String getDefaultType ()
返回 certpathvalidator.type安全属性指定的默认 CertPathValidator类型,如果不存在此类属性,则返回字符串“PKIX”。
当调用 getInstance方法之一时,不希望使用硬编码类型的应用程序可以使用默认的 CertPathValidator类型,并且希望在用户未指定其自己的情况下提供默认类型。
可以通过将 certpathvalidator.type安全属性的值设置为所需的类型来更改默认的 CertPathValidator类型。
| 返回(Returns) | |
|---|---|
String |
the default CertPathValidator type as specified by the certpathvalidator.type security property, or the string "PKIX" if no such property exists. |
也可以看看:
CertPathValidator getInstance (String algorithm)
返回实现指定算法的 CertPathValidator对象。
该方法遍历注册安全提供程序的列表,从最优先的提供程序开始。 返回封装来自支持指定算法的第一个Provider的CertPathValidatorSpi实现的新CertPathValidator对象。
请注意,注册供应商列表可能通过 Security.getProviders()方法检索。
| 参数(Parameters) | |
|---|---|
algorithm |
String: the name of the requested CertPathValidator algorithm. See the CertPathValidator section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard algorithm names. |
| 返回(Returns) | |
|---|---|
CertPathValidator |
a CertPathValidator object that implements the specified algorithm. |
| 抛出异常(Throws) | |
|---|---|
NoSuchAlgorithmException |
if no Provider supports a CertPathValidatorSpi implementation for the specified algorithm. |
也可以看看:
CertPathValidator getInstance (String algorithm, String provider)
返回实现指定算法的 CertPathValidator对象。
返回封装指定提供程序的CertPathValidatorSpi实现的新CertPathValidator对象。 指定的提供者必须在安全提供者列表中注册。
请注意,注册供应商列表可以通过 Security.getProviders()方法检索。
| 参数(Parameters) | |
|---|---|
algorithm |
String: the name of the requested CertPathValidator algorithm. See the CertPathValidator section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard algorithm names. |
provider |
String: the name of the provider. |
| 返回(Returns) | |
|---|---|
CertPathValidator |
a CertPathValidator object that implements the specified algorithm. |
| 抛出异常(Throws) | |
|---|---|
NoSuchAlgorithmException |
if a CertPathValidatorSpi implementation for the specified algorithm is not available from the specified provider. |
NoSuchProviderException |
if the specified provider is not registered in the security provider list. |
IllegalArgumentException |
if the provider is null or empty. |
也可以看看:
CertPathValidator getInstance (String algorithm, Provider provider)
返回实现指定算法的 CertPathValidator对象。
返回封装指定Provider对象的CertPathValidatorSpi实现的新CertPathValidator对象。 请注意,指定的Provider对象不必在提供程序列表中注册。
| 参数(Parameters) | |
|---|---|
algorithm |
String: the name of the requested CertPathValidator algorithm. See the CertPathValidator section in the Java Cryptography Architecture Standard Algorithm Name Documentation for information about standard algorithm names. |
provider |
Provider: the provider. |
| 返回(Returns) | |
|---|---|
CertPathValidator |
a CertPathValidator object that implements the specified algorithm. |
| 抛出异常(Throws) | |
|---|---|
NoSuchAlgorithmException |
if a CertPathValidatorSpi implementation for the specified algorithm is not available from the specified Provider object. |
IllegalArgumentException |
if the provider is null. |
也可以看看:
Provider getProvider ()
返回此 Provider的 CertPathValidator 。
| 返回(Returns) | |
|---|---|
Provider |
the Provider of this CertPathValidator |
CertPathChecker getRevocationChecker ()
返回CertPathChecker ,封装的CertPathValidatorSpi实现用于检查证书的撤销状态。 PKIX实现返回类型为PKIXRevocationChecker对象。 每次调用此方法都会返回一个新的实例CertPathChecker 。
此方法的主要目的是允许调用者指定特定于撤销检查的其他输入参数和选项。 查看示例的类描述。
| 返回(Returns) | |
|---|---|
CertPathChecker |
a CertPathChecker |
| 抛出异常(Throws) | |
|---|---|
UnsupportedOperationException |
if the service provider does not support this method |
CertPathValidatorResult validate (CertPath certPath, CertPathParameters params)
使用指定的算法参数集验证指定的认证路径。
指定的CertPath必须是验证算法支持的类型,否则将引发InvalidAlgorithmParameterException 。 例如,实现PKIX算法的CertPathValidator将验证CertPath X.509类型的对象。
| 参数(Parameters) | |
|---|---|
certPath |
CertPath: the CertPath to be validated |
params |
CertPathParameters: the algorithm parameters |
| 返回(Returns) | |
|---|---|
CertPathValidatorResult |
the result of the validation algorithm |
| 抛出异常(Throws) | |
|---|---|
CertPathValidatorException |
if the CertPath does not validate |
InvalidAlgorithmParameterException |
if the specified parameters or the type of the specified CertPath are inappropriate for this CertPathValidator |