hedwig-im / hedwig

An Adapter-based Bot Framework for Elixir Applications
MIT License
656 stars 73 forks source link

Connect with TLS #23

Closed awenger closed 8 years ago

awenger commented 8 years ago

I'm trying to connect to the GCM XMPP Connection Server [1] with Hedwig. They require a TLS connection and don't support STARTTLS [2]. I tried different combinations in the config but it won't connect.

[info]  Outgoing stanza: {:xmlstreamstart, "stream:stream", [{"to", "gcm.googleapis.com"}, {"version", "1.0"}, {"xml:lang", "en"}, {"xmlns", "jabber:client"}, {"xmlns:stream", "http://etherx.jabber.org/streams"}]}
[error] GenServer #PID<0.165.0> terminating
** (MatchError) no match of right hand side value: {:error, {'not well-formed (invalid token)', <<21, 3, 1, 0, 2, 2, 70>>}}
    (hedwig) lib/hedwig/transports/tcp.ex:158: Hedwig.Transports.TCP.handle_data/3
    (stdlib) gen_server.erl:615: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:681: :gen_server.handle_msg/5
    (stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {:tcp, #Port<0.5575>, <<21, 3, 1, 0, 2, 2, 70>>}
State: %Hedwig.Transports.TCP{client: #PID<0.162.0>, compress?: false, config: %{client: #PID<0.162.0>, ignore_from_self?: true, port: 5235, preferred_auth_mechanisms: ["PLAIN"], require_tls?: true, server: "gcm-xmpp.googleapis.com", transport: Hedwig.Transports.TCP, use_compression?: false, use_stream_management?: true}, parser: {:parser, "", []}, pid: #PID<0.164.0>, socket: #Port<0.5575>, ssl?: false, transport: Hedwig.Transports.TCP}

However, if I replace :gen_tcp with :ssl in the Hedwig.Transports.TCP module the connection is established without errors. Is there some settings to force such behavior in the config?

[1] https://developers.google.com/cloud-messaging/xmpp-server-ref [2] https://developers.google.com/cloud-messaging/ccs

scrogson commented 8 years ago

@awenger thanks for the report. At this time, this is not configurable, but it certainly should be. I'm currently in the middle of rewriting Hedwig so I won't be able to address this right now.

awenger commented 8 years ago

Happy to hear that this will be supported in a future version. Thanks for the lib. For the time being manually replacing :gen_tcp with :ssl is a manageable workaround for me.

scrogson commented 8 years ago

Excellent. I am currently working to make Hedwig more generic (adapter based). The first adapter will be XMPP of course :)

I would love some feedback once it's ready. On Sun, Dec 6, 2015 at 20:47 awenger notifications@github.com wrote:

Happy to hear that this will be supported in a future version. Thanks for the lib. For the time being manually replacing :gen_tcp with :ssl is a manageable workaround for me.

— Reply to this email directly or view it on GitHub https://github.com/hedwig-im/hedwig/issues/23#issuecomment-162341306.

scrogson commented 8 years ago

@awenger thanks again for the report! I've created an issue on scrogson/romeo#2 to address it.