diff options
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/bitmask_libraries/keymanager.py | 15 |
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 |