~emersion/public-inbox

chathistorysync: client: Use SASL authentication v2 APPLIED

Adnan Maolood: 2
 client: Use SASL authentication
 client: Use BOUNCER BIND

 3 files changed, 44 insertions(+), 11 deletions(-)
#780203 .build.yml success
chathistorysync/patches/.build.yml: SUCCESS in 53s

[client: Use SASL authentication][0] v2 from [Adnan Maolood][1]

[0]: https://lists.sr.ht/~emersion/public-inbox/patches/32977
[1]: mailto:me@adnano.co

✓ #780203 SUCCESS chathistorysync/patches/.build.yml https://builds.sr.ht/~emersion/job/780203
Pushed with minor edits, thanks!
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/32977/mbox | git am -3
Learn more about email & git

[PATCH chathistorysync v2 1/2] client: Use SASL authentication Export this patch

---
 client.go | 42 +++++++++++++++++++++++++++++++++++-------
 1 file changed, 35 insertions(+), 7 deletions(-)

diff --git a/client.go b/client.go
index 492a75b..89f4b5a 100644
--- a/client.go
+++ b/client.go
@@ -1,7 +1,10 @@
package main

import (
	"bytes"
	"crypto/tls"
	"encoding/base64"
	"errors"
	"fmt"
	"log"
	"net"
@@ -68,19 +71,13 @@ func dialTLS(addr string) (*client, error) {
}

func (c *client) Register(nick, pass string) {
	caps := []string{"draft/chathistory", "message-tags", "batch", "echo-message", "server-time", "causal.agency/passive", "soju.im/bouncer-networks"}
	caps := []string{"draft/chathistory", "sasl", "message-tags", "batch", "echo-message", "server-time", "causal.agency/passive", "soju.im/bouncer-networks"}
	for _, name := range caps {
		c.WriteMessage(&irc.Message{
			Command: "CAP",
			Params:  []string{"REQ", name},
		})
	}
	if pass != "" {
		c.WriteMessage(&irc.Message{
			Command: "PASS",
			Params:  []string{pass},
		})
	}
	c.WriteMessage(&irc.Message{
		Command: "NICK",
		Params:  []string{nick},
@@ -89,6 +86,23 @@ func (c *client) Register(nick, pass string) {
		Command: "USER",
		Params:  []string{nick, "0", "*", nick},
	})
	if pass != "" {
		var buf bytes.Buffer
		buf.WriteString(nick)
		buf.WriteByte(0)
		buf.WriteString(nick)
		buf.WriteByte(0)
		buf.WriteString(pass)
		payload := base64.StdEncoding.EncodeToString(buf.Bytes())
		c.WriteMessage(&irc.Message{
			Command: "AUTHENTICATE",
			Params:  []string{"PLAIN"},
		})
		c.WriteMessage(&irc.Message{
			Command: "AUTHENTICATE",
			Params:  []string{payload},
		})
	}
	c.WriteMessage(&irc.Message{
		Command: "CAP",
		Params:  []string{"END"},
@@ -143,6 +157,10 @@ func (c *client) ReadMessage() (*message, error) {
				c.caps.chatHistory = ok
			case "soju.im/bouncer-networks":
				c.caps.bouncerNetworks = ok
			case "sasl":
				if !ok {
					return nil, fmt.Errorf("server doesn't support SASL authentication")
				}
			}
		}
	case "BATCH":
@@ -153,6 +171,16 @@ func (c *client) ReadMessage() (*message, error) {
			msg.closeBatch = c.batches[name]
			delete(c.batches, name)
		}
	case "AUTHENTICATE":
		challenge := msg.Params[0]
		if challenge != "+" {
			return nil, fmt.Errorf("unexpected SASL challenge %q", challenge)
		}
	case irc.RPL_SASLSUCCESS:
		// SASL authentication successful
	case irc.ERR_NICKLOCKED, irc.ERR_SASLFAIL, irc.ERR_SASLTOOLONG,
		irc.ERR_SASLABORTED, irc.ERR_SASLALREADY, irc.RPL_SASLMECHS:
		return nil, errors.New(strings.Join(msg.Params[1:], " "))
	}

	return msg, nil
-- 
2.36.1

[PATCH chathistorysync v2 2/2] client: Use BOUNCER BIND Export this patch

---
 client.go | 8 +++++++-
 main.go   | 5 ++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/client.go b/client.go
index 89f4b5a..ddf0a2d 100644
--- a/client.go
+++ b/client.go
@@ -70,7 +70,7 @@ func dialTLS(addr string) (*client, error) {
	}, nil
}

func (c *client) Register(nick, pass string) {
func (c *client) Register(nick, pass, netid string) {
	caps := []string{"draft/chathistory", "sasl", "message-tags", "batch", "echo-message", "server-time", "causal.agency/passive", "soju.im/bouncer-networks"}
	for _, name := range caps {
		c.WriteMessage(&irc.Message{
@@ -103,6 +103,12 @@ func (c *client) Register(nick, pass string) {
			Params:  []string{payload},
		})
	}
	if netid != "" {
		c.WriteMessage(&irc.Message{
			Command: "BOUNCER",
			Params:  []string{"BIND", netid},
		})
	}
	c.WriteMessage(&irc.Message{
		Command: "CAP",
		Params:  []string{"END"},
diff --git a/main.go b/main.go
index c05e494..74b56cd 100644
--- a/main.go
+++ b/main.go
@@ -107,7 +107,7 @@ func main() {
	defer c.Close()

	c.Debug = debug
	c.Register(nick, pass)
	c.Register(nick, pass, "")
	waitRegistered(c)

	if c.caps.bouncerNetworks {
@@ -122,9 +122,8 @@ func main() {
				log.Fatalf("Failed to connect to server: %v", err)
			}

			// TODO: use BOUNCER BIND instead
			c.Debug = debug
			c.Register(nick+"/"+network.name, pass)
			c.Register(nick, pass, network.id)
			waitRegistered(c)

			networkDir := filepath.Join(outputDir, escapeFilename(network.name))
-- 
2.36.1
chathistorysync/patches/.build.yml: SUCCESS in 53s

[client: Use SASL authentication][0] v2 from [Adnan Maolood][1]

[0]: https://lists.sr.ht/~emersion/public-inbox/patches/32977
[1]: mailto:me@adnano.co

✓ #780203 SUCCESS chathistorysync/patches/.build.yml https://builds.sr.ht/~emersion/job/780203
Pushed with minor edits, thanks!