Пример #1
0
class NetWorkClient:
    def __init__(self):
        self.security = Security()
        self.sym_key = None
        self.sock = socket.socket()
        self.AES = AESCrypt()
        self.ExplorerManager = ExplorerManager()
        self.permmisions = permmisions()
        self.Folder_Encrypt = Folder_Encrypt()

    def start(self):
        self.sock.connect((SERVER_ADDRESS, SERVER_PORT))

    def recv_buf(self):
        #content=""
        #while True:
        #    data = self.clientSock.recv(LEN_UNIT_BUF)
        #    if not data:  break
        #    content += data
        #print content
        #return content.split(END_LINE)[0]
        return self.sock.recv(LEN_UNIT_BUF).split(END_LINE)[0]

    def verify_hello(self, data):
        if len(data):
            # Verify Hello at beginning of communication
            if not (data == PROT_START):
                self.sock.send(ERROR_SOCKET + END_LINE +
                               "Error in protocol establishment ( 'Hello' )" +
                               END_LINE)
                time.sleep(0.5)
                self.sock.close()
                return False
            return True
        return False

    def send(self, data):
        data = self.AES.encryptAES(self.sym_key, data)
        self.sock.send(data)

    def recv(self):
        encrypted_data = self.sock.recv(LEN_UNIT_BUF)
        data = self.AES.decryptAES(self.sym_key, encrypted_data)
        return data

    def run(self):
        self.start()
        self.sock.send(PROT_START)
        data = self.recv_buf()
        if not self.verify_hello(data):
            return
        self.sym_key = self.security.key_exchange_client(self.sock)
        file_name = self.recv()
        self.permmisions.Access_Denied(file_name)
        self.ExplorerManager.begin(file_name)
        pipe = Pipe()
        message = ""
        while message != "You failed to login 3 times. Access to folder denied." or message != "login successful":
            loggedindetails = pipe.communication()
            print message
            self.send(loggedindetails)
            message = self.recv()
            pipe.pipesend(message)
        if "login failed" in message:
            self.Folder_Encrypt.encrypt_file(os.urandom(32), file_name)

        print
        raw_input()
        self.permmisions.remove_ace(file_name)
Пример #2
0
class NetWorkClient:
    def __init__(self):
        self.security = Security()
        self.sym_key =None
        self.sock = socket.socket()
        self.AES= AESCrypt()
        self.ExplorerManager = ExplorerManager()
        self.permmisions =  permmisions()
        self.Folder_Encrypt = Folder_Encrypt()
        self.Pipe = Pipe()


    def start(self):
        self.sock.connect((SERVER_ADDRESS, SERVER_PORT))

    def recv_buf(self):
        #content=""
        #while True:
        #    data = self.clientSock.recv(LEN_UNIT_BUF)
        #    if not data:  break
        #    content += data
        #print content
        #return content.split(END_LINE)[0]
        return self.sock.recv(LEN_UNIT_BUF).split(END_LINE)[0]

    def verify_hello(self, data):
        if len(data):
            # Verify Hello at beginning of communication
            if not (data == PROT_START ):
                self.sock.send(ERROR_SOCKET + END_LINE + "Error in protocol establishment ( 'Hello' )" + END_LINE)
                time.sleep(0.5)
                self.sock.close()
                return False
            return True
        return False

    def send(self, data):
        data = self.AES.encryptAES(self.sym_key, data)
        self.sock.send(data)

    def recv(self):
        encrypted_data = self.sock.recv(LEN_UNIT_BUF)
        data = self.AES.decryptAES(self.sym_key, encrypted_data)
        return data

    def run(self):
        self.start()
        self.sock.send(PROT_START)
        data = self.recv_buf()
        if not self.verify_hello(data):
            return
        self.sym_key = self.security.key_exchange_client(self.sock)
        file_name = self.recv()
        self.permmisions.Access_Denied(file_name)
        print self.ExplorerManager.begin(file_name)
        if self.ExplorerManager.begin(file_name)== "folder open":
            #subprocess.check_call(r"C:\Users\User\Desktop\Project-master\Code\GUI\WindowsFormsApplication5\bin\Debug\WindowsFormsApplication5.exe")
            self.Pipe.pipesend("folder open")
        message = ""
        count=0
        while count<3:
            loggedindetails=self.Pipe.communication()
            print message
            self.send(loggedindetails)
            message = self.recv()
            self.Pipe.pipesend(message)
            count+=1
        if "login failed" in message:
            self.Folder_Encrypt.encrypt_file(os.urandom(32), file_name)
        if message == "login successful":
            self.permmisions.remove_ace(file_name)
Пример #3
0
class NetWorkClient:
    def __init__(self):
        self.security = Security()
        self.sym_key =None
        self.sock = socket.socket()
        self.AES= AESCrypt()
        self.ExplorerManager = ExplorerManager()
        self.permmisions =  permmisions()
        self.Folder_Encrypt = Folder_Encrypt()


    def start(self):
        self.sock.connect((SERVER_ADDRESS, SERVER_PORT))

    def recv_buf(self):
        #content=""
        #while True:
        #    data = self.clientSock.recv(LEN_UNIT_BUF)
        #    if not data:  break
        #    content += data
        #print content
        #return content.split(END_LINE)[0]
        return self.sock.recv(LEN_UNIT_BUF).split(END_LINE)[0]

    def verify_hello(self, data):
        if len(data):
            # Verify Hello at beginning of communication
            if not (data == PROT_START ):
                self.sock.send(ERROR_SOCKET + END_LINE + "Error in protocol establishment ( 'Hello' )" + END_LINE)
                time.sleep(0.5)
                self.sock.close()
                return False
            return True
        return False

    def send(self, data):
        data = self.AES.encryptAES(self.sym_key, data)
        self.sock.send(data)

    def recv(self):
        encrypted_data = self.sock.recv(LEN_UNIT_BUF)
        data = self.AES.decryptAES(self.sym_key, encrypted_data)
        return data

    def run(self):
        self.start()
        self.sock.send(PROT_START)
        data = self.recv_buf()
        if not self.verify_hello(data):
            return
        self.sym_key = self.security.key_exchange_client(self.sock)
        file_name =  self.recv()
        self.permmisions.Access_Denied(file_name)
        self.ExplorerManager.begin(file_name)
        pipe=Pipe()
        message=""
        while message!="You failed to login 3 times. Access to folder denied." or message != "login successful":
            loggedindetails=pipe.communication()
            print message
            self.send(loggedindetails)
            message = self.recv()
            pipe.pipesend(message)
        if "login failed" in message:
            self.Folder_Encrypt.encrypt_file(os.urandom(32), file_name)



        print
        raw_input()
        self.permmisions.remove_ace(file_name)