mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-15 00:31:30 -05:00
* adds pkg/jmap/jmap_integration_test.go
* uses ghcr.io/stalwartlabs/stalwart:v0.13.2-alpine
* can be disabled by setting one of the following environment
variables, in the same fashion as ca0493b28
- CI=woodpecker
- CI_SYSTEM_NAME=woodpecker
- USE_TESTCONTAINERS=false
* dependencies:
- bump github.com/go-test/deep from 1.1.0 to 1.1.1
- add github.com/cention-sany/utf7
- add github.com/dustinkirkland/golang-petname
- add github.com/emersion/go-imap/v2
- add github.com/emersion/go-message
- add github.com/emersion/go-sasl
- add github.com/go-crypt/crypt
- add github.com/go-crypt/x
- add github.com/gogs/chardet
- add github.com/inbucket/html2text
- add github.com/jhilleryerd/enmime/v2
- add github.com/ssor/bom
- add gopkg.in/loremipsum.v1
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
package sasl
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
)
|
|
|
|
// The EXTERNAL mechanism name.
|
|
const External = "EXTERNAL"
|
|
|
|
type externalClient struct {
|
|
Identity string
|
|
}
|
|
|
|
func (a *externalClient) Start() (mech string, ir []byte, err error) {
|
|
mech = External
|
|
ir = []byte(a.Identity)
|
|
return
|
|
}
|
|
|
|
func (a *externalClient) Next(challenge []byte) (response []byte, err error) {
|
|
return nil, ErrUnexpectedServerChallenge
|
|
}
|
|
|
|
// An implementation of the EXTERNAL authentication mechanism, as described in
|
|
// RFC 4422. Authorization identity may be left blank to indicate that the
|
|
// client is requesting to act as the identity associated with the
|
|
// authentication credentials.
|
|
func NewExternalClient(identity string) Client {
|
|
return &externalClient{identity}
|
|
}
|
|
|
|
// ExternalAuthenticator authenticates users with the EXTERNAL mechanism. If
|
|
// the identity is left blank, it indicates that it is the same as the one used
|
|
// in the external credentials. If identity is not empty and the server doesn't
|
|
// support it, an error must be returned.
|
|
type ExternalAuthenticator func(identity string) error
|
|
|
|
type externalServer struct {
|
|
done bool
|
|
authenticate ExternalAuthenticator
|
|
}
|
|
|
|
func (a *externalServer) Next(response []byte) (challenge []byte, done bool, err error) {
|
|
if a.done {
|
|
return nil, false, ErrUnexpectedClientResponse
|
|
}
|
|
|
|
// No initial response, send an empty challenge
|
|
if response == nil {
|
|
return []byte{}, false, nil
|
|
}
|
|
|
|
a.done = true
|
|
|
|
if bytes.Contains(response, []byte("\x00")) {
|
|
return nil, false, errors.New("sasl: identity contains a NUL character")
|
|
}
|
|
|
|
return nil, true, a.authenticate(string(response))
|
|
}
|
|
|
|
// NewExternalServer creates a server implementation of the EXTERNAL
|
|
// authentication mechanism, as described in RFC 4422.
|
|
func NewExternalServer(authenticator ExternalAuthenticator) Server {
|
|
return &externalServer{authenticate: authenticator}
|
|
}
|