use of javax.net.ssl.SSLSocketFactory in project robovm by robovm.
the class SSLSocketTest method test_SSLSocket_setSoTimeout_wrapper.
public void test_SSLSocket_setSoTimeout_wrapper() throws Exception {
if (StandardNames.IS_RI) {
// RI cannot handle this case
return;
}
ServerSocket listening = new ServerSocket(0);
// setSoTimeout applies to read, not connect, so connect first
Socket underlying = new Socket(listening.getInetAddress(), listening.getLocalPort());
Socket server = listening.accept();
SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
Socket clientWrapping = sf.createSocket(underlying, null, -1, false);
underlying.setSoTimeout(1);
try {
clientWrapping.getInputStream().read();
fail();
} catch (SocketTimeoutException expected) {
}
clientWrapping.close();
server.close();
underlying.close();
listening.close();
}
use of javax.net.ssl.SSLSocketFactory in project robovm by robovm.
the class SSLContextSpiTest method test_commonTest_01.
/**
* SSLContextSpi#engineGetClientSessionContext()
* SSLContextSpi#engineGetServerSessionContext()
* SSLContextSpi#engineGetServerSocketFactory()
* SSLContextSpi#engineGetSocketFactory()
* Verify exception when SSLContextSpi object wasn't initialiazed.
*/
public void test_commonTest_01() {
SSLContextSpiImpl ssl = new SSLContextSpiImpl();
try {
SSLSessionContext slsc = ssl.engineGetClientSessionContext();
fail("RuntimeException wasn't thrown");
} catch (RuntimeException re) {
String str = re.getMessage();
if (!str.equals("Not initialiazed"))
fail("Incorrect exception message: " + str);
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown");
}
try {
SSLSessionContext slsc = ssl.engineGetServerSessionContext();
fail("RuntimeException wasn't thrown");
} catch (RuntimeException re) {
String str = re.getMessage();
if (!str.equals("Not initialiazed"))
fail("Incorrect exception message: " + str);
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown");
}
try {
SSLServerSocketFactory sssf = ssl.engineGetServerSocketFactory();
fail("RuntimeException wasn't thrown");
} catch (RuntimeException re) {
String str = re.getMessage();
if (!str.equals("Not initialiazed"))
fail("Incorrect exception message: " + str);
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown");
}
try {
SSLSocketFactory ssf = ssl.engineGetSocketFactory();
fail("RuntimeException wasn't thrown");
} catch (RuntimeException re) {
String str = re.getMessage();
if (!str.equals("Not initialiazed"))
fail("Incorrect exception message: " + str);
} catch (Exception e) {
fail("Incorrect exception " + e + " was thrown");
}
}
use of javax.net.ssl.SSLSocketFactory in project robovm by robovm.
the class myHostnameVerifier method test_getSSLSocketFactory.
/**
* javax.net.ssl.HttpsURLConnection#getSSLSocketFactory()
*/
public final void test_getSSLSocketFactory() {
HttpsURLConnection con = new MyHttpsURLConnection(null);
SSLSocketFactory sf = con.getSSLSocketFactory();
if (!sf.equals(SSLSocketFactory.getDefault())) {
fail("incorrect DefaultSSLSocketFactory");
}
}
use of javax.net.ssl.SSLSocketFactory in project robovm by robovm.
the class myHostnameVerifier method test_setDefaultSSLSocketFactory.
/**
* javax.net.ssl.HttpsURLConnection#setDefaultSSLSocketFactory()
*/
public final void test_setDefaultSSLSocketFactory() {
try {
HttpsURLConnection.setDefaultSSLSocketFactory(null);
fail("No expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
HttpsURLConnection.setDefaultSSLSocketFactory(ssf);
}
use of javax.net.ssl.SSLSocketFactory in project ion by koush.
the class ConscryptMiddleware method initialize.
public static void initialize(Context context) {
try {
synchronized (lock) {
if (initialized)
return;
initialized = true;
// GMS Conscrypt is already initialized, from outside ion. Leave it alone.
if (Security.getProvider(GMS_PROVIDER) != null) {
success = true;
return;
}
SSLContext originalDefaultContext = SSLContext.getDefault();
SSLSocketFactory originalDefaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
try {
Class<?> providerInstaller = Class.forName("com.google.android.gms.security.ProviderInstaller");
Method mInsertProvider = providerInstaller.getDeclaredMethod("installIfNeeded", Context.class);
mInsertProvider.invoke(null, context);
} catch (Throwable ignored) {
Context gms = context.createPackageContext("com.google.android.gms", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
gms.getClassLoader().loadClass("com.google.android.gms.common.security.ProviderInstallerImpl").getMethod("insertProvider", Context.class).invoke(null, context);
}
Provider[] providers = Security.getProviders();
Provider provider = Security.getProvider(GMS_PROVIDER);
Security.removeProvider(GMS_PROVIDER);
Security.insertProviderAt(provider, providers.length);
SSLContext.setDefault(originalDefaultContext);
HttpsURLConnection.setDefaultSSLSocketFactory(originalDefaultSSLSocketFactory);
success = true;
}
} catch (Exception e) {
Log.w(LOGTAG, "Conscrypt initialization failed.");
}
}
Aggregations