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

[minion-cvs] Misc bugfixes pending since defcon



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

Modified Files:
	BuildMessage.py ClientDirectory.py benchmark.py test.py 
Log Message:
Misc bugfixes pending since defcon

Index: BuildMessage.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/BuildMessage.py,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- BuildMessage.py	27 Jul 2004 03:00:14 -0000	1.75
+++ BuildMessage.py	7 Aug 2004 14:08:23 -0000	1.76
@@ -255,6 +255,8 @@
         LOG.warn("Inferring expiry time for reply block")
         expiryTime = min([s.getValidUntil() for s in path])
 
+    checkPathLength(None, path, exitType, exitInfo, explicitSwap=0)
+
     LOG.debug("Building reply block for path %s",
                    [s.getNickname() for s in path])
     LOG.debug("  Delivering to %04x:%r", exitType, exitInfo)
@@ -274,12 +276,9 @@
     header = _buildHeader(path, headerSecrets, exitType, tag+exitInfo,
                           paddingPRNG=Crypto.getCommonPRNG())
 
-    # XXXX007 switch to Host info.  We need to use IPV4 for reply blocks
-    # XXXX007 for now, since we don't know which servers will support HOST.
-    # XXXX007    (Do this after all hosts have upgraded to 0.0.6 or later.)
     return ReplyBlock(header, expiryTime,
-                      SWAP_FWD_IPV4_TYPE,
-                      path[0].getIPV4Info().pack(), sharedKey), secrets, tag
+                     SWAP_FWD_HOST_TYPE,
+                     path[0].getMMTPHostInfo().pack(), sharedKey), secrets, tag
 
 # Maybe we shouldn't even allow this to be called with userKey==None.
 def buildReplyBlock(path, exitType, exitInfo, userKey,
@@ -297,7 +296,7 @@
 
        NOTE: We used to allow another kind of 'non-state-carrying' reply
        block that stored its secrets on disk, and used an arbitrary tag to
-       determine
+       determine which set of secrets to use.
        """
     if secretRNG is None:
         secretRNG = Crypto.getCommonPRNG()
@@ -322,14 +321,15 @@
 
 def checkPathLength(path1, path2, exitType, exitInfo, explicitSwap=0,
                     suppressTag=0):
-    """Given two path legs, an exit type and an exitInfo, raise an error
-       if we can't build a hop with the provided legs.  If suppressTag is
-       true, no decoding handle will be included.
+    """Given two path legs (lists of servers), an exit type and an
+       exitInfo, raise an error if we can't build a header with the
+       provided legs.  If suppressTag is true, no decoding handle will
+       be included.
 
        The leg "path1" may be null.
     """
     err = 0 # 0: no error. 1: 1st leg too big. 2: 1st leg okay, 2nd too big.
-    if path1 is not None:
+    if path1 is not None and path2 is not None:
         try:
             rt,ri = path1[-1].getRoutingFor(path2[0],swap=1)
             _getRouting(path1, rt, ri)
@@ -343,7 +343,12 @@
         exitInfo = ""
     if err == 0:
         try:
-            _getRouting(path2, exitType, exitInfo)
+            if path2 and not isinstance(path2, ReplyBlock):
+                try:
+                    _getRouting(path2, exitType, exitInfo)
+                except:
+                    print ">>>>>",path2
+                    raise
         except MixError:
             err = 2
     if err and not explicitSwap:
@@ -526,6 +531,10 @@
         if exitType < MIN_EXIT_TYPE and exitType != DROP_TYPE:
             raise MixError("Invalid exit type: %4x"%exitType)
 
+    checkPathLength(path1, path2, exitType, exitInfo,
+                    explicitSwap=(reply is None),
+                    suppressTag=suppressTag)
+
     ### SETUP CODE: let's handle all the variant cases.
 
     # Set up the random number generators.

Index: ClientDirectory.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ClientDirectory.py,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- ClientDirectory.py	27 Jul 2004 21:51:46 -0000	1.43
+++ ClientDirectory.py	7 Aug 2004 14:08:23 -0000	1.44
@@ -1202,10 +1202,18 @@
         if prng is None:
             prng = mixminion.Crypto.getCommonPRNG()
 
+        path1, path2 = pathSpec.path1[:], pathSpec.path2[:]
+
         paths = []
         lastHop = exitAddress.getLastHop()
         if lastHop:
             plausibleExits = []
+            if path2 and path2[-1]:
+                fixed = path2[-1].getFixedServer(self, startAt,endAt)
+                if fixed and fixed.getNickname().lower() == lastHop.lower():
+                    lastHop = None
+            if lastHop:
+                path2.append(ServerPathElement(lastHop))
         else:
             plausibleExits = exitAddress.getExitServers(self,startAt,endAt)
             if exitAddress.isSSFragmented:
@@ -1215,18 +1223,16 @@
         for _ in xrange(nPaths):
             p1 = []
             p2 = []
-            for p in pathSpec.path1:
+            for p in path1:
                 p1.extend(p.getServerNames())
-            for p in pathSpec.path2:
+            for p in path2:
                 p2.extend(p.getServerNames())
 
             p = p1+p2
             # Make the exit hop _not_ be None; deal with getPath brokenness.
             #XXXX refactor this.
-            if lastHop:
-                if not p or not p[-1] or p[-1].lower()!=lastHop.lower():
-                    p.append(lastHop)
-            elif p[-1] == None and not exitAddress.isReply:
+            if p[-1] == None and not exitAddress.isReply:
+                assert not lastHop
                 p[-1] = prng.pick(plausibleExits)
 
             if pathSpec.lateSplit:
@@ -1234,16 +1240,16 @@
             else:
                 n1 = len(p1)
 
-            path = self._getPath(p, startAt=startAt, endAt=endAt)
-            path1,path2 = path[:n1], path[n1:]
-            paths.append( (path1,path2) )
+            result = self._getPath(p, startAt=startAt, endAt=endAt)
+            r1,r2 = result[:n1], result[n1:]
+            paths.append( (r1,r2) )
             if pathSpec.isReply or pathSpec.isSURB:
                 LOG.info("Selected path is %s",
-                         ",".join([s.getNickname() for s in path]))
+                         ",".join([s.getNickname() for s in result]))
             else:
                 LOG.info("Selected path is %s:%s",
-                         ",".join([s.getNickname() for s in path1]),
-                         ",".join([s.getNickname() for s in path2]))
+                         ",".join([s.getNickname() for s in r1]),
+                         ",".join([s.getNickname() for s in r2]))
 
         return paths
 

