summaryrefslogtreecommitdiff
path: root/bonafide
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-09-09 01:08:36 -0400
committerKali Kaneko <kali@leap.se>2015-09-09 01:08:36 -0400
commit5deec1120fef68b9cd41b29eb6af974fe72aa9d5 (patch)
treec9136c4f06c69c61d1eda1e69d944467f88d3756 /bonafide
parent7576725b8992b621614e725c7a5a1c3b6991303a (diff)
move srp_auth to _srp
Diffstat (limited to 'bonafide')
-rw-r--r--bonafide/src/leap/bonafide/_srp.py (renamed from bonafide/src/leap/bonafide/srp_auth.py)32
1 files changed, 31 insertions, 1 deletions
diff --git a/bonafide/src/leap/bonafide/srp_auth.py b/bonafide/src/leap/bonafide/_srp.py
index d48214f4..dc856abf 100644
--- a/bonafide/src/leap/bonafide/srp_auth.py
+++ b/bonafide/src/leap/bonafide/_srp.py
@@ -25,7 +25,6 @@ import json
import srp
-
class SRPAuthMechanism(object):
"""
@@ -92,6 +91,33 @@ class SRPAuthMechanism(object):
raise SRPAuthBadDataFromServer(msg)
+class SRPSignupMechanism(object):
+
+ """
+ Implement a protocol-agnostic SRP Registration mechanism.
+ """
+
+ def get_signup_params(self, username, password):
+ salt, verifier = srp.create_salted_verification_key(
+ bytes(username), bytes(password),
+ srp.SHA256, srp.NG_1024)
+ user_data = {
+ 'user[login]': username,
+ 'user[password_salt]': binascii.hexlify(salt),
+ 'user[password_verifier]': binascii.hexlify(verifier)}
+ return user_data
+
+ def process_signup(self, signup_response):
+ signup = json.loads(signup_response)
+ errors = signup.get('errors')
+ if errors:
+ msg = 'username ' + errors.get('login')[0]
+ raise SRPRegistrationError(msg)
+ else:
+ username = signup.get('login')
+ return username
+
+
def _safe_unhexlify(val):
return binascii.unhexlify(val) \
if (len(val) % 2 == 0) else binascii.unhexlify('0' + val)
@@ -113,3 +139,7 @@ class SRPAuthNoB(SRPAuthError):
class SRPAuthBadDataFromServer(SRPAuthError):
pass
+
+class SRPRegistrationError(Exception):
+ pass
+