mutable: wire in RSA for real, using pycryptopp

This commit is contained in:
Brian Warner 2007-11-07 17:51:35 -07:00
parent 30e7ca06f5
commit c783128012
2 changed files with 19 additions and 14 deletions

View File

@ -11,6 +11,7 @@ from allmydata.uri import WriteableSSKFileURI
from allmydata.Crypto.Cipher import AES from allmydata.Crypto.Cipher import AES
from allmydata import hashtree, codec from allmydata import hashtree, codec
from allmydata.encode import NotEnoughPeersError from allmydata.encode import NotEnoughPeersError
from pycryptopp.publickey import rsa
class NeedMoreDataError(Exception): class NeedMoreDataError(Exception):
@ -313,10 +314,8 @@ class Retrieve:
return d return d
def _deserialize_pubkey(self, pubkey_s): def _deserialize_pubkey(self, pubkey_s):
# TODO verifier = rsa.create_verifying_key_from_string(pubkey_s)
from allmydata.test.test_mutable import FakePubKey return verifier
return FakePubKey(0)
return None
def _got_results(self, datavs, peerid, readsize): def _got_results(self, datavs, peerid, readsize):
self._queries_outstanding.discard(peerid) self._queries_outstanding.discard(peerid)
@ -957,6 +956,7 @@ class MutableFileNode:
implements(IMutableFileNode) implements(IMutableFileNode)
publish_class = Publish publish_class = Publish
retrieve_class = Retrieve retrieve_class = Retrieve
SIGNATURE_KEY_SIZE = 2048
def __init__(self, client): def __init__(self, client):
self._client = client self._client = client
@ -1010,13 +1010,10 @@ class MutableFileNode:
return d return d
def _generate_pubprivkeys(self): def _generate_pubprivkeys(self):
# TODO: wire these up to pycryptopp # RSA key generation for a 2048 bit key takes between 0.8 and 3.2 secs
privkey = "very private" signer = rsa.generate(self.SIGNATURE_KEY_SIZE)
pubkey = "public" verifier = signer.get_verifying_key()
from allmydata.test.test_mutable import FakePrivKey, FakePubKey return verifier, signer
pubkey = FakePubKey(0)
privkey = FakePrivKey(0)
return pubkey, privkey
def _publish(self, initial_contents): def _publish(self, initial_contents):
p = self.publish_class(self) p = self.publish_class(self)

View File

@ -1,6 +1,6 @@
from base64 import b32encode from base64 import b32encode
import os, sys, time import os, sys, time, re
from cStringIO import StringIO from cStringIO import StringIO
from twisted.trial import unittest from twisted.trial import unittest
from twisted.internet import defer, reactor 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) peerid = idlib.nodeid_b2a(self.clients[client_num].nodeid)
self.failUnless(" WE for nodeid: %s\n" % peerid in output) self.failUnless(" WE for nodeid: %s\n" % peerid in output)
self.failUnless(" num_extra_leases: 0\n" in output) self.failUnless(" num_extra_leases: 0\n" in output)
self.failUnless(" container_size: 382\n" in output) # the pubkey size can vary by a byte, so the container might
self.failUnless(" data_length: 382\n" in output) # 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 self.failUnless(" secrets are for nodeid: %s\n" % peerid
in output) in output)
self.failUnless(" SDMF contents:\n" in output) self.failUnless(" SDMF contents:\n" in output)