Пример #1
0
    def __init__(self, adress="127.0.0.1", port=61111):
        """Setup STServer Instance"""

        self._private_key = None
        self._socket = socket.socket()  # Create a new socket
        self._adress = (adress, port)
        self.data = {
            "public_key": None,
            "prime_number": None,
            "generator": None
        }

        self._workers = []
        self._lock = threading.Lock()

        # Load settings from the previous session
        self._load_settings()

        # Check if STS settings are available
        if not self.data["prime_number"] or not self.data["generator"]:
            self._sts_setup()

        # Check if Private Key is available
        if not self._private_key:
            if GENERAL.DEBUG:
                print("[i] Will generate new RSA Key !")
            self._private_key = crypto.PrivateKey(crypto.rand_rsa_key())
            self.data["public_key"] = self._private_key.public_key

        # SO_REUSEADDR flag tells the kernel to reuse a local socket in
        # TIME_WAIT state, without waiting for its natural timeout to expire.
        self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self._socket.setblocking(1)  # Set blocking mode of the socket
Пример #2
0
    def __init__(self, listen_socket, public_data, rsa_key):
        """
        :param listen_socket: Gatekeeper socket
        :param server: Thread manager
        """

        threading.Thread.__init__(self)  # Call superclass constructor

        # Create a RSAKey object with RSA key recived from Gatekeeper
        self._rsa_key = crypto.PrivateKey(rsa_key)

        self._public_data = public_data  # Prime number | Generator
        self._socket = listen_socket  # Connection to clients
        self._sts = {}  # Information regardin client
        self.online = True  # Exit flag
Пример #3
0
    def _load_settings(self):
        """Try to load the settings from the previous session."""

        if not os.path.exists(GENERAL.CONFIG):
            try:
                os.makedirs(GENERAL.CONFIG)
            except IOError:
                raise ValueError("Invalid value provided for GENERAL.CONFIG")

            return

        if os.path.isfile(CONFIG.SERVER.RSA):
            if GENERAL.DEBUG:
                print("[i] Will load RSA Private Key !")

            try:
                private_key = crypto.PrivateKey(CONFIG.SERVER.RSA)
                self.data["public_key"] = private_key.public_key
                self._private_key = private_key
            except ValueError:
                print("[x] Fail to load RSA Private Key !")

        if os.path.isfile(CONFIG.SERVER.STS):
            if GENERAL.DEBUG:
                print("[i] Will load STS required information !")
            try:
                file_content = []
                file_handler = open(CONFIG.SERVER.STS, "rb")
                while True:
                    chunck = file_handler.read(1024)
                    if not chunck:
                        break
                    file_content.append(chunck)
                file_handler.close()
            except IOError:
                print("[x] Fail to load STS information !")

            if len(file_content):
                try:
                    sts_settings = json.load("".join(file_content))
                    self.data["prime_number"] = sts_settings.get(
                        "prime_number", None)
                    self.data["generator"] = sts_settings.get(
                        "generator", None)
                except ValueError:
                    print("[x] Fail to load STS information !")
Пример #4
0
    def __init__(self, host="127.0.0.1", port=61111):
        """Setup STSClient Isinstance"""
        self._private_key = None
        self.data = {
            "public_key": None,
            "prime_number": None,
            "generator": None
        }
        self._address = (host, port)
        self._sts = {}

        # Check if Private Key is available
        if not self._private_key:
            if GENERAL.DEBUG:
                print("[i] Will generate new RSA Key !")
            self._private_key = crypto.PrivateKey(crypto.rand_rsa_key())

        self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._socket.settimeout(10)
Пример #5
0
    def _load_settings(self):
        """Try to load the settings from the previous session."""

        if not os.path.exists(GENERAL.CONFIG):
            try:
                os.makedirs(GENERAL.CONFIG)
            except IOError:
                raise ValueError("Invalid value provided for GENERAL.CONFIG")

            return

        if os.path.isfile(CONFIG.CLIENT.RSA):
            if GENERAL.DEBUG:
                print("[i] Will load RSA Private Key !")

            try:
                private_key = crypto.PrivateKey(CONFIG.SERVER.RSA)
                self._private_key = private_key
            except ValueError:
                print("[x] Fail to load RSA Private Key !")