scratchyone / wasm-sockets

A rust WASM-specific websocket library
MIT License
31 stars 3 forks source link

Websocket TLS encyption support #5

Closed hanusek closed 1 year ago

hanusek commented 1 year ago

Hello @scratchyone!

I can't find information about support for TLS encryption. Does your library support TLS?

scratchyone commented 1 year ago

Hi! Yes, since this library binds with the JS WebSocket API, the wss:// (WebSocket over HTTPS) protocol is supported. I believe the example in the Readme uses wss://, in case you need a reference. Lemme know if you have any other questions! :)

hanusek commented 1 year ago

@scratchyone In python websockets I can set it:

ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.load_verify_locations(pathlib.PurePath("../keys/eddsa-ca.cert"))
ssl_context.check_hostname = False
websockets.connect("wss://localhost:9999", ssl=ssl_context)
[...]

How to do it with rust/wasm-socket?

scratchyone commented 1 year ago

Hi! I’m not familiar with that library, could you possibly clarify what specific features you’re looking for?

hanusek commented 1 year ago

Hi! I’m not familiar with that library, could you possibly clarify what specific features you’re looking for?

I need to use websocket's client with dioxus_web (WASM) and connect to my server (TLS, based on tokio-rustls). I need to use with it my certificate - ed25519.

scratchyone commented 1 year ago

Unfortunately, as far as I can tell, the standard WebSocket browser API doesn't have support for custom certificates, so there's no way to do that from WASM. You could possibly manually trust the certificate in your browser settings. Here is a Stack Exchange post I found which might be helpful. If you can find a way to do this in pure browser-side JS, please let me know and I'll add support to this library.