define a function to tell if a QUIC version uses the TLS 1.3 handshake

This commit is contained in:
Marten Seemann
2017-09-22 19:47:08 +07:00
parent c78a4b2b73
commit 8312e766ed
5 changed files with 18 additions and 4 deletions

View File

@@ -214,7 +214,7 @@ func (c *client) establishSecureConnection() error {
if ev.err != nil {
return ev.err
}
if c.version != protocol.VersionTLS && ev.encLevel != protocol.EncryptionSecure {
if c.version.UsesTLS() && ev.encLevel != protocol.EncryptionSecure {
return fmt.Errorf("Client BUG: Expected encryption level to be secure, was %s", ev.encLevel)
}
return nil

View File

@@ -4,7 +4,7 @@ import "github.com/lucas-clemente/quic-go/internal/protocol"
// NewNullAEAD creates a NullAEAD
func NewNullAEAD(p protocol.Perspective, v protocol.VersionNumber) AEAD {
if v == protocol.VersionTLS {
if v.UsesTLS() {
return &nullAEADFNV64a{}
}
return &nullAEADFNV128a{

View File

@@ -26,6 +26,11 @@ var SupportedVersions = []VersionNumber{
Version35,
}
// UsesTLS says if this QUIC version uses TLS 1.3 for the handshake
func (vn VersionNumber) UsesTLS() bool {
return vn == VersionTLS
}
// VersionNumberToTag maps version numbers ('32') to tags ('Q032')
func VersionNumberToTag(vn VersionNumber) uint32 {
v := uint32(vn)

View File

@@ -6,6 +6,15 @@ import (
)
var _ = Describe("Version", func() {
It("says if a version supports TLS", func() {
Expect(Version35.UsesTLS()).To(BeFalse())
Expect(Version36.UsesTLS()).To(BeFalse())
Expect(Version37.UsesTLS()).To(BeFalse())
Expect(Version38.UsesTLS()).To(BeFalse())
Expect(Version39.UsesTLS()).To(BeFalse())
Expect(VersionTLS.UsesTLS()).To(BeTrue())
})
It("converts tags to numbers", func() {
Expect(VersionTagToNumber('Q' + '1'<<8 + '2'<<16 + '3'<<24)).To(Equal(VersionNumber(123)))
})

View File

@@ -200,7 +200,7 @@ func (s *session) setup(
verifySourceAddr := func(clientAddr net.Addr, stk *STK) bool {
return s.config.AcceptSTK(clientAddr, stk)
}
if s.version == protocol.VersionTLS {
if s.version.UsesTLS() {
s.cryptoSetup, err = handshake.NewCryptoSetupTLS(
"",
s.perspective,
@@ -224,7 +224,7 @@ func (s *session) setup(
}
} else {
cryptoStream, _ := s.OpenStream()
if s.version == protocol.VersionTLS {
if s.version.UsesTLS() {
s.cryptoSetup, err = handshake.NewCryptoSetupTLS(
hostname,
s.perspective,