from allmydata.control import ControlServer
from allmydata.introducer import IntroducerClient
from allmydata.vdrive import VirtualDrive
+from allmydata.util import hashutil, idlib
class Client(node.Node, Referenceable):
implements(RIClient)
self.logSource="Client"
self.my_furl = None
self.introducer_client = None
+ self.init_secret()
self.init_storage()
self.init_options()
self.add_service(Uploader())
hotline = TimerService(1.0, self._check_hotline, hotline_file)
hotline.setServiceParent(self)
+ def init_secret(self):
+ def make_secret():
+ return idlib.b2a(os.urandom(16)) + "\n"
+ secret_s = self.get_or_create_config("secret", make_secret,
+ filemode=0600)
+ self._secret = idlib.a2b(secret_s)
+
def init_storage(self):
storedir = os.path.join(self.basedir, self.STOREDIR)
sizelimit = None
return False
def get_renewal_secret(self):
- return ""
+ return hashutil.my_renewal_secret_hash(self._secret)
+
def get_cancel_secret(self):
- return ""
+ return hashutil.my_cancel_secret_hash(self._secret)
-import os
+import os, stat
from twisted.trial import unittest
from twisted.application import service
from twisted.internet import reactor, defer
import allmydata
from allmydata import client, introducer
-from allmydata.util import version_class
+from allmydata.util import version_class, idlib
from foolscap.eventual import flushEventualQueue
class MyIntroducerClient(introducer.IntroducerClient):
open(os.path.join(basedir, "introducer.furl"), "w").write("")
c = client.Client(basedir)
+ def test_secrets(self):
+ basedir = "test_client.Basic.test_secrets"
+ os.mkdir(basedir)
+ open(os.path.join(basedir, "introducer.furl"), "w").write("")
+ open(os.path.join(basedir, "vdrive.furl"), "w").write("")
+ c = client.Client(basedir)
+ secret_file = os.path.join(basedir, "secret")
+ self.failUnless(os.path.exists(secret_file))
+ self.failUnlessEqual(os.stat(secret_file)[stat.ST_MODE] & 0777, 0600)
+ renew_secret = c.get_renewal_secret()
+ self.failUnless(idlib.b2a(renew_secret))
+ cancel_secret = c.get_cancel_secret()
+ self.failUnless(idlib.b2a(cancel_secret))
+
def test_sizelimit_1(self):
basedir = "client.Basic.test_sizelimit_1"
os.mkdir(basedir)