Ejemplo n.º 1
0
    def establish_server_connection(self, host: str, port: int, scheme: str):
        address = tcp.Address((host, port))
        tls = (scheme == "https")

        if self.mode is HTTPMode.regular or self.mode is HTTPMode.transparent:
            # If there's an existing connection that doesn't match our expectations, kill it.
            if address != self.server_conn.address or tls != self.server_tls:
                self.set_server(address)
                self.set_server_tls(tls, address.host)
            # Establish connection is neccessary.
            if not self.server_conn.connected():
                self.connect()
        else:
            if not self.server_conn.connected():
                self.connect()
            if tls:
                raise exceptions.HttpProtocolException("Cannot change scheme in upstream proxy mode.")
Ejemplo n.º 2
0
    def establish_server_connection(self, flow):
        address = tcp.Address((flow.request.host, flow.request.port))
        tls = (flow.request.scheme == "https")

        if self.mode == "regular" or self.mode == "transparent":
            # If there's an existing connection that doesn't match our expectations, kill it.
            if address != self.server_conn.address or tls != self.server_tls:
                self.set_server(address)
                self.set_server_tls(tls, address.host)
            # Establish connection is neccessary.
            if not self.server_conn:
                self.connect()
        else:
            if not self.server_conn:
                self.connect()
            if tls:
                raise exceptions.HttpProtocolException(
                    "Cannot change scheme in upstream proxy mode.")
            """
Ejemplo n.º 3
0
 def establish_server_connection(self, host: str, port: int, scheme: str):
     tls = (scheme == "https")
     logging.info('HttpLayer.establish_server_connection: tls=%s', tls)
     if self.mode is HTTPMode.regular or self.mode is HTTPMode.transparent:
         # If there's an existing connection that doesn't match our expectations, kill it.
         address = (host, port)
         if address != self.server_conn.address or tls != self.server_tls:
             logging.info('HttpLayer setting server address to %s', address)
             self.set_server(address)
             self.set_server_tls(tls, address[0])
         # following copied from proxy/root_context.py
         logging.info('filter_http: %s, check_filter: %s',
                      self.config.options.filter_http,
                      self.config.check_filter)
         if self.config.options.filter_http and self.config.check_filter:
             is_filtered = self.config.check_filter(
                 self.server_conn.address)
             logging.info('establish_server_connection: %s is_filtered: %s',
                          vars(self.server_conn), is_filtered)
             if is_filtered:
                 if self.config.options.block_not_ignore:
                     # client address automatically prepended by self.log
                     self.log(
                         '-> {}:{} {} blocked'.format(
                             host, port, datetime.now()), 'info')
                     raise exceptions.Kill(
                         'blocked http request to filtered host {}'.format(
                             host))
         # Establish connection is necessary.
         if not self.server_conn.connected():
             logging.info('HttpLayer connecting to %s', address)
             self.connect()
     else:
         logging.info('HttpLayer: mode is %s', self.mode)
         if not self.server_conn.connected():
             self.connect()
         if tls:
             raise exceptions.HttpProtocolException(
                 "Cannot change scheme in upstream proxy mode.")
     self.log('-> {}:{} {} allowed'.format(host, port, datetime.now()),
              'info')