Exemple #1
0
    def dataReceived(self, data):
        global is_authenticated
        if is_authenticated:
            print str(datetime.utcnow()) + " -- Decrypting Message:"
            print data
            mac = data[-64:]
            data = data[:-64]
            data = aes.decrypt(data, str(k_s))
            hmac = aes.hmac(data, str(k_s))

            if mac == hmac:
                self.factory.app.print_message("Other: " + data)
            else:
                self.factory.app.print_message("Integrity Check fails")
        else:
            if mode == "Server":
                global is_client_initializing
                if is_client_initializing == False:
                    connection = self.factory.app.connection
                    rslt = server_reply(conn=connection,recvMsg=data)
                    is_client_initializing = True;
                    self.factory.app.print_message(str(datetime.utcnow()) + " -- Received \"ClientInit\",ClientNounce from client")
                    connection.write(rslt)
                else:
                    self.factory.app.print_message(str(datetime.utcnow()) + " -- Authentication is done")    
                    server_recv(data)
                    is_authenticated = True
                    is_client_initializing = False;
            else:
                connection = self.factory.app.connection
                rslt = client_reply(recvMsg=data)
                is_authenticated = True
                self.factory.app.print_message(str(datetime.utcnow()) + " -- Server Sent Nounce")
                self.factory.app.print_message(str(datetime.utcnow()) + " -- Authentication is done")
                connection.write(rslt)
Exemple #2
0
 def send_message(self):
     msg = self.message.text
     if True:
     #try:
         self.connection
         self.print_message("Me: " + msg)
         if msg and self.connection:
             text = aes.encrypt(msg, str(k_s))
             hmac = aes.hmac(msg, str(k_s))
             print str(datetime.utcnow()) + " -- Encrypthing messsages"
             print msg
             print ""
             self.connection.write(text + hmac)
             self.message.text = ""