Index: benchmark.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/benchmark.py,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- benchmark.py	3 Jan 2004 07:35:23 -0000	1.51
+++ benchmark.py	7 Aug 2004 14:08:23 -0000	1.52
@@ -800,6 +800,10 @@
     p = pk_generate(512)
     n,e = p.get_public_key()
 
+    if not os.path.exists("/dev/null"):
+        print "No /dev/null found; dying"
+        return
+
     f = open("/dev/null", 'w')
     while 1:
         if 0:

Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.201
retrieving revision 1.202
diff -u -d -r1.201 -r1.202
--- test.py	27 Jul 2004 04:34:36 -0000	1.201
+++ test.py	7 Aug 2004 14:08:23 -0000	1.202
@@ -1817,12 +1817,13 @@
 class FakeServerInfo:
     """Represents a Mixminion server, and the information needed to send
        messages to it."""
-    def __init__(self, addr, port, key, keyid):
+    def __init__(self, addr, port, key, keyid, ip4=0):
         assert key.get_modulus_bytes() == 256
         self.addr = addr
         self.port = port
         self.key = key
         self.keyid = keyid
+        self.ip4 = ip4
 
     def getNickname(self): return "N(%s:%s)"%(self.addr,self.port)
     def getIP(self): return self.addr
@@ -1832,11 +1833,19 @@
     def supportsPacketVersion(self): return 1
 
     def getRoutingInfo(self):
-        return IPV4Info(self.addr, self.port, self.keyid)
+        if self.ip4:
+            return self.getIPV4Info()
+        else:
+            return self.getMMTPHostInfo()
     def getIPV4Info(self):
