Example #1
0
def comunicate(client):
    """Comunicate with client"""
    secret_key = client._sts["secret_key"]
    des3_key = sha256(secret_key).digest()[:16]

    des3_cipher = crypto.DES3Cipher(des3_key)

    prompt()
    while True:
        socket_list = [sys.stdin, client._socket]

        # Get the list sockets which are readable
        read_sockets, _, _ = select.select(socket_list, [], [])

        for sock in read_sockets:

            # incoming message from remote server
            if sock == client._socket:
                try:
                    message = sutil.read_data(client._socket)
                except ValueError as msg:
                    print("[x] {}".format(msg))
                    break
                print(">>> {}".format(des3_cipher.decrypt(message)))
                prompt()

            else:
                message = sys.stdin.readline()
                client._socket.sendall(des3_cipher.encrypt(message))
Example #2
0
def comunicate(worker, connection):
    """Comunicate with client"""

    secret_key = worker._sts["secret_key"]
    des3_key = sha256(secret_key).digest()[:16]

    des3_cipher = crypto.DES3Cipher(des3_key)

    while True:
        socket_list = [connection]

        # Get the list sockets which are readable
        read_sockets, _, _ = select.select(socket_list, [], [])

        for sock in read_sockets:

            # incoming message from remote server
            if sock == connection:
                try:
                    message = sutil.read_data(connection)
                except ValueError as msg:
                    print("[x] {}".format(msg))

                message = des3_cipher.decrypt(message)
                print("<<< {}".format(message))
                message = des3_cipher.encrypt(message)
                print(">>> {}".format(message))
                connection.sendall(message)
Example #3
0
def comunicate(worker, connection):
    """Comunicate with client"""

    secret_key = worker._sts["secret_key"]
    des3_key = sha256(secret_key).digest()[:16]

    des3_cipher = crypto.DES3Cipher(des3_key)

    while True:
        socket_list = [connection]

        # Get the list sockets which are readable
        read_sockets, _, _ = select.select(socket_list, [], [])

        for sock in read_sockets:

            # incoming message from remote server
            if sock == connection:
                try:
                    message = sutil.read_data(connection)
                except ValueError as msg:
                    print("[x] {}".format(msg))

                message = des3_cipher.decrypt(message)
                print("<<< {}".format(message))
                message = des3_cipher.encrypt(message)
                print(">>> {}".format(message))
                connection.sendall(message)
Example #4
0
def comunicate(client):
    """Comunicate with client"""
    secret_key = client._sts["secret_key"]
    des3_key = sha256(secret_key).digest()[:16]

    des3_cipher = crypto.DES3Cipher(des3_key)

    prompt()
    while True:
        socket_list = [sys.stdin, client._socket]

        # Get the list sockets which are readable
        read_sockets, _, _ = select.select(socket_list, [], [])

        for sock in read_sockets:

            # incoming message from remote server
            if sock == client._socket:
                try:
                    message = sutil.read_data(client._socket)
                except ValueError as msg:
                    print("[x] {}".format(msg))
                    break
                print(">>> {}".format(des3_cipher.decrypt(message)))
                prompt()

            else:
                message = sys.stdin.readline()
                client._socket.sendall(des3_cipher.encrypt(message))
Example #5
0
    def authentificate(self):
        """Will validate server identity"""
        # Compute the secret
        self._auth_step_one()

        # Get exponent from server
        sutil.debug("[i] Get Server Secret !")
        self._sts["s_secret"] = sutil.read_data(self._socket)

        # Send authentification data
        sutil.debug("[i] Send authentification step two information !")
        self._socket.sendall(self._auth_step_two())

        # Wait for server response
        sutil.debug("[i] Waiting for server response !")
        message = sutil.read_data(self._socket)

        if not self._check_auth(message):
            return False

        return True
Example #6
0
    def authentificate(self):
        """Will validate server identity"""
        # Compute the secret
        self._auth_step_one()

        # Get exponent from server
        sutil.debug("[i] Get Server Secret !")
        self._sts["s_secret"] = sutil.read_data(self._socket)

        # Send authentification data
        sutil.debug("[i] Send authentification step two information !")
        self._socket.sendall(self._auth_step_two())

        # Wait for server response
        sutil.debug("[i] Waiting for server response !")
        message = sutil.read_data(self._socket)

        if not self._check_auth(message):
            return False

        return True
