Stuck trying TLS w/ cowboy 2

Trying to make a tls connection with cowboy 2 to try and learn some http2 concepts.

Getting stuck on the tls connection:
Referencing this erlang example:
https://ninenines.eu/docs/en/cowboy/2.0/manual/cowboy.start_tls/

Trying my own:

All the tls handshakes fail. Any ideas? Kinda stuck at the moment.

Got a little farther. Handshake seems to work now.

Separated out the crt and key files, changed up some of the config dictionaries based on a github search.

dispatch_config = build_dispatch_config()
{ :ok, _ } = :cowboy.start_tls(:api,
                                100,
                               [port: 8443,
                                keyfile: "/home/crunch/server.key",
                                certfile: "/home/crunch/server.crt"],
                               %{ env: %{dispatch: dispatch_config}}
                               )

Unforunately still fails when I try to send anything over the websocket connection.

What is the error message the server returns you precisely?

Is your github link above of ‘thing’ your test project for this?

The static html hangs.

The websocket handshakes (using wscat), then when I post any message the connection errors out and closes with a tls error message internal to cowboy. Will post the message here later when I’m back at home computer. The code on github (“thing”) is the latest test code I am using, yeah. The certs are just self-signed certs I obtained using heroku’s help page on the subject:

Ah it is not a TLS error. Think I implemented the routers incorrectly. using start_clear yields the same result.

ndle, [{:text, "test"}, []], []}, {:cowboy_websocket, :handler_call, 6, [file: 'c:/Users/ddomb/src/thing/deps/cowboy/src/cowboy_websocket.erl', line: 331]}, {:cowboy_http, :loop, 2,
 [file: 'c:/Users/ddomb/src/thing/deps/cowboy/src/cowboy_http.erl', line: 175]}, {:cowboy_clear, :proc_lib_hack, 5, [file: 'c:/Users/ddomb/src/thing/deps/cowboy/src/cowboy_clear.erl
', line: 29]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]}```

I havn’t had a chance to clone it yet to play, but that error sounds like your websocket handler or callback function or so does not exist with the information supplied (WebsocketHandler.websocket_handle/2?).

Yep I am not used to reading these stack traces but I think you’re right. I copied some example code from something using a previous rc, need to update.

Woo! First http2 request successful.

[  0.004] Connected
The negotiated protocol: h2
[  0.198] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
          (niv=2)
          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
[  0.199] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
          (dep_stream_id=0, weight=201, exclusive=0)
[  0.199] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
          (dep_stream_id=0, weight=101, exclusive=0)
[  0.200] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
          (dep_stream_id=0, weight=1, exclusive=0)
[  0.200] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
          (dep_stream_id=7, weight=1, exclusive=0)
[  0.200] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
          (dep_stream_id=3, weight=1, exclusive=0)
[  0.200] send HEADERS frame <length=38, flags=0x25, stream_id=13>
          ; END_STREAM | END_HEADERS | PRIORITY
          (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
          ; Open new stream
          :method: GET
          :path: /
          :scheme: https
          :authority: localhost:8443
          accept: */*
          accept-encoding: gzip, deflate
          user-agent: nghttp2/1.7.1
[  0.221] recv SETTINGS frame <length=0, flags=0x00, stream_id=0>
          (niv=0)
[  0.222] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[  0.223] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[  0.382] recv (stream_id=13) :status: 200
[  0.383] recv (stream_id=13) content-length: 22
[  0.383] recv (stream_id=13) content-type: text/plain
[  0.384] recv (stream_id=13) date: Wed, 26 Apr 2017 01:56:17 GMT
[  0.384] recv (stream_id=13) server: Cowboy
[  0.384] recv HEADERS frame <length=45, flags=0x04, stream_id=13>
          ; END_HEADERS
          (padlen=0)
          ; First response header
Hello, Cowboy Handler![  0.384] recv DATA frame <length=22, flags=0x01, stream_id=13>
          ; END_STREAM
[  0.385] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
          (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])```

Oooo awesome! You should write up an article about using cowboy2 from Elixir! :smiley: