use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_setCertificateValidLjava_util_Date.
/**
* java.security.cert.X509CertSelector#setCertificateValid(java.util.Date)
*/
public void test_setCertificateValidLjava_util_Date() throws Exception {
X509CertSelector selector = new X509CertSelector();
Date date1 = new Date(100);
Date date2 = new Date(200);
TestCert cert1 = new TestCert(date1);
TestCert cert2 = new TestCert(date2);
selector.setCertificateValid(null);
assertNull(selector.getCertificateValid());
selector.setCertificateValid(date1);
assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
selector.setCertificateValid(date2);
date2.setTime(300);
assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method testMatchMaskedIpv6NameConstraint.
public void testMatchMaskedIpv6NameConstraint() throws Exception {
byte[] excluded = { 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 };
X509CertSelector certSelector = new X509CertSelector();
certSelector.addPathToName(GeneralName.iPAddress, "1::1");
byte[] directMatch = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 127 };
assertTrue(certSelector.match(newCertWithNameConstraint(directMatch, excluded)));
byte[] noMatch = { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 127 };
assertFalse(certSelector.match(newCertWithNameConstraint(noMatch, excluded)));
// TODO: test that requires mask to match
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method testMatchIpv6SubjectAlternativeName.
public void testMatchIpv6SubjectAlternativeName() throws Exception {
X509CertSelector certSelector = new X509CertSelector();
certSelector.setMatchAllSubjectAltNames(false);
certSelector.addSubjectAlternativeName(GeneralName.iPAddress, "::1");
byte[] match = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
assertTrue(certSelector.match(newCertWithSubjectAltNameIpAddress(match)));
byte[] noMatch = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 };
assertFalse(certSelector.match(newCertWithSubjectAltNameIpAddress(noMatch)));
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class CertPathBuilderTestPKIX method getCertPathParameters.
@Override
public CertPathParameters getCertPathParameters() throws Exception {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
X509Certificate selfSignedcertificate = (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(selfSignedCert.getBytes()));
keyStore.setCertificateEntry("selfSignedCert", selfSignedcertificate);
X509CertSelector targetConstraints = new X509CertSelector();
targetConstraints.setCertificate(selfSignedcertificate);
List<Certificate> certList = new ArrayList<Certificate>();
certList.add(selfSignedcertificate);
CertStoreParameters storeParams = new CollectionCertStoreParameters(certList);
CertStore certStore = CertStore.getInstance("Collection", storeParams);
PKIXBuilderParameters parameters = new PKIXBuilderParameters(keyStore, targetConstraints);
parameters.addCertStore(certStore);
parameters.setRevocationEnabled(false);
return parameters;
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class CertPathValidatorTestPKIX method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
X509Certificate selfSignedcertificate = (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(selfSignedCert.getBytes()));
keyStore.setCertificateEntry("selfSignedCert", selfSignedcertificate);
X509CertSelector targetConstraints = new X509CertSelector();
targetConstraints.setCertificate(selfSignedcertificate);
List<Certificate> certList = new ArrayList<Certificate>();
certList.add(selfSignedcertificate);
CertStoreParameters storeParams = new CollectionCertStoreParameters(certList);
CertStore certStore = CertStore.getInstance("Collection", storeParams);
PKIXBuilderParameters parameters = new PKIXBuilderParameters(keyStore, targetConstraints);
parameters.addCertStore(certStore);
parameters.setRevocationEnabled(false);
CertPathBuilder pathBuilder = CertPathBuilder.getInstance("PKIX");
CertPathBuilderResult builderResult = pathBuilder.build(parameters);
certPath = builderResult.getCertPath();
params = new PKIXParameters(keyStore);
params.setRevocationEnabled(false);
}
Aggregations