Search in sources :

Example 51 with KeyManagementException

use of java.security.KeyManagementException in project robovm by robovm.

the class SSLParametersImpl method createDefaultKeyManager.

private static X509KeyManager createDefaultKeyManager() throws KeyManagementException {
    try {
        String algorithm = KeyManagerFactory.getDefaultAlgorithm();
        KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
        kmf.init(null, null);
        KeyManager[] kms = kmf.getKeyManagers();
        return findX509KeyManager(kms);
    } catch (NoSuchAlgorithmException e) {
        throw new KeyManagementException(e);
    } catch (KeyStoreException e) {
        throw new KeyManagementException(e);
    } catch (UnrecoverableKeyException e) {
        throw new KeyManagementException(e);
    }
}
Also used : UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) X509KeyManager(javax.net.ssl.X509KeyManager) KeyManager(javax.net.ssl.KeyManager) KeyManagementException(java.security.KeyManagementException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 52 with KeyManagementException

use of java.security.KeyManagementException in project robovm by robovm.

the class SSLParametersImpl method createDefaultTrustManager.

private static X509TrustManager createDefaultTrustManager() throws KeyManagementException {
    try {
        String algorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
        tmf.init((KeyStore) null);
        TrustManager[] tms = tmf.getTrustManagers();
        X509TrustManager trustManager = findX509TrustManager(tms);
        return trustManager;
    } catch (NoSuchAlgorithmException e) {
        throw new KeyManagementException(e);
    } catch (KeyStoreException e) {
        throw new KeyManagementException(e);
    }
}
Also used : X509TrustManager(javax.net.ssl.X509TrustManager) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 53 with KeyManagementException

use of java.security.KeyManagementException in project robovm by robovm.

the class IdentityTest method testAddCertificate1.

/**
     * verify addCertificate(Certificate certificate) adds a certificate for this identity.
     * If the identity has a public key, the public key in the certificate must be the same
     *
     */
public void testAddCertificate1() throws Exception {
    Identity i = new IdentityStub("iii");
    PublicKeyStub pk1 = new PublicKeyStub("kkk", "fff", new byte[] { 1, 2, 3, 4, 5 });
    i.setPublicKey(pk1);
    // try with the same key
    CertificateStub c1 = new CertificateStub("fff", null, null, pk1);
    i.addCertificate(c1);
    assertSame(c1, i.certificates()[0]);
    // try Certificate with different key
    try {
        i.addCertificate(new CertificateStub("ccc", null, null, new PublicKeyStub("k2", "fff", new byte[] { 6, 7, 8, 9, 0 })));
        fail("KeyManagementException should be thrown");
    } catch (KeyManagementException ok) {
    }
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) CertificateStub(org.apache.harmony.security.tests.support.CertificateStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity) KeyManagementException(java.security.KeyManagementException)

Example 54 with KeyManagementException

use of java.security.KeyManagementException in project robovm by robovm.

the class IdentityTest method testAddCertificate4.

/**
     * verify addCertificate(Certificate certificate) throws KeyManagementException if certificate is null
     */
public void testAddCertificate4() throws Exception {
    try {
        new IdentityStub("aaa").addCertificate(null);
        fail("KeyManagementException should be thrown");
    } catch (KeyManagementException ok) {
    } catch (NullPointerException ok) {
    }
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) KeyManagementException(java.security.KeyManagementException)

Example 55 with KeyManagementException

use of java.security.KeyManagementException in project robovm by robovm.

the class IdentityTest method testSetPublicKey2.

/**
     *
     * verify Identity.setPublicKey() throws KeyManagementException if key is invalid
     *
     */
public void testSetPublicKey2() throws Exception {
    Identity i2 = new IdentityStub("testSetPublicKey2_2", IdentityScope.getSystemScope());
    new PublicKeyStub("kkk", "testSetPublicKey2", new byte[] { 1, 2, 3, 4, 5 });
    try {
        i2.setPublicKey(null);
    //fail("KeyManagementException should be thrown - key is null");
    } catch (KeyManagementException ok) {
    }
}
Also used : IdentityStub(org.apache.harmony.security.tests.support.IdentityStub) PublicKeyStub(org.apache.harmony.security.tests.support.PublicKeyStub) Identity(java.security.Identity) KeyManagementException(java.security.KeyManagementException)

Aggregations

KeyManagementException (java.security.KeyManagementException)157 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)111 SSLContext (javax.net.ssl.SSLContext)83 KeyStoreException (java.security.KeyStoreException)60 IOException (java.io.IOException)55 TrustManager (javax.net.ssl.TrustManager)45 CertificateException (java.security.cert.CertificateException)35 X509TrustManager (javax.net.ssl.X509TrustManager)28 SecureRandom (java.security.SecureRandom)27 X509Certificate (java.security.cert.X509Certificate)26 UnrecoverableKeyException (java.security.UnrecoverableKeyException)24 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)24 KeyStore (java.security.KeyStore)22 KeyManager (javax.net.ssl.KeyManager)19 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)16 HostnameVerifier (javax.net.ssl.HostnameVerifier)15 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)15 InputStream (java.io.InputStream)12 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)11 SSLSession (javax.net.ssl.SSLSession)10