(self, host, port=None, tls=False, timeout=5)
| 787 | self.chan_bindings = GSS_C_NO_CHANNEL_BINDINGS |
| 788 | |
| 789 | def _connect_or_reuse(self, host, port=None, tls=False, timeout=5): |
| 790 | # Get the port |
| 791 | if port is None: |
| 792 | port = 443 if tls else 80 |
| 793 | # If the current socket matches, keep it. |
| 794 | if self._sockinfo == (host, port): |
| 795 | return |
| 796 | # A new socket is needed |
| 797 | if self._sockinfo: |
| 798 | self.close() |
| 799 | sock = socket.socket() |
| 800 | sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) |
| 801 | sock.settimeout(timeout) |
| 802 | if self.verb: |
| 803 | print( |
| 804 | "\u2503 Connecting to %s on port %s%s..." |
| 805 | % ( |
| 806 | host, |
| 807 | port, |
| 808 | " with SSL" if tls else "", |
| 809 | ) |
| 810 | ) |
| 811 | sock.connect((host, port)) |
| 812 | if self.verb: |
| 813 | print( |
| 814 | conf.color_theme.green( |
| 815 | "\u2514 Connected from %s" % repr(sock.getsockname()) |
| 816 | ) |
| 817 | ) |
| 818 | if tls: |
| 819 | if self.sslcontext is None: |
| 820 | if self.no_check_certificate: |
| 821 | context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) |
| 822 | context.check_hostname = False |
| 823 | context.verify_mode = ssl.CERT_NONE |
| 824 | else: |
| 825 | context = ssl.create_default_context() |
| 826 | else: |
| 827 | context = self.sslcontext |
| 828 | sock = context.wrap_socket(sock, server_hostname=host) |
| 829 | if self.ssp and not self.no_chan_bindings: |
| 830 | # Compute the channel binding token (CBT) |
| 831 | self.chan_bindings = GssChannelBindings.fromssl( |
| 832 | ChannelBindingType.TLS_SERVER_END_POINT, |
| 833 | sslsock=sock, |
| 834 | ) |
| 835 | self.sock = SSLStreamSocket(sock, HTTP) |
| 836 | else: |
| 837 | self.sock = StreamSocket(sock, HTTP) |
| 838 | # Store information regarding the current socket |
| 839 | self._sockinfo = (host, port) |
| 840 | |
| 841 | def sr1(self, req, **kwargs): |
| 842 | if self.verb: |
no test coverage detected