mattn/go-xmpp — pull request #43 by seletskiy (2014-11-27 17:13:51+00:00)
Title: do not start tls if server accept starttls only

Ok, after trying StartTLS, that was introduced at #37, I think I've found a flaw: some servers (ejabberd, for example), can start insecure session first, tell that they accept STARTTLS and if you want, you can re-start session using TLS. But if you start with TLS right after establishing TCP connection, protocol will be simply wrong, because server will send plain XML without encryption.

I'm not an XMPP protocol expert, but it's how server I've connection to behave.

Proposed PR will start insecure session first (if o.StartTLS specified), and when server says, that it accept STARTTLS, session will be restarted using TLS.

Current implementation will open TLS connection first, so it's useless with STARTTLS.

@aszxqw, can you try connect to your ejabberd instance using (StartTLS = true) and my fork? I'm able to connect to my ejabberd using changes made in this PR.

@swdunlop, can you, please, validate, that using this PR it is still possible to connect using TLS to the XMPP-server that you use?