I am trying to send some data from an android (4.1) application to a node.js https server, to do so I use Gottox's socket.io with Weberknecht websockets.
I have achieved to communicate the aplication and the server over TLS 1.0 with the cipher suite
TLS_RSA_WITH_AES_128_CBC_SHA
Adding it to options of the server:
var options = {
key: fs.readFileSync(...),
cert: fs.readFileSync(...),
ciphers:('AES128-SHA'),
}
But I want to use the cipher suite of TLS v1.2
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
That is supposed to be supported in android 4.1, so I have changed the ciphers option to
ciphers:('ECDHE-ECDSA-AES256-SHA'),
Moreover, to make it work, in the WebSocketConnection.java of Weberknecht websockets, I have change the Sockets to SSLSockets, so I can enable all the cipher suites supported by android with this code:
socket = (SSLSocket) sslSocketFactory.createSocket(host, port);
String[] suites = socket.getSupportedCipherSuites();
socket.setEnabledCipherSuites(suites);
But it doesn't work, if I delete the ciphers option in the server or I put again the first cipher suite it does, but only over TLS 1.0.
The stack error is:
03-14 16:44:01.215: W/System.err(3762): io.socket.SocketIOException: Error while handshaking
03-14 16:44:01.220: W/System.err(3762): at io.socket.IOConnection.handshake(IOConnection.java:313)
03-14 16:44:01.220: W/System.err(3762): at io.socket.IOConnection.access$7(IOConnection.java:283)
03-14 16:44:01.220: W/System.err(3762): at io.socket.IOConnection$ConnectThread.run(IOConnection.java:199)
03-14 16:44:01.225: W/System.err(3762): Caused by: javax.net.ssl.SSLException: Connection closed by peer
03-14 16:44:01.225: W/System.err(3762): at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
03-14 16:44:01.225: W/System.err(3762): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:371)
03-14 16:44:01.225: W/System.err(3762): at libcore.net.http.HttpConnection.setupSecureSocket(HttpConnection.java:209)
03-14 16:44:01.225: W/System.err(3762): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:478)
03-14 16:44:01.225: W/System.err(3762): at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:442)
03-14 16:44:01.225: W/System.err(3762): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
03-14 16:44:01.225: W/System.err(3762): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
03-14 16:44:01.225: W/System.err(3762): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
03-14 16:44:01.230: W/System.err(3762): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
03-14 16:44:01.230: W/System.err(3762): at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:271)
03-14 16:44:01.230: W/System.err(3762): at io.socket.IOConnection.handshake(IOConnection.java:304)
03-14 16:44:01.230: W/System.err(3762): ... 2 more
I have been going through the WebSocketHandshake.java and IOConnection.java but I don't find the source of the problem...
Any suggestion?
If you want, you can check the code of the client here:
https://github.com/Javi44/LocAALTOn/tree/WebSockets-Gottox
EDIT:
This is the method that is raising the exception:
private void handshake() {
URL url;
String response;
URLConnection connection;
try {
setState(STATE_HANDSHAKE);
url = new URL(IOConnection.this.url.toString() + SOCKET_IO_1);
connection = url.openConnection();
if (connection instanceof HttpsURLConnection) {
((HttpsURLConnection) connection)
.setSSLSocketFactory(sslSocketFactory);
}
connection.setConnectTimeout(connectTimeout);
connection.setReadTimeout(connectTimeout);
/* Setting the request headers */
for (Entry<Object, Object> entry : headers.entrySet()) {
connection.setRequestProperty((String) entry.getKey(),
(String) entry.getValue());
}
InputStream stream = connection.getInputStream();
Scanner in = new Scanner(stream);
response = in.nextLine();
String[] data = response.split(":");
sessionId = data[0];
heartbeatTimeout = Long.parseLong(data[1]) * 1000;
closingTimeout = Long.parseLong(data[2]) * 1000;
protocols = Arrays.asList(data[3].split(","));
} catch (Exception e) {
error(new SocketIOException("Error while handshaking", e));
}
}
May be the problem that is using a url connection instead of a SSLSocket? Would be possible to change the url connection to something with the same functionality but using SSLSockets?