Search in sources :

Example 41 with TrustAnchor

use of java.security.cert.TrustAnchor in project scdl by passy.

the class SystemKeyStore method getPkixParameters.

private PKIXParameters getPkixParameters() {
    try {
        final KeyStore trustStore = this.getTrustStore();
        final Set<TrustAnchor> trusted = new HashSet<TrustAnchor>();
        for (final Enumeration<String> aliases = trustStore.aliases(); aliases.hasMoreElements(); ) {
            final String alias = aliases.nextElement();
            final X509Certificate cert = (X509Certificate) trustStore.getCertificate(alias);
            if (cert != null) {
                trusted.add(new TrustAnchor(cert, null));
            }
        }
        final PKIXParameters parameters = new PKIXParameters(trusted);
        parameters.setRevocationEnabled(false);
        return parameters;
    } catch (final InvalidAlgorithmParameterException e) {
        throw new AssertionError(e);
    } catch (final KeyStoreException e) {
        throw new AssertionError(e);
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) PKIXParameters(java.security.cert.PKIXParameters) TrustAnchor(java.security.cert.TrustAnchor) KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) HashSet(java.util.HashSet)

Example 42 with TrustAnchor

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

the class OldPKIXParametersTest method testToString.

/**
     * Test for <code>toString</code> method<br>
     */
public final void testToString() throws Exception {
    Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet();
    if (taSet == null) {
        fail(getName() + ": not performed (could not create test TrustAnchor set)");
    }
    PKIXParameters p = new PKIXParameters(taSet);
    assertNotNull(p.toString());
    PKIXParameters p1 = null;
    try {
        p1.toString();
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : PKIXParameters(java.security.cert.PKIXParameters) TrustAnchor(java.security.cert.TrustAnchor)

Example 43 with TrustAnchor

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

the class OldPKIXParametersTest method testIsRevocationEnabled.

/**
     * Test for <code>isPolicyMappingInhibited()</code> method<br>
     * Assertion: returns the current value of the RevocationEnabled flag
     * Assertion: when a <code>PKIXParameters</code> object is created, this
     * flag is set to true
     *
     * @throws InvalidAlgorithmParameterException
     */
public final void testIsRevocationEnabled() throws Exception {
    Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet();
    if (taSet == null) {
        fail(getName() + ": not performed (could not create test TrustAnchor set)");
    }
    PKIXParameters p = new PKIXParameters(taSet);
    assertTrue(p.isRevocationEnabled());
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    TestUtils.initCertPathSSCertChain();
    Set<TrustAnchor> taSet2 = Collections.singleton(new TrustAnchor(TestUtils.rootCertificateSS, null));
    p = new PKIXParameters(taSet2);
    assertTrue(p.isRevocationEnabled());
    p.setRevocationEnabled(false);
    assertFalse(p.isRevocationEnabled());
}
Also used : PKIXParameters(java.security.cert.PKIXParameters) TrustAnchor(java.security.cert.TrustAnchor) CertificateFactory(java.security.cert.CertificateFactory)

Example 44 with TrustAnchor

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

the class OldPKIXParametersTest method testIsPolicyMappingInhibited.

/**
     * Test for <code>isPolicyMappingInhibited()</code> method<br>
     * Assertion: returns true if policy mapping is inhibited, false otherwise
     * Assertion: by default, policy mapping is not inhibited (the flag is
     * false)
     *
     * @throws InvalidAlgorithmParameterException
     */
public final void testIsPolicyMappingInhibited() throws Exception {
    Set<TrustAnchor> taSet = TestUtils.getTrustAnchorSet();
    if (taSet == null) {
        fail(getName() + ": not performed (could not create test TrustAnchor set)");
    }
    PKIXParameters p = new PKIXParameters(taSet);
    assertFalse(p.isPolicyMappingInhibited());
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    TestUtils.initCertPathSSCertChain();
    Set<TrustAnchor> taSet2 = Collections.singleton(new TrustAnchor(TestUtils.rootCertificateSS, null));
    p = new PKIXParameters(taSet2);
    assertFalse(p.isPolicyMappingInhibited());
    p.setPolicyMappingInhibited(true);
    assertTrue(p.isRevocationEnabled());
}
Also used : PKIXParameters(java.security.cert.PKIXParameters) TrustAnchor(java.security.cert.TrustAnchor) CertificateFactory(java.security.cert.CertificateFactory)

Example 45 with TrustAnchor

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

the class PKIXCertPathBuilderResultTest method testPKIXCertPathBuilderResult05.

/**
     * Test #5 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor,
     *   PolicyNode, PublicKey)</code> constructor<br>
     * Assertion: <code>NullPointerException</code>
     * if publicKey is <code>null</code>
     */
public final void testPKIXCertPathBuilderResult05() {
    TrustAnchor ta = TestUtils.getTrustAnchor();
    if (ta == null) {
        fail(getName() + ": not performed (could not create test TrustAnchor)");
    }
    try {
        // pass null
        new PKIXCertPathBuilderResult(new MyCertPath(testEncoding), ta, TestUtils.getPolicyTree(), null);
        fail("NPE expected");
    } catch (NullPointerException e) {
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) PKIXCertPathBuilderResult(java.security.cert.PKIXCertPathBuilderResult) TrustAnchor(java.security.cert.TrustAnchor)

Aggregations

TrustAnchor (java.security.cert.TrustAnchor)86 X509Certificate (java.security.cert.X509Certificate)35 PublicKey (java.security.PublicKey)24 X500Principal (javax.security.auth.x500.X500Principal)21 PKIXParameters (java.security.cert.PKIXParameters)17 TestKeyPair (org.apache.harmony.security.tests.support.TestKeyPair)16 HashSet (java.util.HashSet)15 CertificateFactory (java.security.cert.CertificateFactory)14 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)14 PKIXCertPathValidatorResult (java.security.cert.PKIXCertPathValidatorResult)13 X509CertSelector (java.security.cert.X509CertSelector)13 CertPathValidatorException (java.security.cert.CertPathValidatorException)12 PKIXCertPathBuilderResult (java.security.cert.PKIXCertPathBuilderResult)12 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)11 ArrayList (java.util.ArrayList)11 ByteArrayInputStream (java.io.ByteArrayInputStream)8 CertPath (java.security.cert.CertPath)8 IOException (java.io.IOException)7 CertificateException (java.security.cert.CertificateException)7 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)7