forked from jshiffer/go-xmpp
attempt anonymous only when logging in without JID and password
This commit is contained in:
parent
cc56ae0810
commit
e8c25dcffe
@ -32,7 +32,9 @@ func main() {
|
||||
}
|
||||
flag.Parse()
|
||||
if *username == "" || *password == "" {
|
||||
flag.Usage()
|
||||
if *debug {
|
||||
fmt.Fprintf(os.Stderr, "no username or password were given; attempting ANONYMOUS auth\n")
|
||||
}
|
||||
}
|
||||
|
||||
if !*notls {
|
||||
|
24
xmpp.go
24
xmpp.go
@ -44,6 +44,10 @@ const (
|
||||
// Default TLS configuration options
|
||||
var DefaultConfig tls.Config
|
||||
|
||||
func init() {
|
||||
DefaultConfig.InsecureSkipVerify = true
|
||||
}
|
||||
|
||||
// Cookie is a unique XMPP session identifier
|
||||
type Cookie uint64
|
||||
|
||||
@ -272,11 +276,14 @@ func (c *Client) init(o *Options) error {
|
||||
c.p = xml.NewDecoder(c.conn)
|
||||
}
|
||||
|
||||
var domain string
|
||||
a := strings.SplitN(o.User, "@", 2)
|
||||
if len(o.User) > 0 {
|
||||
if len(a) != 2 {
|
||||
return errors.New("xmpp: invalid username (want user@domain): " + o.User)
|
||||
}
|
||||
domain := a[1]
|
||||
domain = a[1]
|
||||
} // Otherwise, we'll be attempting ANONYMOUS
|
||||
|
||||
// Declare intent to be a jabber client and gather stream features.
|
||||
f, err := c.startStream(o, domain)
|
||||
@ -289,6 +296,19 @@ func (c *Client) init(o *Options) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if o.User == "" && o.Password == "" {
|
||||
found_anonymous := false
|
||||
for _, m := range f.Mechanisms.Mechanism {
|
||||
if m == "ANONYMOUS" {
|
||||
fmt.Fprintf(c.conn, "<auth xmlns='%s' mechanism='ANONYMOUS' />\n", nsSASL)
|
||||
found_anonymous = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found_anonymous {
|
||||
return fmt.Errorf("ANONYMOUS authentication is not an option and username and password were not specified")
|
||||
}
|
||||
} else {
|
||||
// Even digest forms of authentication are unsafe if we do not know that the host
|
||||
// we are talking to is the actual server, and not a man in the middle playing
|
||||
// proxy.
|
||||
@ -370,7 +390,7 @@ func (c *Client) init(o *Options) error {
|
||||
if mechanism == "" {
|
||||
return fmt.Errorf("PLAIN authentication is not an option: %v", f.Mechanisms.Mechanism)
|
||||
}
|
||||
|
||||
}
|
||||
// Next message should be either success or failure.
|
||||
name, val, err := next(c.p)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user