diff options
author | NavaL <ayoyo@thoughtworks.com> | 2016-11-21 14:23:20 +0100 |
---|---|---|
committer | Thais Siqueira <thais.siqueira@gmail.com> | 2017-01-02 14:29:45 -0200 |
commit | 7f7cb59a38a3be3d486bafc810133b584d7fd7a7 (patch) | |
tree | d60c6c43e7acbea485fd36d9e1c81c8f00e6d7e2 /service/pixelated | |
parent | a86c55a4baf36c711d946331ea3637ce5a6049f7 (diff) |
[#815] regenerating new keys when the current one expires
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/bitmask_libraries/keymanager.py | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/service/pixelated/bitmask_libraries/keymanager.py b/service/pixelated/bitmask_libraries/keymanager.py index e9868662..4af7d982 100644 --- a/service/pixelated/bitmask_libraries/keymanager.py +++ b/service/pixelated/bitmask_libraries/keymanager.py @@ -40,23 +40,33 @@ class Keymanager(object): @defer.inlineCallbacks def generate_openpgp_key(self): - key_present = yield self._key_exists(self._email) - if not key_present: - logger.info("Generating keys - this could take a while...") - yield self._gen_key() - try: - yield self._send_key_to_leap() - except Exception as e: - yield self.delete_key_pair(self._email) - raise UploadKeyError(e.message) + current_key = yield self._key_exists(self._email) + if not current_key: + yield self._generate_key_and_send_to_leap() + elif current_key.has_expired(): + yield self._regenerate_key() + yield self._send_key_to_leap() + + def _regenerate_key(self): + yield self.keymanager.regenerate_key() + + @defer.inlineCallbacks + def _generate_key_and_send_to_leap(self): + logger.info("Generating keys - this could take a while...") + yield self._gen_key() + try: + yield self._send_key_to_leap() + except Exception as e: + yield self.delete_key_pair(self._email) + raise UploadKeyError(e.message) @defer.inlineCallbacks def _key_exists(self, email): try: - yield self.get_key(email, private=True, fetch_remote=False) - defer.returnValue(True) + current_key = yield self.get_key(email, private=True, fetch_remote=False) + defer.returnValue(current_key) except KeyNotFound: - defer.returnValue(False) + defer.returnValue(None) def get_key(self, email, private=False, fetch_remote=True): return self.keymanager.get_key(email, private=private, fetch_remote=fetch_remote) |