(self, data: bytes)
| 406 | yield from super().on_handshake_error(err) |
| 407 | |
| 408 | def receive_data(self, data: bytes) -> layer.CommandGenerator[None]: |
| 409 | if data: |
| 410 | self.tls.bio_write(data) |
| 411 | |
| 412 | plaintext = bytearray() |
| 413 | close = False |
| 414 | while True: |
| 415 | try: |
| 416 | plaintext.extend(self.tls.recv(65535)) |
| 417 | except SSL.WantReadError: |
| 418 | break |
| 419 | except SSL.ZeroReturnError: |
| 420 | close = True |
| 421 | break |
| 422 | except SSL.Error as e: |
| 423 | # This may be happening because the other side send an alert. |
| 424 | # There's somewhat ugly behavior with Firefox on Android here, |
| 425 | # which upon mistrusting a certificate still completes the handshake |
| 426 | # and then sends an alert in the next packet. At this point we have unfortunately |
| 427 | # already fired out `tls_established_client` hook. |
| 428 | yield commands.Log(f"TLS Error: {e}", WARNING) |
| 429 | break |
| 430 | |
| 431 | # Can we send something? |
| 432 | # Note that this must happen after `recv()`, which may have advanced the state machine. |
| 433 | # https://github.com/mitmproxy/mitmproxy/discussions/7550 |
| 434 | yield from self.tls_interact() |
| 435 | |
| 436 | if plaintext: |
| 437 | yield from self.event_to_child( |
| 438 | events.DataReceived(self.conn, bytes(plaintext)) |
| 439 | ) |
| 440 | if close: |
| 441 | self.conn.state &= ~connection.ConnectionState.CAN_READ |
| 442 | if self.debug: |
| 443 | yield commands.Log(f"{self.debug}[tls] close_notify {self.conn}", DEBUG) |
| 444 | yield from self.event_to_child(events.ConnectionClosed(self.conn)) |
| 445 | |
| 446 | def receive_close(self) -> layer.CommandGenerator[None]: |
| 447 | if self.tls.get_shutdown() & SSL.RECEIVED_SHUTDOWN: |
no test coverage detected