]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
deletion phase2b: create renew/cancel secrets for real.
authorBrian Warner <warner@lothar.com>
Tue, 28 Aug 2007 02:30:26 +0000 (19:30 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 28 Aug 2007 02:30:26 +0000 (19:30 -0700)
src/allmydata/client.py
src/allmydata/test/test_client.py

index 7ff46b68c2afa2caf49ecd412c7ff31022e0de15..746357aebb026a27e03bd64c47fa701e5a3c826c 100644 (file)
@@ -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)
index f5cec18447c9c04ea2c136ff17890ec44ec5eac8..fe17c9e454789e69ef8f1981e69661b094196036 100644 (file)
@@ -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)