comparison src/memory/memory.py @ 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 22adf1eb59f5
children 51a85e8f599a
comparison
equal deleted inserted replaced
1246:8b891f9be183 1247:c6cf44e6330b
150 ids = self._profileGetAllIds(profile) 150 ids = self._profileGetAllIds(profile)
151 if len(ids) > 1: 151 if len(ids) > 1:
152 raise exceptions.InternalError('profileGetUnique has been used but more than one session has been found!') 152 raise exceptions.InternalError('profileGetUnique has been used but more than one session has been found!')
153 return self.profileGet(ids[0], profile) if len(ids) == 1 else None # XXX: timeout might be reset 153 return self.profileGet(ids[0], profile) if len(ids) == 1 else None # XXX: timeout might be reset
154 154
155
156 def profileDelUnique(self, profile): 155 def profileDelUnique(self, profile):
157 """Delete the unique session that is associated to the given profile. 156 """Delete the unique session that is associated to the given profile.
158 157
159 @param profile: %(doc_profile)s 158 @param profile: %(doc_profile)s
160 @return: None, but raise an error if more than one session are found 159 @return: None, but raise an error if more than one session are found
162 ids = self._profileGetAllIds(profile) 161 ids = self._profileGetAllIds(profile)
163 if len(ids) > 1: 162 if len(ids) > 1:
164 raise exceptions.InternalError('profileDelUnique has been used but more than one session has been found!') 163 raise exceptions.InternalError('profileDelUnique has been used but more than one session has been found!')
165 if len(ids) == 1: 164 if len(ids) == 1:
166 del self._sessions[ids[0]] 165 del self._sessions[ids[0]]
166
167
168 class PasswordSessions(ProfileSessions):
169
170 # FIXME: temporary hack for the user personal key not to be lost. The session
171 # must actually be purged and later, when the personal key is needed, the
172 # profile password should be asked again in order to decrypt it.
173 def __init__(self, timeout=None):
174 ProfileSessions.__init__(self, timeout, resettable_timeout=False)
175
176 def _purgeSession(self, session_id):
177 log.debug("FIXME: PasswordSessions should ask for the profile password after the session expired")
167 178
168 179
169 # XXX: tmp update code, will be removed in the future 180 # XXX: tmp update code, will be removed in the future
170 # When you remove this, please add the default value for 181 # When you remove this, please add the default value for
171 # 'local_dir' in sat.core.constants.Const.DEFAULT_CONFIG 182 # 'local_dir' in sat.core.constants.Const.DEFAULT_CONFIG
200 self.initialized = defer.Deferred() 211 self.initialized = defer.Deferred()
201 self.host = host 212 self.host = host
202 self._entities_cache = {} # XXX: keep presence/last resource/other data in cache 213 self._entities_cache = {} # XXX: keep presence/last resource/other data in cache
203 # /!\ an entity is not necessarily in roster 214 # /!\ an entity is not necessarily in roster
204 self.subscriptions = {} 215 self.subscriptions = {}
205 self.auth_sessions = ProfileSessions() # remember the authenticated profiles 216 self.auth_sessions = PasswordSessions() # remember the authenticated profiles
206 self.disco = Discovery(host) 217 self.disco = Discovery(host)
207 fixLocalDir(False) # XXX: tmp update code, will be removed in the future 218 fixLocalDir(False) # XXX: tmp update code, will be removed in the future
208 self.config = self.parseMainConf() 219 self.config = self.parseMainConf()
209 database_file = os.path.expanduser(os.path.join(self.getConfig('', 'local_dir'), C.SAVEFILE_DATABASE)) 220 database_file = os.path.expanduser(os.path.join(self.getConfig('', 'local_dir'), C.SAVEFILE_DATABASE))
210 self.storage = SqliteStorage(database_file, host.__version__) 221 self.storage = SqliteStorage(database_file, host.__version__)
562 @param value (str): the value to encrypt 573 @param value (str): the value to encrypt
563 @param profile (str): %(doc_profile)s 574 @param profile (str): %(doc_profile)s
564 @return: the deferred encrypted value 575 @return: the deferred encrypted value
565 """ 576 """
566 try: 577 try:
567 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] 578 personal_key = self.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY]
568 except TypeError: 579 except TypeError:
569 raise exceptions.InternalError(_('Trying to encrypt a value for %s while the personal key is undefined!') % profile) 580 raise exceptions.InternalError(_('Trying to encrypt a value for %s while the personal key is undefined!') % profile)
570 return BlockCipher.encrypt(personal_key, value) 581 return BlockCipher.encrypt(personal_key, value)
571 582
572 def decryptValue(self, value, profile): 583 def decryptValue(self, value, profile):
577 @param value (str): the value to decrypt 588 @param value (str): the value to decrypt
578 @param profile (str): %(doc_profile)s 589 @param profile (str): %(doc_profile)s
579 @return: the deferred decrypted value 590 @return: the deferred decrypted value
580 """ 591 """
581 try: 592 try:
582 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] 593 personal_key = self.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY]
583 except TypeError: 594 except TypeError:
584 raise exceptions.InternalError(_('Trying to decrypt a value for %s while the personal key is undefined!') % profile) 595 raise exceptions.InternalError(_('Trying to decrypt a value for %s while the personal key is undefined!') % profile)
585 return BlockCipher.decrypt(personal_key, value) 596 return BlockCipher.decrypt(personal_key, value)
586 597
587 def encryptPersonalData(self, data_key, data_value, crypto_key, profile): 598 def encryptPersonalData(self, data_key, data_value, crypto_key, profile):