Search in sources :

Example 11 with MyCertificate

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

the class KSPrivateKeyEntryTest method createParams.

private void createParams(boolean diffCerts, boolean diffKeys) {
    byte[] encoded = { (byte) 0, (byte) 1, (byte) 2, (byte) 3 };
    testChain = new Certificate[5];
    for (int i = 0; i < testChain.length; i++) {
        String s = (diffCerts ? Integer.toString(i) : "NEW");
        testChain[i] = new MyCertificate("MY_TEST_CERTIFICATE_".concat(s), encoded);
    }
    testPrivateKey = (diffKeys ? (PrivateKey) new tmpPrivateKey() : (PrivateKey) new tmpPrivateKey(testChain[0].getPublicKey().getAlgorithm()));
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate)

Example 12 with MyCertificate

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

the class KSTrustedCertificateEntryTest method testTrustedCertificateEntry.

/**
     * Test for <codfe>KeyStore.TrustedCertificateEntry(Certificate trustCert)</code>
     * constructor
     * Assertion: throws NullPointerException when trustCert is null
     */
public void testTrustedCertificateEntry() {
    Certificate cert = null;
    try {
        new KeyStore.TrustedCertificateEntry(cert);
        fail("NullPointerException must be thrown when trustCert is null");
    } catch (NullPointerException e) {
    }
    cert = new MyCertificate("TEST", new byte[10]);
    try {
        KeyStore.TrustedCertificateEntry ksTCE = new KeyStore.TrustedCertificateEntry(cert);
        assertNotNull(ksTCE);
        assertTrue(ksTCE instanceof KeyStore.TrustedCertificateEntry);
    } catch (Exception e) {
        fail("Unexpected exception was thrown when trustCert is not null");
    }
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) KeyStore(java.security.KeyStore) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate)

Example 13 with MyCertificate

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

the class PKIXCertPathCheckerTest method testCheck.

public final void testCheck() throws CertPathValidatorException {
    PKIXCertPathChecker pc = TestUtils.getTestCertPathChecker();
    pc.check(new MyCertificate("", null), new HashSet<String>());
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) PKIXCertPathChecker(java.security.cert.PKIXCertPathChecker)

Example 14 with MyCertificate

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

the class myCertificateFactory method testCertificateFactory16.

/**
     * Test for <code>generateCertPath(List certificates)</code> method
     * Assertion: throws CertificateException when certificates contains
     * incorrect Certificate
     */
public void testCertificateFactory16() {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    MyCertificate ms = createMC();
    List<Certificate> list = new Vector<Certificate>();
    list.add(ms);
    for (int i = 0; i < certFs.length; i++) {
        try {
            certFs[i].generateCertPath(list);
            fail("CertificateException must be thrown");
        } catch (CertificateException e) {
        }
    }
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) CertificateException(java.security.cert.CertificateException) 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 MyCertificate

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

the class myCertificateFactory method testCertificateFactory11.

/*
     * Test for <code> generateCertificate(InputStream inStream) </code><code>
     * generateCertificates(InputStream inStream) </code><code>
     * generateCRL(InputStream inStream) </code><code>
     * generateCRLs(InputStream inStream) </code>
     * methods
     * Assertion: throw CertificateException and CRLException when inStream
     * contains incompatible datas
     */
public void testCertificateFactory11() throws IOException {
    if (!X509Support) {
        fail(NotSupportMsg);
        return;
    }
    CertificateFactory[] certFs = initCertFs();
    assertNotNull("CertificateFactory objects were not created", certFs);
    MyCertificate mc = createMC();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(mc);
    oos.flush();
    oos.close();
    Certificate cer;
    Collection<?> colCer;
    CRL crl;
    Collection<?> colCrl;
    byte[] arr = os.toByteArray();
    ByteArrayInputStream is;
    for (int i = 0; i < certFs.length; i++) {
        is = new ByteArrayInputStream(arr);
        try {
            cer = certFs[i].generateCertificate(is);
            assertNull("Not null certificate was created", cer);
        } catch (CertificateException e) {
        }
        is = new ByteArrayInputStream(arr);
        try {
            colCer = certFs[i].generateCertificates(is);
            if (colCer != null) {
                assertTrue("Not empty certificate Collection was created", colCer.isEmpty());
            }
        } catch (CertificateException e) {
        }
        is = new ByteArrayInputStream(arr);
        try {
            crl = certFs[i].generateCRL(is);
            assertNull("Not null CRL was created", crl);
        } catch (CRLException e) {
        }
        is = new ByteArrayInputStream(arr);
        try {
            colCrl = certFs[i].generateCRLs(is);
            if (colCrl != null) {
                assertTrue("Not empty CRL Collection was created", colCrl.isEmpty());
            }
        } catch (CRLException e) {
        }
    }
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) CertificateException(java.security.cert.CertificateException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) CertificateFactory(java.security.cert.CertificateFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) CRL(java.security.cert.CRL) CRLException(java.security.cert.CRLException) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate)

Aggregations

MyCertificate (org.apache.harmony.security.tests.support.cert.MyCertificate)32 Certificate (java.security.cert.Certificate)26 MyFailingCertificate (org.apache.harmony.security.tests.support.cert.MyFailingCertificate)15 Vector (java.util.Vector)6 CollectionCertStoreParameters (java.security.cert.CollectionCertStoreParameters)5 ObjectStreamException (java.io.ObjectStreamException)4 CertificateException (java.security.cert.CertificateException)4 KeyStore (java.security.KeyStore)3 CertificateFactory (java.security.cert.CertificateFactory)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 MyCertificateRep (org.apache.harmony.security.tests.support.cert.MyCertificate.MyCertificateRep)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ObjectOutputStream (java.io.ObjectOutputStream)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 InvalidKeyException (java.security.InvalidKeyException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 PrivateKey (java.security.PrivateKey)1