Search in sources :

Example 11 with MyCertPath

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

the class PKIXCertPathBuilderResultTest method testPKIXCertPathBuilderResult01.

//
// Tests
//
/**
     * Test #1 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor,
     *   PolicyNode, PublicKey)</code> constructor<br>
     * Assertion: Creates an instance of <code>PKIXCertPathBuilderResult</code>
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     */
public final void testPKIXCertPathBuilderResult01() 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, TestUtils.getPolicyTree(), 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 12 with MyCertPath

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

the class PKIXCertPathBuilderResultTest method testPKIXCertPathBuilderResult04.

/**
     * Test #4 for <code>PKIXCertPathBuilderResult(CertPath, TrustAnchor,
     *   PolicyNode, PublicKey)</code> constructor<br>
     * Assertion: <code>NullPointerException</code>
     * if trustAnchor is <code>null</code>
     */
public final void testPKIXCertPathBuilderResult04() {
    try {
        // pass null
        new PKIXCertPathBuilderResult(new MyCertPath(testEncoding), null, TestUtils.getPolicyTree(), testPublicKey);
        fail("NPE expected");
    } catch (NullPointerException e) {
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) PKIXCertPathBuilderResult(java.security.cert.PKIXCertPathBuilderResult)

Example 13 with MyCertPath

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

the class PKIXCertPathBuilderResultTest method testToString.

/**
     * Test for <code>toString()</code> method<br>
     * Assertion: the printable representation of this object
     * @throws NoSuchAlgorithmException
     * @throws InvalidKeySpecException
     */
public final void testToString() 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, TestUtils.getPolicyTree(), testPublicKey);
    assertNotNull(r.toString());
}
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 14 with MyCertPath

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

the class TimestampTest method testHashCode.

/*
     * Class under test for String hashCode()
     */
public void testHashCode() {
    Timestamp one = new Timestamp(now, cpath);
    Timestamp two = new Timestamp(now, cpath);
    Timestamp three = new Timestamp(now, new MyCertPath(new byte[] { 10, 20, 30 }));
    Timestamp four = null;
    assertTrue(one.hashCode() == two.hashCode());
    assertTrue(one.hashCode() != three.hashCode());
    assertTrue(two.hashCode() != three.hashCode());
    try {
        four.hashCode();
        fail("NullPointerException expected");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) Timestamp(java.security.Timestamp)

Example 15 with MyCertPath

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

the class myCertificateFactory method testCertificateFactory13.

/**
     * Test for <code>generateCertPath(InputStream inStream)</code>
     * <code>generateCertPath(InputStream inStream, String encoding)</code>
     * methods
     * Assertion: throw CertificateException when isStream contains invalid datas
     */
// Test passed on RI
public void testCertificateFactory13() throws IOException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    byte[] enc = { (byte) 0, (byte) 2, (byte) 3, (byte) 4, (byte) 5 };
    MyCertPath mc = new MyCertPath(enc);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(mc);
    oos.flush();
    oos.close();
    byte[] arr = os.toByteArray();
    ByteArrayInputStream is = new ByteArrayInputStream(arr);
    for (int i = 0; i < certFs.length; i++) {
        try {
            certFs[i].generateCertPath(is);
            fail("CertificateException must be thrown because input stream contains incorrect datas");
        } catch (CertificateException e) {
        }
        Iterator<String> it = certFs[i].getCertPathEncodings();
        while (it.hasNext()) {
            try {
                certFs[i].generateCertPath(is, it.next());
                fail("CertificateException must be thrown because input stream contains incorrect datas");
            } catch (CertificateException e) {
            }
        }
    }
}
Also used : MyCertPath(org.apache.harmony.security.tests.support.cert.MyCertPath) ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) CertificateFactory(java.security.cert.CertificateFactory)

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