diff --git a/integrationtests/self/mitm_test.go b/integrationtests/self/mitm_test.go index 860da5af..46031edc 100644 --- a/integrationtests/self/mitm_test.go +++ b/integrationtests/self/mitm_test.go @@ -328,8 +328,8 @@ var _ = Describe("MITM test", func() { // expects hdr from an Initial packet intercepted from client sendForgedInitialPacketWithAck := func(conn net.PacketConn, remoteAddr net.Addr, hdr *wire.Header) { // Fake Initial with ACK for packet 2 (unsent) - ackFrame := testutils.ComposeAckFrame(2, 2) - initialPacket := testutils.ComposeInitialPacket(hdr.DestConnectionID, hdr.SrcConnectionID, hdr.Version, hdr.DestConnectionID, []wire.Frame{ackFrame}) + ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}} + initialPacket := testutils.ComposeInitialPacket(hdr.DestConnectionID, hdr.SrcConnectionID, hdr.Version, hdr.DestConnectionID, []wire.Frame{ack}) _, err := conn.WriteTo(initialPacket, remoteAddr) Expect(err).ToNot(HaveOccurred()) } diff --git a/internal/testutils/testutils.go b/internal/testutils/testutils.go index 51851ad9..b4ed9147 100644 --- a/internal/testutils/testutils.go +++ b/internal/testutils/testutils.go @@ -11,9 +11,6 @@ import ( // Utilities for simulating packet injection and man-in-the-middle (MITM) attacker tests. // Do not use for non-testing purposes. -// CryptoFrameType uses same types as messageType in crypto_setup.go -type CryptoFrameType uint8 - // writePacket returns a new raw packet with the specified header and payload func writePacket(hdr *wire.ExtendedHeader, data []byte) []byte { buf := &bytes.Buffer{} @@ -30,38 +27,6 @@ func packRawPayload(version protocol.VersionNumber, frames []wire.Frame) []byte return buf.Bytes() } -// ComposeCryptoFrame returns a new empty crypto frame of the specified -// type padded to size bytes with zeroes -func ComposeCryptoFrame(cft CryptoFrameType, size int) *wire.CryptoFrame { - data := make([]byte, size) - data[0] = byte(cft) - return &wire.CryptoFrame{ - Offset: 0, - Data: data, - } -} - -// ComposeConnCloseFrame returns a new Connection Close frame with a generic error -func ComposeConnCloseFrame() *wire.ConnectionCloseFrame { - return &wire.ConnectionCloseFrame{ - IsApplicationError: true, - ErrorCode: 0, - ReasonPhrase: "mitm attacker", - } -} - -// ComposeAckFrame returns a new Ack Frame that acknowledges all packets between smallest and largest -func ComposeAckFrame(smallest protocol.PacketNumber, largest protocol.PacketNumber) *wire.AckFrame { - ackRange := wire.AckRange{ - Smallest: smallest, - Largest: largest, - } - return &wire.AckFrame{ - AckRanges: []wire.AckRange{ackRange}, - DelayTime: 0, - } -} - // 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 { diff --git a/session_test.go b/session_test.go index 31681ca7..67fb5bf6 100644 --- a/session_test.go +++ b/session_test.go @@ -2956,8 +2956,8 @@ var _ = Describe("Client Session", func() { // Illustrates that an injected Initial with an ACK frame for an unsent packet causes // the connection to immediately break down It("fails on Initial-level ACK for unsent packet", func() { - ackFrame := testutils.ComposeAckFrame(0, 0) - initialPacket := testutils.ComposeInitialPacket(destConnID, srcConnID, sess.version, destConnID, []wire.Frame{ackFrame}) + ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}} + initialPacket := testutils.ComposeInitialPacket(destConnID, srcConnID, sess.version, destConnID, []wire.Frame{ack}) tracer.EXPECT().ReceivedPacket(gomock.Any(), gomock.Any(), gomock.Any()) Expect(sess.handlePacketImpl(wrapPacket(initialPacket))).To(BeFalse()) }) @@ -2965,7 +2965,10 @@ var _ = Describe("Client Session", func() { // Illustrates that an injected Initial with a CONNECTION_CLOSE frame causes // the connection to immediately break down It("fails on Initial-level CONNECTION_CLOSE frame", func() { - connCloseFrame := testutils.ComposeConnCloseFrame() + connCloseFrame := &wire.ConnectionCloseFrame{ + IsApplicationError: true, + ReasonPhrase: "mitm attacker", + } initialPacket := testutils.ComposeInitialPacket(destConnID, srcConnID, sess.version, destConnID, []wire.Frame{connCloseFrame}) tracer.EXPECT().ReceivedPacket(gomock.Any(), gomock.Any(), gomock.Any()) Expect(sess.handlePacketImpl(wrapPacket(initialPacket))).To(BeTrue())