Mercurial > libervia-backend
changeset 1247:c6cf44e6330b
memory: temporary dirty hack to fix the personnal key issue after the auth session expired
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 19 Oct 2014 15:07:16 +0200 |
parents | 8b891f9be183 |
children | 77a4592816f6 |
files | src/memory/memory.py |
diffstat | 1 files changed, 15 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/memory/memory.py Sat Oct 18 16:28:37 2014 +0200 +++ b/src/memory/memory.py Sun Oct 19 15:07:16 2014 +0200 @@ -152,7 +152,6 @@ raise exceptions.InternalError('profileGetUnique has been used but more than one session has been found!') return self.profileGet(ids[0], profile) if len(ids) == 1 else None # XXX: timeout might be reset - def profileDelUnique(self, profile): """Delete the unique session that is associated to the given profile. @@ -166,6 +165,18 @@ del self._sessions[ids[0]] +class PasswordSessions(ProfileSessions): + + # FIXME: temporary hack for the user personal key not to be lost. The session + # must actually be purged and later, when the personal key is needed, the + # profile password should be asked again in order to decrypt it. + def __init__(self, timeout=None): + ProfileSessions.__init__(self, timeout, resettable_timeout=False) + + def _purgeSession(self, session_id): + log.debug("FIXME: PasswordSessions should ask for the profile password after the session expired") + + # XXX: tmp update code, will be removed in the future # When you remove this, please add the default value for # 'local_dir' in sat.core.constants.Const.DEFAULT_CONFIG @@ -202,7 +213,7 @@ self._entities_cache = {} # XXX: keep presence/last resource/other data in cache # /!\ an entity is not necessarily in roster self.subscriptions = {} - self.auth_sessions = ProfileSessions() # remember the authenticated profiles + self.auth_sessions = PasswordSessions() # remember the authenticated profiles self.disco = Discovery(host) fixLocalDir(False) # XXX: tmp update code, will be removed in the future self.config = self.parseMainConf() @@ -564,7 +575,7 @@ @return: the deferred encrypted value """ try: - personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] + personal_key = self.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] except TypeError: raise exceptions.InternalError(_('Trying to encrypt a value for %s while the personal key is undefined!') % profile) return BlockCipher.encrypt(personal_key, value) @@ -579,7 +590,7 @@ @return: the deferred decrypted value """ try: - personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] + personal_key = self.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] except TypeError: raise exceptions.InternalError(_('Trying to decrypt a value for %s while the personal key is undefined!') % profile) return BlockCipher.decrypt(personal_key, value)