From 7e7e54c5ef5a53e66e4bd0578b24bb1fc62db797 Mon Sep 17 00:00:00 2001 From: "Kali Kaneko (leap communications)" Date: Wed, 30 Nov 2016 10:20:08 +0100 Subject: [bug] make srp token changes propagate to nicknym object the token is set when we get the srp token in the keymanager service, but it wasn't been propagated properly to the internal nicknym object that was refactored recently. here I make the setter write the same token to both keymanager itself and the nicknym. some little additional refactors: - move gpg initialization to a helper method in this way it becomes easier to stub the soledad and keymanager components, for testing. - name nicknym token as publicly visible, since i'm accessing it from the keymanager object. - Resolves: #8651 --- src/leap/bitmask/keymanager/__init__.py | 6 +++++- src/leap/bitmask/keymanager/nicknym.py | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/leap/bitmask/keymanager/__init__.py b/src/leap/bitmask/keymanager/__init__.py index ed3726a..f0f8267 100644 --- a/src/leap/bitmask/keymanager/__init__.py +++ b/src/leap/bitmask/keymanager/__init__.py @@ -90,7 +90,6 @@ class KeyManager(object): self.api_uri = api_uri self.api_version = api_version self.uid = uid - self._openpgp = OpenPGPScheme(soledad, gpgbinary=gpgbinary) create = self._create_combined_bundle_file try: self._combined_ca_bundle = combined_ca_bundle or create() @@ -102,11 +101,15 @@ class KeyManager(object): self._nicknym = Nicknym(self._nickserver_uri, self._ca_cert_path, self._token) self.refresher = None + self._init_gpg(soledad, gpgbinary) # # utilities # + def _init_gpg(self, soledad, gpgbinary): + self._openpgp = OpenPGPScheme(soledad, gpgbinary=gpgbinary) + def start_refresher(self): self.refresher = RandomRefreshPublicKey(self._openpgp, self) self.refresher.start() @@ -376,6 +379,7 @@ class KeyManager(object): def _set_token(self, token): self._token = token + self._nicknym.token = token token = property( _get_token, _set_token, doc='The session token.') diff --git a/src/leap/bitmask/keymanager/nicknym.py b/src/leap/bitmask/keymanager/nicknym.py index 5fe9992..7c738da 100644 --- a/src/leap/bitmask/keymanager/nicknym.py +++ b/src/leap/bitmask/keymanager/nicknym.py @@ -43,7 +43,7 @@ class Nicknym(object): def __init__(self, nickserver_uri, ca_cert_path, token): self._nickserver_uri = nickserver_uri self._async_client_pinned = HTTPClient(ca_cert_path) - self._token = token + self.token = token @defer.inlineCallbacks def put_key(self, uid, key_data, api_uri, api_version): @@ -72,11 +72,11 @@ class Nicknym(object): uid) leap_assert( - self._token is not None, + self.token is not None, 'We need a token to interact with webapp!') if type(data) == dict: data = urllib.urlencode(data) - headers = {'Authorization': [str('Token token=%s' % self._token)]} + headers = {'Authorization': [str('Token token=%s' % self.token)]} headers['Content-Type'] = ['application/x-www-form-urlencoded'] try: res = yield self._async_client_pinned.request(str(uri), 'PUT', -- cgit v1.2.3