use of java.security.cert.X509CertSelector in project robovm by robovm.
the class PKIXBuilderParametersTest method testToString.
/**
* Test for <code>toString()</code>
*/
public final void testToString() throws Exception {
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, null);
ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] cert = new X509Certificate[2];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
keyTest.setCertificateEntry("alias1", cert[0]);
keyTest.setCertificateEntry("alias2", cert[0]);
keyTest.setCertificateEntry("alias3", cert[1]);
PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
assertNotNull(p.toString());
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class PKIXBuilderParametersTest method testPKIXBuilderParametersKeyStoreCertSelector04.
/**
* Test #4 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code>
* constructor<br>
* Assertion: <code>NullPointerException</code> -
* if the <code>keystore</code> is <code>null</code>
*/
public final void testPKIXBuilderParametersKeyStoreCertSelector04() throws Exception {
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, null);
ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] cert = new X509Certificate[2];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
keyTest.setCertificateEntry("alias1", cert[0]);
keyTest.setCertificateEntry("alias2", cert[0]);
keyTest.setCertificateEntry("alias3", cert[1]);
try {
PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
assertEquals(3, p.getTrustAnchors().size());
assertEquals(5, p.getMaxPathLength());
} catch (Exception e) {
fail("Unexpected exception " + e.getMessage());
}
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class PKIXBuilderParametersTest method testGetMaxPathLength.
/**
* Test for <code>getMaxPathLength()</code>
*/
public final void testGetMaxPathLength() throws Exception {
KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, null);
ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate[] cert = new X509Certificate[2];
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
keyTest.setCertificateEntry("alias1", cert[0]);
keyTest.setCertificateEntry("alias2", cert[0]);
keyTest.setCertificateEntry("alias3", cert[1]);
PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
assertEquals(5, p.getMaxPathLength());
p.setMaxPathLength(10);
assertEquals(10, p.getMaxPathLength());
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_toString.
/**
* java.security.cert.X509CertSelector#toString()
*/
public void test_toString() {
X509CertSelector selector = new X509CertSelector();
assertNotNull(selector.toString());
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_setIssuerLjava_lang_String.
/**
* java.security.cert.X509CertSelector#setIssuer(java.lang.String)
*/
public void test_setIssuerLjava_lang_String() throws Exception {
String name1 = "O=First Org.";
String name2 = "O=Second Org.";
X500Principal iss1 = new X500Principal(name1);
X500Principal iss2 = new X500Principal(name2);
TestCert cert1 = new TestCert(iss1);
TestCert cert2 = new TestCert(iss2);
X509CertSelector selector = new X509CertSelector();
selector.setIssuer((String) null);
assertTrue("Any certificates should match " + "in the case of null issuer criteria.", selector.match(cert1) && selector.match(cert2));
selector.setIssuer(name1);
assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
selector.setIssuer(name2);
assertTrue("The certificate should match the selection criteria.", selector.match(cert2));
}
Aggregations