本文整理匯總了Java中java.security.cert.PKIXParameters.setTargetCertConstraints方法的典型用法代碼示例。如果您正苦於以下問題:Java PKIXParameters.setTargetCertConstraints方法的具體用法?Java PKIXParameters.setTargetCertConstraints怎麽用?Java PKIXParameters.setTargetCertConstraints使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.security.cert.PKIXParameters
的用法示例。
在下文中一共展示了PKIXParameters.setTargetCertConstraints方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createPath
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
public static void createPath(String[] certs) throws Exception {
TrustAnchor anchor = new TrustAnchor(getCertFromFile(certs[0]), null);
List list = new ArrayList();
for (int i = 1; i < certs.length; i++) {
list.add(0, getCertFromFile(certs[i]));
}
CertificateFactory cf = CertificateFactory.getInstance("X509");
path = cf.generateCertPath(list);
Set anchors = Collections.singleton(anchor);
params = new PKIXParameters(anchors);
params.setRevocationEnabled(false);
X509CertSelector sel = new X509CertSelector();
sel.setSerialNumber(new BigInteger("1427"));
params.setTargetCertConstraints(sel);
}
示例2: testGetTargetCertConstraints02
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
/**
* Test #2 for <code>getTargetCertConstraints()</code> method<br>
* Assertion: note that the <code>CertSelector</code> returned
* is cloned to protect against subsequent modifications
* @throws InvalidAlgorithmParameterException
* @throws IOException
*/
public final void testGetTargetCertConstraints02() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
X509CertSelector x509cs = new X509CertSelector();
PKIXParameters p = new PKIXParameters(taSet);
p.setTargetCertConstraints(x509cs);
// get cert selector
X509CertSelector cs1 = (X509CertSelector)p.getTargetCertConstraints();
// modify returned selector
cs1.setIssuer(testIssuer);
// get cert selector again
X509CertSelector cs2 = (X509CertSelector)p.getTargetCertConstraints();
// check that selector is not the same
assertNotSame("notTheSame", cs1, cs2);
// check that selector's internal state has
// not been changed by above modification
assertFalse("stateNotChanged", testIssuer.equals(cs2.getIssuerAsString()));
}
示例3: testSetTargetCertConstraints01
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
/**
* Test for <code>setTargetCertConstraints(CertSelector)</code> method<br>
* Assertion: sets the required constraints on the target certificate.
* The constraints are specified as an instance of CertSelector<br>
* Assertion: ... If <code>null</code>, no constraints are defined
* @throws IOException
* @throws InvalidAlgorithmParameterException
*/
public final void testSetTargetCertConstraints01() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
X509CertSelector x509cs = new X509CertSelector();
x509cs.setIssuer(testIssuer);
PKIXParameters p = new PKIXParameters(taSet);
p.setTargetCertConstraints(x509cs);
assertEquals("set",
testIssuer,
((X509CertSelector)p.getTargetCertConstraints()).getIssuerAsString());
p.setTargetCertConstraints(null);
assertNull("unset", p.getTargetCertConstraints());
}
示例4: testSetTargetCertConstraints02
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
/**
* Test #2 for <code>setTargetCertConstraints(CertSelector)</code> method<br>
* Assertion: ... the CertSelector specified is cloned to protect against
* subsequent modifications
* @throws IOException
* @throws InvalidAlgorithmParameterException
*/
public final void testSetTargetCertConstraints02() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
X509CertSelector x509cs = new X509CertSelector();
PKIXParameters p = new PKIXParameters(taSet);
p.setTargetCertConstraints(x509cs);
// modify selector
x509cs.setIssuer(testIssuer);
// get selector
X509CertSelector x509cs1 = (X509CertSelector)p.getTargetCertConstraints();
// check that selector's internal state has
// not been changed by above modification
assertFalse(testIssuer.equals(x509cs1.getIssuerAsString()));
}
示例5: testClone01
import java.security.cert.PKIXParameters; //導入方法依賴的package包/類
/**
* Test #1 for <code>clone()</code> method<br>
* Assertion: Makes a copy of this <code>PKIXParameters</code> object
* @throws KeyStoreException
* @throws InvalidAlgorithmParameterException
* @throws NoSuchAlgorithmException
*/
public final void testClone01() throws Exception {
KeyStore ks = TestUtils.getKeyStore(true, TestUtils.TRUSTED);
if (ks == null) {
fail(getName() + ": not performed (could not create test KeyStore)");
}
PKIXParameters p1 = new PKIXParameters(ks);
// set to some non-default values
p1.setPolicyQualifiersRejected(false);
p1.setAnyPolicyInhibited(true);
p1.setExplicitPolicyRequired(true);
p1.setPolicyMappingInhibited(true);
p1.setRevocationEnabled(false);
String sigProviderName = "Some Provider";
p1.setSigProvider(sigProviderName);
X509CertSelector x509cs = new X509CertSelector();
p1.setTargetCertConstraints(x509cs);
p1.setCertStores(TestUtils.getCollectionCertStoresList());
PKIXCertPathChecker cpc = TestUtils.getTestCertPathChecker();
List l = new ArrayList();
assertTrue("addedOk", l.add(cpc));
p1.setCertPathCheckers(l);
p1.setDate(new Date(555L));
Set s = new HashSet();
s.add("1.2.3.4.5.6.7");
s.add("1.2.3.4.5.6.8");
p1.setInitialPolicies(s);
// TrustAnchors already set
PKIXParameters p2 = (PKIXParameters)p1.clone();
// check that objects match
assertEquals("check1", p1.getPolicyQualifiersRejected(),
p2.getPolicyQualifiersRejected());
assertEquals("check2", p1.isAnyPolicyInhibited(),
p2.isAnyPolicyInhibited());
assertEquals("check3", p1.isExplicitPolicyRequired(),
p2.isExplicitPolicyRequired());
assertEquals("check4", p1.isPolicyMappingInhibited(),
p2.isPolicyMappingInhibited());
assertEquals("check5", p1.isRevocationEnabled(),
p2.isRevocationEnabled());
assertEquals("check6", p1.getSigProvider(), p2.getSigProvider());
// just check that not null
assertNotNull("check7", p2.getTargetCertConstraints());
assertEquals("check8", p1.getCertStores(), p2.getCertStores());
// just check that not empty
assertFalse("check9", p2.getCertPathCheckers().isEmpty());
assertEquals("check10", p1.getDate(), p2.getDate());
assertEquals("check11", p1.getInitialPolicies(),
p2.getInitialPolicies());
assertEquals("check12", p1.getTrustAnchors(), p2.getTrustAnchors());
}