Search in sources :

Example 16 with MyCertPath

use of org.apache.harmony.security.tests.support.cert.MyCertPath 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)

Example 17 with MyCertPath

use of org.apache.harmony.security.tests.support.cert.MyCertPath 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 18 with MyCertPath

use of org.apache.harmony.security.tests.support.cert.MyCertPath in project robovm by robovm.

the class PKIXCertPathBuilderResultTest method test_clone.

public final void test_clone() {
    // Regression for HARMONY-2786.
    TrustAnchor ta = TestUtils.getTrustAnchor();
    assertNotNull(getName() + ": not performed (could not create test TrustAnchor)", ta);
    PKIXCertPathBuilderResult init = new PKIXCertPathBuilderResult(new MyCertPath(testEncoding), ta, TestUtils.getPolicyTree(), testPublicKey);
    PKIXCertPathBuilderResult clone = (PKIXCertPathBuilderResult) init.clone();
    assertSame(init.getCertPath(), clone.getCertPath());
    assertSame(init.getPolicyTree(), clone.getPolicyTree());
    assertSame(init.getPublicKey(), clone.getPublicKey());
    assertSame(init.getTrustAnchor(), clone.getTrustAnchor());
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) PKIXCertPathBuilderResult(java.security.cert.PKIXCertPathBuilderResult) TrustAnchor(java.security.cert.TrustAnchor)

Example 19 with MyCertPath

use of org.apache.harmony.security.tests.support.cert.MyCertPath in project robovm by robovm.

the class PKIXCertPathBuilderResultTest method testPKIXCertPathBuilderResult02.

/**
     * Test #2 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor,
     *   PolicyNode, PublicKey)</code> constructor<br>
     * Assertion: policy tree parameter may be <code>null</code>
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     */
public final void testPKIXCertPathBuilderResult02() throws InvalidKeySpecException, NoSuchAlgorithmException {
    TrustAnchor ta = TestUtils.getTrustAnchor();
    if (ta == null) {
        fail(getName() + ": not performed (could not create test TrustAnchor)");
    }
    CertPathBuilderResult r = new PKIXCertPathBuilderResult(new MyCertPath(testEncoding), ta, null, testPublicKey);
    assertTrue(r instanceof PKIXCertPathBuilderResult);
}
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)

Example 20 with MyCertPath

use of org.apache.harmony.security.tests.support.cert.MyCertPath in project robovm by robovm.

the class CertPathValidator2Test method testValidate.

public void testValidate() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {
    MyCertPath mCP = new MyCertPath(new byte[0]);
    CertPathParameters params = new PKIXParameters(TestUtils.getTrustAnchorSet());
    CertPathValidator certPV = CertPathValidator.getInstance(defaultAlg);
    try {
        certPV.validate(mCP, params);
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (CertPathValidatorException e) {
        fail("unexpected exception: " + e);
    }
    try {
        certPV.validate(null, params);
        fail("NullPointerException must be thrown");
    } catch (InvalidAlgorithmParameterException e) {
        fail("unexpected exception: " + e);
    } catch (CertPathValidatorException e) {
    // ok
    }
    try {
        certPV.validate(mCP, null);
        fail("InvalidAlgorithmParameterException must be thrown");
    } catch (InvalidAlgorithmParameterException e) {
    // ok
    } catch (CertPathValidatorException e) {
        fail("unexpected exception");
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) CertPathValidator(java.security.cert.CertPathValidator) CertPathValidatorException(java.security.cert.CertPathValidatorException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) PKIXParameters(java.security.cert.PKIXParameters) CertPathParameters(java.security.cert.CertPathParameters)

Aggregations

MyCertPath (org.apache.harmony.security.tests.support.cert.MyCertPath)27 CertPath (java.security.cert.CertPath)13 MyFailingCertPath (org.apache.harmony.security.tests.support.cert.MyFailingCertPath)12 PKIXCertPathBuilderResult (java.security.cert.PKIXCertPathBuilderResult)7 TrustAnchor (java.security.cert.TrustAnchor)6 ObjectStreamException (java.io.ObjectStreamException)4 CertPathBuilderResult (java.security.cert.CertPathBuilderResult)4 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 CertPathValidator (java.security.cert.CertPathValidator)3 CertPathParameters (java.security.cert.CertPathParameters)2 PKIXParameters (java.security.cert.PKIXParameters)2 MyCertPathRep (org.apache.harmony.security.tests.support.cert.MyCertPath.MyCertPathRep)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Timestamp (java.security.Timestamp)1 CertPathValidatorException (java.security.cert.CertPathValidatorException)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 CertificateException (java.security.cert.CertificateException)1 CertificateFactory (java.security.cert.CertificateFactory)1