本文整理汇总了Java中java.security.cert.CertPathBuilder类的典型用法代码示例。如果您正苦于以下问题:Java CertPathBuilder类的具体用法?Java CertPathBuilder怎么用?Java CertPathBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CertPathBuilder类属于java.security.cert包,在下文中一共展示了CertPathBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PKIXCertificateValidationProvider
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Initializes a new instance that uses the specified JCE providers for CertPathBuilder
* and Signature.
* @param trustAnchors the keystore with the trust-anchors ({@code TrustedCertificateEntry})
* @param revocationEnabled whether revocation is enabled
* @param maxPathLength the maximum length of the certification paths
* @param certPathBuilderProvider the CertPathBuilder provider
* @param signatureProvider the Signature provider
* @param intermCertsAndCrls a set of {@code CertStore}s that contain certificates to be
* used in the construction of the certification path. May contain CRLs to be used
* if revocation is enabled
* @see xades4j.utils.FileSystemDirectoryCertStore
* @throws NoSuchAlgorithmException if there is no provider for PKIX CertPathBuilder
*/
public PKIXCertificateValidationProvider(
KeyStore trustAnchors,
boolean revocationEnabled,
int maxPathLength,
String certPathBuilderProvider,
String signatureProvider,
CertStore... intermCertsAndCrls) throws NoSuchAlgorithmException, NoSuchProviderException
{
if (null == trustAnchors)
{
throw new NullPointerException("Trust anchors cannot be null");
}
this.trustAnchors = trustAnchors;
this.revocationEnabled = revocationEnabled;
this.maxPathLength = maxPathLength;
this.certPathBuilder = certPathBuilderProvider == null ? CertPathBuilder.getInstance("PKIX") : CertPathBuilder.getInstance("PKIX", certPathBuilderProvider);
this.signatureProvider = signatureProvider;
this.intermCertsAndCrls = intermCertsAndCrls;
}
示例2: createCPBs
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
private static CertPathBuilder[] createCPBs() {
if (!PKIXSupport) {
fail(NotSupportMsg);
return null;
}
try {
CertPathBuilder[] certPBs = new CertPathBuilder[3];
certPBs[0] = CertPathBuilder.getInstance(defaultType);
certPBs[1] = CertPathBuilder.getInstance(defaultType,
defaultProviderName);
certPBs[2] = CertPathBuilder.getInstance(defaultType,
defaultProvider);
return certPBs;
} catch (Exception e) {
return null;
}
}
示例3: testCertPathBuilder03
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>getInstance(String algorithm)</code> method
* Assertion: returns CertPathBuilder object
*/
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies positive functionality.",
method = "getInstance",
args = {java.lang.String.class}
)
public void testCertPathBuilder03() throws NoSuchAlgorithmException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
for (int i = 0; i < validValues.length; i++) {
CertPathBuilder cpb = CertPathBuilder.getInstance(validValues[i]);
assertEquals("Incorrect algorithm", cpb.getAlgorithm(), validValues[i]);
}
}
示例4: testCertPathBuilder05
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>getInstance(String algorithm, String provider)</code> method
* Assertion:
* throws NoSuchProviderException when provider has invalid value
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies that getInstance throws NoSuchProviderException when provider has invalid value.",
method = "getInstance",
args = {java.lang.String.class, java.lang.String.class}
)
public void testCertPathBuilder05()
throws NoSuchAlgorithmException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
for (int i = 0; i < validValues.length; i++ ) {
for (int j = 1; j < invalidValues.length; j++) {
try {
CertPathBuilder.getInstance(validValues[i], invalidValues[j]);
fail("NoSuchProviderException must be hrown");
} catch (NoSuchProviderException e1) {
}
}
}
}
示例5: testCertPathBuilder06
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>getInstance(String algorithm, String provider)</code> method
* Assertion:
* throws NullPointerException when algorithm is null
* throws NoSuchAlgorithmException when algorithm is not correct
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies NullPointerException when algorithm is null; verifies NoSuchAlgorithmException when algorithm is not correct.",
method = "getInstance",
args = {java.lang.String.class, java.lang.String.class}
)
public void testCertPathBuilder06()
throws NoSuchAlgorithmException, NoSuchProviderException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
try {
CertPathBuilder.getInstance(null, defaultProviderName);
fail("No expected NullPointerException");
} catch (NullPointerException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
CertPathBuilder.getInstance(invalidValues[i], defaultProviderName);
fail("NoSuchAlgorithmException must be thrown");
} catch (NoSuchAlgorithmException e1) {
}
}
}
示例6: testCertPathBuilder07
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>getInstance(String algorithm, String provider)</code> method
* Assertion: returns CertPathBuilder object
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies positive case.",
method = "getInstance",
args = {java.lang.String.class, java.lang.String.class}
)
public void testCertPathBuilder07()
throws NoSuchAlgorithmException, NoSuchProviderException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
CertPathBuilder certPB;
for (int i = 0; i < validValues.length; i++) {
certPB = CertPathBuilder.getInstance(validValues[i], defaultProviderName);
assertEquals("Incorrect algorithm", certPB.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider name", certPB.getProvider().getName(), defaultProviderName);
}
}
示例7: testCertPathBuilder08
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>getInstance(String algorithm, Provider provider)</code> method
* Assertion: throws IllegalArgumentException when provider is null
*/
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies that getInstance method throws IllegalArgumentException when provider is null method.",
method = "getInstance",
args = {java.lang.String.class, java.security.Provider.class}
)
public void testCertPathBuilder08()
throws NoSuchAlgorithmException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
Provider prov = null;
for (int t = 0; t < validValues.length; t++ ) {
try {
CertPathBuilder.getInstance(validValues[t], prov);
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e1) {
}
}
}
示例8: testCertPathBuilder09
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>getInstance(String algorithm, String provider)</code> method
* Assertion:
* throws NullPointerException when algorithm is null
* throws NoSuchAlgorithmException when algorithm is not correct
*/
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies that getInstance method throws NullPointerException when algorithm is null, throws NoSuchAlgorithmException when algorithm is not correct.",
method = "getInstance",
args = {java.lang.String.class, java.security.Provider.class}
)
public void testCertPathBuilder09()
throws NoSuchAlgorithmException, NoSuchProviderException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
try {
CertPathBuilder.getInstance(null, defaultProvider);
fail("No expected NullPointerException");
} catch (NullPointerException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
CertPathBuilder.getInstance(invalidValues[i], defaultProvider);
fail("NoSuchAlgorithm must be thrown");
} catch (NoSuchAlgorithmException e1) {
}
}
}
示例9: testCertPathBuilder10
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>getInstance(String algorithm, String provider)</code> method
* Assertion: returns CertPathBuilder object
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies that getInstance returns CertPathBuilder object.",
method = "getInstance",
args = {java.lang.String.class, java.lang.String.class}
)
public void testCertPathBuilder10()
throws NoSuchAlgorithmException, NoSuchProviderException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
CertPathBuilder certPB;
for (int i = 0; i < invalidValues.length; i++) {
certPB = CertPathBuilder.getInstance(validValues[i], defaultProvider);
assertEquals("Incorrect algorithm", certPB.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider name", certPB.getProvider(), defaultProvider);
}
}
示例10: testCertPathBuilder11
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>build(CertPathParameters params)</code> method
* Assertion: throws InvalidAlgorithmParameterException params is null
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies that build method throws InvalidAlgorithmParameterException if a parameter is null.",
method = "build",
args = {java.security.cert.CertPathParameters.class}
)
public void testCertPathBuilder11()
throws NoSuchAlgorithmException, NoSuchProviderException,
CertPathBuilderException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
CertPathBuilder [] certPB = createCPBs();
assertNotNull("CertPathBuilder objects were not created", certPB);
for (int i = 0; i < certPB.length; i++ ){
try {
certPB[i].build(null);
fail("InvalidAlgorithmParameterException must be thrown");
} catch(InvalidAlgorithmParameterException e) {
}
}
}
示例11: testBuild
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
@TestTargetNew(
level=TestLevel.PARTIAL_COMPLETE,
notes = "Verifies normal case",
method="build",
args={CertPathParameters.class}
)
// Test passed on RI
@KnownFailure(value="expired certificate bug 2322662")
public void testBuild() throws Exception {
TestUtils.initCertPathSSCertChain();
CertPathParameters params = TestUtils.getCertPathParameters();
CertPathBuilder builder = TestUtils.getCertPathBuilder();
try {
CertPathBuilderResult result = builder.build(params);
assertNotNull("builder result is null", result);
CertPath certPath = result.getCertPath();
assertNotNull("certpath of builder result is null", certPath);
} catch (InvalidAlgorithmParameterException e) {
fail("unexpected Exception: " + e);
}
}
示例12: checkResult
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
private void checkResult(CertPathBuilder certBuild)
throws InvalidAlgorithmParameterException,
CertPathBuilderException {
String dt = CertPathBuilder.getDefaultType();
String propName = CertPathBuilder1Test.DEFAULT_TYPE_PROPERTY;
String dtN;
for (int i = 0; i <invalidValues.length; i++) {
Security.setProperty(propName, invalidValues[i]);
dtN = CertPathBuilder.getDefaultType();
if (!dtN.equals(invalidValues[i]) && !dtN.equals(dt)) {
fail("Incorrect default type: ".concat(dtN));
}
}
Security.setProperty(propName, dt);
assertEquals("Incorrect default type", CertPathBuilder.getDefaultType(),
dt);
try {
certBuild.build(null);
fail("CertPathBuilderException must be thrown");
} catch (CertPathBuilderException e) {
}
CertPathBuilderResult cpbResult = certBuild.build(null);
assertNull("Not null CertPathBuilderResult", cpbResult);
}
示例13: testCertPathBuilder05
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>getInstance(String algorithm, String provider)</code> method
* Assertion:
* throws NoSuchProviderException when provider has invalid value
*/
public void testCertPathBuilder05()
throws NoSuchAlgorithmException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
for (int i = 0; i < validValues.length; i++ ) {
for (int j = 1; j < invalidValues.length; j++) {
try {
CertPathBuilder.getInstance(validValues[i], invalidValues[j]);
fail("NoSuchProviderException must be hrown");
} catch (NoSuchProviderException e1) {
}
}
}
}
示例14: testCertPathBuilder06
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>getInstance(String algorithm, String provider)</code> method
* Assertion:
* throws NullPointerException when algorithm is null
* throws NoSuchAlgorithmException when algorithm is not correct
*/
public void testCertPathBuilder06()
throws NoSuchAlgorithmException, NoSuchProviderException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
try {
CertPathBuilder.getInstance(null, defaultProviderName);
fail("No expected NullPointerException");
} catch (NullPointerException e) {
}
for (int i = 0; i < invalidValues.length; i++) {
try {
CertPathBuilder.getInstance(invalidValues[i], defaultProviderName);
fail("NoSuchAlgorithmException must be thrown");
} catch (NoSuchAlgorithmException e1) {
}
}
}
示例15: testCertPathBuilder08
import java.security.cert.CertPathBuilder; //导入依赖的package包/类
/**
* Test for <code>getInstance(String algorithm, Provider provider)</code> method
* Assertion: throws IllegalArgumentException when provider is null
*/
public void testCertPathBuilder08()
throws NoSuchAlgorithmException {
if (!PKIXSupport) {
fail(NotSupportMsg);
return;
}
Provider prov = null;
for (int t = 0; t < validValues.length; t++ ) {
try {
CertPathBuilder.getInstance(validValues[t], prov);
fail("IllegalArgumentException must be thrown");
} catch (IllegalArgumentException e1) {
}
}
}