Repository navigation
Add support for raw UDP. - #5414
Conversation
|
I've been working on a layer similar to your suggestion of |
That's actually a great name as it clears up what the layer itself is supposed to do. But I'd still prefer to rename the |
Please correct me if I'm wrong, the goal is to reuse |
Actually QUIC needs both: A But if ALPN yields something besides h3, QUIC streams will be show similar to So we both agree that renaming @mhils: Any comments/suggestions on a name for a unified |
|
I need to think about this a bit longer, but here's a short raw brain dump:
TL;DR: Currently I'm leaning towards separate UDP/TCP layers/flows/event hooks, but I haven't thought about it enough. More input welcome. :) |
I agree, and @kckeiks's solution actually keeps the old hooks.
You're right, RawFlow was also my initial goto name. We can do the same trick mentioned above for As a next step, In
Of course copying is also a possibility, but then we'd definitely need two more copies, UDP and QuicStream :) The advantage of having a base class, however, is that it really makes it easy for developers new to mitmproxy to quickly write an addon for a new protocol that also can show something in the UI, without going through a lot of mitmproxy's internals making changes. (Which also makes it more cumbersome to keep up with main.) The downside is, that subtleties, like QUIC's stream ids, will either not be shown in the UI, or get encoded into something else, like a host name that then results in a |
|
I don't understand enough about how UDP and TCP will work in mitmproxy to really comment on the whole discussion. But intuitively it would be better to have separated hooks. Because if you think about the use-cases you would otherwise almost always end up with if/else in these hooks just to check what type of flow it is. So if you have multiple listeners (TCP and UDP) it would feel more natural to have them separated. I doubt you often want to manipulate two flows from two different listeners in the exact same way (e.g. search & replace the same thing). |
|
You're right, there should be different hooks. This, however, does not imply the need for different flows, if the same functionality as The second part of my suggestion was to then call yield RawMessageHook(flow)
# and
yield QuicStreamMessageHook(flow)so that in mitmproxy If we opt for duplication of flow classes, then we'd have to do something like def handle_message(flow, proto):
show_some_stuff(f"{proto}: {flow.messages[-1].content}")
def quic_stream_message(flow: QuicStreamFlow):
handle_message(flow, "quic")
def tcp_message(flow: TCPFlow):
handle_message(flow, "tcp")
def udp_message(flow: UDPFlow):
handle_message(flow, "udp")for every protocol and everywhere in mitmproxy where currently def raw_message(flow: RAWFlow):
show_some_stuff(f"{flow.proto} {flow.messages[-1].content}")but I'd happily do the code duplication as well (as it's really just copy/pasting functions and tests, there is no change in functionality regarding the flows between the protocols). |
Personally I am in favor of having a |
|
There's a path between that we already use, see #4666 We can internally keep it simple while still making the addon API more accessible by having separate hooks. Essentially moving the if/else dance one layer above (in our code, not the addon author's) Edit: even for driving the UI this would make sense internally to have separate hooks. We wouldn't dump everything in a single table but have different views, right? That would make for a much better UX, because like I said, if you proxy two different things and even protocols, you usually want to do different things with them and look at them separately. |
The (Web) UI would look the same in both cases. In the first case you would have export interface RAWFlow extends _Flow {
type: "tcp" | "udp" | "quicstream"
messages_meta: RAWMessagesMeta,
}
export type Flow = HTTPFlow | DNSFlow | RAWFlow;while in the second you could write export interface TCPFlow extends _Flow {
type: "tcp"
messages_meta: TCPMessagesMeta,
}
export interface UDPFlow extends _Flow {
type: "udp"
messages_meta: UDPMessagesMeta,
}
export interface QuicStreamFlow extends _Flow {
type: "quicstream"
messages_meta: QuicStreamMessagesMeta,
}
export type Flow = HTTPFlow | DNSFlow | TCPFlow | UDPFlow | QuicStreamFlow;which actually collapses to the first case, since all flows have the same But since this PR is now a month old and there are more comments against unification, I'll go ahead and introduce appropriate hooks for UDP and QUIC without unified RAW hooks or flows. |
|
@EndUser509 : I'll keep |
|
@meitinger @mhils #5397 also adds UDPFlow, hooks, etc. How should we resolve? |
|
@meitinger Ok, I have a feeling my PR will be blocked by #5393 (?) so this might move faster. PS you could've just let me know that you really wanted to do the |
I'm sorry, but from your last comment on June 14th, I gathered you were doing a RawLayer (RelayLayer), which got more or less rejected. (At least given the comments on this PR.) Although as you can see, it takes more changes to implement UDPFlow fully (1536) than DTLS with parts of UDPFlow (1371), so maybe it's better to have separate PRs for review. (Also the reason why I was hesitant to implement UDPFlow/QuicStreamFlow in #5435). But again, sorry for the misunderstanding/miscommunication and the extra work you had to do... 😔 |
mhils
left a comment
There was a problem hiding this comment.
Sorry for letting you two hanging for so long here, @meitinger and @kckeiks! 😔 I'll promise that cycle times will be much shorter from my end from now on.
But since this PR is now a month old and there are more comments against unification, I'll go ahead and introduce appropriate hooks for UDP and QUIC without unified RAW hooks or flows.
My lack of communication was not a statement against unification, but of a lack of sufficiently-large chunks of time to play around with things and think about the edge cases. Sorry for causing extra work. I think a RawFlow class with raw_flow_start/... hooks sounds very reasonable long term, but I'm also perfectly happy with the "duplicated" version we have here. I don't think I had considered raw QUIC streams in my initial thinking, which tilts my previous assessment slightly in favor of unification.
In the spirit of unblocking you all, I'm happy to merge either approach for now. We can merge this as-is here (and then later make a decision on whether we want to unify under raw_ only, deprecating tcp_* and udp_*), or switch to a RawFlow instance right away. @meitinger, feel free to make a judgement call on what's easier for your upcoming QUIC work. :)
|
@mhils No problem, and your fantastic #5481, i.e. having a signed store app, was definitely worth the wait :) I think it's best to merge this PR now as-is, so @kckeiks and I can continue building upon it. |
|
Sounds good to me. Resolving the merge conflicts should be straightforward, otherwise LGTM. You should have the necessary permission bits. :) |
Description
To support ignoring connections in QUIC and for #5397 & #5283 a raw UDP layer is needed.
With this small change, the (raw) TCP layer works equally well in the meantime (and has UI support), as half-closing will fail in supported way.
Of course I could also extend this PR and rename the TCPLayer to RAWLayer (or StreamLayer?), TCPFlow to RAWFlow etc., so it can be used for both protocols without confusion about the name. (The TCPLayer could also be duplicated under the name UDPLayer, but that's a lot of duplicated code without real added value.)
User entry points like the 'inject.tcp' command or the 'tcp' filter should be kept and filter for/restrict to the underlying protocol.
Comments are very welcome :)
EDIT: UDP layer and flow have now been implemented without basing it on TCP or unifying RAW hooks.
Checklist