Search in sources :

Example 91 with X509CertSelector

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) {
    }
}
Also used : X509CertSelector(java.security.cert.X509CertSelector) ASN1OctetString(org.apache.harmony.security.asn1.ASN1OctetString) HashSet(java.util.HashSet)

Example 92 with X509CertSelector

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

Example 93 with X509CertSelector

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

Example 94 with X509CertSelector

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

Example 95 with X509CertSelector

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

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