本文整理汇总了Java中java.security.cert.PKIXParameters.setDate方法的典型用法代码示例。如果您正苦于以下问题:Java PKIXParameters.setDate方法的具体用法?Java PKIXParameters.setDate怎么用?Java PKIXParameters.setDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.cert.PKIXParameters
的用法示例。
在下文中一共展示了PKIXParameters.setDate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateNoCache
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
private void validateNoCache(List<? extends X509Certificate> certs)
throws SignatureException {
try {
CertPathValidator validator = CertPathValidator.getInstance(
VALIDATOR_TYPE);
PKIXParameters params = new PKIXParameters(trustRoots);
params.addCertPathChecker(WAVE_OID_CHECKER);
params.setDate(timeSource.now());
// turn off default revocation-checking mechanism
params.setRevocationEnabled(false);
// TODO: add a way for clients to add certificate revocation checks,
// perhaps by letting them pass in PKIXCertPathCheckers. This can also be
// useful to check for Wave-specific certificate extensions.
CertificateFactory certFactory = CertificateFactory.getInstance(
CERTIFICATE_TYPE);
CertPath certPath = certFactory.generateCertPath(certs);
validator.validate(certPath, params);
} catch (GeneralSecurityException e) {
throw new SignatureException("Certificate validation failure", e);
}
}
示例2: runTest
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
private static void runTest(CertificateFactory cf,
List<X509Certificate> certList, TrustAnchor anchor)
throws Exception {
CertPath path = cf.generateCertPath(certList);
CertPathValidator validator = CertPathValidator.getInstance("PKIX");
System.out.println(anchor);
// Attach the OCSP responses to a PKIXParameters object
PKIXRevocationChecker pkrev =
(PKIXRevocationChecker)validator.getRevocationChecker();
Map<X509Certificate, byte[]> responseMap = new HashMap<>();
responseMap.put(certList.get(0), DECODER.decode(EE_OCSP_RESP));
responseMap.put(certList.get(1), DECODER.decode(INT_CA_OCSP_RESP));
pkrev.setOcspResponses(responseMap);
PKIXParameters params =
new PKIXParameters(Collections.singleton(anchor));
params.addCertPathChecker(pkrev);
params.setDate(EVAL_DATE);
validator.validate(path, params);
}
示例3: createPKIXParms
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
private PKIXParameters createPKIXParms(
Collection<X509Certificate> trustAnchorColl, Date dtDate)
throws InvalidAlgorithmParameterException {
// TODO Auto-generated method stub
Set tmpTA = new HashSet();
Iterator<X509Certificate> itLast = trustAnchorColl.iterator();
while (itLast.hasNext()) {
X509Certificate certOnPath = itLast.next();
TrustAnchor trustAnchor = new TrustAnchor(certOnPath, null);
tmpTA.add(trustAnchor);
}
PKIXParameters params = new PKIXParameters(tmpTA);
params.setDate(dtDate);
return params;
}
示例4: testGetDate01
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
/**
* Test #1 for <code>getDate()</code> method<br>
* Assertion: the <code>Date</code>, or <code>null</code> if not set
* @throws InvalidAlgorithmParameterException
*/
public final void testGetDate01() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
PKIXParameters p = new PKIXParameters(taSet);
// the Date has not been set
// the method must return null
assertNull("null", p.getDate());
Date currentDate = new Date();
p.setDate(currentDate);
// the Date returned must match
assertEquals("notNull", currentDate, p.getDate());
}
示例5: testGetDate02
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
/**
* Test #2 for <code>getDate()</code> method<br>
* Assertion: <code>Date</code> returned is copied to protect
* against subsequent modifications
* @throws InvalidAlgorithmParameterException
*/
public final void testGetDate02() throws Exception {
Set taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName() + ": not performed (could not create test TrustAnchor set)");
}
PKIXParameters p = new PKIXParameters(taSet);
Date currentDate = new Date();
p.setDate((Date)currentDate.clone());
Date ret1 = p.getDate();
// modify Date returned
ret1.setTime(0L);
// check that internal Date has not been
// changed by the above modification
assertEquals(currentDate, p.getDate());
}
示例6: main
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// enable CRLDP and AIA extensions
System.setProperty("com.sun.security.enableCRLDP", "true");
System.setProperty("com.sun.security.enableAIAcaIssuers", "true");
// register a local name service
String hostsFileName = System.getProperty("test.src", ".") + "/ExtensionsWithLDAPHosts";
System.setProperty("jdk.net.hosts.file", hostsFileName);
X509Certificate trustedCert = loadCertificate(CA_CERT);
X509Certificate eeCert = loadCertificate(EE_CERT);
Set<TrustAnchor> trustedCertsSet = new HashSet<>();
trustedCertsSet.add(new TrustAnchor(trustedCert, null));
CertPath cp = (CertPath) CertificateFactory.getInstance("X509")
.generateCertPath(Arrays.asList(eeCert));
PKIXParameters params = new PKIXParameters(trustedCertsSet);
params.setDate(validationDate);
// certpath validator should try to parse CRLDP and AIA extensions,
// and load CRLs/certs which they point to
// if a local name service catched requests for resolving host names
// which extensions contain, then it means that certpath validator
// tried to load CRLs/certs which they point to
try {
CertPathValidator.getInstance("PKIX").validate(cp, params);
throw new RuntimeException("CertPathValidatorException not thrown");
} catch (CertPathValidatorException cpve) {
System.out.println("Expected exception: " + cpve);
}
// check if it tried to resolve a host name from CRLDP extension
if (!LocalNameService.requestedHosts.contains(LDAP_HOST_CRLDP)) {
throw new RuntimeException(
"A hostname from CRLDP extension not requested");
}
// check if it tried to resolve a host name from AIA extension
if (!LocalNameService.requestedHosts.contains(LDAP_HOST_AIA)) {
throw new RuntimeException(
"A hostname from AIA extension not requested");
}
System.out.println("Test passed");
}
示例7: testClone
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
/**
* Test for <code>clone()</code> method<br>
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
method = "clone",
args = {}
)
public final void testClone() throws InvalidAlgorithmParameterException {
Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet();
if (taSet == null) {
fail(getName()
+ ": not performed (could not create test TrustAnchor set)");
}
PKIXParameters cpp = new PKIXParameters(taSet);
PKIXParameters cppc = (PKIXParameters) cpp.clone();
assertEquals(cpp.getPolicyQualifiersRejected(), cppc
.getPolicyQualifiersRejected());
assertEquals(cpp.getCertPathCheckers(), cppc.getCertPathCheckers());
assertEquals(cpp.getCertStores(), cppc.getCertStores());
assertEquals(cpp.getDate(), cppc.getDate());
assertEquals(cpp.getInitialPolicies(), cppc.getInitialPolicies());
assertEquals(cpp.getSigProvider(), cppc.getSigProvider());
assertEquals(cpp.getTargetCertConstraints(), cppc
.getTargetCertConstraints());
assertEquals(cpp.getTrustAnchors(), cppc.getTrustAnchors());
assertEquals(cpp.isAnyPolicyInhibited(), cppc.isAnyPolicyInhibited());
assertEquals(cpp.isExplicitPolicyRequired(), cppc
.isExplicitPolicyRequired());
assertEquals(cpp.isPolicyMappingInhibited(), cppc
.isPolicyMappingInhibited());
assertEquals(cpp.isRevocationEnabled(), cppc.isRevocationEnabled());
cpp.setDate(Calendar.getInstance().getTime());
cpp.setPolicyQualifiersRejected(!cppc.getPolicyQualifiersRejected());
assertFalse(cpp.getDate().equals(cppc.getDate()));
assertFalse(cpp.getPolicyQualifiersRejected() == cppc
.getPolicyQualifiersRejected());
cppc.setExplicitPolicyRequired(!cpp.isExplicitPolicyRequired());
cppc.setRevocationEnabled(!cpp.isRevocationEnabled());
assertFalse(cpp.isExplicitPolicyRequired() == cppc
.isExplicitPolicyRequired());
assertFalse(cpp.isRevocationEnabled() == cppc.isRevocationEnabled());
PKIXParameters cpp1 = null;
try {
cpp1.clone();
} catch (NullPointerException e) {
// expected
}
}
示例8: 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());
}
示例9: doTest
import java.security.cert.PKIXParameters; //导入方法依赖的package包/类
private PKIXCertPathValidatorResult doTest(
String trustAnchor,
String[] certs,
String[] crls,
Set policies)
throws Exception
{
Set trustedSet = Collections.singleton(getTrustAnchor(trustAnchor));
List certsAndCrls = new ArrayList();
X509Certificate endCert = loadCert(certs[certs.length - 1]);
for (int i = 0; i != certs.length - 1; i++)
{
certsAndCrls.add(loadCert(certs[i]));
}
certsAndCrls.add(endCert);
CertPath certPath = CertificateFactory.getInstance("X.509","BC").generateCertPath(certsAndCrls);
for (int i = 0; i != crls.length; i++)
{
certsAndCrls.add(loadCrl(crls[i]));
}
CertStore store = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certsAndCrls), "BC");
CertPathValidator validator = CertPathValidator.getInstance("PKIX","BC");
PKIXParameters params = new PKIXParameters(trustedSet);
params.addCertStore(store);
params.setRevocationEnabled(true);
params.setDate(new GregorianCalendar(2010, 1, 1).getTime());
if (policies != null)
{
params.setExplicitPolicyRequired(true);
params.setInitialPolicies(policies);
}
return (PKIXCertPathValidatorResult)validator.validate(certPath, params);
}