示例#1
0
    def on_error(self, excep):
        """
        Handles known errors that the twisted.web.client.Agent or txsocksx.http.SOCKS5Agent
        can throw while connecting through their respective networks.
        """
        if is_common_net_error(State.tenant_cache[1], excep):
            log.err('%s job failed on outgoing network connection with: %s',
                    self.name, excep)
            return

        super(NetLoopingJob, self).on_error(excep)
示例#2
0
    def verify_hostname(self, req_args, *args, **kwargs):
        net_agent = self.state.get_agent()

        url = urlunsplit(('http', req_args['value'], 'robots.txt', None, None)).encode()

        try:
            resp = yield net_agent.request(b'GET', url)
            body = yield readBody(resp)

            server_h = resp.headers.getRawHeaders(b'Server', [None])[-1].lower()
            if not body.startswith(b'User-agent: *') or server_h != b'globaleaks':
                raise EnvironmentError('Response unexpected')

        except Exception as e:
            # Convert networking failures into a generic response
            if is_common_net_error(self.state.tenant_cache[self.request.tid], e):
                raise errors.ExternalResourceError()
            raise e