-        return self.getRoutingInfo()
+        return IPV4Info(self.addr, self.port, self.keyid)
+    def getMMTPHostInfo(self):
+        return MMTPHostInfo(self.addr, self.port, self.keyid)
     def getRoutingFor(self,other,swap):
-        tp = [FWD_IPV4_TYPE,SWAP_FWD_IPV4_TYPE][swap]
+        if other.ip4:
+            tp = [FWD_IPV4_TYPE,SWAP_FWD_IPV4_TYPE][swap]
+        else:
+            tp = [FWD_HOST_TYPE,SWAP_FWD_HOST_TYPE][swap]
         return (tp, other.getRoutingInfo().pack())
 
 
@@ -1924,12 +1933,12 @@
         head = bhead([self.server1, self.server2],
                      ["9"*16, "1"*16], 99, "Hi mom", AESCounterPRNG())
 
-        ipv4 = mixminion.Packet.IPV4Info
+        host = mixminion.Packet.MMTPHostInfo
         self.do_header_test(head,
                             (self.pk1, self.pk2),
                             ["9"*16, "1"*16],
-                            (FWD_IPV4_TYPE, 99),
-                            (ipv4("127.0.0.2",3,"Z"*20).pack(),
+                            (FWD_HOST_TYPE, 99),
+                            (host("127.0.0.2",3,"Z"*20).pack(),
                              "Hi mom"))
 
     def test_buildheader_3hops(self):
@@ -1939,9 +1948,9 @@
         head = bhead([self.server1, self.server2, self.server3], secrets,
                       99, "Hi mom", AESCounterPRNG())
         pks = (self.pk1,self.pk2,self.pk3)
-        rtypes = (FWD_IPV4_TYPE, FWD_IPV4_TYPE, 99)
-        rinfo = (mixminion.Packet.IPV4Info("127.0.0.2", 3, "Z"*20).pack(),
-                 mixminion.Packet.IPV4Info("127.0.0.3", 5, "Q"*20).pack(),
+        rtypes = (FWD_HOST_TYPE, FWD_HOST_TYPE, 99)
+        rinfo = (mixminion.Packet.MMTPHostInfo("127.0.0.2", 3, "Z"*20).pack(),
+                 mixminion.Packet.MMTPHostInfo("127.0.0.3", 5, "Q"*20).pack(),
                  "Hi mom")
         self.do_header_test(head, pks, secrets, rtypes, rinfo)
 
@@ -2054,7 +2063,7 @@
                      longStr,
                      AESCounterPRNG())
         pks = (self.pk2,self.pk1)
-        rtypes = (FWD_IPV4_TYPE,99)
+        rtypes = (FWD_HOST_TYPE,99)
         rinfo = (tag+longStr2,longStr)
         self.do_header_test(head, pks, secrets, rtypes, rinfo)
 
@@ -2183,11 +2192,11 @@
 
         self.do_message_test(m,
                              ( (self.pk1, self.pk2), None,
-                               (FWD_IPV4_TYPE, SWAP_FWD_IPV4_TYPE),
+                               (FWD_HOST_TYPE, SWAP_FWD_HOST_TYPE),
                                (self.server2.getRoutingInfo().pack(),
                                 self.server3.getRoutingInfo().pack()) ),
                              ( (self.pk3, self.pk2), None,
-                               (FWD_IPV4_TYPE, 500),
+                               (FWD_HOST_TYPE, 500),
                                (self.server2.getRoutingInfo().pack(),
                                 "Goodbye") ),
                              "Hello!!!!")
@@ -2201,7 +2210,7 @@
 
         self.do_message_test(m,
                              ( (self.pk1,), None,
-                               (SWAP_FWD_IPV4_TYPE,),
+                               (SWAP_FWD_HOST_TYPE,),
                                (self.server3.getRoutingInfo().pack(),) ),
                              ( (self.pk3,), None,
                                (500,),
@@ -2220,7 +2229,7 @@
 
         self.do_message_test(m,
                              ( (self.pk1,), None,
-                               (SWAP_FWD_IPV4_TYPE,),
+                               (SWAP_FWD_HOST_TYPE,),
                                (self.server3.getRoutingInfo().pack(),) ),
                              ( (self.pk3,), None,
                                (DROP_TYPE,),
@@ -2245,11 +2254,11 @@
                 return payload.getUncompressedContents()
             self.do_message_test(m,
                                  ( (self.pk1, self.pk2), None,
-                                   (FWD_IPV4_TYPE, SWAP_FWD_IPV4_TYPE),
+                                   (FWD_HOST_TYPE, SWAP_FWD_HOST_TYPE),
                                    (self.server2.getRoutingInfo().pack(),
                                     self.server3.getRoutingInfo().pack()) ),
                                  ( (self.pk3, self.pk2), None,
-                                   (FWD_IPV4_TYPE, 500),
+                                   (FWD_HOST_TYPE, 500),
                                    (self.server2.getRoutingInfo().pack(),
                                     "Phello") ),
                                  "<<<<Hello>>>>"*100,
@@ -2313,11 +2322,11 @@
 
         self.do_message_test(m,
                              ((self.pk3, self.pk1), None,
-                              (FWD_IPV4_TYPE,SWAP_FWD_IPV4_TYPE),
+                              (FWD_HOST_TYPE,SWAP_FWD_HOST_TYPE),
                               (self.server1.getRoutingInfo().pack(),
                                self.server3.getRoutingInfo().pack())),
                              (pks_1, hsecrets,
-                              (FWD_IPV4_TYPE,FWD_IPV4_TYPE,FWD_IPV4_TYPE,FWD_IPV4_TYPE,SMTP_TYPE),
+                              (FWD_HOST_TYPE,FWD_HOST_TYPE,FWD_HOST_TYPE,FWD_HOST_TYPE,SMTP_TYPE),
                               infos+("no-such-user@invalid",)),
                              "Information???",
                              decoder=decoder)
@@ -2327,20 +2336,20 @@
                      "fred", "Tyrone Slothrop", 3)
 
         sec,(loc,), _ = self.do_header_test(reply.header, pks_1, None,
-                            (FWD_IPV4_TYPE,FWD_IPV4_TYPE,FWD_IPV4_TYPE,FWD_IPV4_TYPE,MBOX_TYPE),
+                            (FWD_HOST_TYPE,FWD_HOST_TYPE,FWD_HOST_TYPE,FWD_HOST_TYPE,MBOX_TYPE),
                             infos+(None,))
 
         self.assertEquals(loc[20:], "fred")
 
         # (Test reply block formats)
         self.assertEquals(reply.timestamp, 3)
-        self.assertEquals(reply.routingType, SWAP_FWD_IPV4_TYPE)
+        self.assertEquals(reply.routingType, SWAP_FWD_HOST_TYPE)
         self.assertEquals(reply.routingInfo,
                           self.server3.getRoutingInfo().pack())
         self.assertEquals(reply.pack(),
                           "SURB\x00\x01\x00\x00\x00\x03"+reply.header+
                          "\x00"+chr(len(self.server3.getRoutingInfo().pack()))+
-                          "\x00\x02"+reply.encryptionKey+
+                          "\x00\x04"+reply.encryptionKey+
                           self.server3.getRoutingInfo().pack())
         self.assertEquals(reply.pack(), parseReplyBlock(reply.pack()).pack())
         txt = reply.packAsText()
@@ -2392,11 +2401,11 @@
 
         self.do_message_test(m,
                              ((self.pk3, self.pk1), None,
-                              (FWD_IPV4_TYPE,SWAP_FWD_IPV4_TYPE),
+                              (FWD_HOST_TYPE,SWAP_FWD_HOST_TYPE),
                               (self.server1.getRoutingInfo().pack(),
                                self.server3.getRoutingInfo().pack())),
                              (pks_1, None,
-                              (FWD_IPV4_TYPE,FWD_IPV4_TYPE,FWD_IPV4_TYPE,FWD_IPV4_TYPE,MBOX_TYPE),
+                              (FWD_HOST_TYPE,FWD_HOST_TYPE,FWD_HOST_TYPE,FWD_HOST_TYPE,MBOX_TYPE),
                               infos+("fred",)),
                              message,
                              decoder=decoder2)
@@ -2596,7 +2605,7 @@
             res = sp.processPacket(m)
             self.assert_(isinstance(res, DeliveryPacket) or
                          isinstance(res, RelayedPacket))
-            if rt in (FWD_IPV4_TYPE, SWAP_FWD_IPV4_TYPE):
+            if rt in (FWD_HOST_TYPE, SWAP_FWD_HOST_TYPE):
                 self.assert_(not res.isDelivery())
                 self.assertEquals(res.getAddress().pack(), ri)
                 m = res.getPacket()
@@ -2622,7 +2631,7 @@
 
         self.do_test_chain(m,
                            [self.sp1,self.sp2,self.sp3],
-                           [FWD_IPV4_TYPE, FWD_IPV4_TYPE, SMTP_TYPE],
+                           [FWD_HOST_TYPE, FWD_HOST_TYPE, SMTP_TYPE],
                            [self.server2.getRoutingInfo().pack(),
                             self.server3.getRoutingInfo().pack(),
                             "nobody@invalid"],
@@ -2634,7 +2643,7 @@
 
         self.do_test_chain(m,
                            [self.sp1,self.sp3],
-                           [FWD_IPV4_TYPE, SMTP_TYPE],
+                           [FWD_HOST_TYPE, SMTP_TYPE],
                            [self.server3.getRoutingInfo().pack(),
                             "nobody@invalid"],
                            p)
@@ -2642,7 +2651,7 @@
         # Try servers with multiple keys
         m = bfm(BuildMessage.encodeMessage("\n"+p,0)[0],
                 SMTP_TYPE, "nobody@invalid", [self.server2], [self.server3])
-        self.do_test_chain(m, [self.sp2_3, self.sp2_3], [FWD_IPV4_TYPE, SMTP_TYPE],
+        self.do_test_chain(m, [self.sp2_3, self.sp2_3], [FWD_HOST_TYPE, SMTP_TYPE],
                            [self.server3.getRoutingInfo().pack(),
                             "nobody@invalid"], p)
 
@@ -2657,8 +2666,8 @@
             self.do_test_chain(m,
                                [self.sp1,self.sp2,self.sp1,
                                 self.sp3,self.sp1,self.sp2],
-                               [FWD_IPV4_TYPE,FWD_IPV4_TYPE,FWD_IPV4_TYPE,
-                                FWD_IPV4_TYPE,FWD_IPV4_TYPE,SMTP_TYPE],
+                               [FWD_HOST_TYPE,FWD_HOST_TYPE,FWD_HOST_TYPE,
+                                FWD_HOST_TYPE,FWD_HOST_TYPE,SMTP_TYPE],
                                [self.server2.getRoutingInfo().pack(),
                                 self.server1.getRoutingInfo().pack(),
                                 self.server3.getRoutingInfo().pack(),
@@ -2680,7 +2689,7 @@
 
         pkt = self.do_test_chain(m,
                                  [self.sp1,self.sp3],
-                                 [FWD_IPV4_TYPE, SMTP_TYPE],
+                                 [FWD_HOST_TYPE, SMTP_TYPE],
                                  [self.server3.getRoutingInfo().pack(),
                                   "nobody@invalid"],
                                  p)
@@ -2705,7 +2714,7 @@
                 [self.server1], [self.server3])
         pkt = self.do_test_chain(m,
                                  [self.sp1,self.sp3],
-                                 [FWD_IPV4_TYPE, SMTP_TYPE],
+                                 [FWD_HOST_TYPE, SMTP_TYPE],
                                  [self.server3.getRoutingInfo().pack(),
                                   "nobody@invalid"],
                                  pbin)
@@ -2722,7 +2731,7 @@
                 [self.server1], [self.server3])
         pkt = self.do_test_chain(m,
                                  [self.sp1,self.sp3],
-                                 [FWD_IPV4_TYPE, SMTP_TYPE],
+                                 [FWD_HOST_TYPE, SMTP_TYPE],
                                  [self.server3.getRoutingInfo().pack(),
                                   "nobody@invalid"],
                                  "")
@@ -2737,7 +2746,7 @@
                  [self.server3], getRSAKey(0,1024))
         pkt = self.do_test_chain(m,
                                  [self.sp1,self.sp3],
-                                 [FWD_IPV4_TYPE, SMTP_TYPE],
+                                 [FWD_HOST_TYPE, SMTP_TYPE],
                                  [self.server3.getRoutingInfo().pack(),
                                   "nobody@invalid"],
                                  "")
@@ -2756,7 +2765,7 @@
                 SMTP_TYPE, "nobody@invalid",[self.server1], [self.server3])
         pkt = self.do_test_chain(m,
                                  [self.sp1, self.sp3],
-                                 [FWD_IPV4_TYPE, SMTP_TYPE],
+                                 [FWD_HOST_TYPE, SMTP_TYPE],
                                  [self.server3.getRoutingInfo().pack(),
                                   "nobody@invalid"],
                                  "")
@@ -2772,7 +2781,7 @@
                 SMTP_TYPE, "nobody@invalid",[self.server1], [self.server3])
         pkt = self.do_test_chain(m,
                                  [self.sp1, self.sp3],
-                                 [FWD_IPV4_TYPE, SMTP_TYPE],
+                                 [FWD_HOST_TYPE, SMTP_TYPE],
                                  [self.server3.getRoutingInfo().pack(),
                                   "nobody@invalid"],
                                  "")
@@ -2788,7 +2797,7 @@
         brbi = BuildMessage._buildReplyBlockImpl
 
         # A long intermediate header needs to fail.
-        server1X = FakeServerInfo("127.0.0.1", 1, self.pk1, "X"*20)
+        server1X = FakeServerInfo("127.0.0.1", 1, self.pk1, "X"*20, 1)
         class _packable:
             def pack(self): return "x"*200
         server1X.getRoutingInfo = lambda _packable=_packable: _packable()
@@ -2851,12 +2860,12 @@
             # (We temporarily override the setting from 'BuildMessage',
             #  not Packet; BuildMessage has already imported a copy of this
             #  constant.)
-            global SWAP_FWD_IPV4_TYPE# override the copy used by FakeServerInfo
-            save = SWAP_FWD_IPV4_TYPE
-            SWAP_FWD_IPV4_TYPE = 50
+            global SWAP_FWD_HOST_TYPE# override the copy used by FakeServerInfo
+            save = SWAP_FWD_HOST_TYPE
+            SWAP_FWD_HOST_TYPE = 50
             m_x = bfm(zPayload, 500, "", [self.server1], [self.server2])
         finally:
-            SWAP_FWD_IPV4_TYPE = save
+            SWAP_FWD_HOST_TYPE = save
         self.failUnlessRaises(ContentError, self.sp1.processPacket, m_x)
 
         # Subhead with bad length
@@ -2870,8 +2879,8 @@
         # Bad IPV4 info
         subh_real = pk_decrypt(m[:256], self.pk1)
         subh = parseSubheader(subh_real)
-        subh.setRoutingInfo(subh.routinginfo + "X")
-        m_x = pk_encrypt(subh.pack()+subh.underflow[:-1], self.pk1)+m[256:]
+        subh.routingtype = FWD_IPV4_TYPE
+        m_x = pk_encrypt(subh.pack()+subh.underflow, self.pk1)+m[256:]
         self.failUnlessRaises(ParseError, self.sp1.processPacket, m_x)
 
         # Bad Major or Minor
@@ -7748,7 +7757,7 @@
     tc = loader.loadTestsFromTestCase
 
     if 0:
-        suite.addTest(tc(ServerMainTests))
+        suite.addTest(tc(ClientDirectoryTests))
         return suite
     testClasses = [MiscTests,
                    MinionlibCryptoTests,