Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tls_max_version in listener config. #11226

Merged
merged 3 commits into from
Mar 29, 2021
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
3 changes: 3 additions & 0 deletions changelog/11226.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```changelog:enhancement
Copy link
Collaborator

@mladlow mladlow Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be "release-note", although I am getting in here too late for that to be really useful.

core: Add tls_max_version listener config option.
```
2 changes: 2 additions & 0 deletions command/server/config_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ listener "tcp" {
tls_key_file = "./certs/server.key"
tls_client_ca_file = "./certs/rootca.crt"
tls_min_version = "tls12"
tls_max_version = "tls13"
tls_require_and_verify_client_cert = true
tls_disable_client_certs = true
}`))
Expand Down Expand Up @@ -737,6 +738,7 @@ listener "tcp" {
TLSKeyFile: "./certs/server.key",
TLSClientCAFile: "./certs/rootca.crt",
TLSMinVersion: "tls12",
TLSMaxVersion: "tls13",
TLSRequireAndVerifyClientCert: true,
TLSDisableClientCerts: true,
},
Expand Down
24 changes: 19 additions & 5 deletions command/server/listener_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestTCPListener(t *testing.T) {
return net.Dial("tcp", ln.Addr().String())
}

testListenerImpl(t, ln, connFn, "")
testListenerImpl(t, ln, connFn, "", 0)
}

// TestTCPListener_tls tests TLS generally
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestTCPListener_tls(t *testing.T) {
}
}

testListenerImpl(t, ln, connFn(true), "foo.example.com")
testListenerImpl(t, ln, connFn(true), "foo.example.com", 0)

ln, _, _, err = tcpListenerFactory(&configutil.Listener{
Address: "127.0.0.1:0",
Expand All @@ -111,7 +111,7 @@ func TestTCPListener_tls(t *testing.T) {
t.Fatalf("err: %s", err)
}

testListenerImpl(t, ln, connFn(false), "foo.example.com")
testListenerImpl(t, ln, connFn(false), "foo.example.com", 0)
}

func TestTCPListener_tls13(t *testing.T) {
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestTCPListener_tls13(t *testing.T) {
}
}

testListenerImpl(t, ln, connFn(true), "foo.example.com")
testListenerImpl(t, ln, connFn(true), "foo.example.com", tls.VersionTLS13)

ln, _, _, err = tcpListenerFactory(&configutil.Listener{
Address: "127.0.0.1:0",
Expand All @@ -196,5 +196,19 @@ func TestTCPListener_tls13(t *testing.T) {
t.Fatalf("err: %s", err)
}

testListenerImpl(t, ln, connFn(false), "foo.example.com")
testListenerImpl(t, ln, connFn(false), "foo.example.com", tls.VersionTLS13)

ln, _, _, err = tcpListenerFactory(&configutil.Listener{
Address: "127.0.0.1:0",
TLSCertFile: wd + "reload_foo.pem",
TLSKeyFile: wd + "reload_foo.key",
TLSDisableClientCerts: true,
TLSClientCAFile: wd + "reload_ca.pem",
TLSMaxVersion: "tls12",
}, nil, cli.NewMockUi())
if err != nil {
t.Fatalf("err: %s", err)
}

testListenerImpl(t, ln, connFn(false), "foo.example.com", tls.VersionTLS12)
}
5 changes: 4 additions & 1 deletion command/server/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type testListenerConnFn func(net.Listener) (net.Conn, error)

func testListenerImpl(t *testing.T, ln net.Listener, connFn testListenerConnFn, certName string) {
func testListenerImpl(t *testing.T, ln net.Listener, connFn testListenerConnFn, certName string, expectedVersion uint16) {
serverCh := make(chan net.Conn, 1)
go func() {
server, err := ln.Accept()
Expand All @@ -31,6 +31,9 @@ func testListenerImpl(t *testing.T, ln net.Listener, connFn testListenerConnFn,

if certName != "" {
tlsConn := client.(*tls.Conn)
if expectedVersion != 0 && tlsConn.ConnectionState().Version != expectedVersion {
t.Fatalf("expected version %d, got %d", expectedVersion, tlsConn.ConnectionState().Version)
}
if len(tlsConn.ConnectionState().PeerCertificates) != 1 {
t.Fatalf("err: number of certs too long")
}
Expand Down
1 change: 1 addition & 0 deletions internalshared/configutil/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Listener struct {
TLSCertFile string `hcl:"tls_cert_file"`
TLSKeyFile string `hcl:"tls_key_file"`
TLSMinVersion string `hcl:"tls_min_version"`
TLSMaxVersion string `hcl:"tls_max_version"`
TLSCipherSuites []uint16 `hcl:"-"`
TLSCipherSuitesRaw string `hcl:"tls_cipher_suites"`
TLSPreferServerCipherSuites bool `hcl:"-"`
Expand Down
13 changes: 13 additions & 0 deletions internalshared/listenerutil/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,25 @@ PASSPHRASECORRECT:
l.TLSMinVersion = "tls12"
}

if l.TLSMaxVersion == "" {
l.TLSMaxVersion = "tls13"
}

var ok bool
tlsConf.MinVersion, ok = tlsutil.TLSLookup[l.TLSMinVersion]
if !ok {
return nil, nil, fmt.Errorf("'tls_min_version' value %q not supported, please specify one of [tls10,tls11,tls12,tls13]", l.TLSMinVersion)
}

tlsConf.MaxVersion, ok = tlsutil.TLSLookup[l.TLSMaxVersion]
if !ok {
return nil, nil, fmt.Errorf("'tls_max_version' value %q not supported, please specify one of [tls10,tls11,tls12,tls13]", l.TLSMaxVersion)
}

if tlsConf.MaxVersion < tlsConf.MinVersion {
return nil, nil, fmt.Errorf("'tls_max_version' must be greater than or equal to 'tls_min_version'")
}

if len(l.TLSCipherSuites) > 0 {
// HTTP/2 with TLS 1.2 blacklists several cipher suites.
// https://tools.ietf.org/html/rfc7540#appendix-A
Expand Down