From 093ec64e26eb605dc0fa376389e914a87ec3a094 Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Thu, 04 Oct 2012 20:19:05 +0000 Subject: Fix anonymous service call --- diff --git a/sugar-network b/sugar-network index ad70db2..078d2ab 100755 --- a/sugar-network +++ b/sugar-network @@ -120,9 +120,11 @@ class Application(application.Application): result = IPCClient().call(request, response) finally: - if pid_path: + if server is not None: server.close() + if mountset is not None: mountset.close() + if pid_path: os.unlink(pid_path) if result: diff --git a/sugar_network/toolkit/http.py b/sugar_network/toolkit/http.py index 2241183..f820d08 100644 --- a/sugar_network/toolkit/http.py +++ b/sugar_network/toolkit/http.py @@ -66,9 +66,15 @@ class Client(object): headers = {'Accept-Language': ad.default_lang()} if self._sugar_auth: - uid = sugar.uid() - headers['sugar_user'] = uid - headers['sugar_user_signature'] = _sign(uid) + privkey_path = sugar.privkey_path() + if not exists(privkey_path): + _logger.warning('Sugar session was never started, ' + 'fallback to anonymous mode') + self._sugar_auth = False + else: + uid = sugar.uid() + headers['sugar_user'] = uid + headers['sugar_user_signature'] = _sign(privkey_path, uid) self._session = Session(headers=headers, verify=verify, prefetch=False) @@ -292,8 +298,8 @@ class Client(object): return json.loads(response.content) -def _sign(data): - key = DSA.load_key(sugar.privkey_path()) +def _sign(privkey_path, data): + key = DSA.load_key(privkey_path) return key.sign_asn1(hashlib.sha1(data).digest()).encode('hex') diff --git a/sugar_network/toolkit/sugar.py b/sugar_network/toolkit/sugar.py index 4f0bac5..b036492 100644 --- a/sugar_network/toolkit/sugar.py +++ b/sugar_network/toolkit/sugar.py @@ -78,13 +78,13 @@ def privkey_path(): path = keyfile.value if not path: path = profile_path('owner.key') - enforce(exists(path), - 'Sugar session was never started, no privkey') return path def pubkey(): pubkey_path = privkey_path() + '.pub' + enforce(exists(pubkey_path), + 'Sugar session was never started, no privkey') with file(pubkey_path) as f: for line in f.readlines(): line = line.strip() -- cgit v0.9.1