WebSocket SSL not supported in 1.10.2

WebSocket SSL not supported in 1.10.2
0

Hi,

As the topic says, for some reason opening a wss connection doesn’t work on 1.10.2, while the ws connections works perfectly.
This issue is only appearing on Windows and Android. On macOS and iOS, the wss connection works as good as the ws.

I have uploaded a test project.

Best regards

WebSocketTest.zip (713.3 KB)

1 Like

Can confirm the issue for Cocos Creator 2.0.9

Here’s a simple project that tests both unsecure (ws://) and secure (wss://). Both work in web version but secure connection is failed in Android build. I also tried to include CA certificate and specifiy it during WebSocket creation. Doesn’t work. With extra logs I saw this socket callback invocation:

LWS_CALLBACK_CLIENT_CONNECTION_ERROR: lws_ssl_client_connect2 failed

Tested against echo.websocket.org. CA certificate is of Let's Encrypt Authority X3. Particular file used may be found in repo. Full log from WebSocket-libwebsockets.cpp can be found here.

I am facing the same issue with Cocos Creator 2.1.1. When I try to run the project in browser, I have no issue with secure Web Socket connection. However, it fails on the simulator. Are there any solutions to make this work?

Hi,

So I found the following solution after some research on the chinese cocos forums:
Apparently, you have to pass a certificate as the third argument when opening a secure websocket connection.

I use the following code and certificate:

new WebSocket(url, [], cc.url.raw(‘resources/raw/cacert.pem’));

Where the certificate is under the given path.

cacert.zip (118.9 KB)

hi @Orlan ,
in documentation for javascript web sockets, it is indicated that we don’t need to pass the certificate when establishing the wss connection. please verify your answer by actually trying it out as I think it won’t work. also, the field for protocols is also optional, so essentially the command should be :

new WebSocket(“wss://1.2.3.4:8443/echo”);

where the port no is decided by the server, and echo is the name of the endpoint.

thanks!

hi,
firstly welcome to the cocos creator community!
I am really interested in knowing how to establish a wss connection in creator. I tried:

new WebSocket(“wss://1.2.3.4:443/echo”);

but the above just gave me an error that the certificate is invalid. this may be because for testing purposes we are using a self-validated certificate at the server end, and that may be generating the error. we have created an echo server at the url and port, and even an https request in the browser doesn’t establish a connection. do you think this is only because we are not using a proper certificate?
also, when establishing a wss connection, do we need to provide a path to the certificate existing locally(on the client)? @Orlan proposed so, but I think that is not the right way as the player of the game won’t have access to any certificate. anyway, it would be great to know your thoughts on the matter.
thanks!

I tried it out, it works.