Compare commits

...

2 Commits

4 changed files with 17 additions and 3 deletions

View File

@ -115,7 +115,7 @@ func startTLS(stream *Stream, config *ClientConfig) error {
return err return err
} }
tlsConfig := tls.Config{InsecureSkipVerify: config.InsecureSkipVerify} tlsConfig := tls.Config{InsecureSkipVerify: config.InsecureSkipVerify, ServerName: stream.connDomain}
return stream.UpgradeTLS(&tlsConfig) return stream.UpgradeTLS(&tlsConfig)
} }

View File

@ -27,7 +27,18 @@ func HomeServerAddrs(jid JID) (addr []string, err error) {
// Build list of "host:port" strings. // Build list of "host:port" strings.
for _, a := range addrs { for _, a := range addrs {
addr = append(addr, fmt.Sprintf("%s:%d", a.Target, a.Port)) target := parseTargetDomainName(a.Target)
addr = append(addr, fmt.Sprintf("%s:%d", target, a.Port))
}
return
}
// Remove the last dot in the domain name if exist
func parseTargetDomainName(domainName string) (ret string) {
if domainName[len(domainName)-1] == '.' {
ret = parseTargetDomainName(domainName[:len(domainName)-1])
} else {
ret = domainName
} }
return return
} }

View File

@ -172,4 +172,5 @@ var (
FeatureNotImplemented = ErrorCondition{nsErrorStanzas, "feature-not-implemented"} FeatureNotImplemented = ErrorCondition{nsErrorStanzas, "feature-not-implemented"}
RemoteServerNotFound = ErrorCondition{nsErrorStanzas, "remote-server-not-found"} RemoteServerNotFound = ErrorCondition{nsErrorStanzas, "remote-server-not-found"}
ServiceUnavailable = ErrorCondition{nsErrorStanzas, "service-unavailable"} ServiceUnavailable = ErrorCondition{nsErrorStanzas, "service-unavailable"}
NotAuthorized = ErrorCondition{nsErrorStanzas, "not-authorized"}
) )

View File

@ -7,6 +7,7 @@ import (
"io" "io"
"log" "log"
"net" "net"
"strings"
) )
// Stream configuration. // Stream configuration.
@ -24,6 +25,7 @@ type Stream struct {
config *StreamConfig config *StreamConfig
stanzaBuf string stanzaBuf string
incomingNamespace nsMap incomingNamespace nsMap
connDomain string
} }
// Create a XML stream connection. A Steam is used by an XMPP instance to // Create a XML stream connection. A Steam is used by an XMPP instance to
@ -41,7 +43,7 @@ func NewStream(addr string, config *StreamConfig) (*Stream, error) {
return nil, err return nil, err
} }
stream := &Stream{conn: conn, dec: xml.NewDecoder(conn), config: config} stream := &Stream{conn: conn, dec: xml.NewDecoder(conn), config: config, connDomain: strings.SplitN(addr, ":", 2)[0]}
if err := stream.send([]byte("<?xml version='1.0' encoding='utf-8'?>")); err != nil { if err := stream.send([]byte("<?xml version='1.0' encoding='utf-8'?>")); err != nil {
return nil, err return nil, err