github.com/Jeffail/benthos/v3@v3.65.0/lib/util/kafka/sasl/scram.go (about) 1 package sasl 2 3 import ( 4 "crypto/sha256" 5 "crypto/sha512" 6 7 "github.com/xdg/scram" 8 ) 9 10 //------------------------------------------------------------------------------ 11 12 // SHA256 generates the SHA256 hash 13 var SHA256 scram.HashGeneratorFcn = sha256.New 14 15 // SHA512 generates the SHA512 hash 16 var SHA512 scram.HashGeneratorFcn = sha512.New 17 18 // XDGSCRAMClient represents struct to XDG Scram client to initialize conversation 19 type XDGSCRAMClient struct { 20 *scram.Client 21 *scram.ClientConversation 22 scram.HashGeneratorFcn 23 } 24 25 // Begin initializes new client and conversation to securely transmit the provided credentials to Kafka 26 func (x *XDGSCRAMClient) Begin(userName, password, authzID string) (err error) { 27 x.Client, err = x.HashGeneratorFcn.NewClient(userName, password, authzID) 28 if err != nil { 29 return err 30 } 31 x.ClientConversation = x.Client.NewConversation() 32 return nil 33 } 34 35 // Step takes a string provided from a server (or just an empty string for the very first conversation step) 36 // and attempts to move the authentication conversation forward 37 func (x *XDGSCRAMClient) Step(challenge string) (response string, err error) { 38 response, err = x.ClientConversation.Step(challenge) 39 return 40 } 41 42 // Done returns true if the conversation is completed or has errored. 43 func (x *XDGSCRAMClient) Done() bool { 44 return x.ClientConversation.Done() 45 } 46 47 //------------------------------------------------------------------------------