dovecotsasl

package module
v0.0.0-...-c4699d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2020 License: MIT Imports: 15 Imported by: 1

README

go-dovecot-sasl

go.dev reference

Go library implementing Dovecot authentication protocol 1.1. The library is based on emersion/go-sasl.

Examples

Client
s, err := net.Dial("unix", "/var/lib/dovecot/sasl.sock")
if err != nil {
    // Handle error.
}

cl := dovecotsasl.NewClient(s)
err := cl.Do("SMTP", 
    sasl.NewPlainClient("", "foxcpp", "1234"), 

    dovecotsasl.RemoteIP(net.IPv4(1,2,3,4)),
    dovecotsasl.Secured,
)
if err != nil {
    // Nope!
}

// Authenticated!
Server
l, err := net.Listen("unix", "/var/lib/maddy/sasl.sock")
if err != nil {
    // Handle error.
}

var authenticator sasl.PlainAuthenticator = func(_, user, pass string) error {
    if user == "foxcpp" && pass == "1234" {
        return nil
    }
    return errors.New("nope!")
}

s := NewServer()
s.AddMechanism("PLAIN", dovecotsasl.Mechanism{}, 
    func(*dovecotsasl.AuthReq) sasl.Server {
        return sasl.NewPlainServer(authenticator)
    })

go s.Serve(l)

License

MIT.

Documentation

Index

Constants

View Source
const (
	TempFail     = "temp_fail"
	AuthzFail    = "authz_fail"
	UserDisabled = "user_disabled"
	PassExpired  = "pass_expired"
)
View Source
const (
	Secured         = "secured"
	CertUsername    = "cert_username"
	ValidClientCert = "valid-client-cert"
	NoPenalty       = "no-penalty"
)

Constants for Client.Do params. See https://wiki.dovecot.org/Design/AuthProtocol for description.

Variables

This section is empty.

Functions

func LocalIP

func LocalIP(ip net.IP) string

LocalIP formats local server IP for use in Client.Do params.

func LocalPort

func LocalPort(i uint16) string

LocalIP formats local port for use in Client.Do params.

func RemoteIP

func RemoteIP(ip net.IP) string

LocalIP formats remote IP for use in Client.Do params.

func RemotePort

func RemotePort(i uint16) string

LocalIP formats remote port for use in Client.Do params.

Types

type AuthFail

type AuthFail struct {
	RequestID string
	Code      FailCode
	Reason    string
}

func (AuthFail) Error

func (af AuthFail) Error() string

type AuthReq

type AuthReq struct {
	RequestID string
	Mechanism string
	Service   string

	LocalIP   net.IP
	LocalPort uint16

	RemoteIP   net.IP
	RemotePort uint16

	Secured         bool
	ValidClientCert bool
	NoPenalty       bool
	CertUsername    bool

	IR []byte
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(netConn net.Conn) (*Client, error)

func (*Client) Close

func (cl *Client) Close() error

func (*Client) ConnInfo

func (c *Client) ConnInfo() ConnInfo

func (*Client) Do

func (c *Client) Do(service string, cl sasl.Client, extraParams ...string) error

Do performs SASL authentication using Dovecot SASL server and provided sasl.Client implementation.

type ConnInfo

type ConnInfo struct {
	CPID, SPID string

	CUID   string
	Cookie string

	Mechs map[string]Mechanism
}

type FailCode

type FailCode string

type Mechanism

type Mechanism struct {
	Anonymous      bool
	Plaintext      bool
	Dictonary      bool
	Active         bool
	ForwardSecrecy bool
	MutualAuth     bool
	Private        bool
}

type Server

type Server struct {
	Log *log.Logger
	// contains filtered or unexported fields
}

func NewServer

func NewServer() *Server

func (*Server) AddMechanism

func (s *Server) AddMechanism(name string, info Mechanism, handler func(*AuthReq) sasl.Server)

func (*Server) Close

func (s *Server) Close() error

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL