mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
send a reserved version number in version negotiation packets
This commit is contained in:
parent
1f5cd31569
commit
be29963637
6 changed files with 43 additions and 16 deletions
|
@ -369,7 +369,7 @@ var _ = Describe("Client", func() {
|
|||
Expect(firstSession.closeReason).To(Equal(errCloseSessionForNewVersion))
|
||||
Consistently(func() bool { return secondSession.closed }).Should(BeFalse())
|
||||
Expect(cl.connectionID).ToNot(BeEquivalentTo(0x1337))
|
||||
Expect(negotiatedVersions).To(Equal([]protocol.VersionNumber{newVersion}))
|
||||
Expect(negotiatedVersions).To(ContainElement(newVersion))
|
||||
Expect(initialVersion).To(Equal(actualInitialVersion))
|
||||
|
||||
handshakeChan <- handshakeEvent{encLevel: protocol.EncryptionSecure}
|
||||
|
|
|
@ -129,7 +129,10 @@ var _ = Describe("Header", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(hdr.isPublicHeader).To(BeTrue())
|
||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x42)))
|
||||
Expect(hdr.SupportedVersions).To(Equal(versions))
|
||||
// in addition to the versions, the supported versions might contain a reserved version number
|
||||
for _, version := range versions {
|
||||
Expect(hdr.SupportedVersions).To(ContainElement(version))
|
||||
}
|
||||
})
|
||||
|
||||
It("parses an IETF draft style Version Negotiation Packet", func() {
|
||||
|
@ -141,7 +144,11 @@ var _ = Describe("Header", func() {
|
|||
Expect(hdr.IsVersionNegotiation).To(BeTrue())
|
||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x42)))
|
||||
Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0x77)))
|
||||
Expect(hdr.SupportedVersions).To(Equal(versions))
|
||||
Expect(hdr.Version).To(BeZero())
|
||||
// in addition to the versions, the supported versions might contain a reserved version number
|
||||
for _, version := range versions {
|
||||
Expect(hdr.SupportedVersions).To(ContainElement(version))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -28,7 +28,9 @@ var _ = Describe("IETF draft Header", func() {
|
|||
Expect(h.Version).To(BeZero())
|
||||
Expect(h.ConnectionID).To(Equal(protocol.ConnectionID(0x1234567890)))
|
||||
Expect(h.PacketNumber).To(Equal(protocol.PacketNumber(0x1337)))
|
||||
Expect(h.SupportedVersions).To(Equal(versions))
|
||||
for _, v := range versions {
|
||||
Expect(h.SupportedVersions).To(ContainElement(v))
|
||||
}
|
||||
})
|
||||
|
||||
It("errors if it contains versions of the wrong length", func() {
|
||||
|
@ -42,7 +44,8 @@ var _ = Describe("IETF draft Header", func() {
|
|||
It("errors if the version list is emtpy", func() {
|
||||
versions := []protocol.VersionNumber{0x22334455}
|
||||
data := ComposeVersionNegotiation(0x1234567890, 0x1337, versions)
|
||||
_, err := parseHeader(bytes.NewReader(data[:len(data)-4]), protocol.PerspectiveServer)
|
||||
// remove 8 bytes (two versions), since ComposeVersionNegotiation also added a reserved version number
|
||||
_, err := parseHeader(bytes.NewReader(data[:len(data)-8]), protocol.PerspectiveServer)
|
||||
Expect(err).To(MatchError("InvalidVersionNegotiationPacket: empty version list"))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -97,14 +97,18 @@ var _ = Describe("Public Header", func() {
|
|||
return data
|
||||
}
|
||||
|
||||
It("parses version negotiation packets sent by the server", func() {
|
||||
b := bytes.NewReader(ComposeGQUICVersionNegotiation(0x1337, protocol.SupportedVersions))
|
||||
It("parses", func() {
|
||||
versions := []protocol.VersionNumber{0x13, 0x37}
|
||||
b := bytes.NewReader(ComposeGQUICVersionNegotiation(0x1337, versions))
|
||||
hdr, err := parsePublicHeader(b, protocol.PerspectiveServer)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(hdr.VersionFlag).To(BeTrue())
|
||||
Expect(hdr.Version).To(BeZero()) // unitialized
|
||||
Expect(hdr.IsVersionNegotiation).To(BeTrue())
|
||||
Expect(hdr.SupportedVersions).To(Equal(protocol.SupportedVersions))
|
||||
// in addition to the versions, the supported versions might contain a reserved version number
|
||||
for _, version := range versions {
|
||||
Expect(hdr.SupportedVersions).To(ContainElement(version))
|
||||
}
|
||||
Expect(b.Len()).To(BeZero())
|
||||
})
|
||||
|
||||
|
|
|
@ -21,9 +21,7 @@ func ComposeGQUICVersionNegotiation(connID protocol.ConnectionID, versions []pro
|
|||
utils.Errorf("error composing version negotiation packet: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
for _, v := range versions {
|
||||
utils.BigEndian.WriteUint32(fullReply, uint32(v))
|
||||
}
|
||||
writeVersions(fullReply, versions)
|
||||
return fullReply.Bytes()
|
||||
}
|
||||
|
||||
|
@ -48,8 +46,14 @@ func ComposeVersionNegotiation(
|
|||
utils.Errorf("error composing version negotiation packet: %s", err.Error())
|
||||
return nil
|
||||
}
|
||||
for _, v := range versions {
|
||||
utils.BigEndian.WriteUint32(fullReply, uint32(v))
|
||||
}
|
||||
writeVersions(fullReply, versions)
|
||||
return fullReply.Bytes()
|
||||
}
|
||||
|
||||
// writeVersions writes the versions for a Version Negotiation Packet.
|
||||
// It inserts one reserved version number at a random position.
|
||||
func writeVersions(buf *bytes.Buffer, supported []protocol.VersionNumber) {
|
||||
for _, v := range protocol.GetGreasedVersions(supported) {
|
||||
utils.BigEndian.WriteUint32(buf, uint32(v))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,11 @@ var _ = Describe("Version Negotiation Packets", func() {
|
|||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(hdr.VersionFlag).To(BeTrue())
|
||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x1337)))
|
||||
Expect(hdr.SupportedVersions).To(Equal(versions))
|
||||
// the supported versions should include one reserved version number
|
||||
Expect(hdr.SupportedVersions).To(HaveLen(len(versions) + 1))
|
||||
for _, version := range versions {
|
||||
Expect(hdr.SupportedVersions).To(ContainElement(version))
|
||||
}
|
||||
})
|
||||
|
||||
It("writes in IETF draft style", func() {
|
||||
|
@ -27,6 +31,11 @@ var _ = Describe("Version Negotiation Packets", func() {
|
|||
Expect(hdr.IsVersionNegotiation).To(BeTrue())
|
||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x1337)))
|
||||
Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0x42)))
|
||||
Expect(hdr.SupportedVersions).To(Equal(versions))
|
||||
Expect(hdr.Version).To(BeZero())
|
||||
// the supported versions should include one reserved version number
|
||||
Expect(hdr.SupportedVersions).To(HaveLen(len(versions) + 1))
|
||||
for _, version := range versions {
|
||||
Expect(hdr.SupportedVersions).To(ContainElement(version))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue