diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2012-10-04 20:19:05 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2012-10-04 20:19:05 (GMT) |
commit | 093ec64e26eb605dc0fa376389e914a87ec3a094 (patch) | |
tree | 1e2f555fe73712b184f924dc510fbba43907d3c3 | |
parent | b411849fa3e8919a51c43843536614bef6f34b52 (diff) |
Fix anonymous service call
-rwxr-xr-x | sugar-network | 4 | ||||
-rw-r--r-- | sugar_network/toolkit/http.py | 16 | ||||
-rw-r--r-- | sugar_network/toolkit/sugar.py | 4 |
3 files changed, 16 insertions, 8 deletions
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() |