Exemplo n.º 1
0
def run_proxy_mode(config):
    from microproxy.proxy import start_tcp_server
    from microproxy.event import start_events_server
    from microproxy.utils import (
        curr_loop, create_publish_channel, create_event_channel)
    from microproxy.server_state import init_server_state

    ProxyLogger.init_proxy_logger(config)

    # Create zmq related sockets
    publish_socket = create_publish_channel(config["viewer_channel"])
    event_socket = create_event_channel(config["events_channel"])

    ProxyLogger.register_zmq_handler(publish_socket)

    # Initialize server state
    _server_state = init_server_state(config, publish_socket)

    start_events_server(_server_state, event_socket)
    start_tcp_server(_server_state)

    try:
        curr_loop().start()
    except KeyboardInterrupt:
        logger = ProxyLogger.get_logger(__name__)
        logger.info("bye")
Exemplo n.º 2
0
 def test_init_proxy_logger_stream_handler(self, mock_register_file_handler, mock_register_stream_handler):
     config = {
         "logger_config": "",
         "log_file": "",
         "log_level": "INFO"
     }
     ProxyLogger.init_proxy_logger(config)
     mock_register_stream_handler.assert_called_once()
     mock_register_file_handler.assert_not_called()
Exemplo n.º 3
0
 def test_init_proxy_logger_file_handler(self, mock_register_file_handler,
                                         mock_register_stream_handler):
     config = {
         "logger_config": "",
         "log_file": "test.log",
         "log_level": "INFO"
     }
     ProxyLogger.init_proxy_logger(config)
     mock_register_file_handler.assert_called_once_with("test.log")
     mock_register_stream_handler.assert_not_called()
Exemplo n.º 4
0
 def test_init_proxy_logger_file_handler(self,
                                         mock_logging_fileConfig,
                                         mock_register_file_handler,
                                         mock_register_stream_handler):
     config = {
         "logger_config": "test.cfg",
         "log_file": "test.log",
         "log_level": "INFO"
     }
     ProxyLogger.init_proxy_logger(config)
     mock_logging_fileConfig.assert_called_once_with(filename="test.cfg", encoding="utf8")
     mock_register_file_handler.assert_not_called()
     mock_register_stream_handler.assert_not_called()
Exemplo n.º 5
0
 def test_init_proxy_logger_file_handler(self, mock_logging_fileConfig,
                                         mock_register_file_handler,
                                         mock_register_stream_handler):
     config = {
         "logger_config": "test.cfg",
         "log_file": "test.log",
         "log_level": "INFO"
     }
     ProxyLogger.init_proxy_logger(config)
     mock_logging_fileConfig.assert_called_once_with(filename="test.cfg",
                                                     encoding="utf8")
     mock_register_file_handler.assert_not_called()
     mock_register_stream_handler.assert_not_called()
Exemplo n.º 6
0
def verify_config(config_field_info, config):
    fieldInfos = config_field_info
    require_fields = [k for k, v in fieldInfos.iteritems() if v["is_require"]]
    missing_fields = [field for field in require_fields if field not in config]
    if missing_fields:
        raise KeyError("missing config field: [{0}]".format(",".join(missing_fields)))

    # NOTE: Verify that the value in choices
    for field in config:
        try:
            if config[field] not in fieldInfos[field]["choices"]:
                raise ValueError("illgeal value: {0} at field: {1}".format(config[field], field))
        except KeyError:
            pass

    unknown_fields = [field for field in config if field not in fieldInfos]
    if unknown_fields:
        ProxyLogger.get_logger(__name__).warning(
            "Unknown field names: {0}".format(",".join(unknown_fields)))
