forked from quic-go/quic-go
set the H3 ALPN on tls.Configs returned by GetConfigForClient
This commit is contained in:
@@ -99,6 +99,17 @@ func (s *Server) serveImpl(tlsConf *tls.Config, conn net.PacketConn) error {
|
||||
}
|
||||
// Replace existing ALPNs by H3
|
||||
tlsConf.NextProtos = []string{nextProtoH3}
|
||||
if tlsConf.GetConfigForClient != nil {
|
||||
getConfigForClient := tlsConf.GetConfigForClient
|
||||
tlsConf.GetConfigForClient = func(ch *tls.ClientHelloInfo) (*tls.Config, error) {
|
||||
conf, err := getConfigForClient(ch)
|
||||
if err != nil || conf == nil {
|
||||
return conf, err
|
||||
}
|
||||
conf.NextProtos = []string{nextProtoH3}
|
||||
return conf, nil
|
||||
}
|
||||
}
|
||||
|
||||
var ln quic.Listener
|
||||
var err error
|
||||
|
||||
@@ -406,6 +406,30 @@ var _ = Describe("Server", func() {
|
||||
Expect(s.ListenAndServe()).To(HaveOccurred())
|
||||
Expect(receivedConf.NextProtos).To(Equal([]string{nextProtoH3}))
|
||||
})
|
||||
|
||||
It("sets the ALPN for tls.Configs returned by the tls.GetConfigForClient", func() {
|
||||
tlsConf := &tls.Config{
|
||||
GetConfigForClient: func(ch *tls.ClientHelloInfo) (*tls.Config, error) {
|
||||
return &tls.Config{NextProtos: []string{"foo", "bar"}}, 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"}))
|
||||
})
|
||||
})
|
||||
|
||||
Context("ListenAndServeTLS", func() {
|
||||
|
||||
Reference in New Issue
Block a user