use of javax.net.ssl.KeyManager 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));
}
}
use of javax.net.ssl.KeyManager in project robovm by robovm.
the class SSLServerSocketTest method test_creationStressTest.
public void test_creationStressTest() throws Exception {
KeyManager[] keyManagers = getKeyManagers();
// Test the default codepath, which uses /dev/urandom.
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, null, null);
for (int i = 0; i < 2048; ++i) {
sslContext.getServerSocketFactory().createServerSocket().close();
}
// Test the other codepath, which copies a seed from a byte[].
sslContext.init(keyManagers, null, new SecureRandom());
for (int i = 0; i < 2048; ++i) {
sslContext.getServerSocketFactory().createServerSocket().close();
}
}
use of javax.net.ssl.KeyManager 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);
}
}
use of javax.net.ssl.KeyManager in project robovm by robovm.
the class KeyManagerFactoryTest method test_KeyManagerFactory_getKeyManagers.
private void test_KeyManagerFactory_getKeyManagers(KeyManagerFactory kmf, boolean empty) throws Exception {
KeyManager[] keyManagers = kmf.getKeyManagers();
assertNotNull(keyManagers);
assertTrue(keyManagers.length > 0);
for (KeyManager keyManager : keyManagers) {
assertNotNull(keyManager);
if (keyManager instanceof X509KeyManager) {
test_X509KeyManager((X509KeyManager) keyManager, empty, kmf.getAlgorithm());
}
}
}
use of javax.net.ssl.KeyManager in project robovm by robovm.
the class HttpsURLConnectionTest method getContext.
/**
* Builds and returns the context used for secure socket creation.
*/
private static SSLContext getContext() throws Exception {
String type = KeyStore.getDefaultType();
String keyStore = getKeyStoreFileName();
File keyStoreFile = new File(keyStore);
FileInputStream fis = new FileInputStream(keyStoreFile);
KeyStore ks = KeyStore.getInstance(type);
ks.load(fis, KS_PASSWORD.toCharArray());
fis.close();
if (DO_LOG && false) {
TestKeyStore.dump("HttpsURLConnection.getContext", ks, KS_PASSWORD.toCharArray());
}
String kmfAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
KeyManagerFactory kmf = KeyManagerFactory.getInstance(kmfAlgorithm);
kmf.init(ks, KS_PASSWORD.toCharArray());
KeyManager[] keyManagers = kmf.getKeyManagers();
String tmfAlgorthm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorthm);
tmf.init(ks);
TrustManager[] trustManagers = tmf.getTrustManagers();
if (DO_LOG) {
trustManagers = TestTrustManager.wrap(trustManagers);
}
SSLContext ctx = SSLContext.getInstance("TLSv1");
ctx.init(keyManagers, trustManagers, null);
return ctx;
}
Aggregations