Exemplo n.º 7
0
def verify_config(config_field_info, config):
    fieldInfos = config_field_info
    require_fields = [k for k, v in fieldInfos.iteritems() if v["is_require"]]
    missing_fields = [field for field in require_fields if field not in config]
    if missing_fields:
        raise KeyError("missing config field: [{0}]".format(
            ",".join(missing_fields)))

    # NOTE: Verify that the value in choices
    for field in config:
        try:
            if config[field] not in fieldInfos[field]["choices"]:
                raise ValueError("illgeal value: {0} at field: {1}".format(
                    config[field], field))
        except KeyError:
            pass

    unknown_fields = [field for field in config if field not in fieldInfos]
    if unknown_fields:
        ProxyLogger.get_logger(__name__).warning(
            "Unknown field names: {0}".format(",".join(unknown_fields)))
Exemplo n.º 8
0
import h11
import re
from tornado import gen
from tornado.iostream import StreamClosedError

from microproxy.context import HttpResponse
from microproxy.exception import SrcStreamClosedError, DestStreamClosedError
from microproxy.layer.base import ApplicationLayer, DestStreamCreatorMixin
from microproxy.log import ProxyLogger
from microproxy.protocol.http1 import Connection

logger = ProxyLogger.get_logger(__name__)


def _wrap_req_path(context, req):
    return "http://{0}:{1}{2}".format(context.host, context.port, req.path)


def parse_proxy_path(path):
    default_ports = {
        "http": 80,
        "https": 443,
    }
    matcher = re.search(r"^(https?):\/\/([a-zA-Z0-9\.\-]+)(:(\d+))?(/.*)", path)
    groups = matcher.groups() if matcher else []
    if not groups:  # pragma: no cover
        raise ValueError("illegal proxy path {0}".format(path))
    else:
        scheme = groups[0]
        host = groups[1]
        port = int(groups[3]) if groups[3] else default_ports[scheme]
Exemplo n.º 9
0
from __future__ import absolute_import

from OpenSSL import SSL, crypto
import certifi
import construct

from tornado import gen
from microproxy.pyca_tls import _constructs
from microproxy.utils import HAS_ALPN
from microproxy.exception import ProtocolError

from microproxy.log import ProxyLogger
logger = ProxyLogger.get_logger(__name__)

_SUPPROT_CIPHERS_SUITES = (
    "ECDHE-RSA-AES128-GCM-SHA256", "ECDHE-ECDSA-AES128-GCM-SHA256",
    "ECDHE-RSA-AES256-GCM-SHA384", "ECDHE-ECDSA-AES256-GCM-SHA384",
    "DHE-RSA-AES128-GCM-SHA256", "DHE-DSS-AES128-GCM-SHA256", "kEDH+AESGCM",
    "ECDHE-RSA-AES128-SHA256", "ECDHE-ECDSA-AES128-SHA256",
    "ECDHE-RSA-AES128-SHA", "ECDHE-ECDSA-AES128-SHA",
    "ECDHE-RSA-AES256-SHA384", "ECDHE-ECDSA-AES256-SHA384",
    "ECDHE-RSA-AES256-SHA", "ECDHE-ECDSA-AES256-SHA", "DHE-RSA-AES128-SHA256",
    "DHE-RSA-AES128-SHA", "DHE-DSS-AES128-SHA256", "DHE-RSA-AES256-SHA256",
    "DHE-DSS-AES256-SHA", "DHE-RSA-AES256-SHA", "ECDHE-RSA-DES-CBC3-SHA",
    "ECDHE-ECDSA-DES-CBC3-SHA", "AES128-GCM-SHA256", "AES256-GCM-SHA384",
    "AES128-SHA256", "AES256-SHA256", "AES128-SHA", "AES256-SHA", "AES",
    "DES-CBC3-SHA", "HIGH", "!aNULL", "!eNULL", "!EXPORT", "!DES", "!RC4",
    "!MD5", "!PSK", "!aECDH", "!EDH-DSS-DES-CBC3-SHA", "!EDH-RSA-DES-CBC3-SHA",
    "!KRB5-DES-CBC3-SHA")