don't replace the ALPN in the tls.Config returned by GetConfigForClient

This commit is contained in:
Marten Seemann 2019-11-09 17:26:52 +07:00
parent a3663a049d
commit b444ca613c
2 changed files with 26 additions and 0 deletions

View file

@ -113,6 +113,7 @@ func (s *Server) serveImpl(tlsConf *tls.Config, conn net.PacketConn) error {
if err != nil || conf == nil {
return conf, err
}
conf = conf.Clone()
conf.NextProtos = []string{nextProtoH3}
return conf, nil
}

View file

@ -544,6 +544,31 @@ var _ = Describe("Server", func() {
Expect(err).ToNot(HaveOccurred())
Expect(conf.NextProtos).To(Equal([]string{"foo", "bar"}))
})
It("sets the ALPN for tls.Configs returned by the tls.GetConfigForClient, if it returns a static tls.Config", func() {
tlsClientConf := &tls.Config{NextProtos: []string{"foo", "bar"}}
tlsConf := &tls.Config{
GetConfigForClient: func(ch *tls.ClientHelloInfo) (*tls.Config, error) {
return tlsClientConf, nil
},
}
var receivedConf *tls.Config
quicListenAddr = func(addr string, conf *tls.Config, _ *quic.Config) (quic.Listener, error) {
receivedConf = conf
return nil, errors.New("listen err")
}
s.TLSConfig = tlsConf
Expect(s.ListenAndServe()).To(HaveOccurred())
// check that the config used by QUIC uses the h3 ALPN
conf, err := receivedConf.GetConfigForClient(&tls.ClientHelloInfo{})
Expect(err).ToNot(HaveOccurred())
Expect(conf.NextProtos).To(Equal([]string{nextProtoH3}))
// check that the original config was not modified
conf, err = tlsConf.GetConfigForClient(&tls.ClientHelloInfo{})
Expect(err).ToNot(HaveOccurred())
Expect(conf.NextProtos).To(Equal([]string{"foo", "bar"}))
})
})
It("closes gracefully", func() {