changeset 1065:9378c80e3408

memory (sqlite): fixes upgrade to database v2
author souliane <souliane@mailoo.org>
date Thu, 12 Jun 2014 15:56:41 +0200
parents 7ee9d9db67b9
children cbf917a90784
files src/memory/sqlite.py
diffstat 1 files changed, 23 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/memory/sqlite.py	Mon Jun 09 20:40:13 2014 +0200
+++ b/src/memory/sqlite.py	Thu Jun 12 15:56:41 2014 +0200
@@ -764,35 +764,36 @@
         def encrypt_values(values):
             ret = []
             list_ = []
-            for profile_id, xmpp_password in values:
-                def prepare_queries(result):
-                    try:
-                        id_ = result[0][0]
-                    except IndexError:
-                        log.error("Profile of id %d is referenced in 'param_ind' but it doesn't exist!" % profile_id)
-                        return
 
-                    sat_password = xmpp_password
-                    d1 = PasswordHasher.hash(sat_password)
-                    personal_key = BlockCipher.getRandomKey(base64=True)
-                    d2 = BlockCipher.encrypt(sat_password, personal_key)
-                    d3 = BlockCipher.encrypt(personal_key, xmpp_password)
+            def prepare_queries(result, xmpp_password):
+                try:
+                    id_ = result[0][0]
+                except IndexError:
+                    log.error("Profile of id %d is referenced in 'param_ind' but it doesn't exist!" % profile_id)
+                    return
+
+                sat_password = xmpp_password
+                d1 = PasswordHasher.hash(sat_password)
+                personal_key = BlockCipher.getRandomKey(base64=True)
+                d2 = BlockCipher.encrypt(sat_password, personal_key)
+                d3 = BlockCipher.encrypt(personal_key, xmpp_password)
 
-                    def gotValues(res):
-                        sat_cipher, personal_cipher, xmpp_cipher = res[0][1], res[1][1], res[2][1]
-                        ret.append("INSERT INTO param_ind(category,name,profile_id,value) VALUES ('%s','%s',%s,'%s')" %
-                                   (C.PROFILE_PASS_PATH[0], C.PROFILE_PASS_PATH[1], id_, sat_cipher))
+                def gotValues(res):
+                    sat_cipher, personal_cipher, xmpp_cipher = res[0][1], res[1][1], res[2][1]
+                    ret.append("INSERT INTO param_ind(category,name,profile_id,value) VALUES ('%s','%s',%s,'%s')" %
+                               (C.PROFILE_PASS_PATH[0], C.PROFILE_PASS_PATH[1], id_, sat_cipher))
 
-                        ret.append("INSERT INTO private_ind(namespace,key,profile_id,value) VALUES ('%s','%s',%s,'%s')" %
-                                   (C.MEMORY_CRYPTO_NAMESPACE, C.MEMORY_CRYPTO_KEY, id_, personal_cipher))
+                    ret.append("INSERT INTO private_ind(namespace,key,profile_id,value) VALUES ('%s','%s',%s,'%s')" %
+                               (C.MEMORY_CRYPTO_NAMESPACE, C.MEMORY_CRYPTO_KEY, id_, personal_cipher))
 
-                        ret.append("REPLACE INTO param_ind(category,name,profile_id,value) VALUES ('%s','%s',%s,'%s')" %
-                                   (xmpp_pass_path[0], xmpp_pass_path[1], id_, xmpp_cipher))
+                    ret.append("REPLACE INTO param_ind(category,name,profile_id,value) VALUES ('%s','%s',%s,'%s')" %
+                               (xmpp_pass_path[0], xmpp_pass_path[1], id_, xmpp_cipher))
 
-                    return defer.DeferredList([d1, d2, d3]).addCallback(gotValues)
+                return defer.DeferredList([d1, d2, d3]).addCallback(gotValues)
 
+            for profile_id, xmpp_password in values:
                 d = self.dbpool.runQuery("SELECT id FROM profiles WHERE id=?", (profile_id,))
-                d.addCallback(prepare_queries)
+                d.addCallback(prepare_queries, xmpp_password)
                 list_.append(d)
 
             d_list = defer.DeferredList(list_)