Search in sources :

Example 26 with KeyManagerFactory

use of javax.net.ssl.KeyManagerFactory in project robovm by robovm.

the class ProtectionParameterImpl method test_initLjava_security_KeyStore$C.

/**
     * Test for <code>init(KeyStore keyStore, char[] password)</code> and
     * <code>getKeyManagers()</code>
     * Assertion: returns not empty KeyManager array
     */
public void test_initLjava_security_KeyStore$C() throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
    if (!DEFSupported) {
        fail(NotSupportedMsg);
        return;
    }
    KeyManagerFactory[] keyMF = createKMFac();
    assertNotNull("KeyManagerFactory object were not created", keyMF);
    KeyStore ksNull = null;
    KeyManager[] km;
    for (int i = 0; i < keyMF.length; i++) {
        keyMF[i].init(ksNull, new char[10]);
        km = keyMF[i].getKeyManagers();
        assertNotNull("Result should not be null", km);
        assertTrue("Length of result KeyManager array should not be 0", (km.length > 0));
    }
    KeyStore ks;
    try {
        ks = KeyStore.getInstance(KeyStore.getDefaultType());
        ks.load(null, null);
    } catch (KeyStoreException e) {
        fail(e.toString() + "default KeyStore type is not supported");
        return;
    } catch (Exception e) {
        fail("Unexpected: " + e.toString());
        return;
    }
    for (int i = 0; i < keyMF.length; i++) {
        try {
            keyMF[i].init(ks, new char[10]);
        } catch (KeyStoreException e) {
        }
        km = keyMF[i].getKeyManagers();
        assertNotNull("Result has not be null", km);
        assertTrue("Length of result KeyManager array should not be 0", (km.length > 0));
    }
}
Also used : KeyStoreException(java.security.KeyStoreException) KeyStore(java.security.KeyStore) KeyManager(javax.net.ssl.KeyManager) IOException(java.io.IOException) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchProviderException(java.security.NoSuchProviderException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 27 with KeyManagerFactory

use of javax.net.ssl.KeyManagerFactory in project robovm by robovm.

the class ProtectionParameterImpl method test_getInstanceLjava_lang_StringLjava_lang_String04.

/**
     * Test for <code>getInstance(String algorithm, String provider)</code>
     * method Assertion: returns instance of KeyManagerFactory
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String04() throws NoSuchProviderException, NoSuchAlgorithmException {
    if (!DEFSupported) {
        fail(NotSupportedMsg);
        return;
    }
    KeyManagerFactory kMF;
    for (int i = 0; i < validValues.length; i++) {
        kMF = KeyManagerFactory.getInstance(validValues[i], defaultProviderName);
        assertNotNull("No KeyManagerFactory created", kMF);
        assertEquals("Incorrect algorithm", kMF.getAlgorithm(), validValues[i]);
        assertEquals("Incorrect provider", kMF.getProvider().getName(), defaultProviderName);
    }
}
Also used : KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 28 with KeyManagerFactory

use of javax.net.ssl.KeyManagerFactory in project robovm by robovm.

the class ProtectionParameterImpl method test_getKeyManagers.

/**
     * avax.net.ssl.KeyManagerFactory#getKeyManagers()
     * @throws NoSuchAlgorithmException
     * @throws KeyStoreException
     * @throws IOException
     * @throws CertificateException
     * @throws UnrecoverableKeyException
     */
public void test_getKeyManagers() throws Exception {
    if (!DEFSupported)
        fail(NotSupportedMsg);
    KeyManagerFactory kmf = KeyManagerFactory.getInstance(defaultAlgorithm);
    char[] pass = "password".toCharArray();
    kmf.init(null, pass);
    assertNotNull("Key manager array is null", kmf.getKeyManagers());
    assertEquals("Incorrect size of array", 1, kmf.getKeyManagers().length);
}
Also used : KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 29 with KeyManagerFactory

use of javax.net.ssl.KeyManagerFactory in project robovm by robovm.

the class KeyManagerFactory2Test method test_getInstanceLjava_lang_StringLjava_lang_String.

/**
     * Test for <code>getInstance(String algorithm, String provider)</code>
     * method
     * Assertions:
     * throws NullPointerException when algorithm is null;
     * throws NoSuchAlgorithmException when algorithm is not correct;
     * throws IllegalArgumentException when provider is null or empty;
     * throws NoSuchProviderException when provider is available;
     * returns KeyManagerFactory object
     */
public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
    try {
        KeyManagerFactory.getInstance(null, mProv.getName());
        fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
    } catch (NoSuchAlgorithmException e) {
    } catch (NullPointerException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            KeyManagerFactory.getInstance(invalidValues[i], mProv.getName());
            fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
        } catch (NoSuchAlgorithmException e) {
        }
    }
    String prov = null;
    for (int i = 0; i < validValues.length; i++) {
        try {
            KeyManagerFactory.getInstance(validValues[i], prov);
            fail("IllegalArgumentException must be thrown when provider is null (algorithm: ".concat(invalidValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
        try {
            KeyManagerFactory.getInstance(validValues[i], "");
            fail("IllegalArgumentException must be thrown when provider is empty (algorithm: ".concat(invalidValues[i]).concat(")"));
        } catch (IllegalArgumentException e) {
        }
    }
    for (int i = 0; i < validValues.length; i++) {
        for (int j = 1; j < invalidValues.length; j++) {
            try {
                KeyManagerFactory.getInstance(validValues[i], invalidValues[j]);
                fail("NoSuchProviderException must be thrown (algorithm: ".concat(invalidValues[i]).concat(" provider: ").concat(invalidValues[j]).concat(")"));
            } catch (NoSuchProviderException e) {
            }
        }
    }
    KeyManagerFactory keyMF;
    for (int i = 0; i < validValues.length; i++) {
        keyMF = KeyManagerFactory.getInstance(validValues[i], mProv.getName());
        assertEquals("Incorrect algorithm", keyMF.getAlgorithm(), validValues[i]);
        assertEquals("Incorrect provider", keyMF.getProvider().getName(), mProv.getName());
        checkResult(keyMF);
    }
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 30 with KeyManagerFactory

use of javax.net.ssl.KeyManagerFactory in project robovm by robovm.

the class KeyManagerFactory2Test method test_getInstanceLjava_lang_String.

/**
     * Test for <code>getInstance(String algorithm)</code> method
     * Assertions:
     * throws NullPointerException when algorithm is null;
     * throws NoSuchAlgorithmException when algorithm is not correct;
     * returns KeyManagerFactory object
     */
public void test_getInstanceLjava_lang_String() throws Exception {
    try {
        KeyManagerFactory.getInstance(null);
        fail("NoSuchAlgorithmException or NullPointerException should be thrown (algorithm is null");
    } catch (NoSuchAlgorithmException e) {
    } catch (NullPointerException e) {
    }
    for (int i = 0; i < invalidValues.length; i++) {
        try {
            KeyManagerFactory.getInstance(invalidValues[i]);
            fail("NoSuchAlgorithmException must be thrown (algorithm: ".concat(invalidValues[i]).concat(")"));
        } catch (NoSuchAlgorithmException e) {
        }
    }
    KeyManagerFactory keyMF;
    for (int i = 0; i < validValues.length; i++) {
        keyMF = KeyManagerFactory.getInstance(validValues[i]);
        assertEquals("Incorrect algorithm", keyMF.getAlgorithm(), validValues[i]);
        assertEquals("Incorrect provider", keyMF.getProvider(), mProv);
        checkResult(keyMF);
    }
}
Also used : NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Aggregations

KeyManagerFactory (javax.net.ssl.KeyManagerFactory)156 KeyStore (java.security.KeyStore)114 SSLContext (javax.net.ssl.SSLContext)80 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)69 FileInputStream (java.io.FileInputStream)44 KeyManager (javax.net.ssl.KeyManager)31 TrustManager (javax.net.ssl.TrustManager)30 IOException (java.io.IOException)29 InputStream (java.io.InputStream)28 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)28 KeyStoreException (java.security.KeyStoreException)21 SecureRandom (java.security.SecureRandom)18 UnrecoverableKeyException (java.security.UnrecoverableKeyException)18 KeyManagementException (java.security.KeyManagementException)17 CertificateException (java.security.cert.CertificateException)17 File (java.io.File)10 Certificate (java.security.cert.Certificate)10 NoSuchProviderException (java.security.NoSuchProviderException)9 SSLEngine (javax.net.ssl.SSLEngine)9 X509TrustManager (javax.net.ssl.X509TrustManager)9