use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_getExtendedKeyUsage.
/**
* java.security.cert.X509CertSelector#getExtendedKeyUsage()
*/
public void test_getExtendedKeyUsage() throws Exception {
HashSet<String> ku = new HashSet<String>(Arrays.asList(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" }));
X509CertSelector selector = new X509CertSelector();
assertNull("Selector should return null", selector.getExtendedKeyUsage());
selector.setExtendedKeyUsage(ku);
assertTrue("The returned extendedKeyUsage should be equal to specified", ku.equals(selector.getExtendedKeyUsage()));
try {
selector.getExtendedKeyUsage().add("KRIBLEGRABLI");
fail("The returned Set should be immutable.");
} catch (UnsupportedOperationException expected) {
}
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_setBasicConstraintsLint.
/**
* java.security.cert.X509CertSelector#setBasicConstraints(int)
*/
public void test_setBasicConstraintsLint() {
X509CertSelector selector = new X509CertSelector();
int[] invalidValues = { -3, -4, -5, 1000000000 };
for (int i = 0; i < invalidValues.length; i++) {
try {
selector.setBasicConstraints(-3);
} catch (IllegalArgumentException expected) {
}
}
int[] validValues = { -2, -1, 0, 1, 2, 3, 10, 20 };
for (int i = 0; i < validValues.length; i++) {
selector.setBasicConstraints(validValues[i]);
assertEquals(validValues[i], selector.getBasicConstraints());
}
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_setSubjectLB$.
/**
* java.security.cert.X509CertSelector#setSubject(byte[])
*/
public void test_setSubjectLB$() 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 sub1 = new X500Principal(name1);
X500Principal sub2 = new X500Principal(name2);
TestCert cert1 = new TestCert(sub1);
TestCert cert2 = new TestCert(sub2);
X509CertSelector selector = new X509CertSelector();
selector.setSubject((byte[]) null);
assertTrue("Any certificates should match " + "in the case of null issuer criteria.", selector.match(cert1) && selector.match(cert2));
selector.setSubject(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.setSubject(name2);
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_getKeyUsage.
/**
* java.security.cert.X509CertSelector#getKeyUsage()
*/
public void test_getKeyUsage() {
boolean[] ku = new boolean[] { true, false, true, false, true, false, true, false, true };
X509CertSelector selector = new X509CertSelector();
assertNull("Selector should return null", selector.getKeyUsage());
selector.setKeyUsage(ku);
assertTrue("The returned date should be equal to specified", Arrays.equals(ku, selector.getKeyUsage()));
boolean[] result = selector.getKeyUsage();
result[0] = !result[0];
assertTrue("The returned keyUsage should be equal to specified", Arrays.equals(ku, selector.getKeyUsage()));
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_setNameConstraintsLB$.
/**
* java.security.cert.X509CertSelector#setNameConstraints(byte[]
* bytes)
*/
public void test_setNameConstraintsLB$() throws IOException {
// GeneralName[] name_constraints = new GeneralName[] {
// new GeneralName(1, "822.Name"),
// new GeneralName(1, "rfc@822.Name"),
// new GeneralName(2, "Name.org"),
// new GeneralName(2, "dNS.Name.org"),
//
// new GeneralName(6, "http://Resource.Id"),
// new GeneralName(6, "http://uniform.Resource.Id"),
// new GeneralName(7, "1.1.1.1"),
//
// new GeneralName(new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
// 1, 1, 1, 1, 1 }), };
//
// for (int i = 0; i < name_constraints.length; i++) {
// GeneralSubtree subtree = new GeneralSubtree(name_constraints[i]);
// GeneralSubtrees subtrees = new GeneralSubtrees();
// subtrees.addSubtree(subtree);
// NameConstraints constraints = new NameConstraints(subtrees,
// subtrees);
// }
X509CertSelector selector = new X509CertSelector();
for (int i = 0; i < constraintBytes.length; i++) {
selector.setNameConstraints(constraintBytes[i]);
assertTrue(Arrays.equals(constraintBytes[i], selector.getNameConstraints()));
}
}
Aggregations