Search in sources :

Example 36 with CertPath

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

the class CertificateFactory3Test method testGenerateCertPath02.

/**
     * Test for
     * <code>generateCertPath(InputStream inStream, String encoding)</code>
     * method Assertion: returns CertPath with 1 Certificate
     */
public void testGenerateCertPath02() throws Exception {
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    for (int i = 0; i < certFs.length; i++) {
        CertPath certPath = null;
        InputStream fis = Support_Resources.getResourceStream(fileCertPathPki);
        certPath = certFs[i].generateCertPath(fis, "PkiPath");
        fis.close();
        assertEquals(defaultType, certPath.getType());
        List<? extends Certificate> list1 = certPath.getCertificates();
        assertFalse("Result list is empty", list1.isEmpty());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CertPath(java.security.cert.CertPath) CertificateFactory(java.security.cert.CertificateFactory)

Example 37 with CertPath

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

the class CertificateFactory3Test method testGenerateCertPath03.

/**
     * Test for <code>generateCertPath(InputStream inStream)</code> method
     * Assertion: returns CertPath with 1 Certificate
     */
public void testGenerateCertPath03() throws Exception {
    String certPathEncoding = "PkiPath";
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    for (int i = 0; i < certFs.length; i++) {
        Iterator<String> it = certFs[0].getCertPathEncodings();
        assertTrue("no CertPath encodings", it.hasNext());
        assertEquals("Incorrect default encoding", certPathEncoding, it.next());
        CertPath certPath = null;
        InputStream fis = Support_Resources.getResourceStream(fileCertPathPki);
        certPath = certFs[i].generateCertPath(fis);
        fis.close();
        assertEquals(defaultType, certPath.getType());
        List<? extends Certificate> list1 = certPath.getCertificates();
        assertFalse("Result list is empty", list1.isEmpty());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CertPath(java.security.cert.CertPath) CertificateFactory(java.security.cert.CertificateFactory)

Example 38 with CertPath

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

the class PKIXCertPathBuilderResultTest method testGetCertPath.

/**
     * Test for <code>getCertPath()</code> method<br>
     * Assertion: the built and validated <code>CertPath</code>
     * (never <code>null</code>)
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     */
public final void testGetCertPath() throws Exception {
    TrustAnchor ta = TestUtils.getTrustAnchor();
    if (ta == null) {
        fail(getName() + ": not performed (could not create test TrustAnchor)");
    }
    CertPath cp = new MyCertPath(testEncoding);
    CertPathBuilderResult r = new PKIXCertPathBuilderResult(cp, ta, TestUtils.getPolicyTree(), testPublicKey);
    // must return the same reference
    // as passed to the constructor
    assertSame(cp, r.getCertPath());
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) PKIXCertPathBuilderResult(java.security.cert.PKIXCertPathBuilderResult) CertPathBuilderResult(java.security.cert.CertPathBuilderResult) PKIXCertPathBuilderResult(java.security.cert.PKIXCertPathBuilderResult) TrustAnchor(java.security.cert.TrustAnchor) MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) CertPath(java.security.cert.CertPath)

Example 39 with CertPath

use of java.security.cert.CertPath 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)

Example 40 with CertPath

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

the class CertificateTest method testVerifyMD5_chain.

public void testVerifyMD5_chain() throws Exception {
    CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
    // First check with the trust anchor not included in the chain
    CertPath path = certificateFactory.generateCertPath(getCertList(false, 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(false, true));
    certPathValidator = CertPathValidator.getInstance("PKIX");
    params = createPKIXParams();
    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()));
}
Also used : CertPathValidator(java.security.cert.CertPathValidator) 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

CertPath (java.security.cert.CertPath)55 X509Certificate (java.security.cert.X509Certificate)17 MyCertPath (org.apache.harmony.security.tests.support.cert.MyCertPath)16 CertificateFactory (java.security.cert.CertificateFactory)15 MyFailingCertPath (org.apache.harmony.security.tests.support.cert.MyFailingCertPath)14 CertPathValidatorException (java.security.cert.CertPathValidatorException)13 ArrayList (java.util.ArrayList)10 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)9 CertPathValidator (java.security.cert.CertPathValidator)9 CertPathBuilderResult (java.security.cert.CertPathBuilderResult)8 TrustAnchor (java.security.cert.TrustAnchor)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Certificate (java.security.cert.Certificate)7 PKIXCertPathValidatorResult (java.security.cert.PKIXCertPathValidatorResult)7 PKIXParameters (java.security.cert.PKIXParameters)7 HashSet (java.util.HashSet)7 CertPathBuilder (java.security.cert.CertPathBuilder)6 CertPathBuilderException (java.security.cert.CertPathBuilderException)6 CertificateException (java.security.cert.CertificateException)6 PKIXBuilderParameters (java.security.cert.PKIXBuilderParameters)6