[Nym3-commit] r187 - trunk/nym3/Server

laurent at conuropsis.org laurent at conuropsis.org
Mon Apr 11 20:54:24 CEST 2005


Author: laurent
Date: 2005-04-11 20:54:20 +0200 (Mon, 11 Apr 2005)
New Revision: 187

Modified:
   trunk/nym3/Server/Main.py
   trunk/nym3/Server/User.py
Log:
Make the key usage in the server consistent with ASN.1 encoding.


Modified: trunk/nym3/Server/Main.py
===================================================================
--- trunk/nym3/Server/Main.py	2005-04-10 16:32:34 UTC (rev 186)
+++ trunk/nym3/Server/Main.py	2005-04-11 18:54:20 UTC (rev 187)
@@ -81,9 +81,9 @@
                 nymUser = None
 	        #phase 1 we look for the command create
                 for idx, com in enumerate(comList):
-                    if(com.ct() == 0):
+                    if(com.ct() == 0): # TODO : evil numeric litteral
 		        #the Create command
-                        for pnym in self.list:
+                        for pnym in com.list:
                             try:
                                 nymUser = User.User(pnym,1)
                             except User.AlreadySuchUser:
@@ -114,10 +114,10 @@
                     raise MyException()
 	        #phase 3 the last command should be a Newpk
                 com = comList[0]
-                if(com.ct() != 3):
+                if(com.ct() != 3): # TODO : evil numeric litteral
                     nymUser.abort()
                     raise MyException()
-                nymUser.setKeys(com.kid,com.kenc)
+                nymUser.setKeys(com.ekid, com.ekenc)
                 if(not nymUser.checkMessageSign(msg[Message.sigLength:],h.sig)):
                    nymUser.abort()
                    raise MyException()

Modified: trunk/nym3/Server/User.py
===================================================================
--- trunk/nym3/Server/User.py	2005-04-10 16:32:34 UTC (rev 186)
+++ trunk/nym3/Server/User.py	2005-04-11 18:54:20 UTC (rev 187)
@@ -1,4 +1,5 @@
 # $Id$
+# -*- coding: utf-8 -*-
 #
 # Copyright (c) 2004,2005 Jean-René Reinhard <jr at komite.net>
 # and Laurent Fousse <laurent at komite.net>.
@@ -112,8 +113,7 @@
 	return self.data[key]
 
     def __setitem__(self, key, value):
-	"""Sets the fields of this Object as if a hashtable
-	"""
+	"""Sets the fields of this Object as if a hashtable"""
 	self.data[key] = value
 
     def _lock(self):
@@ -392,9 +392,9 @@
 	    else: return
 
     def setKeys(self, kid, kenc):
-        """given 2 modulus (int) set the public keys of the user"""
-	self.data['idKey'] = _cr.pk_from_modulus(kid)
-	self.data['encKey'] = _cr.pk_from_modulus(kenc)
+        """Set the identity and encryption key of the user, ASN.1 encoded"""
+	self.data['idKey'] = kid
+	self.data['encKey'] = kenc
 
     def isInitialized(self):
 	"""True if the first 3 commands :
@@ -416,7 +416,12 @@
     def checkMessageSign(self, m, s):
 	"""Checks s is the signature of message m using sha1, RSA-OAEP and
 	the public key of this user"""
-        return (s == _cr.pk_check_signature(_cr.sha1(m), self.idKey()))
+	try:
+	    key = _cr.pk_decode_public_key(self['idKey'])
+	    sig = s[:len(s) - key.get_modulus_bytes()]
+	    print "Sig has length %s" % len(sig)
+	    return (_cr.sha1(m) == _cr.pk_check_signature(sig, key))
+	except _cr.CryptoError: return False
 	    
     def checkChallenge(self, cr):
 	"""Checks the correctness of the challenge"""



More information about the Nym3-commit mailing list