[Nym3-commit] r183 - in trunk/nym3: . Client

laurent at conuropsis.org laurent at conuropsis.org
Sun Apr 10 17:55:27 CEST 2005


Author: laurent
Date: 2005-04-10 17:55:13 +0200 (Sun, 10 Apr 2005)
New Revision: 183

Modified:
   trunk/nym3/Client/Account.py
   trunk/nym3/Client/Config.py
   trunk/nym3/Client/Main.py
   trunk/nym3/Message.py
Log:
Forgot to add the keys to the account data.


Modified: trunk/nym3/Client/Account.py
===================================================================
--- trunk/nym3/Client/Account.py	2005-04-10 14:41:20 UTC (rev 182)
+++ trunk/nym3/Client/Account.py	2005-04-10 15:55:13 UTC (rev 183)
@@ -36,8 +36,10 @@
 import pickle
 import tempfile
 import time
+import re
 
 SEQNO_LEN = 20
+SURB_LEN = 2104
 
 class NoSuchAccount(Exception): pass
 """Exception thrown when a user identified by her nym can't be found"""
@@ -127,7 +129,15 @@
 	- synbox is the synopsis box, stored in synboxfile()
 	- mbox is self explanatory, stored in mboxfile()
 	- a journal which is hash of seqno -> (message, time sent) and is
-	  pickled from/to journalfile()"""
+	  pickled from/to journalfile()
+	- the keys used by the account. The actual keys are stored in the
+	  Keyring, we only store the handles in the account. An account can
+	  have at most two identity keys at the same time, one active and one
+	  pending acknowledgment. The active key is named idKey (string), and
+	  the pending one is name pendingKey (string * seqno) and holds the
+	  sequence number of the message whose ack by the server would turn
+	  into the main idKey. The number of encryption keys is not limited,
+	  they are stored in the encKeys list, last generated first."""
 
     def __init__(self, config, nickname, create = False):
 	"""Load from an existing account, or create a new, or fail"""
@@ -139,6 +149,7 @@
 	if create:
 	    tagmap = TagMap(config.path + os.sep + 'tagmap')
 	    self.data = {}
+	    self.succeded = False
 	    self['idTag'] = tagmap.getnewId(nickname)
 	    # If the nick already existed, we're out of this because of
 	    # a thrown AlreadySuchAccount.
@@ -152,6 +163,9 @@
 	    self.mbox_status = 'dirty'
 	    self.synbox = []
 	    self.synbox_status = 'dirty'
+	    self['encKeys'] = []
+	    self.idKey = None
+	    self.pendingKey = None
 	else:
 	    self._load_data()
 	    self.journal = None
@@ -161,6 +175,7 @@
 	    self.synbox = None
 	    self.synbox_status = 'unloaded'
 	    self.base_path = config.path + os.sep + self['idTag']
+	self.succeded = True
 	self._lock()
 
     def generateSurbs(self, n):
@@ -176,8 +191,13 @@
 	f.close()
 	os.unlink(surbspath)
 	os.rmdir(surbdir)
-	# TODO : the size of the generated surbs is wrong in minion-cvs
-	return data
+	surbs = re.split("SURB", data)
+	ret = ""
+	for i in surbs:
+	    if len(i) > SURB_LEN - 4:
+		i = "SURB" + i
+		ret = i[:SURB_LEN] + ret
+	return ret
 
     def __getitem__(self, key):
 	"""Gets user account field as in a hashtable"""
@@ -300,6 +320,7 @@
 
     def __del__(self):
 	"""Flushes the user account to the disk"""
+	if not self.succeded: return
         self._save_synbox()
         self._save_mbox()
 	self._save_journal()
@@ -341,3 +362,6 @@
 	except IOError:
 	    self.journal = {}
 	self.journal_status = 'ok'
+
+    def add_enckey(self, key):
+	self['encKeys'].insert(0, key)

Modified: trunk/nym3/Client/Config.py
===================================================================
--- trunk/nym3/Client/Config.py	2005-04-10 14:41:20 UTC (rev 182)
+++ trunk/nym3/Client/Config.py	2005-04-10 15:55:13 UTC (rev 183)
@@ -39,5 +39,9 @@
 	#address where surbs point to"""
 	self.defaultAddress = "smtp:nobody at nowhere.net"
 
+	# Default key length
+	self.default_idkey_length = 1024
+	self.default_enckey_length = 1024
+
     def load_from_file(self, filename):
 	pass

Modified: trunk/nym3/Client/Main.py
===================================================================
--- trunk/nym3/Client/Main.py	2005-04-10 14:41:20 UTC (rev 182)
+++ trunk/nym3/Client/Main.py	2005-04-10 15:55:13 UTC (rev 183)
@@ -123,8 +123,8 @@
 	emailAddress = ui.prompt("What is the default email address for "
 				 "returning messages")
     account['returnaddress'] = emailAddress
-    idKey = _cr.pk_generate(bits=2048)
-    encKey = _cr.pk_generate(bits=2048)
+    idKey = _cr.pk_generate(bits=config.default_idkey_length)
+    encKey = _cr.pk_generate(bits=config.default_enckey_length)
     # We have gathered the relevant information for this account, except for
     # the policy which we don't let the user change at this point for the sake
     # of simplicity. So, let's store all of that in the account and prepare the
@@ -156,6 +156,8 @@
     
     idtag = secring.store(_cr.pk_encode_private_key(idKey))
     enctag = secring.store(_cr.pk_encode_private_key(encKey))
+    account.add_enckey(enctag)
+    account['idKey'] = idtag
     pubring.update_key(idtag, _cr.pk_encode_public_key(idKey))
     pubring.update_key(enctag, _cr.pk_encode_public_key(encKey))
     secring.save(passphrase1)

Modified: trunk/nym3/Message.py
===================================================================
--- trunk/nym3/Message.py	2005-04-10 14:41:20 UTC (rev 182)
+++ trunk/nym3/Message.py	2005-04-10 15:55:13 UTC (rev 183)
@@ -265,7 +265,7 @@
 			self.sig = chr(0) * sigLength
 		else:
 			if(len(sig) != sigLength):
-				raise BadArgument("Buildheader.__init__ : sig length doesn't match sigLength")	
+				self.sig = chr(0) * (sigLength - len(sig)) + sig
 			else: self.sig = sig
 		self.nl = len(nym)
 		self.nym = nym



More information about the Nym3-commit mailing list