@@ -2,11 +2,14 @@ package proxy
22
33import (
44 "bytes"
5+ "crypto/sha256"
6+ "crypto/sha512"
57 "encoding/binary"
68 "fmt"
79 "github.com/grepplabs/kafka-proxy/proxy/protocol"
810 "github.com/sirupsen/logrus"
911 "github.com/xdg/scram"
12+ "hash"
1013 "io"
1114 "time"
1215)
@@ -30,6 +33,11 @@ type SASLSCRAMAuth struct {
3033 SCRAMAuthzID string
3134}
3235
36+ // Workaround for xdg-go not having accepted this pull request:
37+ // https://github.com/xdg-go/scram/pull/1/commits
38+ var SHA256 scram.HashGeneratorFcn = func () hash.Hash { return sha256 .New () }
39+ var SHA512 scram.HashGeneratorFcn = func () hash.Hash { return sha512 .New () }
40+
3341// Maps to Sarama sendAndReceiveSASLSCRAMv1
3442func (b * SASLSCRAMAuth ) sendAndReceiveSASLAuth (conn DeadlineReaderWriter ) error {
3543
@@ -41,18 +49,17 @@ func (b *SASLSCRAMAuth) sendAndReceiveSASLAuth(conn DeadlineReaderWriter) error
4149
4250 var scramClient * scram.Client
4351 if b .mechanism == "SCRAM-SHA-256" {
44- scramClient , err = scram . SHA256 .NewClient (b .username , b .password , "" )
52+ scramClient , err = SHA256 .NewClient (b .username , b .password , "" )
4553 if err != nil {
4654 logrus .Debugf ("Unable to make scram client for SCRAM-SHA-256: %v" , err )
4755 return err
4856 }
4957 } else if b .mechanism == "SCRAM-SHA-512" {
50- // Awaiting upstream acceptance in the scram library for this to work
51- // scramClient, err = scram.SHA512.NewClient(b.username, b.password, "")
52- //if err != nil {
53- // logrus.Debugf("Unable to make scram client for SCRAM-SHA-512: %v", err)
54- // return err
55- //}
58+ scramClient , err = SHA512 .NewClient (b .username , b .password , "" )
59+ if err != nil {
60+ logrus .Debugf ("Unable to make scram client for SCRAM-SHA-512: %v" , err )
61+ return err
62+ }
5663 } else {
5764 return fmt .Errorf ("Invalid SCRAM specification provided: %s. Expected one of [\" SCRAM-SHA-256\" ,\" SCRAM-SHA-512\" ]" , b .mechanism )
5865 }
0 commit comments