Search in sources :

Example 11 with CertPath

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

the class CertPathValidatorExceptionTest method testCertPathValidatorException13.

/**
     * Test for
     * <code>CertPathValidatorException(String, Throwable, CertPath, int)</code>
     * constructor Assertion: constructs CertPathValidatorException when
     * <code>cause</code> not null <code>msg</code> not null
     * <code>certPath</code> not null <code>index</code>< -1 || >=
     * certPath.getCertificates().size() throws: IndexOutOfBoundsException
     */
public void testCertPathValidatorException13() {
    myCertPath mcp = new myCertPath("X.509", "");
    CertPath cp = mcp.get("X.509");
    int[] indx = { -2, -100, 0, 1, 100, Integer.MAX_VALUE, Integer.MIN_VALUE };
    for (int j = 0; j < indx.length; j++) {
        for (int i = 0; i < msgs.length; i++) {
            try {
                new CertPathValidatorException(msgs[i], tCause, cp, indx[j]);
                fail("IndexOutOfBoundsException was not thrown as expected. " + " msg: " + msgs[i] + ", certPath is null and index is " + indx[j]);
            } catch (IndexOutOfBoundsException e) {
            }
        }
    }
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) CertPath(java.security.cert.CertPath)

Example 12 with CertPath

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

the class CertPathValidatorExceptionTest method testCertPathValidatorException16.

/**
     * Test for <code>getIndex()</code>. Returns the index of the certificate
     * in the certification path that caused the exception to be thrown. Note
     * that the list of certificates in a CertPath is zero based. If no index
     * has been set, -1 is returned.
     */
public void testCertPathValidatorException16() {
    CertPathValidatorException tE = new CertPathValidatorException();
    assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
    for (int i = 0; i < msgs.length; i++) {
        tE = new CertPathValidatorException(msgs[i]);
        assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
    }
    Throwable cause = null;
    tE = new CertPathValidatorException(cause);
    assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
    tE = new CertPathValidatorException(tCause);
    assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
    for (int i = 0; i < msgs.length; i++) {
        tE = new CertPathValidatorException(msgs[i], tCause);
        assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
    }
    tE = new CertPathValidatorException(null, null, null, -1);
    assertEquals("getIndex() must be equals -1", -1, tE.getIndex());
    myCertPath mcp = new myCertPath("X.509", "");
    CertPath cp = mcp.get("X.509");
    for (int i = 0; i < msgs.length; i++) {
        try {
            tE = new CertPathValidatorException(msgs[i], tCause, cp, -1);
            assertNotNull("getIndex() must not return null", tE.getCertPath());
            assertEquals("getIndex() must return ".concat(cp.toString()), tE.getCertPath(), cp);
        } catch (IndexOutOfBoundsException e) {
            fail("Unexpected IndexOutOfBoundsException was thrown. " + e.getMessage());
        }
    }
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) CertPath(java.security.cert.CertPath)

Example 13 with CertPath

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

the class CertPathValidatorSpiTest method testCertPathValidatorSpi01.

/**
     * Test for <code>CertPathValidatorSpi</code> constructor Assertion:
     * constructs CertPathValidatorSpi
     */
