Documentation ¶
Overview ¶
nolint: gosec
Index ¶
- Constants
- Variables
- func AuthMessage(...) string
- func ClientKey(h HashFunc, saltedPassword []byte) []byte
- func ClientProof(clientKey, clientSignature string) []byte
- func ClientSignature(h HashFunc, storedKey, authMessage string) []byte
- func H(hf HashFunc, data []byte) []byte
- func HMAC(hf HashFunc, key []byte, data []byte) []byte
- func Hi(h HashFunc, str string, salt []byte, i int) []byte
- func IsStandardError(err error) bool
- func SaltedPassword(h HashFunc, password string, salt []byte, i int) ([]byte, error)
- func ServerKey(h HashFunc, saltedPassword []byte) []byte
- func ServerSignature(h HashFunc, serverKey, authMessage string) []byte
- func StoredKey(h HashFunc, clientKey []byte) []byte
- func XOR(a, b []byte) []byte
- type Attribute
- type AttributeMap
- func (m *AttributeMap) Attribute(name string) (string, bool)
- func (m *AttributeMap) AuthorizationID() (string, bool)
- func (m *AttributeMap) ChannelBindingData() (string, bool)
- func (m *AttributeMap) ClientProof() ([]byte, bool)
- func (m *AttributeMap) DecodeAttribute(name string) ([]byte, bool)
- func (m *AttributeMap) EncodeAttribute(name string, value []byte)
- func (m *AttributeMap) Equals(other AttributeMap) bool
- func (m *AttributeMap) Error() (string, bool)
- func (m *AttributeMap) FutureFutureExtensibility() (string, bool)
- func (m *AttributeMap) IterationCount() (int, bool)
- func (m *AttributeMap) RandomSequence() (string, bool)
- func (m *AttributeMap) Salt() ([]byte, bool)
- func (m *AttributeMap) ServerSignature() ([]byte, bool)
- func (m *AttributeMap) SetAttribute(name, value string)
- func (m *AttributeMap) SetChannelBindingData(value string)
- func (m *AttributeMap) SetClientProof(value []byte)
- func (m *AttributeMap) SetError(value string)
- func (m *AttributeMap) SetFutureExtensibility(value string)
- func (m *AttributeMap) SetIterationCount(value int)
- func (m *AttributeMap) SetRandomSequence(value string)
- func (m *AttributeMap) SetSalt(value string)
- func (m *AttributeMap) SetSaltBytes(value []byte)
- func (m *AttributeMap) SetServerSignature(value []byte)
- func (m *AttributeMap) SetUsername(value string)
- func (m *AttributeMap) String() string
- func (m *AttributeMap) StringWithoutProof() string
- func (m *AttributeMap) Username() (string, bool)
- type Client
- func (client *Client) FinalMessageFrom(serverFirstMsg *Message) (*Message, error)
- func (client *Client) FirstMessage() (*Message, error)
- func (client *Client) HashFunc() HashFunc
- func (client *Client) SetOptions(opts ...ClientOption) error
- func (client *Client) ValidateServerFinalMessage(serverFinalMsg *Message) error
- type ClientOption
- func WithClientAuthzID(authzID string) ClientOption
- func WithClientChallenge(challenge string) ClientOption
- func WithClientHashFunc(hashFunc HashFunc) ClientOption
- func WithClientPassword(password string) ClientOption
- func WithClientPayload(payload mech.Payload) ClientOption
- func WithClientRandomSequence(randomSequence string) ClientOption
- func WithClientUsername(username string) ClientOption
- type HashFunc
- type Message
- func NewMessage(opts ...MessageOption) *Message
- func NewMessageFrom(v any) (*Message, error)
- func NewMessageFromString(msg string) (*Message, error)
- func NewMessageFromStringWithHeader(msg string) (*Message, error)
- func NewMessageFromWithHeader(v any) (*Message, error)
- func NewMessageWithError(err error) *Message
- func (msg *Message) Bytes() []byte
- func (msg *Message) Equals(other *Message) bool
- func (msg *Message) HasHeader() bool
- func (msg *Message) ParseString(str string) error
- func (msg *Message) ParseStringWithHeader(str string) error
- func (msg *Message) ParseStrings(props []string) error
- func (msg *Message) ParseStringsWithHeader(props []string) error
- func (msg *Message) String() string
- func (msg *Message) StringWithoutHeader() string
- func (msg *Message) StringWithoutProof() string
- type MessageOption
- type Server
- type ServerOption
- func WithServeMechanism(mechanism string) ServerOption
- func WithServerAuthenticators(authenticators cred.Authenticators) ServerOption
- func WithServerHashFunc(hashFunc HashFunc) ServerOption
- func WithServerIterationCount(iterationCount int) ServerOption
- func WithServerRandomSequence(randomSequence string) ServerOption
- func WithServerSaltString(salt string) ServerOption
Constants ¶
const ( AuthorizationIDAttr = "a" UserNameAttr = "n" FutureExtensibilityAttr = "m" RandomSequenceAttr = "r" ChannelBindingDataAttr = "c" SaltAttr = "s" IterationCountAttr = "i" ClientProofAttr = "p" ServerSignatureAttr = "v" ErrorAttr = "e" )
const ( // SHA1 is the SHA-1 hash function. SHA1 = "SCRAM-SHA-1" // SHA256 is the SHA-256 hash function. SHA256 = "SCRAM-SHA-256" // SHA512 is the SHA-512 hash function. SHA512 = "SCRAM-SHA-512" )
const ( UsernameID = "username" PasswordID = "password" RandomSequenceID = "randomSequence" SaltedPasswordID = "saltedPassword" ClientKeyID = "clientKey" ServerKeyID = "serverKey" StoredKeyID = "storedKey" AuthMessageID = "authMessage" ClientSignatureID = "clientSignature" ServerSignatureID = "serverSignature" SaltID = "salt" IterationCountID = "iterationCount" ClientProofID = "clientProof" )
Variables ¶
var ErrChannelBindingNotSupported = errors.New("channel-binding-not-supported")
ErrChannelBindingNotSupported is returned when the channel binding is not supported.
var ErrChannelBindingsDontMatch = errors.New("channel-bindings-dont-match")
ErrChannelBindingsDontMatch is returned when the channel bindings don't match.
var ErrExtensionsNotSupported = errors.New("extensions-not-supported")
ErrExtensionsNotSupported is returned when the extensions are not supported.
var ErrInvalidEncoding = errors.New("invalid-encoding")
ErrInvalidEncoding is returned when the encoding is invalid.
var ErrInvalidProof = errors.New("invalid-proof")
ErrInvalidProof is returned when the proof is invalid.
var ErrInvalidUsernameEncoding = errors.New("invalid-username-encoding")
ErrInvalidUsernameEncoding is returned when the username encoding is invalid.
var ErrNoResources = errors.New("no-resources")
ErrNoResources is returned when there are no resources.
var ErrOtherError = errors.New("other-error")
ErrOtherError is returned when there is another error.
var ErrServerDoesSupportChannelBinding = errors.New("server-does-not-support-channel-binding")
ErrServerDoesSupportChannelBinding is returned when the server does not support channel binding.
var ErrUnknownUser = errors.New("unknown-user")
ErrUnknownUser is returned when the user is unknown.
var ErrUnsupportedChannelBindingType = errors.New("unsupported-channel-binding-type")
ErrUnsupportedChannelBindingType is returned when the channel binding type is unsupported.
Functions ¶
func AuthMessage ¶
func AuthMessage(clientFirstMessageBare, serverFirstMessage, clientFinalMessageWithoutProof string) string
AuthMessage := client-first-message-bare + "," +
server-first-message + "," + client-final-message-without-proof
func ClientProof ¶
ClientProof := ClientKey XOR ClientSignature.
func ClientSignature ¶
ClientSignature := HMAC(StoredKey, AuthMessage).
func HMAC ¶
HMAC(key, data) is defined as:. 2.2. Notation RFC 2104 - HMAC: Keyed-Hashing for Message Authentication https://datatracker.ietf.org/doc/html/rfc2104
func IsStandardError ¶ added in v1.2.1
IsStandardError returns true if the error is a standard error.
func SaltedPassword ¶
SaltedPassword := Hi(Normalize(password), salt, i).
func ServerSignature ¶
ServerSignature := HMAC(ServerKey, AuthMessage).
Types ¶
type Attribute ¶
type Attribute interface { // Name returns the property name. Name() string // Value returns the property value. Value() string }
Attribute represents a message property.
func NewAttribute ¶
NewAttribute returns a new SASL attribute.
type AttributeMap ¶
type AttributeMap struct {
// contains filtered or unexported fields
}
AttributeMap represents a SCRAM attribute map.
func NewAttributeMap ¶
func NewAttributeMap() AttributeMap
NewAttributeMap returns a new SCRAM attribute map.
func (*AttributeMap) Attribute ¶
func (m *AttributeMap) Attribute(name string) (string, bool)
Attribute returns an attribute from the map.
func (*AttributeMap) AuthorizationID ¶
func (m *AttributeMap) AuthorizationID() (string, bool)
AuthorizationID returns the authorization ID attribute from the map.
func (*AttributeMap) ChannelBindingData ¶
func (m *AttributeMap) ChannelBindingData() (string, bool)
ChannelBindingData returns the channel binding data attribute from the map.
func (*AttributeMap) ClientProof ¶
func (m *AttributeMap) ClientProof() ([]byte, bool)
ClientProof returns the client proof attribute from the map.
func (*AttributeMap) DecodeAttribute ¶
func (m *AttributeMap) DecodeAttribute(name string) ([]byte, bool)
DecodeAttribute returns a base64 decoded attribute from the map.
func (*AttributeMap) EncodeAttribute ¶
func (m *AttributeMap) EncodeAttribute(name string, value []byte)
EncodeAttribute sets a base64 encoded attribute to the map.
func (*AttributeMap) Equals ¶
func (m *AttributeMap) Equals(other AttributeMap) bool
Equals returns true if the map is equal to the other map.
func (*AttributeMap) Error ¶
func (m *AttributeMap) Error() (string, bool)
Error returns the error attribute from the map.
func (*AttributeMap) FutureFutureExtensibility ¶
func (m *AttributeMap) FutureFutureExtensibility() (string, bool)
FutureExtensions returns the future extensibility attribute from the map.
func (*AttributeMap) IterationCount ¶
func (m *AttributeMap) IterationCount() (int, bool)
IterationCount returns the iteration count attribute from the map.
func (*AttributeMap) RandomSequence ¶
func (m *AttributeMap) RandomSequence() (string, bool)
RandomSequence returns the random sequence attribute from the map.
func (*AttributeMap) Salt ¶
func (m *AttributeMap) Salt() ([]byte, bool)
Salt returns the salt attribute from the map.
func (*AttributeMap) ServerSignature ¶
func (m *AttributeMap) ServerSignature() ([]byte, bool)
ServerSignature returns the server signature attribute from the map.
func (*AttributeMap) SetAttribute ¶
func (m *AttributeMap) SetAttribute(name, value string)
SetAttribute sets an attribute to the map.
func (*AttributeMap) SetChannelBindingData ¶
func (m *AttributeMap) SetChannelBindingData(value string)
SetChannelBindingData sets the channel binding data attribute to the map.
func (*AttributeMap) SetClientProof ¶
func (m *AttributeMap) SetClientProof(value []byte)
SetClientProof sets the client proof attribute to the map.
func (*AttributeMap) SetError ¶
func (m *AttributeMap) SetError(value string)
SetError sets the error attribute to the map.
func (*AttributeMap) SetFutureExtensibility ¶
func (m *AttributeMap) SetFutureExtensibility(value string)
SetFutureExtensibility sets the future extensibility attribute to the map.
func (*AttributeMap) SetIterationCount ¶
func (m *AttributeMap) SetIterationCount(value int)
SetIterationCount sets the iteration count attribute to the map.
func (*AttributeMap) SetRandomSequence ¶
func (m *AttributeMap) SetRandomSequence(value string)
SetRandomSequence sets the random sequence attribute to the map.
func (*AttributeMap) SetSalt ¶
func (m *AttributeMap) SetSalt(value string)
SetSalt sets the salt attribute to the map.
func (*AttributeMap) SetSaltBytes ¶
func (m *AttributeMap) SetSaltBytes(value []byte)
SetSaltBytes sets the salt attribute to the map.
func (*AttributeMap) SetServerSignature ¶
func (m *AttributeMap) SetServerSignature(value []byte)
SetServerSignature sets the server signature attribute to the map.
func (*AttributeMap) SetUsername ¶
func (m *AttributeMap) SetUsername(value string)
SetUsername sets the user name attribute to the map.
func (*AttributeMap) String ¶
func (m *AttributeMap) String() string
String returns the string representation of the map.
func (*AttributeMap) StringWithoutProof ¶
func (m *AttributeMap) StringWithoutProof() string
StringWithoutProof returns the string representation of the map without the proof.
func (*AttributeMap) Username ¶
func (m *AttributeMap) Username() (string, bool)
Username returns the user name attribute from the map.
type Client ¶
Client is a SCRAM client.
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient returns a new SCRAM client with options.
func NewClientFromPayload ¶ added in v1.1.0
NewClientFromPayload returns a new SCRAM client from the specified payload.
func NewClientFromPayloadWithHeader ¶ added in v1.1.0
NewClientFromPayloadWithHeader returns a new SCRAM client from the specified payload with the header.
func (*Client) FinalMessageFrom ¶
FinalMessageFrom returns the final message from the specified server first message.
func (*Client) FirstMessage ¶
FirstMessage returns the first message.
func (*Client) SetOptions ¶ added in v1.1.0
func (client *Client) SetOptions(opts ...ClientOption) error
SetOptions sets the client options.
func (*Client) ValidateServerFinalMessage ¶
ValidateServerFinalMessage validates the final message from the specified server final message.
type ClientOption ¶
ClientOption represents a client option function.
func WithClientAuthzID ¶
func WithClientAuthzID(authzID string) ClientOption
WithClientAuthzID returns a client option to set the authorization ID.
func WithClientChallenge ¶
func WithClientChallenge(challenge string) ClientOption
WithClientChallenge returns a client option to set the challenge.
func WithClientHashFunc ¶
func WithClientHashFunc(hashFunc HashFunc) ClientOption
WithClientHashFunc returns a client option to set the hash function.
func WithClientPassword ¶
func WithClientPassword(password string) ClientOption
WithClientPassword returns a client option to set the password.
func WithClientPayload ¶ added in v1.1.0
func WithClientPayload(payload mech.Payload) ClientOption
func WithClientRandomSequence ¶
func WithClientRandomSequence(randomSequence string) ClientOption
WithClientRandomSequence returns a client option to set the random sequence.
func WithClientUsername ¶
func WithClientUsername(username string) ClientOption
WithClientUsername returns a client option to set the username.
type HashFunc ¶
HashFunc is a function that returns a hash.Hash.
type Message ¶
type Message struct { *gss.Header AttributeMap }
Message represents a SCRAM message.
func NewMessageFrom ¶
NewMessageFrom returns a new message from the specified value.
func NewMessageFromString ¶
NewMessageFromString returns a new message from the specified string.
func NewMessageFromStringWithHeader ¶
NewMessageFromStringWithHeader returns a new message from the specified string with the GS2 header.
func NewMessageFromWithHeader ¶ added in v1.2.0
NewMessageFromWithHeader returns a new message from the specified value with the GS2 header.
func NewMessageWithError ¶ added in v1.2.1
NewMessageWithError returns a new message from the specified error.
func (*Message) ParseString ¶
ParseStringWithHeader parses the specified string.
func (*Message) ParseStringWithHeader ¶
ParseStringWithHeader parses the specified string with the GS2 header.
func (*Message) ParseStrings ¶
ParseStringsWithHeader parses the specified property strings.
func (*Message) ParseStringsWithHeader ¶
ParseStringsWithHeader parses the specified property strings with the GS2 header.
func (*Message) StringWithoutHeader ¶ added in v1.2.0
StringWithoutHeader returns the string representation of the message without the header.
func (*Message) StringWithoutProof ¶
StringWithoutProof returns the string representation of the message without the proof.
type MessageOption ¶
type MessageOption func(*Message)
MessageOption represents a message option.
func WithAttribute ¶
func WithAttribute(name, value string) MessageOption
func WithHeader ¶
func WithHeader(header *gss.Header) MessageOption
WithHeader returns an option to set the GS2 header.
type Server ¶
type Server struct { mech.Store *cred.CredentialStore // contains filtered or unexported fields }
Server represents a SCRAM server.
func NewServer ¶
func NewServer(opts ...ServerOption) (*Server, error)
NewServer returns a new SCRAM server.
func (*Server) FinalMessageFrom ¶
FinalMessageFrom returns a new server final message from the specified client final message.
func (*Server) FirstMessageFrom ¶
FirstMessageFrom returns a new server first message from the specified client message.
func (*Server) SetOptions ¶ added in v1.2.0
func (server *Server) SetOptions(opts ...ServerOption) error
SetOptions sets the specified options.
type ServerOption ¶
ServerOption represents a server option.
func WithServeMechanism ¶ added in v1.2.1
func WithServeMechanism(mechanism string) ServerOption
WithServeMechanism returns a server option to set the mechanism.
func WithServerAuthenticators ¶
func WithServerAuthenticators(authenticators cred.Authenticators) ServerOption
WithServerAuthenticators returns a server option to set the authenticators.
func WithServerHashFunc ¶
func WithServerHashFunc(hashFunc HashFunc) ServerOption
WithServerHashFunc returns a server option to set the hash function.
func WithServerIterationCount ¶
func WithServerIterationCount(iterationCount int) ServerOption
WithServerIterationCount returns a server option to set the iteration count.
func WithServerRandomSequence ¶
func WithServerRandomSequence(randomSequence string) ServerOption
WithServerRandomSequence returns a server option to set the random sequence.
func WithServerSaltString ¶
func WithServerSaltString(salt string) ServerOption
WithServerSaltString returns a server option to set the salt.