From 41fd432f889d7a6fb73135dfc4a42d49ccae7544 Mon Sep 17 00:00:00 2001 From: Marin Date: Sun, 14 Sep 2014 23:15:56 -0700 Subject: [PATCH 1/2] optional TLS config --- xmpp.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xmpp.go b/xmpp.go index 6515fcc..e647087 100644 --- a/xmpp.go +++ b/xmpp.go @@ -135,7 +135,7 @@ type Options struct { } // NewClient establishes a new Client connection based on a set of Options. -func (o Options) NewClient() (*Client, error) { +func (o Options) NewClient(tlsCfg ...tls.Config) (*Client, error) { host := o.Host c, err := connect(host, o.User, o.Password) if err != nil { @@ -146,7 +146,12 @@ func (o Options) NewClient() (*Client, error) { if o.NoTLS { client.conn = c } else { - tlsconn := tls.Client(c, &DefaultConfig) + var tlsconn *tls.Conn + if len(tlsCfg) > 0 { + tlsconn = tls.Client(c, &tlsCfg[0]) + } else { + tlsconn = tls.Client(c, &DefaultConfig) + } if err = tlsconn.Handshake(); err != nil { return nil, err } From f06f19e1217d95b49fe4917944251ea028e1c4bf Mon Sep 17 00:00:00 2001 From: Marin Date: Sun, 14 Sep 2014 23:21:06 -0700 Subject: [PATCH 2/2] moved to Options instead of NewClient --- xmpp.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/xmpp.go b/xmpp.go index e647087..afdf593 100644 --- a/xmpp.go +++ b/xmpp.go @@ -123,6 +123,9 @@ type Options struct { // from the server. Use "" to let the server generate one for your client. Resource string + // TLS Config + TLSConfig *tls.Config + // NoTLS disables TLS and specifies that a plain old unencrypted TCP connection should // be used. NoTLS bool @@ -135,7 +138,7 @@ type Options struct { } // NewClient establishes a new Client connection based on a set of Options. -func (o Options) NewClient(tlsCfg ...tls.Config) (*Client, error) { +func (o Options) NewClient() (*Client, error) { host := o.Host c, err := connect(host, o.User, o.Password) if err != nil { @@ -147,8 +150,8 @@ func (o Options) NewClient(tlsCfg ...tls.Config) (*Client, error) { client.conn = c } else { var tlsconn *tls.Conn - if len(tlsCfg) > 0 { - tlsconn = tls.Client(c, &tlsCfg[0]) + if o.TLSConfig != nil { + tlsconn = tls.Client(c, o.TLSConfig) } else { tlsconn = tls.Client(c, &DefaultConfig) }