1

I am working on the Android client implementation that connects via websocket to a server. I've just enabled HTTPS on the server instance and now I am receiving this issue:

 W/System.err: com.neovisionaries.ws.client.HostnameUnverifiedException: The certificate of the peer (CN=otherdomain.com) does not match the expected hostname (domain.com)
    at com.neovisionaries.ws.client.SocketConnector.verifyHostname(SocketConnector.java:171)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:126)
    at com.neovisionaries.ws.client.SocketConnector.connect(SocketConnector.java:83)
    at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2152)
    at com.neovisionaries.ws.client.ConnectThread.runMain(ConnectThread.java:32)
    at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)

It seems that the websocket client is finding mismatched server host names.

Some other related info:

otherdomain.com is a different one of our URLs. It is pointed to separate instance of the same web application running on the same server as domain.com which is the app I am currently working on.

My code is logging the URL that it is connecting to and I can see that it is correctly referencing domain.com:

connecting to: wss://domain.com?session_key=TheCorrectSessionKey

As noted otherdomain.com is another instance of the same web application. That instance already previously had HTTPS enabled and everything is working properly with that instance. The same client code I am using now is able to connect successfully to this instance.

The same web application has a front end page that also connects to the websocket via wss://. This is working properly in both Chrome and Firefox browsers for domain.com, as far as I can tell the only client having issues is the Android client, and it's only the domain.com variant of the app having issues, the otherdomain.com one seems to be working fine.

I found this issue opened on the library I am using for websockets. But I'm not 100% sure if my problem is related to it, but it may be. In particular someone states:

Not being able to connect to a WebSocket-enabled server domain unless it is also configured to be the default server on the website.

I assume only one site can be default, and perhaps otherdomain.com got set to default since it was completed first. This is all a bit over my head though to be honest, I'm not sure if this is relavent or not.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • I think you've correctly identified SNI as the problem! Did you try the solution [here](https://github.com/TakahikoKawasaki/nv-websocket-client/issues/106#issuecomment-296411124)? – greeble31 Nov 26 '18 at 22:41
  • @greeble31 I'm not sure how to try what is linked in that post. I'm not using an SSLSocket object or anything in my code. I've used `WebSocketFactory.createSocket()` to open my connection. – FoamyGuy Nov 26 '18 at 23:01
  • @greeble31 I did see further down in this discussion `None of this changes the fact that the library did not check the hostname in versions prior to 2.1`. I tried changing the versions of my websocket client down to `2.0` and now my connection is working successfully. However I suspect downgrading is not an ideal solution. – FoamyGuy Nov 26 '18 at 23:08
  • "and now my connection is working successfully" <-- Hmm. That really shouldn't have happened... I don't know too much about nv-websocket-client, so I can't help you there. The statement about hostname checking has more to do with good security practices on the client, rather than connectivity issues. Of course you should be concerned with both, but if your library has big security holes, may be time to check out a different library... – greeble31 Nov 26 '18 at 23:24

0 Answers0