Exemplo n.º 1
0
def listenHttp(httpoprt):
    factory = HTTPFactory()
    def _dummy(*args, **argd):
        pass 
    factory.log = _dummy
    factory.protocol = TyHttpChannel
    reactor.listenTCP(httpoprt, factory)
Exemplo n.º 2
0
Arquivo: main.py Projeto: gil/pac4cli
def start_server(port, reactor):
    factory = HTTPFactory()
    factory.protocol = proxy.Proxy
    factory.protocol.requestFactory = WPADProxyRequest

    yield reactor.listenTCP(port, factory, interface="127.0.0.1")
    
    servicemanager.notify_ready();
Exemplo n.º 3
0
def start_server(port, reactor):
    factory = HTTPFactory()
    factory.protocol = proxy.Proxy
    factory.protocol.requestFactory = WPADProxyRequest

    yield reactor.listenTCP(port, factory, interface="127.0.0.1")

    systemd.daemon.notify(systemd.daemon.Notification.READY)
Exemplo n.º 4
0
def listenHttp(httpoprt):
    factory = HTTPFactory()

    def _dummy(*args, **argd):
        pass

    factory.log = _dummy
    factory.protocol = TyHttpChannel
    reactor.listenTCP(httpoprt, factory)
Exemplo n.º 5
0
def start_proxy(port):
    """Start the internal HTTP proxy server.

    The proxy, which runs locally, serves as a middleware,
    i.e. the client handler forwards clients' requests to the proxy,
    and the proxy is reponsible for communicating with the target server.

    It is suggested that an external HTTP proxy is specified
    in place of the internal one,
    for performance and stability considerations.
    See command line arguments for detailed information.
    """
    factory = HTTPFactory()
    factory.protocol = ConnectProxy
    reactor.listenTCP(port, factory, interface="127.0.0.1")
Exemplo n.º 6
0
def start_proxy(port):
    """Start the internal HTTP proxy server.

    The proxy, which runs locally, serves as a middleware,
    i.e. the client handler forwards clients' requests to the proxy,
    and the proxy is reponsible for communicating with the target server.

    It is suggested that an external HTTP proxy is specified
    in place of the internal one,
    for performance and stability considerations.
    See command line arguments for detailed information.
    """
    factory = HTTPFactory()
    factory.protocol = ConnectProxy
    reactor.listenTCP(port, factory, interface="127.0.0.1")
Exemplo n.º 7
0
def start_server(interface, port, reactor):
    factory = HTTPFactory()
    factory.protocol = proxy.Proxy
    factory.protocol.requestFactory = WPADProxyRequest

    interface_ips = resolve(interface)
    print(interface_ips)
    for interface_ip in interface_ips:
        logger.info("Binding to interface: '%s'" % interface_ip)
        try:
            yield reactor.listenTCP(port, factory, interface=interface_ip)
        except OSError as e:
            # Most likely the most famous reason we will see this log for,
            # is that we are trying to bind to an IPv6 interface on a
            # system that has the IPv6 stack disabled.
            logger.error("Failed to bind to interface '%s'" % interface_ip)
            continue

    servicemanager.notify_ready()
Exemplo n.º 8
0
    def clientConnectionFailed(self, connector, reason):
        self.request.fail("Gateway Error", str(reason))


if __name__ == '__main__':
    _log.startLogging(sys.stdout)

    ap = argparse.ArgumentParser()
    ap.add_argument('port', default=8090, nargs='?', type=int)
    ap.add_argument('--ssl-cert', type=str)
    ap.add_argument('--ssl-key', type=str)
    ns = ap.parse_args()

    factory = HTTPFactory()
    factory.protocol = ConnectProxy

    if ns.ssl_key and not ns.ssl_cert:
        log.info("--ssl-key must be used with --ssl-cert")
        sys.exit(1)
    if ns.ssl_cert:
        with open(ns.ssl_cert, 'rb') as fp:
            ssl_cert = fp.read()
        if ns.ssl_key:
            from OpenSSL import crypto
            with open(ns.ssl_key, 'rb') as fp:
                ssl_key = fp.read()
            certificate = ssl.PrivateCertificate.load(
                ssl_cert, ssl.KeyPair.load(ssl_key, crypto.FILETYPE_PEM),
                crypto.FILETYPE_PEM)
        else:
Exemplo n.º 9
0
def Proxy(createEndpoint, **kwargs):
    factory = HTTPFactory()
    factory.protocol = _Proxy
    factory.protocol.createEndpoint = createEndpoint
    return factory
Exemplo n.º 10
0
All requests will be rewritten to https.""")
    parser.add_argument('-c',
                        '--cert',
                        dest="cert",
                        type=str,
                        required=True,
                        help="The certificate to use in pem format.")
    parser.add_argument('-k',
                        '--key',
                        dest="key",
                        type=str,
                        required=True,
                        help="The private key to use in pem format.")
    parser.add_argument(
        '-p',
        '--port',
        dest='port',
        type=int,
        default=8080,
        help="The port the HTTP proxy listens on (default: 8080).")
    args = parser.parse_args()

    CERTFILE = args.cert
    KEYFILE = args.key

    httpFactory = HTTPFactory()
    httpFactory.protocol = HTTPSClientCertProxyChannel
    reactor.listenTCP(args.port, httpFactory)
    print "now starting..."
    reactor.run()
Exemplo n.º 11
0
def Proxy(createEndpoint, **kwargs):
    factory = HTTPFactory()
    factory.protocol = _Proxy
    factory.protocol.createEndpoint = createEndpoint
    return factory
class HTTPSClientCertProxyChannel(HTTPChannel):

    requestFactory = ClientCertRequest


if __name__ == "__main__":

    import argparse

    parser = argparse.ArgumentParser(description="""HTTP proxy that uses a given client certificate to authenticate all proxied
requests with the server.
Notice, that all requests have to be http, even if the target is https.
All requests will be rewritten to https.""")
    parser.add_argument('-c', '--cert', dest="cert", type=str, required=True,
                        help="The certificate to use in pem format.")
    parser.add_argument('-k', '--key', dest="key", type=str, required=True,
                        help="The private key to use in pem format.")
    parser.add_argument('-p', '--port', dest='port', type=int, default=8080,
                        help="The port the HTTP proxy listens on (default: 8080).")
    args = parser.parse_args()

    CERTFILE = args.cert
    KEYFILE = args.key

    httpFactory = HTTPFactory()
    httpFactory.protocol = HTTPSClientCertProxyChannel
    reactor.listenTCP(args.port, httpFactory)
    print "now starting..."
    reactor.run()