remove support for version 32 from PublicHeader

ref #215
This commit is contained in:
Marten Seemann 2016-07-31 15:08:17 +07:00 committed by Lucas Clemente
parent ad91d02cbd
commit 5ec7ee7f01
3 changed files with 23 additions and 27 deletions

View file

@ -44,12 +44,9 @@ func (h *PublicHeader) WritePublicHeader(b *bytes.Buffer, version protocol.Versi
publicFlagByte |= 0x02 publicFlagByte |= 0x02
} }
if !h.TruncateConnectionID { if !h.TruncateConnectionID {
if version < protocol.Version33 {
publicFlagByte |= 0x0c
} else {
publicFlagByte |= 0x08 publicFlagByte |= 0x08
} }
}
if len(h.DiversificationNonce) > 0 { if len(h.DiversificationNonce) > 0 {
if len(h.DiversificationNonce) != 32 { if len(h.DiversificationNonce) != 32 {
return errors.New("invalid diversification nonce length") return errors.New("invalid diversification nonce length")
@ -110,10 +107,9 @@ func ParsePublicHeader(b io.ByteReader) (*PublicHeader, error) {
header.VersionFlag = publicFlagByte&0x01 > 0 header.VersionFlag = publicFlagByte&0x01 > 0
header.ResetFlag = publicFlagByte&0x02 > 0 header.ResetFlag = publicFlagByte&0x02 > 0
// TODO: Add this check when we drop support for <v33 if publicFlagByte&0x04 > 0 {
// if publicFlagByte&0x04 > 0 { return nil, errors.New("diversification nonces should only be sent by servers")
// return nil, errors.New("diversification nonces should only be sent by servers") }
// }
if publicFlagByte&0x08 == 0 { if publicFlagByte&0x08 == 0 {
return nil, errReceivedTruncatedConnectionID return nil, errReceivedTruncatedConnectionID

View file

@ -66,7 +66,7 @@ var _ = Describe("Public Header", func() {
Expect(b.Len()).To(BeZero()) Expect(b.Len()).To(BeZero())
}) })
PIt("rejects diversification nonces", func() { It("rejects diversification nonces sent by the client", func() {
b := bytes.NewReader([]byte{0x0c, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, b := bytes.NewReader([]byte{0x0c, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
0x01, 0x01,
@ -84,8 +84,8 @@ var _ = Describe("Public Header", func() {
PacketNumber: 2, PacketNumber: 2,
PacketNumberLen: protocol.PacketNumberLen6, PacketNumberLen: protocol.PacketNumberLen6,
} }
hdr.WritePublicHeader(b, protocol.Version32) hdr.WritePublicHeader(b, protocol.Version33)
Expect(b.Bytes()).To(Equal([]byte{0x38 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 2, 0, 0, 0, 0, 0})) Expect(b.Bytes()).To(Equal([]byte{0x38, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 2, 0, 0, 0, 0, 0}))
}) })
It("sets the Version Flag", func() { It("sets the Version Flag", func() {
@ -96,7 +96,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 2, PacketNumber: 2,
PacketNumberLen: protocol.PacketNumberLen6, PacketNumberLen: protocol.PacketNumberLen6,
} }
hdr.WritePublicHeader(b, protocol.Version32) hdr.WritePublicHeader(b, protocol.VersionWhatever)
// must be the first assertion // must be the first assertion
Expect(b.Len()).To(Equal(1 + 8)) // 1 FlagByte + 8 ConnectionID Expect(b.Len()).To(Equal(1 + 8)) // 1 FlagByte + 8 ConnectionID
firstByte, _ := b.ReadByte() firstByte, _ := b.ReadByte()
@ -111,7 +111,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 2, PacketNumber: 2,
PacketNumberLen: protocol.PacketNumberLen6, PacketNumberLen: protocol.PacketNumberLen6,
} }
hdr.WritePublicHeader(b, protocol.Version32) hdr.WritePublicHeader(b, protocol.VersionWhatever)
// must be the first assertion // must be the first assertion
Expect(b.Len()).To(Equal(1 + 8)) // 1 FlagByte + 8 ConnectionID Expect(b.Len()).To(Equal(1 + 8)) // 1 FlagByte + 8 ConnectionID
firstByte, _ := b.ReadByte() firstByte, _ := b.ReadByte()
@ -127,7 +127,7 @@ var _ = Describe("Public Header", func() {
PacketNumber: 2, PacketNumber: 2,
PacketNumberLen: protocol.PacketNumberLen6, PacketNumberLen: protocol.PacketNumberLen6,
} }
err := hdr.WritePublicHeader(b, protocol.Version32) err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
Expect(err).To(MatchError(errResetAndVersionFlagSet)) Expect(err).To(MatchError(errResetAndVersionFlagSet))
}) })
@ -139,7 +139,7 @@ var _ = Describe("Public Header", func() {
PacketNumberLen: protocol.PacketNumberLen6, PacketNumberLen: protocol.PacketNumberLen6,
PacketNumber: 1, PacketNumber: 1,
} }
err := hdr.WritePublicHeader(b, protocol.Version32) err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x30, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0})) Expect(b.Bytes()).To(Equal([]byte{0x30, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0}))
}) })
@ -247,7 +247,7 @@ var _ = Describe("Public Header", func() {
ConnectionID: 0x4cfa9f9b668619f6, ConnectionID: 0x4cfa9f9b668619f6,
PacketNumber: 0xDECAFBAD, PacketNumber: 0xDECAFBAD,
} }
err := hdr.WritePublicHeader(b, protocol.Version32) err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
Expect(err).To(MatchError(errPacketNumberLenNotSet)) Expect(err).To(MatchError(errPacketNumberLenNotSet))
}) })
@ -258,9 +258,9 @@ var _ = Describe("Public Header", func() {
PacketNumber: 0xDECAFBAD, PacketNumber: 0xDECAFBAD,
PacketNumberLen: protocol.PacketNumberLen1, PacketNumberLen: protocol.PacketNumberLen1,
} }
err := hdr.WritePublicHeader(b, protocol.Version32) err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x08 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD})) Expect(b.Bytes()).To(Equal([]byte{0x08, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD}))
}) })
It("writes a header with a 2-byte packet number", func() { It("writes a header with a 2-byte packet number", func() {
@ -270,9 +270,9 @@ var _ = Describe("Public Header", func() {
PacketNumber: 0xDECAFBAD, PacketNumber: 0xDECAFBAD,
PacketNumberLen: protocol.PacketNumberLen2, PacketNumberLen: protocol.PacketNumberLen2,
} }
err := hdr.WritePublicHeader(b, protocol.Version32) err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x18 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD, 0xFB})) Expect(b.Bytes()).To(Equal([]byte{0x18, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD, 0xFB}))
}) })
It("writes a header with a 4-byte packet number", func() { It("writes a header with a 4-byte packet number", func() {
@ -282,9 +282,9 @@ var _ = Describe("Public Header", func() {
PacketNumber: 0x13DECAFBAD, PacketNumber: 0x13DECAFBAD,
PacketNumberLen: protocol.PacketNumberLen4, PacketNumberLen: protocol.PacketNumberLen4,
} }
err := hdr.WritePublicHeader(b, protocol.Version32) err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x28 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD, 0xFB, 0xCA, 0xDE})) Expect(b.Bytes()).To(Equal([]byte{0x28, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD, 0xFB, 0xCA, 0xDE}))
}) })
It("writes a header with a 6-byte packet number", func() { It("writes a header with a 6-byte packet number", func() {
@ -294,9 +294,9 @@ var _ = Describe("Public Header", func() {
PacketNumber: 0xBE1337DECAFBAD, PacketNumber: 0xBE1337DECAFBAD,
PacketNumberLen: protocol.PacketNumberLen6, PacketNumberLen: protocol.PacketNumberLen6,
} }
err := hdr.WritePublicHeader(b, protocol.Version32) err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(b.Bytes()).To(Equal([]byte{0x38 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD, 0xFB, 0xCA, 0xDE, 0x37, 0x13})) Expect(b.Bytes()).To(Equal([]byte{0x38, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 0xAD, 0xFB, 0xCA, 0xDE, 0x37, 0x13}))
}) })
}) })
}) })

View file

@ -48,7 +48,7 @@ var _ = Describe("Server", func() {
It("composes version negotiation packets", func() { It("composes version negotiation packets", func() {
expected := append( expected := append(
[]byte{0x01 | 0x08 | 0x04, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, []byte{0x01 | 0x08, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
protocol.SupportedVersionsAsTags..., protocol.SupportedVersionsAsTags...,
) )
Expect(composeVersionNegotiation(1)).To(Equal(expected)) Expect(composeVersionNegotiation(1)).To(Equal(expected))
@ -141,7 +141,7 @@ var _ = Describe("Server", func() {
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
data = data[:n] data = data[:n]
expected := append( expected := append(
[]byte{0xd, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, []byte{0x9, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
protocol.SupportedVersionsAsTags..., protocol.SupportedVersionsAsTags...,
) )
Expect(data).To(Equal(expected)) Expect(data).To(Equal(expected))