Skip to content

Commit

Permalink
http3: expose ALPN values (#3580)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Oct 11, 2022
1 parent fe277dc commit c75bf49
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions http3/client_test.go
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
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
Expand Up @@ -959,7 +959,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 @@ -969,7 +969,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 @@ -1163,10 +1163,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

0 comments on commit c75bf49

Please sign in to comment.