- java.lang.Object
-
- java.security.cert.CertPathValidator
-
public class CertPathValidator extends Object
用于验证认证路径(也称为证书链)的类。这个类使用基于提供者的架构。 要创建一个
CertPathValidator,调用静态一个getInstance方法,传递的算法名称CertPathValidator所需和可选要求的供应商的名称。一旦创建了一个
CertPathValidator对象,它可以用于通过调用validate方法来验证认证路径,并将其CertPath给要验证的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);Java平台的每个实现都需要支持以下标准的
CertPathValidator算法:-
PKIX
并发访问
该类的静态方法保证线程安全。 多个线程可以同时调用此类中定义的静态方法,而不会产生不良影响。
但是,对于此类定义的非静态方法,这不是真的。 除非特定提供者另有说明,否则需要同时访问单个
CertPathValidator实例的线程应在CertPathValidator同步并提供必要的锁定。 多个线程每个操作不同的CertPathValidator实例不需要同步。- 从以下版本开始:
- 1.4
- 另请参见:
-
CertPath
-
-
-
构造方法摘要
构造方法 Modifier Constructor 描述 protectedCertPathValidator(CertPathValidatorSpi validatorSpi, Provider provider, String algorithm)创建给定算法的CertPathValidator对象,并将给定的提供者实现(SPI对象)封装在其中。
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 StringgetAlgorithm()返回此CertPathValidator的算法名称。static StringgetDefaultType()返回由certpathvalidator.type安全属性指定的默认CertPathValidator类型,如果不存在此属性,则返回字符串“PKIX”。static CertPathValidatorgetInstance(String algorithm)返回实现指定算法的CertPathValidator对象。static CertPathValidatorgetInstance(String algorithm, String provider)返回实现指定算法的CertPathValidator对象。static CertPathValidatorgetInstance(String algorithm, Provider provider)返回实现指定算法的CertPathValidator对象。ProvidergetProvider()返回Provider的CertPathValidator。CertPathCheckergetRevocationChecker()返回CertPathChecker封装的CertPathValidatorSpi实现用于检查证书的撤销状态。CertPathValidatorResultvalidate(CertPath certPath, CertPathParameters params)使用指定的算法参数集验证指定的认证路径。
-
-
-
构造方法详细信息
-
CertPathValidator
protected CertPathValidator(CertPathValidatorSpi validatorSpi, Provider provider, String algorithm)
创建给定算法的CertPathValidator对象,并将给定的提供者实现(SPI对象)封装在其中。- 参数
-
validatorSpi- 提供商实现 -
provider- 提供商 -
algorithm- 算法名称
-
-
方法详细信息
-
getInstance
public static CertPathValidator getInstance(String algorithm) throws NoSuchAlgorithmException
返回实现指定算法的CertPathValidator对象。此方法遍历已注册的安全提供程序列表,从最优选的提供程序开始。 返回从支持指定算法的第一个Provider中封装CertPathValidatorSpi实现的新CertPathValidator对象。
请注意,可以通过
Security.getProviders()方法检索已注册提供商的列表。- Implementation Note:
-
JDK参考实现另外使用
jdk.security.provider.preferredSecurity属性来确定指定算法的首选提供者顺序。 这可能与由Security.getProviders()返回的提供商的顺序不同。 - 参数
-
algorithm- 请求的名称CertPathValidator算法。 有关标准算法名称的信息,请参阅Java Security Standard Algorithm Names Specification中的CertPathValidator部分。 - 结果
-
一个实现指定算法的
CertPathValidator对象 - 异常
-
NoSuchAlgorithmException- 如果没有Provider支持指定算法的CertPathValidatorSpi实现 -
NullPointerException- 如果algorithm是null - 另请参见:
-
Provider
-
getInstance
public static CertPathValidator getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
返回实现指定算法的CertPathValidator对象。返回从指定提供程序封装CertPathValidatorSpi实现的新CertPathValidator对象。 指定的提供者必须在安全提供程序列表中注册。
请注意,注册提供商的列表可以通过
Security.getProviders()方法检索。- 参数
-
algorithm- 请求的名称CertPathValidator算法。 有关标准算法名称的信息,请参阅Java Security Standard Algorithm Names Specification中的CertPathValidator部分。 -
provider- 提供商的名称。 - 结果
-
一个实现指定算法的
CertPathValidator对象 - 异常
-
IllegalArgumentException- 如果provider是null或空 -
NoSuchAlgorithmException- 如果指定算法的CertPathValidatorSpi实现不能从指定的提供者获得 -
NoSuchProviderException- 如果指定的提供程序未在安全提供程序列表中注册 -
NullPointerException- 如果algorithm是null - 另请参见:
-
Provider
-
getInstance
public static CertPathValidator getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
返回实现指定算法的CertPathValidator对象。返回从指定的Provider对象封装CertPathValidatorSpi实现的新CertPathValidator对象。 请注意,指定的Provider对象不必在提供者列表中注册。
- 参数
-
algorithm- 请求的名称CertPathValidator算法。 有关标准算法名称的信息,请参阅Java Security Standard Algorithm Names Specification中的CertPathValidator部分。 -
provider- 提供商。 - 结果
-
一个实现指定算法的
CertPathValidator对象 - 异常
-
IllegalArgumentException- 如果provider是null -
NoSuchAlgorithmException- 如果指定的算法的一个CertPathValidatorSpi实现从指定的Provider对象不可用 -
NullPointerException- 如果algorithm是null - 另请参见:
-
Provider
-
getProvider
public final Provider getProvider()
返回此Provider的CertPathValidator。- 结果
-
这个
Provider的CertPathValidator
-
getAlgorithm
public final String getAlgorithm()
返回此CertPathValidator的算法名称。- 结果
-
该算法名称为
CertPathValidator
-
validate
public final CertPathValidatorResult validate(CertPath certPath, CertPathParameters params) throws CertPathValidatorException, InvalidAlgorithmParameterException
使用指定的算法参数集验证指定的认证路径。指定的
CertPath必须是验证算法支持的类型,否则将抛出InvalidAlgorithmParameterException。 例如,CertPathValidator实现该算法PKIX验证CertPath类型X.509的对象。- 参数
-
certPath- 要验证的CertPath -
params- 算法参数 - 结果
- 验证算法的结果
- 异常
-
CertPathValidatorException- 如果CertPath没有验证 -
InvalidAlgorithmParameterException- 如果指定的参数或指定的类型CertPath不适合此CertPathValidator
-
getDefaultType
public static final String getDefaultType()
返回由certpathvalidator.type安全属性指定的默认CertPathValidator类型,如果不存在此属性,则返回字符串“PKIX”。默认的
CertPathValidator类型可以由不想使用硬编码类型的应用程序使用,当调用getInstance方法之一时,并且希望提供默认类型,以防用户没有指定自己的类型。通过将
certpathvalidator.type安全属性的值设置为CertPathValidator类型,可以更改默认值certpathvalidator.type类型。- 结果
-
默认的
CertPathValidator类型由certpathvalidator.type指定的安全属性,或字符串“PKIX”,如果没有这样的属性存在。 - 另请参见:
-
security properties
-
getRevocationChecker
public final CertPathChecker getRevocationChecker()
返回CertPathChecker,该封装CertPathValidatorSpi实现使用检查证书的吊销状态。 PKIX实现返回PKIXRevocationChecker类型的PKIXRevocationChecker。 此方法的每次调用将返回一个新的实例CertPathChecker。此方法的主要目的是允许调用者指定额外的输入参数和特定于撤销检查的选项。 参见课程说明一个例子。
- 结果
-
一个
CertPathChecker - 异常
-
UnsupportedOperationException- 如果服务提供商不支持此方法 - 从以下版本开始:
- 1.8
-
-