Search in sources :

Example 76 with Certificate

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

the class HttpsURLConnectionTest method checkConnectionStateParameters.

/**
     * Checks the HttpsURLConnection getter's values and compares
     * them with actual corresponding values of remote peer.
     */
public static void checkConnectionStateParameters(HttpsURLConnection clientConnection, SSLSocket serverPeer) throws Exception {
    SSLSession session = serverPeer.getSession();
    assertEquals(session.getCipherSuite(), clientConnection.getCipherSuite());
    assertEquals(session.getLocalPrincipal(), clientConnection.getPeerPrincipal());
    assertEquals(session.getPeerPrincipal(), clientConnection.getLocalPrincipal());
    Certificate[] serverCertificates = clientConnection.getServerCertificates();
    Certificate[] localCertificates = session.getLocalCertificates();
    assertTrue("Server certificates differ from expected", Arrays.equals(serverCertificates, localCertificates));
    localCertificates = clientConnection.getLocalCertificates();
    serverCertificates = session.getPeerCertificates();
    assertTrue("Local certificates differ from expected", Arrays.equals(serverCertificates, localCertificates));
}
Also used : SSLSession(javax.net.ssl.SSLSession) Certificate(java.security.cert.Certificate)

Example 77 with Certificate

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

the class CollectionCertStoreParametersTest method testClone01.

/**
     * Test #1 for <code>clone()</code> method<br>
     */
public final void testClone01() {
    Vector<Certificate> certificates = new Vector<Certificate>();
    certificates.add(new MyCertificate("TEST", new byte[] { (byte) 4 }));
    CollectionCertStoreParameters cp1 = new CollectionCertStoreParameters(certificates);
    CollectionCertStoreParameters cp2 = (CollectionCertStoreParameters) cp1.clone();
    // check that that we have new object
    assertTrue(cp1 != cp2);
}
Also used : MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate) CollectionCertStoreParameters(java.security.cert.CollectionCertStoreParameters) Vector(java.util.Vector) Certificate(java.security.cert.Certificate) MyCertificate(org.apache.harmony.security.tests.support.cert.MyCertificate)

Example 78 with Certificate

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

the class KeyStoreTest method test_KeyStore_cacerts.

public void test_KeyStore_cacerts() throws Exception {
    if (StandardNames.IS_RI) {
        return;
    }
    KeyStore ks = KeyStore.getInstance("AndroidCAStore");
    assertEquals("AndroidCAStore", ks.getType());
    assertEquals("HarmonyJSSE", ks.getProvider().getName());
    ks.load(null, null);
    for (String alias : Collections.list(ks.aliases())) {
        Certificate c = null;
        try {
            c = ks.getCertificate(alias);
            assertNotNull(c);
            assertTrue(ks.isCertificateEntry(alias));
            assertTrue(ks.entryInstanceOf(alias, TrustedCertificateEntry.class));
            assertEquals(alias, ks.getCertificateAlias(c));
            assertTrue(c instanceof X509Certificate);
            X509Certificate cert = (X509Certificate) c;
            assertEquals(cert.getSubjectUniqueID(), cert.getIssuerUniqueID());
            assertNotNull(cert.getPublicKey());
            assertTrue(ks.containsAlias(alias));
            assertNotNull(ks.getCreationDate(alias));
            assertNotNull(ks.getEntry(alias, null));
            assertFalse(ks.isKeyEntry(alias));
            assertNull(ks.getKey(alias, null));
            assertNull(ks.getCertificateChain(alias));
        } catch (Throwable t) {
            throw new Exception("alias=" + alias + " cert=" + c, t);
        }
    }
}
Also used : KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) KeyStoreException(java.security.KeyStoreException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) TrustedCertificateEntry(java.security.KeyStore.TrustedCertificateEntry)

Example 79 with Certificate

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

the class CertificateFactoryTest method test_generateCertificate_InputStream_InvalidStart_Failure.

private void test_generateCertificate_InputStream_InvalidStart_Failure(CertificateFactory cf) throws Exception {
    try {
        Certificate c = cf.generateCertificate(new ByteArrayInputStream("-----BEGIN CERTIFICATE-----".getBytes()));
        if (!"BC".equals(cf.getProvider().getName())) {
            fail("should throw CertificateException: " + cf.getProvider().getName());
        }
        assertNull(c);
    } catch (CertificateException expected) {
        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 80 with Certificate

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

the class CertificateFactoryTest method test_generateCertificate_InputStream_Offset_Correct.

private void test_generateCertificate_InputStream_Offset_Correct(CertificateFactory cf) throws Exception {
    byte[] valid = VALID_CERTIFICATE_PEM.getBytes();
    byte[] doubleCertificateData = new byte[valid.length * 2];
    System.arraycopy(valid, 0, doubleCertificateData, 0, valid.length);
    System.arraycopy(valid, 0, doubleCertificateData, valid.length, valid.length);
    MeasuredInputStream certStream = new MeasuredInputStream(new ByteArrayInputStream(doubleCertificateData));
    Certificate certificate = cf.generateCertificate(certStream);
    assertNotNull(certificate);
    assertEquals(valid.length, certStream.getCount());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

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