Search in sources :

Example 16 with PKIXParameters

use of java.security.cert.PKIXParameters 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 17 with PKIXParameters

use of java.security.cert.PKIXParameters 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 18 with PKIXParameters

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

the class OldPKIXParametersTest method testPKIXParametersKeyStore04.

/**
     * Test #4 for <code>PKIXParameters(KeyStore)</code> constructor<br>
     *
     * @throws InvalidAlgorithmParameterException
     * @throws KeyStoreException
     */
@BrokenTest("Fails in CTS environment, but passes in CoreTestRunner")
public final void testPKIXParametersKeyStore04() throws Exception {
    KeyStore store = KeyStore.getInstance("PKCS12");
    KeyStoreTestPKCS12 k = new KeyStoreTestPKCS12();
    ByteArrayInputStream stream = new ByteArrayInputStream(k.keyStoreData);
    try {
        PKIXParameters p = new PKIXParameters(store);
    } catch (KeyStoreException e) {
    // ok
    }
    store = KeyStore.getInstance("PKCS12");
    store.load(stream, new String(KeyStoreTestPKCS12.keyStorePassword).toCharArray());
    stream.close();
    try {
        PKIXParameters p = new PKIXParameters(store);
    } catch (InvalidAlgorithmParameterException e) {
    // ok
    }
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    keystore.load(null, null);
    keystore.setCertificateEntry("test", TestUtils.rootCertificateSS);
    PKIXParameters p = new PKIXParameters(keystore);
}
Also used : KeyStoreTestPKCS12(tests.targets.security.KeyStoreTestPKCS12) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) ByteArrayInputStream(java.io.ByteArrayInputStream) PKIXParameters(java.security.cert.PKIXParameters) KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) BrokenTest(dalvik.annotation.BrokenTest)

Example 19 with PKIXParameters

use of java.security.cert.PKIXParameters 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 20 with PKIXParameters

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

the class CertificateTest method testVerifyMD2_chain.

public void testVerifyMD2_chain() throws Exception {
    CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
    // First check with the trust anchor not included in the chain
    CertPath path = certificateFactory.generateCertPath(getCertList(true, false));
    CertPathValidator certPathValidator = CertPathValidator.getInstance("PKIX");
    PKIXParameters params = createPKIXParams();
    CertPathValidatorResult res = certPathValidator.validate(path, params);
    assertTrue("wrong result type", res instanceof PKIXCertPathValidatorResult);
    PKIXCertPathValidatorResult r = (PKIXCertPathValidatorResult) res;
    assertTrue("Wrong trust anchor returned", params.getTrustAnchors().contains(r.getTrustAnchor()));
    // Now check with the trust anchor included in the chain
    path = certificateFactory.generateCertPath(getCertList(true, true));
    certPathValidator = CertPathValidator.getInstance("PKIX");
    params = createPKIXParams();
    if (StandardNames.IS_RI) {
        res = certPathValidator.validate(path, params);
        assertTrue("wrong result type", res instanceof PKIXCertPathValidatorResult);
        r = (PKIXCertPathValidatorResult) res;
        assertTrue("Wrong trust anchor returned", params.getTrustAnchors().contains(r.getTrustAnchor()));
    } else {
        try {
            certPathValidator.validate(path, params);
            fail();
        } catch (CertPathValidatorException expected) {
        }
    }
}
Also used : CertPathValidator(java.security.cert.CertPathValidator) CertPathValidatorException(java.security.cert.CertPathValidatorException) PKIXParameters(java.security.cert.PKIXParameters) PKIXCertPathValidatorResult(java.security.cert.PKIXCertPathValidatorResult) CertPath(java.security.cert.CertPath) CertPathValidatorResult(java.security.cert.CertPathValidatorResult) PKIXCertPathValidatorResult(java.security.cert.PKIXCertPathValidatorResult) CertificateFactory(java.security.cert.CertificateFactory)

Aggregations

PKIXParameters (java.security.cert.PKIXParameters)28 TrustAnchor (java.security.cert.TrustAnchor)17 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)11 X509Certificate (java.security.cert.X509Certificate)11 CertificateFactory (java.security.cert.CertificateFactory)10 ArrayList (java.util.ArrayList)9 CertPath (java.security.cert.CertPath)7 KeyStore (java.security.KeyStore)6 CertPathValidator (java.security.cert.CertPathValidator)6 CertPathValidatorException (java.security.cert.CertPathValidatorException)6 HashSet (java.util.HashSet)6 PKIXCertPathValidatorResult (java.security.cert.PKIXCertPathValidatorResult)5 List (java.util.List)5 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)4 X509CertSelector (java.security.cert.X509CertSelector)4 Set (java.util.Set)4 BigInteger (java.math.BigInteger)3 CertPathValidatorResult (java.security.cert.CertPathValidatorResult)3 CertificateException (java.security.cert.CertificateException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2