Mercurial > libervia-backend
comparison src/memory/params.py @ 1090:594fbdda4a87
memory: add helper methods encryptValue and decryptValue
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 25 Jun 2014 19:01:00 +0200 |
parents | b29452cab50b |
children | f91e7028e2c3 |
comparison
equal
deleted
inserted
replaced
1089:8e0072754413 | 1090:594fbdda4a87 |
---|---|
383 param_name = node.getAttribute('name') | 383 param_name = node.getAttribute('name') |
384 if ((param_cat, param_name) == C.PROFILE_PASS_PATH) or not value: | 384 if ((param_cat, param_name) == C.PROFILE_PASS_PATH) or not value: |
385 return defer.succeed(value) # profile password and empty passwords are returned "as is" | 385 return defer.succeed(value) # profile password and empty passwords are returned "as is" |
386 if not profile: | 386 if not profile: |
387 raise exceptions.ProfileUnknownError('The profile is needed to decrypt a password') | 387 raise exceptions.ProfileUnknownError('The profile is needed to decrypt a password') |
388 try: | 388 d = self.host.memory.decryptValue(value, profile) |
389 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] | |
390 except TypeError: | |
391 raise exceptions.InternalError(_('Trying to decrypt a password while the personal key is undefined!')) | |
392 d = BlockCipher.decrypt(personal_key, value) | |
393 | 389 |
394 def gotPlainPassword(password): | 390 def gotPlainPassword(password): |
395 if password is None: # empty value means empty password, None means decryption failure | 391 if password is None: # empty value means empty password, None means decryption failure |
396 raise exceptions.InternalError(_('The stored password could not be decrypted!')) | 392 raise exceptions.InternalError(_('The stored password could not be decrypted!')) |
397 return password | 393 return password |