Azolo / websockex

An Elixir Websocket Client
MIT License
515 stars 97 forks source link

example echo_client not working #69

Open farmio opened 5 years ago

farmio commented 5 years ago

When running echo_client example in iex I get an error: %WebSockex.ConnError{original: :closed} from start_link()

It works fine if I replace wss:// with ws://

def start_link(opts \\ []) do
    WebSockex.start_link("ws://echo.websocket.org/?encoding=text", __MODULE__, :fake_state, opts)
  end
redmar commented 5 years ago

change the (above) example code to the following to make it work:

def start_link(opts \\ []) do
    WebSockex.start_link("wss://echo.websocket.org/?encoding=text", __MODULE__, :fake_state,
      ssl_options: [
        ciphers: :ssl.cipher_suites() ++ [{:rsa, :aes_128_cbc, :sha}]
      ]
    )
end

In recent versions of the erlang OTP distribution they dropped old/unsafe cipher suites from the default list. You can add specific ciphers back as shown in the above code, it adds the cipher that's (currently) used by the echo.websocket.org webserver.

(I found this specific cipher by iterating over all ciphers :ssl.cipher_suites(:all) and evaluate if the connection can be made, in the case of the echo.websocket.org webserver it only supports the {:rsa, :aes_128_cbc, :sha} cipher currently. They could change this at any time by upgrading/changing their webserver configuration by the way)