public void testCertPathValidatorSpi01() throws CertPathValidatorException, InvalidAlgorithmParameterException {
    CertPathValidatorSpi certPathValid = new MyCertPathValidatorSpi();
    CertPathParameters params = null;
    CertPath certPath = null;
    CertPathValidatorResult cpvResult = certPathValid.engineValidate(certPath, params);
    assertNull("Not null CertPathValidatorResult", cpvResult);
    try {
        certPathValid.engineValidate(certPath, params);
        fail("CertPathValidatorException must be thrown");
    } catch (CertPathValidatorException e) {
    }
    try {
        certPathValid.engineValidate(certPath, params);
        fail("InvalidAlgorithmParameterException must be thrown");
    } catch (InvalidAlgorithmParameterException e) {
    }
}
Also used : CertPathValidatorException(java.security.cert.CertPathValidatorException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CertPathParameters(java.security.cert.CertPathParameters) CertPath(java.security.cert.CertPath) CertPathValidatorResult(java.security.cert.CertPathValidatorResult) MyCertPathValidatorSpi(org.apache.harmony.security.tests.support.cert.MyCertPathValidatorSpi) MyCertPathValidatorSpi(org.apache.harmony.security.tests.support.cert.MyCertPathValidatorSpi) CertPathValidatorSpi(java.security.cert.CertPathValidatorSpi)

Example 14 with CertPath

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

the class myCertificateFactory method testCertificateFactory15.

/**
     * Test for <code>generateCertPath(List certificates)</code> method
     * Assertion: returns empty CertPath if certificates is empty
     */
public void testCertificateFactory15() throws CertificateException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    List<Certificate> list = new Vector<Certificate>();
    for (int i = 0; i < certFs.length; i++) {
        CertPath cp = certFs[i].generateCertPath(list);
        List<? extends Certificate> list1 = cp.getCertificates();
        assertTrue("List should be empty", list1.isEmpty());
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) CertPath(java.security.cert.CertPath) CertificateFactory(java.security.cert.CertificateFactory) Vector(java.util.Vector) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate)

Example 15 with CertPath

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

the class CertificateFactory2Test method checkResult.

private void checkResult(CertificateFactory certFactory, boolean mode) throws CertificateException, CRLException {
    MyCertificateFactorySpi.putMode(mode);
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]);
    DataInputStream dis = new DataInputStream(bais);
    try {
        certFactory.generateCertPath(bais);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    try {
        certFactory.generateCertPath(dis);
        if (!mode) {
            fail("CertificateException must be thrown because encodings list is empty");
        }
    } catch (CertificateException e) {
        if (mode) {
            fail("Unexpected CertificateFactoryException was thrown");
        }
    }
    try {
        certFactory.generateCertPath(bais, "aa");
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    try {
        certFactory.generateCertPath(dis, "");
        if (mode) {
            fail("IllegalArgumentException must be thrown");
        }
    } catch (IllegalArgumentException e) {
        if (!mode) {
            fail("Unexpected IllegalArgumentException was thrown");
        }
    }
    certFactory.generateCertPath(dis, "ss");
    try {
        certFactory.generateCertificate(bais);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    try {
        certFactory.generateCertificates(null);
        fail("CertificateException must be thrown");
    } catch (CertificateException e) {
    }
    Certificate cert = certFactory.generateCertificate(dis);
    assertNull("Result must be null", cert);
    Collection<? extends Certificate> col = certFactory.generateCertificates(dis);
    assertNull("Result must be null", col);
    try {
        certFactory.generateCRL(bais);
        fail("CRLException must be thrown");
    } catch (CRLException e) {
    }
    try {
        certFactory.generateCRLs(null);
        fail("CRLException must be thrown");
    } catch (CRLException e) {
    }
    CRL crl = certFactory.generateCRL(dis);
    assertNull("Result must be null", crl);
    Collection<? extends CRL> colc = certFactory.generateCRLs(dis);
    assertNull("Result must be null", colc);
    List<Certificate> list = null;
    CertPath cp;
    try {
        cp = certFactory.generateCertPath(list);
        if (mode) {
            fail("NullPointerException must be thrown");
        } else {
            assertNull("Must be null", cp);
        }
    } catch (NullPointerException e) {
        if (!mode) {
            fail("Unexpected NullPointerException was thrown");
        }
    }
    Iterator<String> it = certFactory.getCertPathEncodings();
    if (mode) {
        assertTrue(it.hasNext());
    } else {
        assertFalse(it.hasNext());
    }
}
Also used : CertificateException(java.security.cert.CertificateException) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CRL(java.security.cert.CRL) CertPath(java.security.cert.CertPath) CRLException(java.security.cert.CRLException) Certificate(java.security.cert.Certificate)

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