Search in sources :

Example 36 with PKIXBuilderParameters

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

the class ExtendedPKIXBuilderParameters method setParams.

/**
     * Can alse handle <code>ExtendedPKIXBuilderParameters</code> and
     * <code>PKIXBuilderParameters</code>.
     * 
     * @param params Parameters to set.
     * @see org.bouncycastle.x509.ExtendedPKIXParameters#setParams(java.security.cert.PKIXParameters)
     */
protected void setParams(PKIXParameters params) {
    super.setParams(params);
    if (params instanceof ExtendedPKIXBuilderParameters) {
        ExtendedPKIXBuilderParameters _params = (ExtendedPKIXBuilderParameters) params;
        maxPathLength = _params.maxPathLength;
        excludedCerts = new HashSet(_params.excludedCerts);
    }
    if (params instanceof PKIXBuilderParameters) {
        PKIXBuilderParameters _params = (PKIXBuilderParameters) params;
        maxPathLength = _params.getMaxPathLength();
    }
}
Also used : PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) HashSet(java.util.HashSet)

Example 37 with PKIXBuilderParameters

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

the class PKIXBuilderParametersTest method testPKIXBuilderParametersKeyStoreCertSelector01.

/**
     * Test #1 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code>
     * constructor<br>
     * Assertion: <code>NullPointerException</code> - if the
     * <code>keystore</code> is <code>null</code>
     */
public final void testPKIXBuilderParametersKeyStoreCertSelector01() throws Exception {
    try {
        new PKIXBuilderParameters((KeyStore) null, new X509CertSelector());
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) X509CertSelector(java.security.cert.X509CertSelector)

Example 38 with PKIXBuilderParameters

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

the class PKIXBuilderParametersTest method testPKIXBuilderParametersKeyStoreCertSelector02.

/**
     * Test #2 for <code>PKIXBuilderParameters(KeyStore, CertSelector)</code>
     * constructor<br>
     * Assertion: <code>KeyStoreException</code> - if the
     * <code>keystore</code> has not been initialized
     */
public final void testPKIXBuilderParametersKeyStoreCertSelector02() throws Exception {
    KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
    try {
        new PKIXBuilderParameters(keyTest, null);
        fail("KeyStoreException expected");
    } catch (KeyStoreException e) {
    // expected
    }
}
Also used : PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore)

Example 39 with PKIXBuilderParameters

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

the class PKIXBuilderParametersTest method testSetMaxPathLength.

/**
     * Test for <code>setMaxPathLength()</code>
     */
public final void testSetMaxPathLength() 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());
    p.setMaxPathLength(0);
    assertEquals(0, p.getMaxPathLength());
    p.setMaxPathLength(-1);
    assertEquals(-1, p.getMaxPathLength());
    int[] maxPathLength = { -2, -10, Integer.MIN_VALUE };
    for (int i = 0; i < maxPathLength.length; i++) {
        try {
            p.setMaxPathLength(maxPathLength[i]);
            fail("InvalidParameterException expected ");
        } catch (InvalidParameterException e) {
        // expected
        }
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) 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 40 with PKIXBuilderParameters

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

the class TestUtils method getCertPathParameters.

public static CertPathParameters getCertPathParameters() throws InvalidAlgorithmParameterException {
    if ((rootCertificateSS == null) || (theCertSelector == null) || (builder == null)) {
        throw new RuntimeException("Call initCertPathSSCertChain prior to buildCertPath");
    }
    PKIXBuilderParameters buildParams = new PKIXBuilderParameters(Collections.singleton(new TrustAnchor(rootCertificateSS, null)), theCertSelector);
    buildParams.addCertStore(store);
    buildParams.setRevocationEnabled(false);
    return buildParams;
}
Also used : PKIXBuilderParameters(java.security.cert.PKIXBuilderParameters) TrustAnchor(java.security.cert.TrustAnchor)

Aggregations

PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)66 X509CertSelector (java.security.cert.X509CertSelector)55 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)33 X509Certificate (java.security.cert.X509Certificate)29 CertPathBuilder (java.security.cert.CertPathBuilder)23 TrustAnchor (java.security.cert.TrustAnchor)21 HashSet (java.util.HashSet)19 KeyStore (java.security.KeyStore)17 CertStore (java.security.cert.CertStore)17 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)16 CertPathTrustManagerParameters (javax.net.ssl.CertPathTrustManagerParameters)15 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 PKIXCertPathBuilderResult (java.security.cert.PKIXCertPathBuilderResult)13 ArrayList (java.util.ArrayList)13 CertPathBuilderException (java.security.cert.CertPathBuilderException)12 CertPathBuilderResult (java.security.cert.CertPathBuilderResult)11 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)11 IOException (java.io.IOException)10 CertPath (java.security.cert.CertPath)10 CertificateException (java.security.cert.CertificateException)10