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

Support Application-Layer Protocol negotiation via nextProtos flag in tlsconfig #713

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,10 @@ func NewTLSConfigWithContext(ctx context.Context, cfg *TLSConfig, optFuncs ...TL
tlsConfig.ServerName = cfg.ServerName
}

if len(cfg.NextProtos) > 0 {
tlsConfig.NextProtos = cfg.NextProtos
}

// If a client cert & key is provided then configure TLS config accordingly.
if cfg.usingClientCert() && cfg.usingClientKey() {
// Verify that client cert and key are valid.
Expand Down Expand Up @@ -1118,6 +1122,8 @@ type TLSConfig struct {
MinVersion TLSVersion `yaml:"min_version,omitempty" json:"min_version,omitempty"`
// Maximum TLS version.
MaxVersion TLSVersion `yaml:"max_version,omitempty" json:"max_version,omitempty"`
// Additional ALPN protocols to be presented when connecting to the server.
NextProtos []string `yaml:"next_protos,omitempty" json:"next_protos,omitempty"`
}

// SetDirectory joins any relative file paths with dir.
Expand Down
1 change: 1 addition & 0 deletions config/testdata/tls_config.next_protos.good.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"next_protos": ["h2", "http/1.1"]}
1 change: 1 addition & 0 deletions config/testdata/tls_config.next_protos.good.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
next_protos: ["h2", "http/1.1"]
8 changes: 8 additions & 0 deletions config/tls_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ var expectedTLSConfigs = []struct {
filename: "tls_config.insecure.good.json",
config: &tls.Config{InsecureSkipVerify: true},
},
{
filename: "tls_config.next_protos.good.json",
config: &tls.Config{NextProtos: []string{"h2", "http/1.1"}},
},
{
filename: "tls_config.tlsversion.good.json",
config: &tls.Config{MinVersion: tls.VersionTLS11},
Expand All @@ -79,6 +83,10 @@ var expectedTLSConfigs = []struct {
filename: "tls_config.insecure.good.yml",
config: &tls.Config{InsecureSkipVerify: true},
},
{
filename: "tls_config.next_protos.good.yml",
config: &tls.Config{NextProtos: []string{"h2", "http/1.1"}},
},
{
filename: "tls_config.tlsversion.good.yml",
config: &tls.Config{MinVersion: tls.VersionTLS11},
Expand Down