Example #7
0
    def authentificate(self, connection):
        """Will validate client identity"""

        sutil.debug("[i] Authentification - Send exponent")
        # Compute pow(genrator, random_value) and send to client
        connection.sendall(self._auth_step_one())

        sutil.debug("[i] Authentification - Check client response")

        # Get response for step one and process it
        message = sutil.read_data(connection)
        if not self._check_step_one(message):
            return False

        # User is valid - send confirmation
        sutil.debug("[i] Authentification complete - Send confirmation")
        connection.sendall(self._auth_step_two())
        return True
Example #8
0
    def authentificate(self, connection):
        """Will validate client identity"""

        sutil.debug("[i] Authentification - Send exponent")
        # Compute pow(genrator, random_value) and send to client
        connection.sendall(self._auth_step_one())

        sutil.debug("[i] Authentification - Check client response")

        # Get response for step one and process it
        message = sutil.read_data(connection)
        if not self._check_step_one(message):
            return False

        # User is valid - send confirmation
        sutil.debug("[i] Authentification complete - Send confirmation")
        connection.sendall(self._auth_step_two())
        return True
Example #9
0
    def handshake(self):
        """Exchange cryptographic keys whit user"""

        try:
            # Recive information from server
            sutil.debug("[i] Waiting for Public Information")
            message = sutil.read_data(self._socket)
            message = json.loads(message)
            for key in self.data:
                if not key in message:
                    raise ValueError("Missing {} field !".format(key))
                self.data[key] = message[key]
        except ValueError as exc:
            print("[x] {}".format(exc))
            return False

        except TypeError:
            print("[x] Invalid information recived !")
            return False

        except Exception as exc:
            print("[x] {}".format(exc))
            return False

        # Send Public key
        sutil.debug("[i] Send public key to server !")
        self._socket.sendall(self._private_key.public_key)

        try:
            # Will check if recived message is a RSA Public Key
            sutil.debug("[i] Check if recived message is a RSA Public Key")
            self.data["public_key"] = crypto.PublicKey(self.data["public_key"])
        except ValueError as exc:
            print("[x] {}".format(exc))
            return False

        return True
Example #10
0
    def handshake(self):
        """Exchange cryptographic keys whit user"""

        try:
            # Recive information from server
            sutil.debug("[i] Waiting for Public Information")
            message = sutil.read_data(self._socket)
            message = json.loads(message)
            for key in self.data:
                if not key in message:
                    raise ValueError("Missing {} field !".format(key))
                self.data[key] = message[key]
        except ValueError as exc:
            print("[x] {}".format(exc))
            return False

        except TypeError:
            print("[x] Invalid information recived !")
            return False

        except Exception as exc:
            print("[x] {}".format(exc))
            return False

        # Send Public key
        sutil.debug("[i] Send public key to server !")
        self._socket.sendall(self._private_key.public_key)

        try:
            # Will check if recived message is a RSA Public Key
            sutil.debug("[i] Check if recived message is a RSA Public Key")
            self.data["public_key"] = crypto.PublicKey(self.data["public_key"])
        except ValueError as exc:
            print("[x] {}".format(exc))
            return False

        return True
Example #11
0
    def handshake(self, connection):
        """Exchange cryptographic keys whit user"""

        # Send public information - Public key | Prime number | Generator
        sutil.debug("[i] Send public information to client !")
        connection.sendall(json.dumps(self._public_data))

        try:
            # Recive information from client
            sutil.debug("[i] Waiting for client RSA Public Key")
            message = sutil.read_data(connection)
        except ValueError as exc:
            print("[x] {}".format(exc))
            return False

        try:
            # Will check if recived message is a RSA Public Key
            sutil.debug("[i] Check if recived message is a RSA Public Key")
            self._sts["public_key"] = crypto.PublicKey(message)
        except ValueError as exc:
            print("[x] {}".format(exc))
            return False

        return True
Example #12
0
    def handshake(self, connection):
        """Exchange cryptographic keys whit user"""

        # Send public information - Public key | Prime number | Generator
        sutil.debug("[i] Send public information to client !")
        connection.sendall(json.dumps(self._public_data))

        try:
            # Recive information from client
            sutil.debug("[i] Waiting for client RSA Public Key")
            message = sutil.read_data(connection)
        except ValueError as exc:
            print("[x] {}".format(exc))
            return False

        try:
            # Will check if recived message is a RSA Public Key
            sutil.debug("[i] Check if recived message is a RSA Public Key")
            self._sts["public_key"] = crypto.PublicKey(message)
        except ValueError as exc:
            print("[x] {}".format(exc))
            return False

        return True