changeset 1686:1ed269c5f295

profile (params): fixed password setting: if profile was not connected, set was silently ignored
author Goffi <goffi@goffi.org>
date Thu, 26 Nov 2015 15:47:01 +0100 (2015-11-26)
parents 43a127b6a4f2
children de9cc4d62a4a
files src/memory/params.py
diffstat 1 files changed, 16 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/memory/params.py	Wed Nov 25 23:19:36 2015 +0100
+++ b/src/memory/params.py	Thu Nov 26 15:47:01 2015 +0100
@@ -827,6 +827,7 @@
                         raise exceptions.InternalError("Invalid integer parameter constraint: %s" % constraint)
                     value = str(min(max(int(value), min_), max_))
 
+
         log.info(_("Setting parameter (%(category)s, %(name)s) = %(value)s") %
                  {'category': category, 'name': name, 'value': value if type_ != 'password' else '********'})
 
@@ -842,36 +843,37 @@
         assert node[0] == C.INDIVIDUAL
         assert profile_key != C.PROF_KEY_NONE
 
-        d_list = []
         if type_ == "button":
             log.debug(u"Clicked param button %s" % node.toxml())
             return defer.succeed(None)
-        d = defer.succeed(value)
-        if type_ == "password":
+        elif type_ == "password":
             try:
                 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY]
             except TypeError:
                 raise exceptions.InternalError(_('Trying to encrypt a password while the personal key is undefined!'))
             if (category, name) == C.PROFILE_PASS_PATH:
                 # using 'value' as the encryption key to encrypt another encryption key... could be confusing!
-                d_list.append(self.host.memory.encryptPersonalData(data_key=C.MEMORY_CRYPTO_KEY,
-                                                                    data_value=personal_key,
-                                                                    crypto_key=value,
-                                                                    profile=profile))
-                d = PasswordHasher.hash(value)  # profile password is hashed (empty value stays empty)
+                d = self.host.memory.encryptPersonalData(data_key=C.MEMORY_CRYPTO_KEY,
+                                                         data_value=personal_key,
+                                                         crypto_key=value,
+                                                         profile=profile)
+                d.addCallback(lambda dummy: PasswordHasher.hash(value))  # profile password is hashed (empty value stays empty)
             elif value:  # other non empty passwords are encrypted with the personal key
                 d = BlockCipher.encrypt(personal_key, value)
+        else:
+            d = defer.succeed(value)
 
         def gotFinalValue(value):
-            if self.host.isConnected(profile):  # key can not exists if profile is not connected
+            if self.host.memory.isSessionStarted(profile):
                 self.params[profile][(category, name)] = value
-            self.host.bridge.paramUpdate(name, value, category, profile)
-            self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile)
-            return self.storage.setIndParam(category, name, value, profile)
+                self.host.bridge.paramUpdate(name, value, category, profile)
+                self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile)
+                return self.storage.setIndParam(category, name, value, profile)
+            else:
+                raise exceptions.ProfileNotConnected
 
         d.addCallback(gotFinalValue)
-        d_list.append(d)
-        return defer.DeferredList(d_list).addCallback(lambda dummy: None)
+        return d
 
     def _getNodesOfTypes(self, attr_type, node_type="@ALL@"):
         """Return all the nodes matching the given types.