diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2016-10-03 17:40:09 -0400 |
---|---|---|
committer | Kali Kaneko (leap communications) <kali@leap.se> | 2016-10-04 11:48:30 -0400 |
commit | af27100e35f30f91f3c8f3eb4b8fcef978d11eae (patch) | |
tree | 92e1bdb9ebdb8e00aa84dbfefbda1b75e6cb883c /src/leap/bitmask/bonafide/_srp.py | |
parent | ff3ed1e9418eab21fd42bb5ddd96a3851a25801c (diff) |
[feature] handle invite codes
In the command line, --invitecode is a new optional parameter to
the command "user create".
bonafide service handles the invite codes.
javascript library should be updated accordingly
- Resolves: #7550
Diffstat (limited to 'src/leap/bitmask/bonafide/_srp.py')
-rw-r--r-- | src/leap/bitmask/bonafide/_srp.py | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/leap/bitmask/bonafide/_srp.py b/src/leap/bitmask/bonafide/_srp.py index 34a75a56..3f69b33b 100644 --- a/src/leap/bitmask/bonafide/_srp.py +++ b/src/leap/bitmask/bonafide/_srp.py @@ -19,12 +19,17 @@ SRP Authentication. """ +from twisted.logger import Logger + import binascii import json import srp +log = Logger() + + class SRPAuthMechanism(object): """ @@ -100,19 +105,34 @@ class SRPSignupMechanism(object): Implement a protocol-agnostic SRP Registration mechanism. """ - def get_signup_params(self, username, password): + def get_signup_params(self, username, password, invite=None): salt, verifier = _get_salt_verifier(username, password) user_data = { 'user[login]': username, 'user[password_salt]': binascii.hexlify(salt), 'user[password_verifier]': binascii.hexlify(verifier)} + if invite is not None: + user_data.update({'user[invite_code]': invite}) 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] + errmsg = json.dumps(errors) + log.error('Oops! Errors during signup: {data!r}', data=errmsg) + msg = errors.get('invite_code') + if msg: + msg = msg[0] + else: + msg = errors.get('login') + if msg: + # there is a bug https://leap.se/code/issues/8504 + # the server tells us 'has already been taken' several + # times + msg = 'username ' + msg[0] + else: + msg = 'unknown signup error' raise SRPRegistrationError(msg) else: username = signup.get('login') |