]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
mutable: wire in RSA for real, using pycryptopp
authorBrian Warner <warner@allmydata.com>
Thu, 8 Nov 2007 00:51:35 +0000 (17:51 -0700)
committerBrian Warner <warner@allmydata.com>
Thu, 8 Nov 2007 00:51:35 +0000 (17:51 -0700)
src/allmydata/mutable.py
src/allmydata/test/test_system.py

index 909049bb8cf618f98bfa03e50550014ac9925771..aa44dcc6fef952a109f4b29f595f0380a11fa1ac 100644 (file)
@@ -11,6 +11,7 @@ from allmydata.uri import WriteableSSKFileURI
 from allmydata.Crypto.Cipher import AES
 from allmydata import hashtree, codec
 from allmydata.encode import NotEnoughPeersError
+from pycryptopp.publickey import rsa
 
 
 class NeedMoreDataError(Exception):
@@ -313,10 +314,8 @@ class Retrieve:
         return d
 
     def _deserialize_pubkey(self, pubkey_s):
-        # TODO
-        from allmydata.test.test_mutable import FakePubKey
-        return FakePubKey(0)
-        return None
+        verifier = rsa.create_verifying_key_from_string(pubkey_s)
+        return verifier
 
     def _got_results(self, datavs, peerid, readsize):
         self._queries_outstanding.discard(peerid)
@@ -957,6 +956,7 @@ class MutableFileNode:
     implements(IMutableFileNode)
     publish_class = Publish
     retrieve_class = Retrieve
+    SIGNATURE_KEY_SIZE = 2048
 
     def __init__(self, client):
         self._client = client
@@ -1010,13 +1010,10 @@ class MutableFileNode:
         return d
 
     def _generate_pubprivkeys(self):
-        # TODO: wire these up to pycryptopp
-        privkey = "very private"
-        pubkey = "public"
-        from allmydata.test.test_mutable import FakePrivKey, FakePubKey
-        pubkey = FakePubKey(0)
-        privkey = FakePrivKey(0)
-        return pubkey, privkey
+        # RSA key generation for a 2048 bit key takes between 0.8 and 3.2 secs
+        signer = rsa.generate(self.SIGNATURE_KEY_SIZE)
+        verifier = signer.get_verifying_key()
+        return verifier, signer
 
     def _publish(self, initial_contents):
         p = self.publish_class(self)
index 6cf99eaf5fabcfe947b6fb978ceb780ce506ef36..07ac4ee2f10a48e6e511d93bb914faae8f4dcbf5 100644 (file)
@@ -1,6 +1,6 @@
 
 from base64 import b32encode
-import os, sys, time
+import os, sys, time, re
 from cStringIO import StringIO
 from twisted.trial import unittest
 from twisted.internet import defer, reactor
@@ -294,8 +294,16 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase):
                 peerid = idlib.nodeid_b2a(self.clients[client_num].nodeid)
                 self.failUnless(" WE for nodeid: %s\n" % peerid in output)
                 self.failUnless(" num_extra_leases: 0\n" in output)
-                self.failUnless(" container_size: 382\n" in output)
-                self.failUnless(" data_length: 382\n" in output)
+                # the pubkey size can vary by a byte, so the container might
+                # be a bit larger on some runs.
+                m = re.search(r'^ container_size: (\d+)$', output, re.M)
+                self.failUnless(m)
+                container_size = int(m.group(1))
+                self.failUnless(2046 <= container_size <= 2049)
+                m = re.search(r'^ data_length: (\d+)$', output, re.M)
+                self.failUnless(m)
+                data_length = int(m.group(1))
+                self.failUnless(2046 <= data_length <= 2049)
                 self.failUnless("  secrets are for nodeid: %s\n" % peerid
                                 in output)
                 self.failUnless(" SDMF contents:\n" in output)