mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-05 05:07:36 +03:00
parent
ad91d02cbd
commit
5ec7ee7f01
3 changed files with 23 additions and 27 deletions
|
@ -44,12 +44,9 @@ func (h *PublicHeader) WritePublicHeader(b *bytes.Buffer, version protocol.Versi
|
|||
publicFlagByte |= 0x02
|
||||
}
|
||||
if !h.TruncateConnectionID {
|
||||
if version < protocol.Version33 {
|
||||
publicFlagByte |= 0x0c
|
||||
} else {
|
||||
publicFlagByte |= 0x08
|
||||
}
|
||||
}
|
||||
|
||||
if len(h.DiversificationNonce) > 0 {
|
||||
if len(h.DiversificationNonce) != 32 {
|
||||
return errors.New("invalid diversification nonce length")
|
||||
|
@ -110,10 +107,9 @@ func ParsePublicHeader(b io.ByteReader) (*PublicHeader, error) {
|
|||
header.VersionFlag = publicFlagByte&0x01 > 0
|
||||
header.ResetFlag = publicFlagByte&0x02 > 0
|
||||
|
||||
// TODO: Add this check when we drop support for <v33
|
||||
// if publicFlagByte&0x04 > 0 {
|
||||
// return nil, errors.New("diversification nonces should only be sent by servers")
|
||||
// }
|
||||
if publicFlagByte&0x04 > 0 {
|
||||
return nil, errors.New("diversification nonces should only be sent by servers")
|
||||
}
|
||||
|
||||
if publicFlagByte&0x08 == 0 {
|
||||
return nil, errReceivedTruncatedConnectionID
|
||||
|
|
|
@ -66,7 +66,7 @@ var _ = Describe("Public Header", func() {
|
|||
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,
|
||||
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,
|
||||
|
@ -84,8 +84,8 @@ var _ = Describe("Public Header", func() {
|
|||
PacketNumber: 2,
|
||||
PacketNumberLen: protocol.PacketNumberLen6,
|
||||
}
|
||||
hdr.WritePublicHeader(b, protocol.Version32)
|
||||
Expect(b.Bytes()).To(Equal([]byte{0x38 | 0x04, 0xf6, 0x19, 0x86, 0x66, 0x9b, 0x9f, 0xfa, 0x4c, 2, 0, 0, 0, 0, 0}))
|
||||
hdr.WritePublicHeader(b, protocol.Version33)
|
||||
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() {
|
||||
|
@ -96,7 +96,7 @@ var _ = Describe("Public Header", func() {
|
|||
PacketNumber: 2,
|
||||
PacketNumberLen: protocol.PacketNumberLen6,
|
||||
}
|
||||
hdr.WritePublicHeader(b, protocol.Version32)
|
||||
hdr.WritePublicHeader(b, protocol.VersionWhatever)
|
||||
// must be the first assertion
|
||||
Expect(b.Len()).To(Equal(1 + 8)) // 1 FlagByte + 8 ConnectionID
|
||||
firstByte, _ := b.ReadByte()
|
||||
|
@ -111,7 +111,7 @@ var _ = Describe("Public Header", func() {
|
|||
PacketNumber: 2,
|
||||
PacketNumberLen: protocol.PacketNumberLen6,
|
||||
}
|
||||
hdr.WritePublicHeader(b, protocol.Version32)
|
||||
hdr.WritePublicHeader(b, protocol.VersionWhatever)
|
||||
// must be the first assertion
|
||||
Expect(b.Len()).To(Equal(1 + 8)) // 1 FlagByte + 8 ConnectionID
|
||||
firstByte, _ := b.ReadByte()
|
||||
|
@ -127,7 +127,7 @@ var _ = Describe("Public Header", func() {
|
|||
PacketNumber: 2,
|
||||
PacketNumberLen: protocol.PacketNumberLen6,
|
||||
}
|
||||
err := hdr.WritePublicHeader(b, protocol.Version32)
|
||||
err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
|
||||
Expect(err).To(MatchError(errResetAndVersionFlagSet))
|
||||
})
|
||||
|
||||
|
@ -139,7 +139,7 @@ var _ = Describe("Public Header", func() {
|
|||
PacketNumberLen: protocol.PacketNumberLen6,
|
||||
PacketNumber: 1,
|
||||
}
|
||||
err := hdr.WritePublicHeader(b, protocol.Version32)
|
||||
err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(b.Bytes()).To(Equal([]byte{0x30, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0}))
|
||||
})
|
||||
|
@ -247,7 +247,7 @@ var _ = Describe("Public Header", func() {
|
|||
ConnectionID: 0x4cfa9f9b668619f6,
|
||||
PacketNumber: 0xDECAFBAD,
|
||||
}
|
||||
err := hdr.WritePublicHeader(b, protocol.Version32)
|
||||
err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
|
||||
Expect(err).To(MatchError(errPacketNumberLenNotSet))
|
||||
})
|
||||
|
||||
|
@ -258,9 +258,9 @@ var _ = Describe("Public Header", func() {
|
|||
PacketNumber: 0xDECAFBAD,
|
||||
PacketNumberLen: protocol.PacketNumberLen1,
|
||||
}
|
||||
err := hdr.WritePublicHeader(b, protocol.Version32)
|
||||
err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
|
||||
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() {
|
||||
|
@ -270,9 +270,9 @@ var _ = Describe("Public Header", func() {
|
|||
PacketNumber: 0xDECAFBAD,
|
||||
PacketNumberLen: protocol.PacketNumberLen2,
|
||||
}
|
||||
err := hdr.WritePublicHeader(b, protocol.Version32)
|
||||
err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
|
||||
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() {
|
||||
|
@ -282,9 +282,9 @@ var _ = Describe("Public Header", func() {
|
|||
PacketNumber: 0x13DECAFBAD,
|
||||
PacketNumberLen: protocol.PacketNumberLen4,
|
||||
}
|
||||
err := hdr.WritePublicHeader(b, protocol.Version32)
|
||||
err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
|
||||
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() {
|
||||
|
@ -294,9 +294,9 @@ var _ = Describe("Public Header", func() {
|
|||
PacketNumber: 0xBE1337DECAFBAD,
|
||||
PacketNumberLen: protocol.PacketNumberLen6,
|
||||
}
|
||||
err := hdr.WritePublicHeader(b, protocol.Version32)
|
||||
err := hdr.WritePublicHeader(b, protocol.VersionWhatever)
|
||||
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}))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -48,7 +48,7 @@ var _ = Describe("Server", func() {
|
|||
|
||||
It("composes version negotiation packets", func() {
|
||||
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...,
|
||||
)
|
||||
Expect(composeVersionNegotiation(1)).To(Equal(expected))
|
||||
|
@ -141,7 +141,7 @@ var _ = Describe("Server", func() {
|
|||
Expect(err).NotTo(HaveOccurred())
|
||||
data = data[:n]
|
||||
expected := append(
|
||||
[]byte{0xd, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
|
||||
[]byte{0x9, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
|
||||
protocol.SupportedVersionsAsTags...,
|
||||
)
|
||||
Expect(data).To(Equal(expected))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue