diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2014-08-06 11:41:11 +0200 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2014-08-06 11:41:11 +0200 |
commit | 1e1fd328bc43e820e178de7c08f626b1488505e1 (patch) | |
tree | d6525d978d88422b3ab53425c4e98b30fe732b3e /service/app | |
parent | 26cbb616eb3ada3a0fb82e3156737b43cd2bc1ac (diff) |
Added register to leap_srp.
- Not yet called from anywhere
Diffstat (limited to 'service/app')
-rw-r--r-- | service/app/bitmask_libraries/leap_srp.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/service/app/bitmask_libraries/leap_srp.py b/service/app/bitmask_libraries/leap_srp.py index a1de7de3..d534e732 100644 --- a/service/app/bitmask_libraries/leap_srp.py +++ b/service/app/bitmask_libraries/leap_srp.py @@ -1,11 +1,16 @@ import binascii import json +import requests from requests import Session -from srp import User, srp +from srp import User, srp, create_salted_verification_key from requests.exceptions import HTTPError, SSLError, Timeout from config import SYSTEM_CA_BUNDLE +REGISTER_USER_LOGIN_KEY = 'user[login]' +REGISTER_USER_VERIFIER_KEY = 'user[password_verifier]' +REGISTER_USER_SALT_KEY = 'user[password_salt]' + class LeapAuthException(Exception): def __init__(self, *args, **kwargs): @@ -98,6 +103,28 @@ class LeapSecureRemotePassword(object): if not user.authenticated(): raise LeapAuthException() + def register(self, api_uri, username, password): + try: + salt, verifier = create_salted_verification_key(username, password, self.hash_alg, self.ng_type) + return self._post_registration_data(api_uri, username, salt, verifier) + except (HTTPError, SSLError, Timeout), e: + raise LeapAuthException(e) + + def _post_registration_data(self, api_uri, username, salt, verifier): + users_url = '%s/%s/users' % (api_uri, self.leap_api_version) + + user_data = { + REGISTER_USER_LOGIN_KEY: username, + REGISTER_USER_SALT_KEY: binascii.hexlify(salt), + REGISTER_USER_VERIFIER_KEY: binascii.hexlify(verifier) + } + + response = requests.post(users_url, data=user_data, verify=self.ca_bundle, timeout=self.timeout_in_s) + response.raise_for_status() + reg_json = json.loads(response.content) + + return reg_json['ok'] + def _safe_unhexlify(hex_str): return binascii.unhexlify(hex_str) \ |