75bc079445c5 — cedricbonhomme 11 years ago
The client can generate RSA key from 128 bits to 3072 bits.
1 files changed, 26 insertions(+), 13 deletions(-)

M source/simpleGui.py
M source/simpleGui.py +26 -13
@@ 88,6 88,7 @@ class SimpleGui(object):
         self.agent_host = agent_host
         self.ontology = agent_ontology
         self.pubkey = agent_pubkey
+        self.rsa_nb_bits = 256
         self.my_rsa_keys = None
         self.client_agent = None
 

          
@@ 366,11 367,17 @@ class SimpleGui(object):
         ontology_entry.grid(row = 3, column = 1, pady = 2, sticky = W)
         ontology_entry.insert(0, self.ontology)
 
+        Scale(msg, length=400, orient = HORIZONTAL, \
+            sliderlength = 25, label = 'RSA key length :', \
+            from_=128, to=3072, tickinterval = 256, \
+            resolution = 128, showvalue = self.rsa_nb_bits, \
+            command = self.rsa_key_length).grid(row = 4, columnspan = 2, pady = 2)
+
         Button(msg, text="Generate RSA key", \
-            command = self.generate_rsa_keys).grid(row = 4, columnspan = 2, pady = 2)
+            command = self.generate_rsa_keys).grid(row = 5, columnspan = 2, pady = 2)
 
         Button(msg, text="OK", \
-            command = execute).grid(row = 5, columnspan = 2, pady = 2)
+            command = execute).grid(row = 6, columnspan = 2, pady = 2)
 
         self.set_top_level_window(msg)
 

          
@@ 478,7 485,7 @@ class SimpleGui(object):
     def block_sender(self, event = None):
         """
         Block the selected client.
-        Message from this client will be
+        Messages from this client will be ignored.
         """
         client = None
         try:

          
@@ 534,7 541,7 @@ class SimpleGui(object):
             return
 
         # Construct the RSA key of the new interlocutor
-        rsa_interlocutor = rsa.RSA(nb_bits = 128)
+        rsa_interlocutor = rsa.RSA()
         rsa_interlocutor.b = int(pubkey.split('-')[0])
         rsa_interlocutor.n = int(pubkey.split('-')[1])
 

          
@@ 632,6 639,21 @@ class SimpleGui(object):
         self.conversation_zone.insert(END, msg)
         self.conversation_zone.config(state=DISABLED)
 
+    def rsa_key_length(self, nb):
+        """
+        Change the length of the RSA key.
+        """
+        self.rsa_nb_bits = int(nb)
+
+    def generate_rsa_keys(self):
+        """
+        Generate new pairs of RSA keys.
+        """
+        rsa_key = rsa.RSA(nb_bits = self.rsa_nb_bits)
+
+        with open("./security/keys" + self.user_name, "w") as pub_key:
+            pickle.dump(rsa_key, pub_key)
+
     def load_rsa_keys(self):
         """
         Load the RSA keys of the local client.

          
@@ 643,15 665,6 @@ class SimpleGui(object):
         except Exception , e:
             self.my_rsa_keys = None
 
-    def generate_rsa_keys(self):
-        """
-        Generate new pairs of RSA keys.
-        """
-        rsa_key = rsa.RSA(nb_bits = 128)
-
-        with open("./security/keys" + self.user_name, "w") as pub_key:
-            pickle.dump(rsa_key, pub_key)
-
     def clear_window(self):
         """
         Clear the conversation zone.