mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
testutils: add a perspective function parameter to ComposeInitialPacket (#4276)
Currently not used, but this is useful when crafting Initial packets sent from the client. No functional change expected.
This commit is contained in:
parent
940feef063
commit
03ba124241
3 changed files with 15 additions and 10 deletions
|
@ -3167,7 +3167,7 @@ var _ = Describe("Client Connection", func() {
|
|||
// the connection to immediately break down
|
||||
It("fails on Initial-level ACK for unsent packet", func() {
|
||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
|
||||
initialPacket := testutils.ComposeInitialPacket(destConnID, srcConnID, conn.version, destConnID, []wire.Frame{ack})
|
||||
initialPacket := testutils.ComposeInitialPacket(destConnID, srcConnID, destConnID, []wire.Frame{ack}, protocol.PerspectiveServer, conn.version)
|
||||
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
|
||||
Expect(conn.handlePacketImpl(wrapPacket(initialPacket))).To(BeFalse())
|
||||
})
|
||||
|
@ -3179,7 +3179,7 @@ var _ = Describe("Client Connection", func() {
|
|||
IsApplicationError: true,
|
||||
ReasonPhrase: "mitm attacker",
|
||||
}
|
||||
initialPacket := testutils.ComposeInitialPacket(destConnID, srcConnID, conn.version, destConnID, []wire.Frame{connCloseFrame})
|
||||
initialPacket := testutils.ComposeInitialPacket(destConnID, srcConnID, destConnID, []wire.Frame{connCloseFrame}, protocol.PerspectiveServer, conn.version)
|
||||
tracer.EXPECT().ReceivedLongHeaderPacket(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
|
||||
Expect(conn.handlePacketImpl(wrapPacket(initialPacket))).To(BeTrue())
|
||||
})
|
||||
|
@ -3197,7 +3197,7 @@ var _ = Describe("Client Connection", func() {
|
|||
|
||||
tracer.EXPECT().ReceivedRetry(gomock.Any())
|
||||
conn.handlePacketImpl(wrapPacket(testutils.ComposeRetryPacket(newSrcConnID, destConnID, destConnID, []byte("foobar"), conn.version)))
|
||||
initialPacket := testutils.ComposeInitialPacket(conn.connIDManager.Get(), srcConnID, conn.version, conn.connIDManager.Get(), nil)
|
||||
initialPacket := testutils.ComposeInitialPacket(conn.connIDManager.Get(), srcConnID, conn.connIDManager.Get(), nil, protocol.PerspectiveServer, conn.version)
|
||||
tracer.EXPECT().DroppedPacket(gomock.Any(), protocol.InvalidPacketNumber, gomock.Any(), gomock.Any())
|
||||
Expect(conn.handlePacketImpl(wrapPacket(initialPacket))).To(BeFalse())
|
||||
})
|
||||
|
|
|
@ -417,7 +417,7 @@ var _ = Describe("MITM test", func() {
|
|||
}
|
||||
defer close(done)
|
||||
injected = true
|
||||
initialPacket := testutils.ComposeInitialPacket(hdr.DestConnectionID, hdr.SrcConnectionID, hdr.Version, hdr.DestConnectionID, nil)
|
||||
initialPacket := testutils.ComposeInitialPacket(hdr.DestConnectionID, hdr.SrcConnectionID, hdr.DestConnectionID, nil, protocol.PerspectiveServer, hdr.Version)
|
||||
_, err = serverTransport.WriteTo(initialPacket, clientTransport.Conn.LocalAddr())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
@ -449,7 +449,7 @@ var _ = Describe("MITM test", func() {
|
|||
injected = true
|
||||
// Fake Initial with ACK for packet 2 (unsent)
|
||||
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
|
||||
initialPacket := testutils.ComposeInitialPacket(hdr.DestConnectionID, hdr.SrcConnectionID, hdr.Version, hdr.DestConnectionID, []wire.Frame{ack})
|
||||
initialPacket := testutils.ComposeInitialPacket(hdr.DestConnectionID, hdr.SrcConnectionID, hdr.DestConnectionID, []wire.Frame{ack}, protocol.PerspectiveServer, hdr.Version)
|
||||
_, err = serverTransport.WriteTo(initialPacket, clientTransport.Conn.LocalAddr())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
|
|
@ -33,10 +33,15 @@ func packRawPayload(version protocol.VersionNumber, frames []wire.Frame) []byte
|
|||
return b
|
||||
}
|
||||
|
||||
// ComposeInitialPacket returns an Initial packet encrypted under key
|
||||
// (the original destination connection ID) containing specified frames
|
||||
func ComposeInitialPacket(srcConnID protocol.ConnectionID, destConnID protocol.ConnectionID, version protocol.VersionNumber, key protocol.ConnectionID, frames []wire.Frame) []byte {
|
||||
sealer, _ := handshake.NewInitialAEAD(key, protocol.PerspectiveServer, version)
|
||||
// ComposeInitialPacket returns an Initial packet encrypted under key (the original destination connection ID)
|
||||
// containing specified frames.
|
||||
func ComposeInitialPacket(
|
||||
srcConnID, destConnID, key protocol.ConnectionID,
|
||||
frames []wire.Frame,
|
||||
sentBy protocol.Perspective,
|
||||
version protocol.VersionNumber,
|
||||
) []byte {
|
||||
sealer, _ := handshake.NewInitialAEAD(key, sentBy, version)
|
||||
|
||||
// compose payload
|
||||
var payload []byte
|
||||
|
@ -48,7 +53,7 @@ func ComposeInitialPacket(srcConnID protocol.ConnectionID, destConnID protocol.C
|
|||
|
||||
// compose Initial header
|
||||
payloadSize := len(payload)
|
||||
pnLength := protocol.PacketNumberLen4
|
||||
const pnLength = protocol.PacketNumberLen4
|
||||
length := payloadSize + int(pnLength) + sealer.Overhead()
|
||||
hdr := &wire.ExtendedHeader{
|
||||
Header: wire.Header{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue