From 6907535153ce0482f611de3ecf2696306b05223b Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Thu, 2 Apr 2020 19:35:12 +0200 Subject: [PATCH] Add ALPN support This should make go-sendxmpp work on servers using ALPN e.g. when using sslh on port 443 to use a httpd and XMPP over TLS on the same port. --- go-sendxmpp.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/go-sendxmpp.go b/go-sendxmpp.go index 9c59c3f..97e2be8 100644 --- a/go-sendxmpp.go +++ b/go-sendxmpp.go @@ -83,7 +83,7 @@ func parseConfig(configPath string) (configuration, error) { // Read config file per line. for scanner.Scan() { - if strings.HasPrefix(scanner.Text(), "#"){ + if strings.HasPrefix(scanner.Text(), "#") { continue } @@ -100,7 +100,7 @@ func parseConfig(configPath string) (configuration, error) { output.port = row[1] default: if len(row) >= 2 { - if strings.Contains(scanner.Text(), ";"){ + if strings.Contains(scanner.Text(), ";") { output.username = strings.Split(row[0], ";")[0] output.jserver = strings.Split(row[0], ";")[1] output.password = row[1] @@ -238,15 +238,21 @@ func main() { password = *flagPassword } + // Use ALPN + tlsConfig := xmpp.DefaultConfig + tlsConfig.ServerName = strings.Split(server, ":")[0] + tlsConfig.NextProtos = append(tlsConfig.NextProtos, "xmpp-client") + // Set XMPP connection options. options := xmpp.Options{ - Host: server, - User: user, - Resource: *flagResource, - Password: password, - NoTLS: !*flagTLS, - StartTLS: *flagStartTLS, - Debug: *flagDebug, + Host: server, + User: user, + Resource: *flagResource, + Password: password, + NoTLS: !*flagTLS, + StartTLS: *flagStartTLS, + Debug: *flagDebug, + TLSConfig: &tlsConfig, } // Read message from file.