Skip to content

Commit

Permalink
add next_protos support to tlsconfig
Browse files Browse the repository at this point in the history
Signed-off-by: david kydd <[email protected]>
  • Loading branch information
davidkydd committed Nov 4, 2024
1 parent 653e0fa commit dfb55b0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
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": ["testproto1", "testproto2"]}
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: ["testproto1", "testproto2"]
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{"testproto1", "testproto2"}},
},
{
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{"testproto1", "testproto2"}},
},
{
filename: "tls_config.tlsversion.good.yml",
config: &tls.Config{MinVersion: tls.VersionTLS11},
Expand Down

0 comments on commit dfb55b0

Please sign in to comment.