From fb7eef011cc672f1884bcfcd4c859a549d8f3e49 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Tue, 31 Oct 2017 11:02:00 +0100 Subject: [feat] extend the expiration of private keys if needed Check on every fetch of the private key if the expiration is less than two months before it expire. And extend the expiration if needed. - Resolves: #8217 --- src/leap/bitmask/keymanager/__init__.py | 9 +++++++++ src/leap/bitmask/keymanager/keys.py | 2 ++ 2 files changed, 11 insertions(+) (limited to 'src/leap/bitmask/keymanager') diff --git a/src/leap/bitmask/keymanager/__init__.py b/src/leap/bitmask/keymanager/__init__.py index c1095877..dc6b88d3 100644 --- a/src/leap/bitmask/keymanager/__init__.py +++ b/src/leap/bitmask/keymanager/__init__.py @@ -254,6 +254,13 @@ class KeyManager(object): self.log.debug('Getting key for %s' % (address,)) emit_async(catalog.KEYMANAGER_LOOKING_FOR_KEY, address) + @defer.inlineCallbacks + def maybe_extend_expiration(key): + if key.needs_renewal(): + key = yield self._openpgp.expire(key, expiration_time='1y') + yield self.send_key() + defer.returnValue(key) + def key_found(key): emit_async(catalog.KEYMANAGER_KEY_FOUND, address) return key @@ -288,6 +295,8 @@ class KeyManager(object): # return key if it exists in local database d = self._openpgp.get_key(address, private=private) + if private: + d.addCallback(maybe_extend_expiration) d.addCallbacks(ensure_valid, key_not_found) return d diff --git a/src/leap/bitmask/keymanager/keys.py b/src/leap/bitmask/keymanager/keys.py index 0f68c06b..efc6f925 100644 --- a/src/leap/bitmask/keymanager/keys.py +++ b/src/leap/bitmask/keymanager/keys.py @@ -338,6 +338,8 @@ class OpenPGPKey(object): :return: True if the current date is within the threshold :rtype: Boolean """ + if self.expiry_date is None: + return False days_till_expiry = (self.expiry_date - datetime.now()) return days_till_expiry.days < pre_expiration_threshold -- cgit v1.2.3