Search in sources :

Example 81 with Certificate

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

the class CertificateFactoryTest method test_generateCertificate_InputStream_Empty.

private void test_generateCertificate_InputStream_Empty(CertificateFactory cf) throws Exception {
    try {
        Certificate c = cf.generateCertificate(new ByteArrayInputStream(new byte[0]));
        if (!"BC".equals(cf.getProvider().getName())) {
            fail("should throw CertificateException: " + cf.getProvider().getName());
        }
        assertNull(c);
    } catch (CertificateException e) {
        if ("BC".equals(cf.getProvider().getName())) {
            fail("should return null: " + cf.getProvider().getName());
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 82 with Certificate

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

the class KeyStore2Test method test_getCertificateChainLjava_lang_String.

/**
     * java.security.KeyStore#getCertificateChain(java.lang.String)
     */
public void test_getCertificateChainLjava_lang_String() throws Exception {
    // Test for method java.security.cert.Certificate[]
    // java.security.KeyStore.getCertificateChain(java.lang.String)
    // creatCertificate();
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    X509Certificate[] cert = new X509Certificate[2];
    cert[0] = (X509Certificate) cf.generateCertificate(certArray);
    cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
    KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
    try {
        keyTest.getCertificateChain("anAlias");
        fail();
    } catch (KeyStoreException expected) {
    }
    keyTest.load(null, null);
    // alias 1
    keyTest.setCertificateEntry("alias1", cert[0]);
    // alias 2
    keyTest.setKeyEntry("alias2", getPrivateKey(), pssWord, cert);
    Certificate[] certRes = keyTest.getCertificateChain("alias2");
    assertEquals("there are more than two certificate returned from getCertificateChain", 2, certRes.length);
    assertEquals("the first certificate returned from getCertificateChain is not correct", cert[0].getPublicKey(), certRes[0].getPublicKey());
    assertEquals("the second certificate returned from getCertificateChain is not correct", cert[1].getPublicKey(), certRes[1].getPublicKey());
    Certificate[] certResNull = keyTest.getCertificateChain("alias1");
    assertNull("the certificate chain returned from getCertificateChain is NOT null", certResNull);
    try {
        keyTest.getCertificateChain(null);
        fail();
    } catch (NullPointerException expected) {
    }
}
Also used : KeyStoreException(java.security.KeyStoreException) CertificateFactory(java.security.cert.CertificateFactory) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 83 with Certificate

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

the class KSTrustedCertificateEntryTest method testToString.

/**
     * Test for <codfe>toString()</code> method
     * Assertion: returns non null string
     */
public void testToString() {
    Certificate cert = new MyCertificate("TEST", new byte[10]);
    KeyStore.TrustedCertificateEntry ksTCE = new KeyStore.TrustedCertificateEntry(cert);
    assertNotNull("toString() returns null string", ksTCE.toString());
}
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 84 with Certificate

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

the class KSTrustedCertificateEntryTest method testGetTrustedCertificate.

/**
     * Test for <codfe>getTrustedCertificate()</code> method
     * Assertion: returns trusted Certificate from goven entry
     */
public void testGetTrustedCertificate() {
    Certificate cert = new MyCertificate("TEST", new byte[10]);
    KeyStore.TrustedCertificateEntry ksTCE = new KeyStore.TrustedCertificateEntry(cert);
    assertEquals("Incorrect certificate", cert, ksTCE.getTrustedCertificate());
}
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 85 with Certificate

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

the class KSPrivateKeyEntryTest method testPrivateKeyEntry01.

/**
     * Test for <code>PrivateKeyEntry(PrivateKey privateKey, Certificate[] chain)</code>
     * constructor
     * Assertion: throws NullPointerException when privateKey is null
     */
public void testPrivateKeyEntry01() {
    //new Certificate[1];
    Certificate[] certs = new MyCertificate[1];
    PrivateKey pk = null;
    try {
        new KeyStore.PrivateKeyEntry(pk, certs);
        fail("NullPointerException must be thrown when privateKey is null");
    } catch (NullPointerException e) {
    }
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) PrivateKey(java.security.PrivateKey) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate)

Aggregations

Certificate (java.security.cert.Certificate)723 X509Certificate (java.security.cert.X509Certificate)469 CertificateFactory (java.security.cert.CertificateFactory)272 ByteArrayInputStream (java.io.ByteArrayInputStream)237 KeyStore (java.security.KeyStore)133 PrivateKey (java.security.PrivateKey)132 IOException (java.io.IOException)106 CertificateException (java.security.cert.CertificateException)102 KeyFactory (java.security.KeyFactory)89 KeyStoreException (java.security.KeyStoreException)88 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)72 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)69 PrivateKeyEntry (java.security.KeyStore.PrivateKeyEntry)63 ArrayList (java.util.ArrayList)63 TrustedCertificateEntry (java.security.KeyStore.TrustedCertificateEntry)56 Entry (java.security.KeyStore.Entry)53 PublicKey (java.security.PublicKey)48 InputStream (java.io.InputStream)40 FileInputStream (java.io.FileInputStream)39 Key (java.security.Key)36