From 72135514fcb1e3ad5c5e8f35f76b8e2f3c9370f9 Mon Sep 17 00:00:00 2001 From: Chteufleur Date: Mon, 15 Aug 2016 22:37:28 +0200 Subject: [PATCH] Fix certificat domain check in case of SRV --- src/xmpp/ad-hoc.go | 8 ++++---- src/xmpp/client.go | 2 +- src/xmpp/stream.go | 9 +++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/xmpp/ad-hoc.go b/src/xmpp/ad-hoc.go index 182089b..95e1f00 100644 --- a/src/xmpp/ad-hoc.go +++ b/src/xmpp/ad-hoc.go @@ -26,10 +26,10 @@ const ( TypeAdHocNoteWarning = "warn" TypeAdHocNoteError = "error" - TypeAdHocFieldListMulti = "list-multi" - TypeAdHocFieldListSingle = "list-single" - TypeAdHocFieldTextSingle = "text-single" - TypeAdHocFieldJidSingle = "jid-single" + TypeAdHocFieldListMulti = "list-multi" + TypeAdHocFieldListSingle = "list-single" + TypeAdHocFieldTextSingle = "text-single" + TypeAdHocFieldJidSingle = "jid-single" TypeAdHocFieldTextPrivate = "text-private" ) diff --git a/src/xmpp/client.go b/src/xmpp/client.go index 8e5b817..a53d920 100644 --- a/src/xmpp/client.go +++ b/src/xmpp/client.go @@ -115,7 +115,7 @@ func startTLS(stream *Stream, config *ClientConfig) error { return err } - tlsConfig := tls.Config{InsecureSkipVerify: config.InsecureSkipVerify, ServerName: stream.connDomain} + tlsConfig := tls.Config{InsecureSkipVerify: config.InsecureSkipVerify, ServerName: stream.config.ConnectionDomain} return stream.UpgradeTLS(&tlsConfig) } diff --git a/src/xmpp/stream.go b/src/xmpp/stream.go index b1cd8d5..5ee18b5 100644 --- a/src/xmpp/stream.go +++ b/src/xmpp/stream.go @@ -17,6 +17,9 @@ type StreamConfig struct { // are either sent to the server or delivered to the application. It also // causes incoming stanzas to be XML-parsed a second time. LogStanzas bool + + // The dommain connection for certificat validation. + ConnectionDomain string } type Stream struct { @@ -25,7 +28,6 @@ type Stream struct { config *StreamConfig stanzaBuf string incomingNamespace nsMap - connDomain string } // Create a XML stream connection. A Steam is used by an XMPP instance to @@ -43,7 +45,10 @@ func NewStream(addr string, config *StreamConfig) (*Stream, error) { return nil, err } - stream := &Stream{conn: conn, dec: xml.NewDecoder(conn), config: config, connDomain: strings.SplitN(addr, ":", 2)[0]} + stream := &Stream{conn: conn, dec: xml.NewDecoder(conn), config: config} + if config.ConnectionDomain == "" { + config.ConnectionDomain = strings.SplitN(addr, ":", 2)[0] + } if err := stream.send([]byte("")); err != nil { return nil, err