use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class HttpsURLConnectionTest method testSetDefaultSSLSocketFactory.
/**
* Tests possibility to set up the default SSLSocketFactory
* to be used by HttpsURLConnection.
*/
public void testSetDefaultSSLSocketFactory() throws Throwable {
// create the SSLServerSocket which will be used by server side
SSLContext ctx = getContext();
SSLServerSocket ss = (SSLServerSocket) ctx.getServerSocketFactory().createServerSocket(0);
SSLSocketFactory socketFactory = (SSLSocketFactory) ctx.getSocketFactory();
// set up the factory as default
HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory);
// check the result
assertSame("Default SSLSocketFactory differs from expected", socketFactory, HttpsURLConnection.getDefaultSSLSocketFactory());
// create the HostnameVerifier to check hostname verification
TestHostnameVerifier hnv = new TestHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
// create HttpsURLConnection to be tested
URL url = new URL("https://localhost:" + ss.getLocalPort());
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
TestHostnameVerifier hnv_late = new TestHostnameVerifier();
// late initialization: should not be used for created connection
HttpsURLConnection.setDefaultHostnameVerifier(hnv_late);
// perform the interaction between the peers
SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
// check the connection state
checkConnectionStateParameters(connection, peerSocket);
// check the verification process
assertTrue("Hostname verification was not done", hnv.verified);
assertFalse("Hostname verification should not be done by this verifier", hnv_late.verified);
// check the used SSLSocketFactory
assertSame("Default SSLSocketFactory should be used", HttpsURLConnection.getDefaultSSLSocketFactory(), connection.getSSLSocketFactory());
// should silently exit
connection.connect();
}
use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class HttpsURLConnectionTest method testProxyAuthConnectionFailed.
/**
* Tests HTTPS connection process made through the proxy server.
* Proxy server needs authentication but client fails to authenticate
* (Authenticator was not set up in the system).
*/
public void testProxyAuthConnectionFailed() throws Throwable {
// setting up the properties pointing to the key/trust stores
setUpStoreProperties();
// create the SSLServerSocket which will be used by server side
ServerSocket ss = new ServerSocket(0);
// create the HostnameVerifier to check that Hostname verification
// is done
TestHostnameVerifier hnv = new TestHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
// create HttpsURLConnection to be tested
URL url = new URL("https://requested.host:55555/requested.data");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", ss.getLocalPort())));
connection.setSSLSocketFactory(getContext().getSocketFactory());
// perform the interaction between the peers and check the results
try {
doInteraction(connection, ss, AUTHENTICATION_REQUIRED_CODE, true);
} catch (IOException e) {
// SSL Tunnelling failed
if (DO_LOG) {
System.out.println("Got expected IOException: " + e.getMessage());
}
}
}
use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class HttpsURLConnectionTest method testProxyConnection_Not_Found_Response.
/**
* Tests the behaviour of HTTPS connection in case of unavailability
* of requested resource.
*/
public void testProxyConnection_Not_Found_Response() throws Throwable {
// setting up the properties pointing to the key/trust stores
setUpStoreProperties();
// create the SSLServerSocket which will be used by server side
ServerSocket ss = new ServerSocket(0);
// create the HostnameVerifier to check that Hostname verification
// is done
TestHostnameVerifier hnv = new TestHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
// create HttpsURLConnection to be tested
URL url = new URL("https://localhost:" + ss.getLocalPort());
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", ss.getLocalPort())));
connection.setSSLSocketFactory(getContext().getSocketFactory());
try {
// NOT FOUND
doInteraction(connection, ss, NOT_FOUND_CODE);
fail("Expected exception was not thrown.");
} catch (FileNotFoundException e) {
if (DO_LOG) {
System.out.println("Expected exception was thrown: " + e.getMessage());
}
}
}
use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class HttpsURLConnectionTest method testSetHostnameVerifier.
/**
* Tests if setHostnameVerifier() method replaces default verifier.
*/
public void testSetHostnameVerifier() throws Throwable {
// setting up the properties pointing to the key/trust stores
setUpStoreProperties();
// create the SSLServerSocket which will be used by server side
SSLServerSocket ss = (SSLServerSocket) getContext().getServerSocketFactory().createServerSocket(0);
// create the HostnameVerifier to check that Hostname verification
// is done
TestHostnameVerifier hnv = new TestHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
// create HttpsURLConnection to be tested
URL url = new URL("https://localhost:" + ss.getLocalPort());
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setSSLSocketFactory(getContext().getSocketFactory());
TestHostnameVerifier hnv_late = new TestHostnameVerifier();
// replace default verifier
connection.setHostnameVerifier(hnv_late);
// perform the interaction between the peers and check the results
SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
assertTrue("Hostname verification was not done", hnv_late.verified);
assertFalse("Hostname verification should not be done by this verifier", hnv.verified);
checkConnectionStateParameters(connection, peerSocket);
// should silently exit
connection.connect();
}
use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class HttpsURLConnectionTest method test_doOutput.
/**
* Tests the behaviour in case of sending the data to the server.
*/
public void test_doOutput() throws Throwable {
// setting up the properties pointing to the key/trust stores
setUpStoreProperties();
// create the SSLServerSocket which will be used by server side
SSLServerSocket ss = (SSLServerSocket) getContext().getServerSocketFactory().createServerSocket(0);
// create the HostnameVerifier to check that Hostname verification
// is done
TestHostnameVerifier hnv = new TestHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
// create HttpsURLConnection to be tested
URL url = new URL("https://localhost:" + ss.getLocalPort());
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setSSLSocketFactory(getContext().getSocketFactory());
connection.setDoOutput(true);
// perform the interaction between the peers and check the results
SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
checkConnectionStateParameters(connection, peerSocket);
// should silently exit
connection.connect();
}
Aggregations