use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method testMatchIpv4SubjectAlternativeName.
public void testMatchIpv4SubjectAlternativeName() throws Exception {
X509CertSelector certSelector = new X509CertSelector();
certSelector.addSubjectAlternativeName(GeneralName.iPAddress, "127.0.0.1");
byte[] match = { 127, 0, 0, 1 };
assertTrue(certSelector.match(newCertWithSubjectAltNameIpAddress(match)));
byte[] noMatch = { 127, 0, 0, 2 };
assertFalse(certSelector.match(newCertWithSubjectAltNameIpAddress(noMatch)));
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method testMatchIpv4MappedSubjectAlternativeName.
public void testMatchIpv4MappedSubjectAlternativeName() throws Exception {
X509CertSelector certSelector = new X509CertSelector();
certSelector.addSubjectAlternativeName(GeneralName.iPAddress, "::ffff:127.0.0.1");
byte[] match = { 127, 0, 0, 1 };
assertTrue(certSelector.match(newCertWithSubjectAltNameIpAddress(match)));
byte[] noMatch = { 127, 0, 0, 2 };
assertFalse(certSelector.match(newCertWithSubjectAltNameIpAddress(noMatch)));
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method testMatchMalformedSubjectAlternativeName.
public void testMatchMalformedSubjectAlternativeName() throws Exception {
X509CertSelector certSelector = new X509CertSelector();
try {
certSelector.addSubjectAlternativeName(GeneralName.iPAddress, "1::x");
fail();
} catch (IOException expected) {
}
try {
certSelector.addSubjectAlternativeName(GeneralName.iPAddress, "127.0.0.x");
fail();
} catch (IOException expected) {
}
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class PKIXBuilderParametersTest method testPKIXBuilderParametersKeyStoreCertSelector01.
/**
* Test #1 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code>
* constructor<br>
* Assertion: <code>NullPointerException</code> - if the
* <code>keystore</code> is <code>null</code>
*/
public final void testPKIXBuilderParametersKeyStoreCertSelector01() throws Exception {
try {
new PKIXBuilderParameters((KeyStore) null, new X509CertSelector());
fail("NullPointerException expected");
} catch (NullPointerException e) {
// expected
}
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class PKIXBuilderParametersTest method testSetMaxPathLength.
/**
* Test for <code>setMaxPathLength()</code>
*/
public final void testSetMaxPathLength() 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());
p.setMaxPathLength(0);
assertEquals(0, p.getMaxPathLength());
p.setMaxPathLength(-1);
assertEquals(-1, p.getMaxPathLength());
int[] maxPathLength = { -2, -10, Integer.MIN_VALUE };
for (int i = 0; i < maxPathLength.length; i++) {
try {
p.setMaxPathLength(maxPathLength[i]);
fail("InvalidParameterException expected ");
} catch (InvalidParameterException e) {
// expected
}
}
}
Aggregations