Esempio n. 1
0
	def __init__(self, config):
		"""
		Secure socket and state machine initialization
		"""
		self.ctx = ssl.create_default_context();
		self.ctx.load_verify_locations(config["CA_CERTIFICATE"]);
		self.sock = socket.create_connection((config["SERVER_IP"], config["SERVER_PORT"]));
		self.ctx.check_hostname = True;
		self.secure_socket = self.ctx.wrap_socket(self.sock, server_hostname=config["SERVER_HOSTNAME"], server_side=False);
		self.sm = state.StateMachine();
		self.sm.connected();
		self.buffer_size = config["BUFFER_SIZE"];
		self.default_gw = config["DEFAULT_GW"];
		self.dns_server = config["DNS_SERVER"];
		self.server_ip = config["SERVER_IP"];

		"""
		Initialize secure socket buffer
		"""
		self.secure_socket_buffer = [];

		"""
		Routing and DNS configurators
		"""
		self.routing_ = routing.Routing();
		self.dns_ = dns.DNS();
Esempio n. 2
0
	def __init__(self, config, database):
		"""
		Initialize the database
		"""
		self.database = database;

		"""
		Initialize state machine
		"""
		self.sm = state.StateMachine();

		"""
		Initialize IP address pool
		"""

		self.ip_pool = pool.IpPool(config["TUN_ADDRESS"], config["TUN_NETMASK"]);

		"""
		Server configuration 
		"""

		self.hostname = config["LISTEN_ADDRESS"];
		self.port = config["LISTEN_PORT"];
		self.tun_address = config["TUN_ADDRESS"];
		self.tun_name = config["TUN_NAME"];
		self.tun_netmask = config["TUN_NETMASK"];
		self.tun_mtu = config["TUN_MTU"];
		self.buffer_size = config["BUFFER_SIZE"];
		self.salt = config["SALT"];

		"""
		Create secure socket and bind it to address and port
		"""

		self.ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2);
		self.ctx.load_cert_chain(config["CERTIFICATE_CHAIN"], config["PRIVATE_KEY"]);
		self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0);
		self.sock.bind((self.hostname, self.port));
		self.sock.listen(5);
		self.secure_sock = self.ctx.wrap_socket(self.sock, server_side=True);

		"""
		Create tun interface
		"""
		self.tun = tun.Tun(self.tun_name, self.tun_address, self.tun_netmask, self.tun_mtu);

		"""
		Configure NATing
		"""
		self.nat_ = nat.NAT();
		self.nat_.enable_forwarding();
		self.nat_.masquerade_tun_interface();
		"""
		Initialize secure socket buffer
		"""
		self.secure_socket_buffer = [];
Esempio n. 3
0
    def __init__(self, config):
        """
		Secure socket and state machine initialization
		"""
        self.ctx = ssl.create_default_context()
        if config.get("CA_CERTIFICATE"):
            self.ctx.load_verify_locations(config["CA_CERTIFICATE"])
        hostname = config["SERVER_HOSTNAME"]
        if not config.get("SERVER_IP"):
            config["SERVER_IP"] = socket.gethostbyname(hostname)
            print("Using %s as server IP ..." % config["SERVER_IP"])
        self.sock = socket.create_connection(
            (config["SERVER_IP"], config["SERVER_PORT"]))
        self.ctx.check_hostname = True
        self.secure_socket = self.ctx.wrap_socket(self.sock,
                                                  server_hostname=hostname,
                                                  server_side=False)
        self.sm = state.StateMachine()
        self.sm.connected()
        self.buffer_size = config["BUFFER_SIZE"]
        if not config.get("DEFAULT_GW"):
            config["DEFAULT_GW"] = get_default_gateway()
            if not config["DEFAULT_GW"]:
                raise Exception(
                    'Could not determine default gateway, please configure manually'
                )
            print("Using %s as default gateway ..." % config["DEFAULT_GW"])
        self.default_gw = config["DEFAULT_GW"]
        self.dns_server = config["DNS_SERVER"]
        self.server_ip = config["SERVER_IP"]
        """
		Initialize secure socket buffer
		"""
        self.secure_socket_buffer = []
        """
		Routing and DNS configurators
		"""
        self.routing_ = routing.Routing()
        self.dns_ = dns.DNS()
        self.nat_ = nat.NAT()