summaryrefslogtreecommitdiff
path: root/bonafide/src
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-10-27 09:49:34 -0400
committerKali Kaneko <kali@leap.se>2015-10-27 09:49:34 -0400
commit4ed4a4019c306879653549b3062fee61edee77b4 (patch)
treec5945bc7e3fc95a6e439668825304c5c02eca744 /bonafide/src
parentca925d5033383b64e719775fc34a6c36e9672122 (diff)
handle unicode errors
Diffstat (limited to 'bonafide/src')
-rw-r--r--bonafide/src/leap/bonafide/_http.py1
-rw-r--r--bonafide/src/leap/bonafide/_srp.py6
-rwxr-xr-xbonafide/src/leap/bonafide/bonafide_cli2
-rw-r--r--bonafide/src/leap/bonafide/provider.py2
-rw-r--r--bonafide/src/leap/bonafide/session.py16
5 files changed, 23 insertions, 4 deletions
diff --git a/bonafide/src/leap/bonafide/_http.py b/bonafide/src/leap/bonafide/_http.py
index 39aababd..b92cf57b 100644
--- a/bonafide/src/leap/bonafide/_http.py
+++ b/bonafide/src/leap/bonafide/_http.py
@@ -50,6 +50,7 @@ def httpRequest(agent, url, values={}, headers={}, method='POST', token=None):
headers['Authorization'] = ['Token token="%s"' % (bytes(token))]
def handle_response(response):
+ print "RESPONSE CODE", response.code
if response.code == 204:
d = defer.succeed('')
else:
diff --git a/bonafide/src/leap/bonafide/_srp.py b/bonafide/src/leap/bonafide/_srp.py
index dc856abf..4f4a6058 100644
--- a/bonafide/src/leap/bonafide/_srp.py
+++ b/bonafide/src/leap/bonafide/_srp.py
@@ -32,8 +32,7 @@ class SRPAuthMechanism(object):
"""
def initialize(self, username, password):
- srp_user = srp.User(username.encode('utf-8'),
- password.encode('utf-8'),
+ srp_user = srp.User(username, password,
srp.SHA256, srp.NG_1024)
_, A = srp_user.start_authentication()
return srp_user, A
@@ -71,7 +70,7 @@ class SRPAuthMechanism(object):
def _check_for_errors(self, response):
if 'errors' in response:
msg = response['errors']['base']
- raise SRPAuthError(msg)
+ raise SRPAuthError(unicode(msg).encode('utf-8'))
def _unhex_salt_B(self, salt, B):
if salt is None:
@@ -142,4 +141,3 @@ class SRPAuthBadDataFromServer(SRPAuthError):
class SRPRegistrationError(Exception):
pass
-
diff --git a/bonafide/src/leap/bonafide/bonafide_cli b/bonafide/src/leap/bonafide/bonafide_cli
index 64aa6ad5..15a7a009 100755
--- a/bonafide/src/leap/bonafide/bonafide_cli
+++ b/bonafide/src/leap/bonafide/bonafide_cli
@@ -53,6 +53,8 @@ def _display_token(result, _session):
if result == session.OK:
print('[ok] token--> ' + Fore.GREEN +
_session.token + Fore.RESET)
+ print('[ok] uuid --> ' + Fore.GREEN +
+ _session.uuid + Fore.RESET)
def _display_registered(result, _session, _provider):
ok, user = result
diff --git a/bonafide/src/leap/bonafide/provider.py b/bonafide/src/leap/bonafide/provider.py
index 470b413c..c22be3c7 100644
--- a/bonafide/src/leap/bonafide/provider.py
+++ b/bonafide/src/leap/bonafide/provider.py
@@ -79,6 +79,8 @@ class Api(object):
An object that has all the information that a client needs to communicate
with the remote methods exposed by the web API of a LEAP provider.
+ The actions are described in https://leap.se/bonafide
+
By using the _MetaActionDispatcher as a metaclass, the _actions dict will be
translated dynamically into a set of instance methods that will allow
getting the uri and method for each action.
diff --git a/bonafide/src/leap/bonafide/session.py b/bonafide/src/leap/bonafide/session.py
index 6b60b6af..4fa32999 100644
--- a/bonafide/src/leap/bonafide/session.py
+++ b/bonafide/src/leap/bonafide/session.py
@@ -61,6 +61,10 @@ class Session(object):
return self._token
@property
+ def uuid(self):
+ return self._uuid
+
+ @property
def is_authenticated(self):
if not self._srp_user:
return False
@@ -98,10 +102,16 @@ class Session(object):
defer.returnValue(OK)
@auth_required
+ @defer.inlineCallbacks
def logout(self):
+ uri = self._api.get_logout_uri()
+ met = self._api.get_logout_method()
+ auth = yield self._request(self._agent, uri, method=met)
+ print "AUTH RESULT->", auth
self.username = None
self.password = None
self._initialize_session()
+ defer.returnValue(OK)
# User certificates
@@ -177,6 +187,12 @@ if __name__ == "__main__":
d = session.authenticate()
d.addCallback(print_result)
d.addErrback(auth_eb)
+
+ d.addCallback(lambda _: session.get_smtp_cert())
+ #d.addCallback(lambda _: session.get_vpn_cert())
+ d.addCallback(print_result)
+ d.addErrback(auth_eb)
+
d.addCallback(lambda _: session.logout())
d.addErrback(auth_eb)
d.addBoth(cbShutDown)