Search in sources :

Example 21 with X509CertSelector

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");
}
Also used : MyCRL(org.apache.harmony.security.tests.support.cert.MyCRL) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) X509CertSelector(java.security.cert.X509CertSelector) CertificateFactory(java.security.cert.CertificateFactory)

Example 22 with X509CertSelector

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();
}
Also used : GeneralNames(org.apache.harmony.security.x509.GeneralNames) OtherName(org.apache.harmony.security.x509.OtherName) X509CertSelector(java.security.cert.X509CertSelector) List(java.util.List) ArrayList(java.util.ArrayList) GeneralName(org.apache.harmony.security.x509.GeneralName) ORAddress(org.apache.harmony.security.x509.ORAddress) GeneralName(org.apache.harmony.security.x509.GeneralName) OtherName(org.apache.harmony.security.x509.OtherName) Name(org.apache.harmony.security.x501.Name)

Example 23 with X509CertSelector

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

Example 24 with X509CertSelector

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

Example 25 with X509CertSelector

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

Aggregations

X509CertSelector (java.security.cert.X509CertSelector)151 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)54 X509Certificate (java.security.cert.X509Certificate)41 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)33 IOException (java.io.IOException)23 CertPathBuilder (java.security.cert.CertPathBuilder)22 HashSet (java.util.HashSet)22 TrustAnchor (java.security.cert.TrustAnchor)20 X500Principal (javax.security.auth.x500.X500Principal)20 KeyStore (java.security.KeyStore)18 ArrayList (java.util.ArrayList)18 CertStore (java.security.cert.CertStore)17 CertPathTrustManagerParameters (javax.net.ssl.CertPathTrustManagerParameters)15 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 CertificateException (java.security.cert.CertificateException)11 CertificateFactory (java.security.cert.CertificateFactory)11 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Date (java.util.Date)10