MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / _get_client_hello

Method _get_client_hello

mitmproxy/addons/next_layer.py:300–338  ·  view source on GitHub ↗

Try to read a TLS/DTLS/QUIC ClientHello from data_client. Returns: A complete ClientHello, or None, if no ClientHello was found. Raises: NeedsMoreData, if the ClientHello is incomplete.

(context: Context, data_client: bytes)

Source from the content-addressed store, hash-verified

298
299 @staticmethod
300 def _get_client_hello(context: Context, data_client: bytes) -> ClientHello | None:
301 """
302 Try to read a TLS/DTLS/QUIC ClientHello from data_client.
303
304 Returns:
305 A complete ClientHello, or None, if no ClientHello was found.
306
307 Raises:
308 NeedsMoreData, if the ClientHello is incomplete.
309 """
310 match context.client.transport_protocol:
311 case "tcp":
312 if starts_like_tls_record(data_client):
313 try:
314 ch = parse_client_hello(data_client)
315 except ValueError:
316 pass
317 else:
318 if ch is None:
319 raise NeedsMoreData
320 return ch
321 return None
322 case "udp":
323 try:
324 return quic_parse_client_hello_from_datagrams([data_client])
325 except ValueError:
326 pass
327
328 try:
329 ch = dtls_parse_client_hello(data_client)
330 except ValueError:
331 pass
332 else:
333 if ch is None:
334 raise NeedsMoreData
335 return ch
336 return None
337 case _: # pragma: no cover
338 assert_never(context.client.transport_protocol)
339
340 @staticmethod
341 def _setup_reverse_proxy(context: Context, data_client: bytes) -> Layer:

Callers 1

_ignore_connectionMethod · 0.95

Calls 4

starts_like_tls_recordFunction · 0.90
parse_client_helloFunction · 0.90
dtls_parse_client_helloFunction · 0.90

Tested by

no test coverage detected