memory (sqlite): fixes upgrade to database v2
This commit is contained in:
parent
76413b3679
commit
4e2366a3d5
1 changed files with 23 additions and 22 deletions
|
|
@ -764,35 +764,36 @@ class Updater(object):
|
|||
def encrypt_values(values):
|
||||
ret = []
|
||||
list_ = []
|
||||
|
||||
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))
|
||||
|
||||
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))
|
||||
|
||||
return defer.DeferredList([d1, d2, d3]).addCallback(gotValues)
|
||||
|
||||
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 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("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)
|
||||
|
||||
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_)
|
||||
|
|
|
|||
Loading…
Reference in a new issue