use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method setupEnvironment.
private void setupEnvironment() throws Exception {
// create certificates and CRLs
CertificateFactory cf = CertificateFactory.getInstance("X.509");
ByteArrayInputStream bi = new ByteArrayInputStream(TestUtils.rootCert.getBytes());
rootCertificate = (X509Certificate) cf.generateCertificate(bi);
bi = new ByteArrayInputStream(TestUtils.endCert.getBytes());
endCertificate = (X509Certificate) cf.generateCertificate(bi);
BigInteger revokedSerialNumber = BigInteger.valueOf(1);
crl = new MyCRL("X.509");
// X509CRL rootCRL = X509CRL;
// X509CRL interCRL = X509CRLExample.createCRL(interCert,
// interPair.getPrivate(),
// revokedSerialNumber);
// create CertStore to support path building
List<Object> list = new ArrayList<Object>();
list.add(rootCertificate);
list.add(endCertificate);
// CollectionCertStoreParameters params = new CollectionCertStoreParameters(list);
// CertStore store = CertStore.getInstance("Collection", params);
//
theCertSelector = new X509CertSelector();
theCertSelector.setCertificate(endCertificate);
theCertSelector.setIssuer(endCertificate.getIssuerX500Principal().getEncoded());
// build the path
builder = CertPathBuilder.getInstance("PKIX");
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_getPathToNames.
/**
* java.security.cert.X509CertSelector#getPathToNames()
*/
public void test_getPathToNames() throws Exception {
GeneralName san0 = new GeneralName(new OtherName("1.2.3.4.5", new byte[] { 1, 2, 0, 1 }));
GeneralName san1 = new GeneralName(1, "rfc@822.Name");
GeneralName san2 = new GeneralName(2, "dNSName");
GeneralName san3 = new GeneralName(new ORAddress());
GeneralName san4 = new GeneralName(new Name("O=Organization"));
GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id");
GeneralName san7 = new GeneralName(7, "1.1.1.1");
GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555");
GeneralNames sans1 = new GeneralNames();
sans1.addName(san0);
sans1.addName(san1);
sans1.addName(san2);
sans1.addName(san3);
sans1.addName(san4);
sans1.addName(san6);
sans1.addName(san7);
sans1.addName(san8);
GeneralNames sans2 = new GeneralNames();
sans2.addName(san0);
TestCert cert1 = new TestCert(sans1);
TestCert cert2 = new TestCert(sans2);
X509CertSelector selector = new X509CertSelector();
selector.setMatchAllSubjectAltNames(true);
selector.setPathToNames(null);
assertTrue("Any certificate should match in the case of null " + "subjectAlternativeNames criteria.", selector.match(cert1) && selector.match(cert2));
Collection<List<?>> sans = sans1.getPairsList();
selector.setPathToNames(sans);
selector.getPathToNames();
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_setPolicyLjava_util_Set.
/**
* java.security.cert.X509CertSelector#setPolicy(Set<String>)
*/
public void test_setPolicyLjava_util_Set() throws IOException {
String[] policies1 = new String[] { "1.3.6.1.5.5.7.3.1", "1.3.6.1.5.5.7.3.2", "1.3.6.1.5.5.7.3.3", "1.3.6.1.5.5.7.3.4", "1.3.6.1.5.5.7.3.8", "1.3.6.1.5.5.7.3.9", "1.3.6.1.5.5.7.3.5", "1.3.6.1.5.5.7.3.6", "1.3.6.1.5.5.7.3.7" };
String[] policies2 = new String[] { "1.3.6.7.3.1" };
HashSet<String> p1 = new HashSet<String>(Arrays.asList(policies1));
HashSet<String> p2 = new HashSet<String>(Arrays.asList(policies2));
X509CertSelector selector = new X509CertSelector();
TestCert cert1 = new TestCert(policies1);
TestCert cert2 = new TestCert(policies2);
selector.setPolicy(null);
assertTrue("Any certificate should match in the case of null " + "privateKeyValid criteria.", selector.match(cert1) && selector.match(cert2));
selector.setPolicy(p1);
assertTrue("The certificate should match the selection criteria.", selector.match(cert1));
assertFalse("The certificate should not match the selection criteria.", selector.match(cert2));
selector.setPolicy(p2);
assertFalse("The certificate should not match the selection criteria.", selector.match(cert1));
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 test_addSubjectAlternativeNameLintLbyte_array.
/**
* java.security.cert.X509CertSelector#addSubjectAlternativeName(int, byte[])
*/
public void test_addSubjectAlternativeNameLintLbyte_array() throws IOException {
// Regression for HARMONY-2487
int[] types = { GeneralName.OTHER_NAME, GeneralName.RFC822_NAME, GeneralName.DNS_NAME, GeneralName.X400_ADDR, GeneralName.DIR_NAME, GeneralName.EDIP_NAME, GeneralName.UR_ID, GeneralName.IP_ADDR, GeneralName.REG_ID };
for (int i = 0; i < types.length; i++) {
try {
new X509CertSelector().addSubjectAlternativeName(types[i], (byte[]) null);
fail("No expected NullPointerException for type: " + types[i]);
} catch (NullPointerException expected) {
}
}
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_setIssuerLB$.
/**
* java.security.cert.X509CertSelector#setIssuer(byte[])
*/
public void test_setIssuerLB$() throws Exception {
byte[] name1 = new byte[] // manually obtained DER encoding of "O=First Org." issuer name;
{ 48, 21, 49, 19, 48, 17, 6, 3, 85, 4, 10, 19, 10, 70, 105, 114, 115, 116, 32, 79, 114, 103, 46 };
byte[] name2 = new byte[] // manually obtained DER encoding of "O=Second Org." issuer name;
{ 48, 22, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 83, 101, 99, 111, 110, 100, 32, 79, 114, 103, 46 };
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((byte[]) 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