Changeset 724 in code for trunk/upstream.go


Ignore:
Timestamp:
Nov 21, 2021, 3:10:54 PM (4 years ago)
Author:
contact
Message:

Add support for post-connection-registration upstream SASL auth

Once the downstream connection has logged in with their bouncer
credentials, allow them to issue more SASL auths which will be
redirected to the upstream network. This allows downstream clients
to provide UIs to login to transparently login to upstream networks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/upstream.go

    r722 r724  
    3232        "message-tags":     true,
    3333        "multi-prefix":     true,
     34        "sasl":             true,
    3435        "server-time":      true,
    3536        "setname":          true,
     
    294295                                        Params:  []string{dc.nick, mask, "End of /WHO"},
    295296                                })
     297                        case "AUTHENTICATE":
     298                                dc.endSASL(&irc.Message{
     299                                        Prefix:  dc.srv.prefix(),
     300                                        Command: irc.ERR_SASLABORTED,
     301                                        Params:  []string{dc.nick, "SASL authentication aborted"},
     302                                })
    296303                        default:
    297304                                panic(fmt.Errorf("Unsupported pending command %q", pendingCmd.msg.Command))
     
    312319func (uc *upstreamConn) enqueueCommand(dc *downstreamConn, msg *irc.Message) {
    313320        switch msg.Command {
    314         case "LIST", "WHO":
     321        case "LIST", "WHO", "AUTHENTICATE":
    315322                // Supported
    316323        default:
     
    613620                uc.saslStarted = false
    614621
    615                 uc.SendMessage(&irc.Message{
    616                         Command: "CAP",
    617                         Params:  []string{"END"},
    618                 })
     622                if dc, _ := uc.dequeueCommand("AUTHENTICATE"); dc != nil && dc.sasl != nil {
     623                        if msg.Command == irc.RPL_SASLSUCCESS {
     624                                uc.network.autoSaveSASLPlain(context.TODO(), dc.sasl.plainUsername, dc.sasl.plainPassword)
     625                        }
     626
     627                        dc.endSASL(msg)
     628                }
     629
     630                if !uc.registered {
     631                        uc.SendMessage(&irc.Message{
     632                                Command: "CAP",
     633                                Params:  []string{"END"},
     634                        })
     635                }
    619636        case irc.RPL_WELCOME:
    620637                uc.registered = true
     
    17051722        }
    17061723
    1707         if uc.requestSASL() && !uc.caps["sasl"] {
    1708                 requestCaps = append(requestCaps, "sasl")
    1709         }
    1710 
    17111724        if len(requestCaps) == 0 {
    17121725                return
     
    17501763        switch name {
    17511764        case "sasl":
     1765                if !uc.requestSASL() {
     1766                        return nil
     1767                }
    17521768                if !ok {
    17531769                        uc.logger.Printf("server refused to acknowledge the SASL capability")
Note: See TracChangeset for help on using the changeset viewer.