Search in sources :

Example 81 with X509CertSelector

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());
}
Also used : X509CertSelector(java.security.cert.X509CertSelector) Date(java.util.Date)

Example 82 with X509CertSelector

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()));
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) X509CertSelector(java.security.cert.X509CertSelector)

Example 83 with X509CertSelector

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()));
    }
}
Also used : X509CertSelector(java.security.cert.X509CertSelector)

Example 84 with X509CertSelector

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));
}
Also used : X500Principal(javax.security.auth.x500.X500Principal) X509CertSelector(java.security.cert.X509CertSelector) ASN1OctetString(org.apache.harmony.security.asn1.ASN1OctetString)

Example 85 with X509CertSelector

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) X509CertSelector(java.security.cert.X509CertSelector) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Aggregations

X509CertSelector (java.security.cert.X509CertSelector)116 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)29 X509Certificate (java.security.cert.X509Certificate)23 IOException (java.io.IOException)18 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)17 X500Principal (javax.security.auth.x500.X500Principal)16 ArrayList (java.util.ArrayList)14 TrustAnchor (java.security.cert.TrustAnchor)13 CertificateFactory (java.security.cert.CertificateFactory)11 HashSet (java.util.HashSet)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 KeyStore (java.security.KeyStore)10 CertPathBuilder (java.security.cert.CertPathBuilder)10 CertStore (java.security.cert.CertStore)10 PublicKey (java.security.PublicKey)9 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)8 CertificateException (java.security.cert.CertificateException)8 ASN1OctetString (org.apache.harmony.security.asn1.ASN1OctetString)8 BigInteger (java.math.BigInteger)7 Date (java.util.Date)7