use the updated TLS extension code point for draft-34

This commit is contained in:
Marten Seemann 2021-02-05 13:48:16 +08:00
parent f01a2c6b96
commit 9dba8141ba
3 changed files with 83 additions and 34 deletions

View file

@ -237,7 +237,7 @@ func newCryptoSetup(
tracer.UpdatedKeyFromTLS(protocol.EncryptionInitial, protocol.PerspectiveClient) tracer.UpdatedKeyFromTLS(protocol.EncryptionInitial, protocol.PerspectiveClient)
tracer.UpdatedKeyFromTLS(protocol.EncryptionInitial, protocol.PerspectiveServer) tracer.UpdatedKeyFromTLS(protocol.EncryptionInitial, protocol.PerspectiveServer)
} }
extHandler := newExtensionHandler(tp.Marshal(perspective), perspective) extHandler := newExtensionHandler(tp.Marshal(perspective), perspective, version)
cs := &cryptoSetup{ cs := &cryptoSetup{
tlsConf: tlsConf, tlsConf: tlsConf,
initialStream: initialStream, initialStream: initialStream,

View file

@ -5,23 +5,33 @@ import (
"github.com/lucas-clemente/quic-go/internal/qtls" "github.com/lucas-clemente/quic-go/internal/qtls"
) )
const quicTLSExtensionType = 0xffa5 const (
quicTLSExtensionTypeOldDrafts = 0xffa5
quicTLSExtensionType = 0x39
)
type extensionHandler struct { type extensionHandler struct {
ourParams []byte ourParams []byte
paramsChan chan []byte paramsChan chan []byte
extensionType uint16
perspective protocol.Perspective perspective protocol.Perspective
} }
var _ tlsExtensionHandler = &extensionHandler{} var _ tlsExtensionHandler = &extensionHandler{}
// newExtensionHandler creates a new extension handler // newExtensionHandler creates a new extension handler
func newExtensionHandler(params []byte, pers protocol.Perspective) tlsExtensionHandler { func newExtensionHandler(params []byte, pers protocol.Perspective, v protocol.VersionNumber) tlsExtensionHandler {
et := uint16(quicTLSExtensionType)
if v != protocol.VersionDraft34 {
et = quicTLSExtensionTypeOldDrafts
}
return &extensionHandler{ return &extensionHandler{
ourParams: params, ourParams: params,
paramsChan: make(chan []byte), paramsChan: make(chan []byte),
perspective: pers, perspective: pers,
extensionType: et,
} }
} }
@ -31,7 +41,7 @@ func (h *extensionHandler) GetExtensions(msgType uint8) []qtls.Extension {
return nil return nil
} }
return []qtls.Extension{{ return []qtls.Extension{{
Type: quicTLSExtensionType, Type: h.extensionType,
Data: h.ourParams, Data: h.ourParams,
}} }}
} }
@ -44,7 +54,7 @@ func (h *extensionHandler) ReceivedExtensions(msgType uint8, exts []qtls.Extensi
var data []byte var data []byte
for _, ext := range exts { for _, ext := range exts {
if ext.Type == quicTLSExtensionType { if ext.Type == h.extensionType {
data = ext.Data data = ext.Data
break break
} }

View file

@ -1,6 +1,8 @@
package handshake package handshake
import ( import (
"fmt"
"github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/qtls" "github.com/lucas-clemente/quic-go/internal/qtls"
@ -12,39 +14,61 @@ var _ = Describe("TLS Extension Handler, for the server", func() {
var ( var (
handlerServer tlsExtensionHandler handlerServer tlsExtensionHandler
handlerClient tlsExtensionHandler handlerClient tlsExtensionHandler
version protocol.VersionNumber
) )
BeforeEach(func() { BeforeEach(func() {
version = protocol.VersionDraft29
})
JustBeforeEach(func() {
handlerServer = newExtensionHandler( handlerServer = newExtensionHandler(
[]byte("foobar"), []byte("foobar"),
protocol.PerspectiveServer, protocol.PerspectiveServer,
version,
) )
handlerClient = newExtensionHandler( handlerClient = newExtensionHandler(
[]byte("raboof"), []byte("raboof"),
protocol.PerspectiveClient, protocol.PerspectiveClient,
version,
) )
}) })
Context("for the server", func() { Context("for the server", func() {
Context("sending", func() { for _, ver := range []protocol.VersionNumber{protocol.VersionDraft29, protocol.VersionDraft34} {
It("only adds TransportParameters for the Encrypted Extensions", func() { v := ver
// test 2 other handshake types
Expect(handlerServer.GetExtensions(uint8(typeCertificate))).To(BeEmpty())
Expect(handlerServer.GetExtensions(uint8(typeFinished))).To(BeEmpty())
})
It("adds TransportParameters to the EncryptedExtensions message", func() { Context(fmt.Sprintf("sending, for version %s", v), func() {
exts := handlerServer.GetExtensions(uint8(typeEncryptedExtensions)) var extensionType uint16
Expect(exts).To(HaveLen(1))
Expect(exts[0].Type).To(BeEquivalentTo(quicTLSExtensionType)) BeforeEach(func() {
Expect(exts[0].Data).To(Equal([]byte("foobar"))) version = v
if v == protocol.VersionDraft29 {
extensionType = quicTLSExtensionTypeOldDrafts
} else {
extensionType = quicTLSExtensionType
}
})
It("only adds TransportParameters for the Encrypted Extensions", func() {
// test 2 other handshake types
Expect(handlerServer.GetExtensions(uint8(typeCertificate))).To(BeEmpty())
Expect(handlerServer.GetExtensions(uint8(typeFinished))).To(BeEmpty())
})
It("adds TransportParameters to the EncryptedExtensions message", func() {
exts := handlerServer.GetExtensions(uint8(typeEncryptedExtensions))
Expect(exts).To(HaveLen(1))
Expect(exts[0].Type).To(BeEquivalentTo(extensionType))
Expect(exts[0].Data).To(Equal([]byte("foobar")))
})
}) })
}) }
Context("receiving", func() { Context("receiving", func() {
var chExts []qtls.Extension var chExts []qtls.Extension
BeforeEach(func() { JustBeforeEach(func() {
chExts = handlerClient.GetExtensions(uint8(typeClientHello)) chExts = handlerClient.GetExtensions(uint8(typeClientHello))
Expect(chExts).To(HaveLen(1)) Expect(chExts).To(HaveLen(1))
}) })
@ -98,25 +122,40 @@ var _ = Describe("TLS Extension Handler, for the server", func() {
}) })
Context("for the client", func() { Context("for the client", func() {
Context("sending", func() { for _, ver := range []protocol.VersionNumber{protocol.VersionDraft29, protocol.VersionDraft34} {
It("only adds TransportParameters for the Encrypted Extensions", func() { v := ver
// test 2 other handshake types
Expect(handlerClient.GetExtensions(uint8(typeCertificate))).To(BeEmpty())
Expect(handlerClient.GetExtensions(uint8(typeFinished))).To(BeEmpty())
})
It("adds TransportParameters to the ClientHello message", func() { Context(fmt.Sprintf("sending, for version %s", v), func() {
exts := handlerClient.GetExtensions(uint8(typeClientHello)) var extensionType uint16
Expect(exts).To(HaveLen(1))
Expect(exts[0].Type).To(BeEquivalentTo(quicTLSExtensionType)) BeforeEach(func() {
Expect(exts[0].Data).To(Equal([]byte("raboof"))) version = v
if v == protocol.VersionDraft29 {
extensionType = quicTLSExtensionTypeOldDrafts
} else {
extensionType = quicTLSExtensionType
}
})
It("only adds TransportParameters for the Encrypted Extensions", func() {
// test 2 other handshake types
Expect(handlerClient.GetExtensions(uint8(typeCertificate))).To(BeEmpty())
Expect(handlerClient.GetExtensions(uint8(typeFinished))).To(BeEmpty())
})
It("adds TransportParameters to the ClientHello message", func() {
exts := handlerClient.GetExtensions(uint8(typeClientHello))
Expect(exts).To(HaveLen(1))
Expect(exts[0].Type).To(BeEquivalentTo(extensionType))
Expect(exts[0].Data).To(Equal([]byte("raboof")))
})
}) })
}) }
Context("receiving", func() { Context("receiving", func() {
var chExts []qtls.Extension var chExts []qtls.Extension
BeforeEach(func() { JustBeforeEach(func() {
chExts = handlerServer.GetExtensions(uint8(typeEncryptedExtensions)) chExts = handlerServer.GetExtensions(uint8(typeEncryptedExtensions))
Expect(chExts).To(HaveLen(1)) Expect(chExts).To(HaveLen(1))
}) })