use of java.security.KeyStore 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;
}
use of java.security.KeyStore in project robovm by robovm.
the class MyProvider method test_engineInit_02.
/**
* @throws InvalidAlgorithmParameterException
* @throws NoSuchAlgorithmException
* javax.net.ssl.TrustManagerFactorySpi#engineInit(ManagerFactoryParameters spec)
*/
public void test_engineInit_02() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {
factory.reset();
Provider provider = new MyProvider();
TrustManagerFactory tmf = TrustManagerFactory.getInstance("MyTMF", provider);
Parameters pr = null;
try {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
pr = new Parameters(ks);
tmf.init(pr);
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
assertTrue(factory.isEngineInitCalled());
assertEquals(pr, factory.getSpec());
factory.reset();
tmf.init((ManagerFactoryParameters) null);
assertTrue(factory.isEngineInitCalled());
assertNull(factory.getSpec());
}
use of java.security.KeyStore in project robovm by robovm.
the class MyProvider method test_engineGetTrustManagers.
/**
* @throws NoSuchAlgorithmException
* javax.net.ssl.TrustManagerFactorySpi#engineGetTrustManagers()
*/
public void test_engineGetTrustManagers() throws NoSuchAlgorithmException {
factory.reset();
Provider provider = new MyProvider();
TrustManagerFactory tmf = TrustManagerFactory.getInstance("MyTMF", provider);
TrustManager[] tm = tmf.getTrustManagers();
assertTrue(factory.isEngineGetTrustManagersCalled());
factory.reset();
try {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
tmf.init(ks);
tm = tmf.getTrustManagers();
assertTrue(factory.isEngineGetTrustManagersCalled());
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
}
use of java.security.KeyStore in project robovm by robovm.
the class myTrustManagerFactory method test_initLjava_security_KeyStore_01.
/**
* Test for <code>init(KeyStore keyStore)</code>
* Assertion: call method with null parameter
*/
public void test_initLjava_security_KeyStore_01() throws Exception {
KeyStore ksNull = null;
TrustManagerFactory[] trustMF = createTMFac();
assertNotNull("TrustManagerFactory objects were not created", trustMF);
// null parameter
try {
trustMF[0].init(ksNull);
} catch (Exception ex) {
fail(ex + " unexpected exception was thrown for null parameter");
}
}
use of java.security.KeyStore in project robovm by robovm.
the class myTrustManagerFactory method test_getTrustManagers.
/**
* Test for <code>geTrustManagers()</code>
* @throws KeyStoreException
* @throws IOException
* @throws CertificateException
* @throws NoSuchAlgorithmException
*/
public void test_getTrustManagers() {
try {
TrustManagerFactory trustMF = TrustManagerFactory.getInstance(getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
trustMF.init(ks);
TrustManager[] tm = trustMF.getTrustManagers();
assertNotNull("Result has not be null", tm);
assertTrue("Length of result TrustManager array should not be 0", (tm.length > 0));
} catch (Exception ex) {
fail("Unexpected exception " + ex.toString());
}
}
Aggregations