[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] More tests and debugging for consensus directories.



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv7571/lib/mixminion

Modified Files:
	ServerInfo.py test.py 
Log Message:
More tests and debugging for consensus directories.

Index: ServerInfo.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ServerInfo.py,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -d -r1.89 -r1.90
--- ServerInfo.py	13 Dec 2004 06:01:58 -0000	1.89
+++ ServerInfo.py	13 Dec 2004 07:06:10 -0000	1.90
@@ -22,7 +22,7 @@
      formatBase64, formatDate, formatTime, readPossiblyGzippedFile
 from mixminion.Config import ConfigError
 from mixminion.Crypto import CryptoError, DIGEST_LEN, pk_check_signature, \
-     pk_encode_public_key, pk_sign, sha1
+     pk_encode_public_key, pk_fingerprint, pk_sign, sha1
 
 # Longest allowed Contact email
 MAX_CONTACT = 256
@@ -607,8 +607,8 @@
         for idx in range(len(sigs)):
             sig = _DirectorySignature(sigs[idx])
             if sig.getDigest() != digest:
-                LOG.warn("Mismatched digest on signature #%s; skipping",
-                         idx)
+                LOG.warn("Signature #%s does not match directory; skipping",
+                         idx+1)
                 badsigs += 1
             else:
                 self.signatures.append(sig)
@@ -635,18 +635,20 @@
         sigs = {}
         self.signers = []
         for s in self.signatures:
-            sigs[s.getKeyDigest()] = s
+            sigs[s.getKeyFingerprint()] = s
         for digest, url in self.dirInfo.voters:
             try:
                 s = sigs[digest]
             except KeyError:
-                #XXXX008 warn
+                #XXXX008 log something.
                 continue
             if s.checkSignature():
-                # XXXX008 LOG.debug("Valid signature from %s")
+                LOG.trace("Found valid signature from %s at %s",
+                          digest, url)
                 self.signers.append((digest, url))
             else:
-                #LOG.debug("Invalid signature from %s") XXXX008
+                LOG.trace("Signature claiming to be from %s was not valid",
+                          digest)
                 continue
 
         return self.signers
@@ -829,13 +831,13 @@
     def getDigest(self):
         return self['Signed-Directory']['Directory-Digest']
 
-    def getKeyDigest(self):
-        return sha1(pk_encode_public_key(
-              self['Signed-Directory']['Directory-Identity']))
+    def getKeyFingerprint(self):
+        return pk_fingerprint(self['Signed-Directory']['Directory-Identity'])
 
     def checkSignature(self):
         if self.sigStatus is not None:
             return self.sigStatus
+
         sec = self['Signed-Directory']
         try:
             r = mixminion.Crypto.pk_check_signature(sec['Directory-Signature'],

Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.213
retrieving revision 1.214
diff -u -d -r1.213 -r1.214
--- test.py	13 Dec 2004 06:01:58 -0000	1.213
+++ test.py	13 Dec 2004 07:06:10 -0000	1.214
@@ -5232,6 +5232,7 @@
 
     def testNewDirectoryFormats(self):
         DF = mixminion.directory.DirFormats
+        SI = mixminion.ServerInfo
         examples = getExampleServerDescriptors()
         id0 = getRSAKey(1,2048)
         id1 = getRSAKey(3,2048)
@@ -5250,11 +5251,51 @@
                examples['Joe'][0], examples['Alice'][0] ]
         vd1 = {}
         s_vote1 = DF.generateVoteDirectory(
-            id0, s1, [ "Fred", "Lola", "Joe" ],
-            voters, va, ["0.0.8", "0.0.8.1"], ["0.0.8.1"], validatedDigests=vd1)
+            id0, s1, [ "Fred", "Lola", "joe" ],
+            voters, va, ["0.0.8", "0.0.8.1"], ["0.0.8.1"],
+            validatedDigests=vd1)
+        self.assert_(s_vote1.startswith('[Signed-Directory]\n'))
 
         # Test parsing it.
-        vote1 = mixminion.ServerInfo.SignedDirectory(string=s_vote1)
+        vote1 = SI.SignedDirectory(string=s_vote1)
+        DF.checkVoteDirectory(voters, va, vote1)
+        self.assertEquals(vote1['Directory-Info']['Valid-After'],
+                          previousMidnight(va))
+        self.assertEquals(vote1['Directory-Info']['Valid-Until'],
+                          succeedingMidnight(va))
+        self.assertEquals(vote1['Directory-Info']['Status'], "vote")
+        self.assertEquals(vote1.getSigners(), [(keyid0, ub0)])
+        self.assertEquals(vote1['Directory-Info']['Recommended-Servers'],
+                          [ "fred", "joe", "lola" ])
+        self.assertUnorderedEq(vote1['Directory-Info']['Voting-Server'],
+                               [ "%s %s"%(k,u) for k,u in voters ])
+        expected = [ SI.ServerInfo(string=s,assumeValid=1).getDigest()
+                     for s in s1 ]
+        got = [ s.getDigest() for s in vote1.getAllServers() ]
+        self.assertUnorderedEq(got, expected)
+
+        # Now make two more, and have them vote.
+        s1 = [ examples['Fred'][1], examples['Fred'][2], examples['Lola'][1],
+               examples['Joe'][0], examples['Alice'][0] ]
+        s2 = [ examples['Fred'][2], examples['Lola'][1],
+               examples['Alice'][0], examples['Alice'][1],
+               examples['Bob'][1], examples['Bob'][2],
+               examples['Lisa'][1] ]
+        vd2 = {}
+        s_vote2 = DF.generateVoteDirectory(
+            id1, s2, [ "Fred", "Lola", "Alice", "Bob", "Lisa"],
+            voters, va, [ "0.0.8", "0.0.8.1", "0.0.9.1" ],["0.0.8.1", "0.0.8"],
+            validatedDigests=vd2)
+        s3 = [ examples['Alice'][1], examples['Bob'][2], examples['Fred'][2] ]
+        s_vote3 = DF.generateVoteDirectory(
+            id2, s2, [ "Fred", "Lola", "Alice", "Bob", "Lisa"],
+            voters, va, [ "0.0.8", "0.0.8.1", "0.0.9.1" ],["0.0.8.1", "0.0.8"],
+            validatedDigests=vd2)
+
+        s_voted1 = DF.generateConsensusDirectory(
+            id0, voters, va,
+            [ ("voter1",s_vote1), ("voter2",s_vote2), ("voter3",s_vote3) ],
+            vd1)
 
 #----------------------------------------------------------------------
 # EventStats
@@ -7868,7 +7909,7 @@
     loader = unittest.TestLoader()
     tc = loader.loadTestsFromTestCase
 
-    if 1:
+    if 0:
         suite.addTest(tc(ServerInfoTests))
         return suite
     testClasses = [MiscTests,