Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http3: expose ALPN values #3580

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions http3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var _ = Describe("Client", func() {
var dialAddrCalled bool
dialAddr = func(_ context.Context, _ string, tlsConf *tls.Config, quicConf *quic.Config) (quic.EarlyConnection, error) {
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}))
dialAddrCalled = true
return nil, errors.New("test done")
Expand Down Expand Up @@ -102,7 +102,7 @@ var _ = Describe("Client", func() {
dialAddr = func(_ context.Context, host string, tlsConfP *tls.Config, quicConfP *quic.Config) (quic.EarlyConnection, error) {
Expect(host).To(Equal("localhost:1337"))
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))
dialAddrCalled = true
return nil, errors.New("test done")
Expand Down
12 changes: 7 additions & 5 deletions http3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ var (
)

const (
nextProtoH3Draft29 = "h3-29"
nextProtoH3 = "h3"
// NextProtoH3Draft29 is the ALPN protocol negotiated during the TLS handshake, for QUIC draft 29.
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.
Expand All @@ -44,10 +46,10 @@ const (

func versionToALPN(v protocol.VersionNumber) string {
if v == protocol.Version1 || v == protocol.Version2 {
return nextProtoH3
return NextProtoH3
}
if v == protocol.VersionTLS || v == protocol.VersionDraft29 {
return nextProtoH3Draft29
return NextProtoH3Draft29
}
return ""
}
Expand All @@ -62,7 +64,7 @@ func ConfigureTLSConfig(tlsConf *tls.Config) *tls.Config {
return &tls.Config{
GetConfigForClient: func(ch *tls.ClientHelloInfo) (*tls.Config, error) {
// determine the ALPN from the QUIC version used
proto := nextProtoH3
proto := NextProtoH3
if qconn, ok := ch.Conn.(handshake.ConnWithVersion); ok {
proto = versionToALPN(qconn.GetQUICVersion())
}
Expand Down
8 changes: 4 additions & 4 deletions http3/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ var _ = Describe("Server", func() {

config, err := tlsConf.GetConfigForClient(ch)
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() {
Expand All @@ -952,7 +952,7 @@ var _ = Describe("Server", func() {
ch.Conn = newMockConn(protocol.VersionDraft29)
config, err := tlsConf.GetConfigForClient(ch)
Expect(err).NotTo(HaveOccurred())
Expect(config.NextProtos).To(Equal([]string{nextProtoH3Draft29}))
Expect(config.NextProtos).To(Equal([]string{NextProtoH3Draft29}))
})
})

Expand Down Expand Up @@ -1146,10 +1146,10 @@ var _ = Describe("Server", func() {
checkGetConfigForClientVersions := func(conf *tls.Config) {
c, err := conf.GetConfigForClient(&tls.ClientHelloInfo{Conn: newMockConn(protocol.VersionDraft29)})
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)})
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() {
Expand Down