MCPcopy Create free account
hub / github.com/mitmproxy/mitmproxy / on_handshake_error

Method on_handshake_error

mitmproxy/proxy/layers/tls.py:637–675  ·  view source on GitHub ↗
(self, err: str)

Source from the content-addressed store, hash-verified

635 return err
636
637 def on_handshake_error(self, err: str) -> layer.CommandGenerator[None]:
638 if self.conn.sni:
639 dest = self.conn.sni
640 else:
641 dest = human.format_address(self.context.server.address)
642 level: int = WARNING
643 if err.startswith("Cannot parse ClientHello"):
644 pass
645 elif (
646 "('SSL routines', 'tls_early_post_process_client_hello', 'unsupported protocol')"
647 in err
648 or "('SSL routines', '', 'unsupported protocol')" in err # OpenSSL 3+
649 ):
650 err = (
651 f"Client and mitmproxy cannot agree on a TLS version to use. "
652 f"You may need to adjust mitmproxy's tls_version_client_min option."
653 )
654 elif (
655 "unknown ca" in err
656 or "bad certificate" in err
657 or "certificate unknown" in err
658 ):
659 err = (
660 f"The client does not trust the proxy's certificate for {dest} ({err})"
661 )
662 elif err == "connection closed":
663 err = (
664 f"The client disconnected during the handshake. If this happens consistently for {dest}, "
665 f"this may indicate that the client does not trust the proxy's certificate."
666 )
667 level = INFO
668 elif err == "connection closed early":
669 pass
670 else:
671 err = f"The client may not trust the proxy's certificate for {dest} ({err})"
672 if err != "connection closed early":
673 yield commands.Log(f"Client TLS handshake failed. {err}", level=level)
674 yield from super().on_handshake_error(err)
675 self.event_to_child = self.errored # type: ignore
676
677 def errored(self, event: events.Event) -> layer.CommandGenerator[None]:
678 if self.debug is not None:

Callers

nothing calls this directly

Calls 1

on_handshake_errorMethod · 0.45

Tested by

no test coverage detected