Cédric Bonhomme avatar Cédric Bonhomme committed 1d3e600

Added user login verification, sha1 hash for password, etc.

Comments (0)

Files changed (5)

source/authenticationAgent.py

             if self.msg:
                 command = self.msg.getContent().split(':')
                 if command[0] == "signin":
-                    xml = xmlParser.add_client(command[1], command[2], \
-                                        command[3], command[4])
-                    xmlParser.write(xml)
+                    try:
+                        xml = xmlParser.add_client(command[1], command[2], \
+                                            command[3], command[4])
+                        xmlParser.write(xml)
+                    except Exception, e:
+                        self.myAgent.outgoing_message = e
+
                 elif command[0] == "signout":
                     pass
-                elif command[0] == "login":
-                    if command[2] == xmlParser.get_password(command[1]):
-                        self.myAgent.receiver = self.msg.getSender().getName()
-                        self.myAgent.outgoing_message = "logged"
-
-                        answer = self.myAgent.SendMessage()
-                        self.myAgent.addBehaviour(answer, None)
 
                 elif command[0] == "addinterlocutor":
                     pubkey = xmlParser.get_pub_key(command[1])
 
                     self.myAgent.outgoing_message = "newinterlocutor:" + command[1] + \
                                             ":" + ontology + ":" + pubkey
-                    self.myAgent.receiver = self.msg.getSender().getName().split('@')[0]
 
-                    # send the message with a OneShotBehaviour
-                    self.myAgent.addBehaviour(self.myAgent.SendMessage(), None)
+
+
+                self.myAgent.receiver = self.msg.getSender().getName().split('@')[0]
+
+                # send the message with a OneShotBehaviour
+                self.myAgent.addBehaviour(self.myAgent.SendMessage(), None)
 
 
 

source/clientAgent.py

                 elif command[0] == "newinterlocutor":
                     self.myAgent.gui.add_client(command[1], command[2], command[3])
 
+                elif command[0] == "already_registered":
+                    self.myAgent.gui.show_info("Username already used !")
+
     class SendMessageToAuthenticator(spade.Behaviour.OneShotBehaviour):
         """
         This class is in charge of sending request to the authentication agent.

source/configurations/clients_informations.xml

-<?xml version="1.0" ?><clients><client><name>alice</name><password>test</password><ontology>ontoAlice</ontology><pubkey>4413640456802970359958819867786197408453489371548701665267530055070712297215-8149084184870463884392736659501734367204950963478774650476228472285913318373</pubkey></client><client><name>bob</name><password>ok</password><ontology>ontoBob</ontology><pubkey>336157154364177700567196415836642782812315670057464236539294389658026259649-635512810071753351683978628986879506250752731383408481064361473116599973409</pubkey></client></clients>
+<?xml version="1.0" ?><clients><client><name>bob</name><password>8e59a08ba401da8aedd958b3a65c2d8e70dc8da2</password><ontology>ontoBob</ontology><pubkey>766783389288939640580351230849226379164475686792472868248054665275188439433-787712353635913217583082263020675343302966328442248522285595350929589790883</pubkey></client></clients>

source/simpleGui.py

 
 import time
 import pickle
+import hashlib
 import threading
 import tkMessageBox
 
                 tkMessageBox.showerror('Error', 'Bad entry')
                 return
 
-            if password1 == password2:
+            if password1 == password2 and \
+                                    len(password1) >= 6 and \
+                                    self.my_rsa_keys is not None:
+
                 # set the outgoing message
                 self.load_rsa_keys()
                 pubkey = str(self.my_rsa_keys.b) + "-" + str(self.my_rsa_keys.n)
 
+                sha1_hash = hashlib.sha1()
+                sha1_hash.update(password1)
+                hashed_passwd = sha1_hash.hexdigest()
+
                 self.client_agent.outgoing_message = "signin:" + \
                                             self.name.lower() + \
-                                            ":" + password1 + \
+                                            ":" + hashed_passwd + \
                                             ":" + self.ontology + \
                                             ":" + pubkey
 
         with open("./security/keys" + self.name, "w") as pub_key:
             pickle.dump(rsa_key, pub_key)
 
+    def show_info(self, message):
+        """
+        Display an information message.
+        """
+        tkMessageBox.showinfo('Information', message)
+
     def onClose(self):
         """Close the client.
         """

source/xmlParser.py

         root = xml.createElement("clients")
         xml.appendChild(root)
 
+    # test if username already exists
+    for client in xml.getElementsByTagName("client"):
+        if client_name == client.getElementsByTagName("name")[0].childNodes[0].nodeValue:
+            raise Exception('already_registered')
+
+    # add the client
     client = xml.createElement("client")
     xml.getElementsByTagName("clients").item(0).appendChild(client)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.