Search in sources :

Example 16 with X509CertSelector

use of java.security.cert.X509CertSelector in project robovm by robovm.

the class PKIXBuilderParametersTest method testToString.

/**
     * Test for <code>toString()</code>
     */
public final void testToString() throws Exception {
    KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
    keyTest.load(null, null);
    ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
    ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate[] cert = new X509Certificate[2];
    cert[0] = (X509Certificate) cf.generateCertificate(certArray);
    cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
    keyTest.setCertificateEntry("alias1", cert[0]);
    keyTest.setCertificateEntry("alias2", cert[0]);
    keyTest.setCertificateEntry("alias3", cert[1]);
    PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
    assertNotNull(p.toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) X509CertSelector(java.security.cert.X509CertSelector) KeyStore(java.security.KeyStore) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Example 17 with X509CertSelector

use of java.security.cert.X509CertSelector in project robovm by robovm.

the class PKIXBuilderParametersTest method testPKIXBuilderParametersKeyStoreCertSelector04.

/**
     * Test #4 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code>
     * constructor<br>
     * Assertion: <code>NullPointerException</code> -
     * if the <code>keystore</code> is <code>null</code>
     */
public final void testPKIXBuilderParametersKeyStoreCertSelector04() throws Exception {
    KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
    keyTest.load(null, null);
    ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
    ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate[] cert = new X509Certificate[2];
    cert[0] = (X509Certificate) cf.generateCertificate(certArray);
    cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
    keyTest.setCertificateEntry("alias1", cert[0]);
    keyTest.setCertificateEntry("alias2", cert[0]);
    keyTest.setCertificateEntry("alias3", cert[1]);
    try {
        PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
        assertEquals(3, p.getTrustAnchors().size());
        assertEquals(5, p.getMaxPathLength());
    } catch (Exception e) {
        fail("Unexpected exception " + e.getMessage());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) X509CertSelector(java.security.cert.X509CertSelector) KeyStore(java.security.KeyStore) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) InvalidParameterException(java.security.InvalidParameterException)

Example 18 with X509CertSelector

use of java.security.cert.X509CertSelector in project robovm by robovm.

the class PKIXBuilderParametersTest method testGetMaxPathLength.

/**
     * Test for <code>getMaxPathLength()</code>
     */
public final void testGetMaxPathLength() throws Exception {
    KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
    keyTest.load(null, null);
    ByteArrayInputStream certArray = new ByteArrayInputStream(certificate.getBytes());
    ByteArrayInputStream certArray2 = new ByteArrayInputStream(certificate2.getBytes());
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate[] cert = new X509Certificate[2];
    cert[0] = (X509Certificate) cf.generateCertificate(certArray);
    cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
    keyTest.setCertificateEntry("alias1", cert[0]);
    keyTest.setCertificateEntry("alias2", cert[0]);
    keyTest.setCertificateEntry("alias3", cert[1]);
    PKIXBuilderParameters p = new PKIXBuilderParameters(keyTest, new X509CertSelector());
    assertEquals(5, p.getMaxPathLength());
    p.setMaxPathLength(10);
    assertEquals(10, p.getMaxPathLength());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) X509CertSelector(java.security.cert.X509CertSelector) KeyStore(java.security.KeyStore) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate)

Example 19 with X509CertSelector

use of java.security.cert.X509CertSelector in project robovm by robovm.

the class X509CertSelectorTest method test_toString.

/**
     * java.security.cert.X509CertSelector#toString()
     */
public void test_toString() {
    X509CertSelector selector = new X509CertSelector();
    assertNotNull(selector.toString());
}
Also used : X509CertSelector(java.security.cert.X509CertSelector)

Example 20 with X509CertSelector

use of java.security.cert.X509CertSelector in project robovm by robovm.

the class X509CertSelectorTest method test_setIssuerLjava_lang_String.

/**
     * java.security.cert.X509CertSelector#setIssuer(java.lang.String)
     */
public void test_setIssuerLjava_lang_String() throws Exception {
    String name1 = "O=First Org.";
    String name2 = "O=Second Org.";
    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((String) 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) ASN1OctetString(org.apache.harmony.security.asn1.ASN1OctetString)

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