http3: expose ALPN values (#3580)

This commit is contained in:
Marten Seemann 2022-10-11 14:27:49 +03:00 committed by GitHub
parent fe277dc663
commit c75bf49422
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 11 deletions

View file

@ -66,7 +66,7 @@ var _ = Describe("Client", func() {
var dialAddrCalled bool var dialAddrCalled bool
dialAddr = func(_ context.Context, _ string, tlsConf *tls.Config, quicConf *quic.Config) (quic.EarlyConnection, error) { dialAddr = func(_ context.Context, _ string, tlsConf *tls.Config, quicConf *quic.Config) (quic.EarlyConnection, error) {
Expect(quicConf).To(Equal(defaultQuicConfig)) Expect(quicConf).To(Equal(defaultQuicConfig))
Expect(tlsConf.NextProtos).To(Equal([]string{nextProtoH3})) Expect(tlsConf.NextProtos).To(Equal([]string{NextProtoH3}))
Expect(quicConf.Versions).To(Equal([]protocol.VersionNumber{protocol.Version1})) Expect(quicConf.Versions).To(Equal([]protocol.VersionNumber{protocol.Version1}))
dialAddrCalled = true dialAddrCalled = true
return nil, errors.New("test done") return nil, errors.New("test done")
@ -102,7 +102,7 @@ var _ = Describe("Client", func() {
dialAddr = func(_ context.Context, host string, tlsConfP *tls.Config, quicConfP *quic.Config) (quic.EarlyConnection, error) { dialAddr = func(_ context.Context, host string, tlsConfP *tls.Config, quicConfP *quic.Config) (quic.EarlyConnection, error) {
Expect(host).To(Equal("localhost:1337")) Expect(host).To(Equal("localhost:1337"))
Expect(tlsConfP.ServerName).To(Equal(tlsConf.ServerName)) Expect(tlsConfP.ServerName).To(Equal(tlsConf.ServerName))
Expect(tlsConfP.NextProtos).To(Equal([]string{nextProtoH3})) Expect(tlsConfP.NextProtos).To(Equal([]string{NextProtoH3}))
Expect(quicConfP.MaxIdleTimeout).To(Equal(quicConf.MaxIdleTimeout)) Expect(quicConfP.MaxIdleTimeout).To(Equal(quicConf.MaxIdleTimeout))
dialAddrCalled = true dialAddrCalled = true
return nil, errors.New("test done") return nil, errors.New("test done")

View file

@ -28,8 +28,10 @@ var (
) )
const ( const (
nextProtoH3Draft29 = "h3-29" // NextProtoH3Draft29 is the ALPN protocol negotiated during the TLS handshake, for QUIC draft 29.
nextProtoH3 = "h3" NextProtoH3Draft29 = "h3-29"
// NextProtoH3 is the ALPN protocol negotiated during the TLS handshake, for QUIC v1 and v2.
NextProtoH3 = "h3"
) )
// StreamType is the stream type of a unidirectional stream. // StreamType is the stream type of a unidirectional stream.
@ -44,10 +46,10 @@ const (
func versionToALPN(v protocol.VersionNumber) string { func versionToALPN(v protocol.VersionNumber) string {
if v == protocol.Version1 || v == protocol.Version2 { if v == protocol.Version1 || v == protocol.Version2 {
return nextProtoH3 return NextProtoH3
} }
if v == protocol.VersionTLS || v == protocol.VersionDraft29 { if v == protocol.VersionTLS || v == protocol.VersionDraft29 {
return nextProtoH3Draft29 return NextProtoH3Draft29
} }
return "" return ""
} }
@ -62,7 +64,7 @@ func ConfigureTLSConfig(tlsConf *tls.Config) *tls.Config {
return &tls.Config{ return &tls.Config{
GetConfigForClient: func(ch *tls.ClientHelloInfo) (*tls.Config, error) { GetConfigForClient: func(ch *tls.ClientHelloInfo) (*tls.Config, error) {
// determine the ALPN from the QUIC version used // determine the ALPN from the QUIC version used
proto := nextProtoH3 proto := NextProtoH3
if qconn, ok := ch.Conn.(handshake.ConnWithVersion); ok { if qconn, ok := ch.Conn.(handshake.ConnWithVersion); ok {
proto = versionToALPN(qconn.GetQUICVersion()) proto = versionToALPN(qconn.GetQUICVersion())
} }

View file

@ -959,7 +959,7 @@ var _ = Describe("Server", func() {
config, err := tlsConf.GetConfigForClient(ch) config, err := tlsConf.GetConfigForClient(ch)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(config.NextProtos).To(Equal([]string{nextProtoH3})) Expect(config.NextProtos).To(Equal([]string{NextProtoH3}))
}) })
It("advertises h3-29 for draft-29", func() { It("advertises h3-29 for draft-29", func() {
@ -969,7 +969,7 @@ var _ = Describe("Server", func() {
ch.Conn = newMockConn(protocol.VersionDraft29) ch.Conn = newMockConn(protocol.VersionDraft29)
config, err := tlsConf.GetConfigForClient(ch) config, err := tlsConf.GetConfigForClient(ch)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
Expect(config.NextProtos).To(Equal([]string{nextProtoH3Draft29})) Expect(config.NextProtos).To(Equal([]string{NextProtoH3Draft29}))
}) })
}) })
@ -1163,10 +1163,10 @@ var _ = Describe("Server", func() {
checkGetConfigForClientVersions := func(conf *tls.Config) { checkGetConfigForClientVersions := func(conf *tls.Config) {
c, err := conf.GetConfigForClient(&tls.ClientHelloInfo{Conn: newMockConn(protocol.VersionDraft29)}) c, err := conf.GetConfigForClient(&tls.ClientHelloInfo{Conn: newMockConn(protocol.VersionDraft29)})
ExpectWithOffset(1, err).ToNot(HaveOccurred()) ExpectWithOffset(1, err).ToNot(HaveOccurred())
ExpectWithOffset(1, c.NextProtos).To(Equal([]string{nextProtoH3Draft29})) ExpectWithOffset(1, c.NextProtos).To(Equal([]string{NextProtoH3Draft29}))
c, err = conf.GetConfigForClient(&tls.ClientHelloInfo{Conn: newMockConn(protocol.Version1)}) c, err = conf.GetConfigForClient(&tls.ClientHelloInfo{Conn: newMockConn(protocol.Version1)})
ExpectWithOffset(1, err).ToNot(HaveOccurred()) ExpectWithOffset(1, err).ToNot(HaveOccurred())
ExpectWithOffset(1, c.NextProtos).To(Equal([]string{nextProtoH3})) ExpectWithOffset(1, c.NextProtos).To(Equal([]string{NextProtoH3}))
} }
It("uses the quic.Config to start the QUIC server", func() { It("uses the quic.Config to start the QUIC server", func() {