summaryrefslogtreecommitdiff
path: root/service/pixelated
diff options
context:
space:
mode:
authorTulio Casagrande <tcasagra@thoughtworks.com>2017-01-10 14:52:21 -0200
committerTulio Casagrande <tcasagra@thoughtworks.com>2017-01-10 14:52:21 -0200
commiteb971354658c7075362bb5b07dc90c8d74e00e8e (patch)
tree0e291b64c211e998ff6f165c9313e07cd4b1cb1b /service/pixelated
parent71a5f5150b5e9d7cb402e4424930545896a13727 (diff)
Check if key is synchronized with server at every login
This is a temporary solution when uploading a regenerated key fails. It's going to attempt the upload again on the subsequent logins. The drawback with this solution, is that the fetch remote can increase the login time, specially with multiple users. See: #815
Diffstat (limited to 'service/pixelated')
-rw-r--r--service/pixelated/bitmask_libraries/keymanager.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/service/pixelated/bitmask_libraries/keymanager.py b/service/pixelated/bitmask_libraries/keymanager.py
index 28d5f9db..4171c655 100644
--- a/service/pixelated/bitmask_libraries/keymanager.py
+++ b/service/pixelated/bitmask_libraries/keymanager.py
@@ -52,9 +52,23 @@ class Keymanager(object):
elif current_key.needs_renewal(DEFAULT_EXTENSION_THRESHOLD):
current_key = yield self._regenerate_key_and_send_to_leap()
+ self._synchronize_remote_key(current_key)
logger.info("Current key for {}: {}".format(self._email, current_key.fingerprint))
@defer.inlineCallbacks
+ def _synchronize_remote_key(self, current_key):
+ if not self._is_key_synchronized_with_server(current_key):
+ try:
+ yield self.keymanager.send_key()
+ except Exception as e:
+ raise UploadKeyError(e.message)
+
+ @defer.inlineCallbacks
+ def _is_key_synchronized_with_server(self, current_key):
+ remote_key = yield self.get_key(self._email, private=False, fetch_remote=True)
+ defer.returnValue(remote_key.fingerprint == current_key.fingerprint)
+
+ @defer.inlineCallbacks
def _regenerate_key_and_send_to_leap(self):
logger.info("Regenerating keys - this could take a while...")
key = yield self.keymanager.regenerate_key()
@@ -62,7 +76,6 @@ class Keymanager(object):
yield self.keymanager.send_key()
defer.returnValue(key)
except Exception as e:
- # what to be done when upload key error
raise UploadKeyError(e.message)
@defer.inlineCallbacks