use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_getCertificateValid.
/**
* java.security.cert.X509CertSelector#getCertificateValid()
*/
public void test_getCertificateValid() {
Date date1 = new Date(100);
Date date2 = new Date(200);
Date date3 = Calendar.getInstance().getTime();
X509CertSelector selector = new X509CertSelector();
assertNull("Selector should return null", selector.getCertificateValid());
selector.setCertificateValid(date1);
assertTrue("The returned date should be equal to specified", date1.equals(selector.getCertificateValid()));
selector.getCertificateValid().setTime(200);
assertTrue("The returned date should be equal to specified", date1.equals(selector.getCertificateValid()));
assertFalse("The returned date should differ", date2.equals(selector.getCertificateValid()));
selector.setCertificateValid(date3);
assertTrue("The returned date should be equal to specified", date3.equals(selector.getCertificateValid()));
selector.setCertificateValid(null);
assertNull(selector.getCertificateValid());
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_getSubject.
/**
* java.security.cert.X509CertSelector#getSubject()
*/
public void test_getSubject() {
X500Principal sub1 = new X500Principal("O=First Org.");
X500Principal sub2 = new X500Principal("O=Second Org.");
X509CertSelector selector = new X509CertSelector();
assertNull("Selector should return null", selector.getSubject());
selector.setSubject(sub1);
assertEquals("The returned subject should be equal to specified", sub1, selector.getSubject());
assertFalse("The returned subject should differ", sub2.equals(selector.getSubject()));
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_getNameConstraints.
/**
* java.security.cert.X509CertSelector#getNameConstraints()
*/
public void test_getNameConstraints() throws IOException {
// Used to generate following byte array
// 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 }), };
//
// constraintBytes = new byte[name_constraints.length][];
//
// 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);
// constraintBytes[i] = constraints.getEncoded();
// }
// System.out.println("XXX"+Arrays.deepToString(constraintBytes)+"XXX");
X509CertSelector selector = new X509CertSelector();
for (int i = 0; i < constraintBytes.length; i++) {
selector.setNameConstraints(constraintBytes[i]);
assertTrue(Arrays.equals(constraintBytes[i], selector.getNameConstraints()));
}
}
use of java.security.cert.X509CertSelector in project robovm by robovm.
the class X509CertSelectorTest method test_setSubjectLjava_lang_String.
/**
* java.security.cert.X509CertSelector#setSubject(java.lang.String)
*/
public void test_setSubjectLjava_lang_String() throws Exception {
String name1 = "O=First Org.";
String name2 = "O=Second Org.";
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((String) null);
assertTrue("Any certificates should match " + "in the case of null subject 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_getCertificate.
/**
* java.security.cert.X509CertSelector#getCertificate()
*/
public void test_getCertificate() throws Exception {
X509CertSelector selector = new X509CertSelector();
CertificateFactory certFact = CertificateFactory.getInstance("X509");
X509Certificate cert1 = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v3()));
X509Certificate cert2 = (X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(TestUtils.getX509Certificate_v1()));
selector.setCertificate(cert1);
assertEquals(cert1, selector.getCertificate());
selector.setCertificate(cert2);
assertEquals(cert2, selector.getCertificate());
selector.setCertificate(null);
assertNull(selector.getCertificate());
}
Aggregations