Java WebSockets and SocketIO SSL seem incompatible on android #60
Description
I was getting silent failures whenever using SSL on android. I ended up install the source for this project and the Java WebSockets project and debugged where the exception was occuring. This was the exception causing it to not work
"org.apache.harmony.xnet.provider.jsse.OpenSSLSessionImpl cannot be cast to org.apache.harmony.xnet.provider.jsse.SSLSessionImpl"
It turns out for some reason the SSLContext SSLContext.getDefault works great for socket.io and it can negotiate just fine. But when it calls the parent "transport" it does not work because the parent needs the "HarmonyJSSE" provider and not the OpenSSL provider. I don't have enough knowledge of how android SSL works to really make sense of why this is, but it definitely is the case.
I was able to get the negotiation and transport working by doing the following:
SocketIO.setDefaultSSLSocketFactory(SSLContext.getDefault());
Then I had to edit the WebsocketTransport as follows:
public WebsocketTransport(URI uri, IOConnection connection) {
super(uri);
this.connection = connection;
SSLContext context = null;
try {
context = SSLContext.getInstance("TLS", "HarmonyJSSE");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
}
try {
context.init(null, null, null);
} catch (KeyManagementException e) {
e.printStackTrace();
}
if("wss".equals(uri.getScheme()) && context != null) {
this.setWebSocketFactory(new DefaultSSLWebSocketClientFactory(context));
}
}
This problem might require some coordination with the upstream library.