self._privkey = "very private"
self._pubkey = "public"
self._writekey = hashutil.ssk_writekey_hash(self._privkey)
- self._fingerprint = hashutil.ssk_pubkey_fingerprint_hash(self._pubkey)
+ privkey_s = self._privkey.serialize()
+ self._encprivkey = self._encrypt_privkey(self._writekey, privkey_s)
+ pubkey_s = self._pubkey.serialize()
+ self._fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey_s)
self._uri = WriteableSSKFileURI(self._writekey, self._fingerprint)
- d = defer.succeed(None)
+ self._current_seqnum = 0
+ self._current_roothash = "\x00"*32
+ return self._publish(initial_contents)
+
+ def _publish(self, initial_contents):
+ # TODO: actually do all that stuff
+ p = Publish(self)
+ d = p.publish(initial_contents)
+ d.addCallback(lambda res: self)
return d
+ def _encrypt_privkey(self, writekey, privkey):
+ enc = AES.new(key=writekey, mode=AES.MODE_CTR, counterstart="\x00"*16)
+ crypttext = enc.encrypt(privkey)
+ return crypttext
def get_write_enabler(self, nodeid):
return hashutil.ssk_write_enabler_hash(self._writekey, nodeid)
ccs = self._client.get_cancel_secret()
fcs = hashutil.file_cancel_secret_hash(ccs, self._storage_index)
return hashutil.bucket_cancel_secret_hash(fcs, nodeid)
+
def get_writekey(self):
return self._writekey
+ def get_readkey(self):
+ return self._readkey
+ def get_privkey(self):
+ return self._privkey
+ def get_encprivkey(self):
+ return self._encprivkey
+ def get_pubkey(self):
+ return self._pubkey
+
+ def get_required_shares(self):
+ return 3 # TODO: where should this come from?
+ def get_total_shares(self):
+ return 10 # TODO: same
+
def get_uri(self):
return self._uri.to_string()
old_roothash = self._node._current_roothash
old_seqnum = self._node._current_seqnum
- readkey = self._node.readkey
- required_shares = self._node.required_shares
- total_shares = self._node.total_shares
- privkey = self._node.privkey
- pubkey = self._node.pubkey
+ readkey = self._node.get_readkey()
+ required_shares = self._node.get_required_shares()
+ total_shares = self._node.get_total_shares()
+ privkey = self._node.get_privkey()
+ encprivkey = self._node.get_encprivkey()
+ pubkey = self._node.get_pubkey()
d = defer.succeed(newdata)
d.addCallback(self._encrypt_and_encode, readkey,
required_shares, total_shares)
d.addCallback(self._generate_shares, old_seqnum+1,
- privkey, self._encprivkey, pubkey)
+ privkey, encprivkey, pubkey)
d.addCallback(self._query_peers, total_shares)
d.addCallback(self._send_shares)
from twisted.python import failure
from allmydata import mutable, uri, dirnode2
from allmydata.dirnode2 import split_netstring
+from allmydata.util import hashutil
from allmydata.util.hashutil import netstring, tagged_hash
from allmydata.encode import NotEnoughPeersError
self.init_from_uri(uri.WriteableSSKFileURI("key%d" % count,
"fingerprint%d" % count))
self.all_contents[self._uri] = initial_contents
- return defer.succeed(None)
+ self._privkey = FakePrivKey()
+ self._pubkey = FakePubKey()
+ self._encprivkey = "encrypted private key"
+ privkey_s = self._privkey.serialize()
+ #self._encprivkey = self._encrypt_privkey(self._writekey, privkey_s)
+ pubkey_s = self._pubkey.serialize()
+ self._fingerprint = hashutil.ssk_pubkey_fingerprint_hash(pubkey_s)
+ self._current_seqnum = 0
+ self._current_roothash = "\x00"*32
+ return defer.succeed(self)
def download_to_data(self):
return defer.succeed(self.all_contents[self._uri])
def replace(self, newdata):
d.addCallback(_done)
return d
+ def setup_for_publish(self, num_peers):
+ c = MyClient(num_peers)
+ fn = FakeFilenode(c)
+ # .create usually returns a Deferred, but we happen to know it's
+ # synchronous
+ fn.create("")
+ p = FakePublish(fn)
+ p._peers = {}
+ for peerid in c._peerids:
+ p._peers[peerid] = {}
+ return c, fn, p
+
+ def test_publish(self):
+ c, fn, p = self.setup_for_publish(20)
+ d = p.publish("new contents of the mutable filenode")
+ def _done(res):
+ # TODO: examine peers and check on their shares
+ pass
+ d.addCallback(_done)
+ return d
class FakePubKey:
def serialize(self):
return "PUBKEY"
class FakePrivKey:
+ def serialize(self):
+ return "PRIVKEY"
def sign(self, data):
return "SIGN(%s)" % data