mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +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))
|
Expect(firstSession.closeReason).To(Equal(errCloseSessionForNewVersion))
|
||||||
Consistently(func() bool { return secondSession.closed }).Should(BeFalse())
|
Consistently(func() bool { return secondSession.closed }).Should(BeFalse())
|
||||||
Expect(cl.connectionID).ToNot(BeEquivalentTo(0x1337))
|
Expect(cl.connectionID).ToNot(BeEquivalentTo(0x1337))
|
||||||
Expect(negotiatedVersions).To(Equal([]protocol.VersionNumber{newVersion}))
|
Expect(negotiatedVersions).To(ContainElement(newVersion))
|
||||||
Expect(initialVersion).To(Equal(actualInitialVersion))
|
Expect(initialVersion).To(Equal(actualInitialVersion))
|
||||||
|
|
||||||
handshakeChan <- handshakeEvent{encLevel: protocol.EncryptionSecure}
|
handshakeChan <- handshakeEvent{encLevel: protocol.EncryptionSecure}
|
||||||
|
|
|
@ -129,7 +129,10 @@ var _ = Describe("Header", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.isPublicHeader).To(BeTrue())
|
Expect(hdr.isPublicHeader).To(BeTrue())
|
||||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x42)))
|
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() {
|
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.IsVersionNegotiation).To(BeTrue())
|
||||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x42)))
|
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x42)))
|
||||||
Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0x77)))
|
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.Version).To(BeZero())
|
||||||
Expect(h.ConnectionID).To(Equal(protocol.ConnectionID(0x1234567890)))
|
Expect(h.ConnectionID).To(Equal(protocol.ConnectionID(0x1234567890)))
|
||||||
Expect(h.PacketNumber).To(Equal(protocol.PacketNumber(0x1337)))
|
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() {
|
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() {
|
It("errors if the version list is emtpy", func() {
|
||||||
versions := []protocol.VersionNumber{0x22334455}
|
versions := []protocol.VersionNumber{0x22334455}
|
||||||
data := ComposeVersionNegotiation(0x1234567890, 0x1337, versions)
|
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"))
|
Expect(err).To(MatchError("InvalidVersionNegotiationPacket: empty version list"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -97,14 +97,18 @@ var _ = Describe("Public Header", func() {
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
It("parses version negotiation packets sent by the server", func() {
|
It("parses", func() {
|
||||||
b := bytes.NewReader(ComposeGQUICVersionNegotiation(0x1337, protocol.SupportedVersions))
|
versions := []protocol.VersionNumber{0x13, 0x37}
|
||||||
|
b := bytes.NewReader(ComposeGQUICVersionNegotiation(0x1337, versions))
|
||||||
hdr, err := parsePublicHeader(b, protocol.PerspectiveServer)
|
hdr, err := parsePublicHeader(b, protocol.PerspectiveServer)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.VersionFlag).To(BeTrue())
|
Expect(hdr.VersionFlag).To(BeTrue())
|
||||||
Expect(hdr.Version).To(BeZero()) // unitialized
|
Expect(hdr.Version).To(BeZero()) // unitialized
|
||||||
Expect(hdr.IsVersionNegotiation).To(BeTrue())
|
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())
|
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())
|
utils.Errorf("error composing version negotiation packet: %s", err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, v := range versions {
|
writeVersions(fullReply, versions)
|
||||||
utils.BigEndian.WriteUint32(fullReply, uint32(v))
|
|
||||||
}
|
|
||||||
return fullReply.Bytes()
|
return fullReply.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,8 +46,14 @@ func ComposeVersionNegotiation(
|
||||||
utils.Errorf("error composing version negotiation packet: %s", err.Error())
|
utils.Errorf("error composing version negotiation packet: %s", err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, v := range versions {
|
writeVersions(fullReply, versions)
|
||||||
utils.BigEndian.WriteUint32(fullReply, uint32(v))
|
|
||||||
}
|
|
||||||
return fullReply.Bytes()
|
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(err).ToNot(HaveOccurred())
|
||||||
Expect(hdr.VersionFlag).To(BeTrue())
|
Expect(hdr.VersionFlag).To(BeTrue())
|
||||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x1337)))
|
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() {
|
It("writes in IETF draft style", func() {
|
||||||
|
@ -27,6 +31,11 @@ var _ = Describe("Version Negotiation Packets", func() {
|
||||||
Expect(hdr.IsVersionNegotiation).To(BeTrue())
|
Expect(hdr.IsVersionNegotiation).To(BeTrue())
|
||||||
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x1337)))
|
Expect(hdr.ConnectionID).To(Equal(protocol.ConnectionID(0x1337)))
|
||||||
Expect(hdr.PacketNumber).To(Equal(protocol.PacketNumber(0x42)))
|
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