From: Brian Warner Date: Tue, 28 Aug 2007 02:30:26 +0000 (-0700) Subject: deletion phase2b: create renew/cancel secrets for real. X-Git-Url: https://git.rkrishnan.org/pf/content/install.html?a=commitdiff_plain;h=850bc9da027654d2cb861c053bf7189998cf83cd;p=tahoe-lafs%2Ftahoe-lafs.git deletion phase2b: create renew/cancel secrets for real. --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 7ff46b68..746357ae 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -18,6 +18,7 @@ from allmydata.webish import WebishServer 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) @@ -34,6 +35,7 @@ class Client(node.Node, Referenceable): self.logSource="Client" self.my_furl = None self.introducer_client = None + self.init_secret() self.init_storage() self.init_options() self.add_service(Uploader()) @@ -52,6 +54,13 @@ class Client(node.Node, Referenceable): 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 @@ -172,6 +181,7 @@ class Client(node.Node, Referenceable): 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) diff --git a/src/allmydata/test/test_client.py b/src/allmydata/test/test_client.py index f5cec184..fe17c9e4 100644 --- a/src/allmydata/test/test_client.py +++ b/src/allmydata/test/test_client.py @@ -1,12 +1,12 @@ -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): @@ -30,6 +30,20 @@ class Basic(unittest.TestCase): 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)