Skip to content

Commit

Permalink
tlsconfig: add ability to set server's NextProtos (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhenke authored and nmiyake committed Dec 21, 2017
1 parent 72fc21d commit 6d7700b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tlsconfig/tlsconfig_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,12 @@ func ServerClientAuthType(authType tls.ClientAuthType) ServerParam {
func ServerCipherSuites(cipherSuites ...uint16) ServerParam {
return serverParam(cipherSuitesParam(cipherSuites...))
}

// ServerNextProtos sets the list of application level protocols supported by
// the server e.g. "http/1.1" or "h2".
func ServerNextProtos(protos ...string) ServerParam {
return serverParam(func(cfg *tls.Config) error {
cfg.NextProtos = protos
return nil
})
}
8 changes: 8 additions & 0 deletions tlsconfig/tlsconfig_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestNewServerConfig(t *testing.T) {
clientCAFiles []string
authType tls.ClientAuthType
cipherSuites []uint16
nextProtos []string
}{
{
name: "defaults",
Expand All @@ -41,12 +42,19 @@ func TestNewServerConfig(t *testing.T) {
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
},
},
{
name: "nextProtos specified",
nextProtos: []string{
"http/1.1",
},
},
} {
cfg, err := tlsconfig.NewServerConfig(
tlsconfig.TLSCertFromFiles(serverCertFile, serverKeyFile),
tlsconfig.ServerClientCAFiles(currCase.clientCAFiles...),
tlsconfig.ServerClientAuthType(currCase.authType),
tlsconfig.ServerCipherSuites(currCase.cipherSuites...),
tlsconfig.ServerNextProtos(currCase.nextProtos...),
)
require.NoError(t, err)
assert.NotNil(t, cfg, "Case %d: %s", currCaseNum, currCase.name)
Expand Down

0 comments on commit 6d7700b

Please sign in to comment.