Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Support tls-exporter channel binding type #243

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## jackal - main / unreleased

* [ENHANCEMENT] Re-enable TLS 1.3 channel binding during auth using [RFC 9266](https://www.rfc-editor.org/rfc/rfc9266).

## 0.61.0 (2022/06/06)

* [ENHANCEMENT] Helm: added support for cloud LB. [237](https://github.com/ortuman/jackal/pull/237)
Expand Down
2 changes: 2 additions & 0 deletions pkg/auth/scram.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ func (s *Scram) getCBindInputString() string {
switch s.params.cbMechanism {
SamWhited marked this conversation as resolved.
Show resolved Hide resolved
case "tls-unique":
buf.Write(s.tr.ChannelBindingBytes(transport.TLSUnique))
case "tls-exporter":
buf.Write(s.tr.ChannelBindingBytes(transport.TLSExporter))
}
}
return base64.StdEncoding.EncodeToString(buf.Bytes())
Expand Down
2 changes: 1 addition & 1 deletion pkg/c2s/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ func (s *inC2S) unauthenticatedFeatures() []stravaganza.Element {
sb.WithAttribute(stravaganza.Namespace, saslNamespace)
for _, authenticator := range s.authSt.authenticators {
if authenticator.UsesChannelBinding() && !supportsCb {
continue // transport doesn't support channel binding (eg. TLS 1.3)
continue // transport doesn't support channel binding
}
sb.WithChild(
stravaganza.NewBuilder("mechanism").
Expand Down
14 changes: 8 additions & 6 deletions pkg/transport/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ type socketTransport struct {
wr io.Writer
bw *bufio.Writer
compressed bool
supportsCb bool
connectTimeout time.Duration
keepAliveTimeout time.Duration
}
Expand Down Expand Up @@ -147,7 +146,6 @@ func (s *socketTransport) StartTLS(cfg *tls.Config, asClient bool) {
tlsConn = tls.Server(s.conn, cfg)
}
s.conn = newDeadlineConn(tlsConn, s.connectTimeout, s.keepAliveTimeout)
s.supportsCb = tlsConn.ConnectionState().Version < tls.VersionTLS13

lr := ratelimiter.NewReader(s.conn)
if rLim := s.lr.ReadRateLimiter(); rLim != nil {
Expand All @@ -169,13 +167,10 @@ func (s *socketTransport) EnableCompression(level compress.Level) {
}

func (s *socketTransport) SupportsChannelBinding() bool {
return s.supportsCb
return true
SamWhited marked this conversation as resolved.
Show resolved Hide resolved
}

func (s *socketTransport) ChannelBindingBytes(mechanism ChannelBindingMechanism) []byte {
if !s.supportsCb {
return nil
}
conn, ok := s.conn.underlyingConn().(tlsStateQueryable)
if !ok {
return nil
Expand All @@ -184,6 +179,13 @@ func (s *socketTransport) ChannelBindingBytes(mechanism ChannelBindingMechanism)
case TLSUnique:
connSt := conn.ConnectionState()
return connSt.TLSUnique
case TLSExporter:
connSt := conn.ConnectionState()
ekm, err := connSt.ExportKeyingMaterial("EXPORTER-Channel-Binding", nil, 32)
if err != nil {
return nil
}
return ekm
default:
break
}
Expand Down
1 change: 1 addition & 0 deletions pkg/transport/socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func TestSocket(t *testing.T) {

require.Nil(t, st2.ChannelBindingBytes(ChannelBindingMechanism(99)))
require.Nil(t, st2.ChannelBindingBytes(TLSUnique))
require.Nil(t, st2.ChannelBindingBytes(TLSExporter))

_ = st.Close()
require.True(t, conn.closed)
Expand Down
2 changes: 2 additions & 0 deletions pkg/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type ChannelBindingMechanism int
const (
// TLSUnique represents 'tls-unique' channel binding mechanism.
TLSUnique ChannelBindingMechanism = iota
// TLSExporter represents the 'tls-exporter' channel binding mechanism.
TLSExporter
)

// Transport represents a stream transport mechanism.
Expand Down