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 /sugar_network/toolkit/http.py | |
parent | b411849fa3e8919a51c43843536614bef6f34b52 (diff) |
Fix anonymous service call
Diffstat (limited to 'sugar_network/toolkit/http.py')
-rw-r--r-- | sugar_network/toolkit/http.py | 16 |
1 files changed, 11 insertions, 5 deletions
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') |